5.1 Continuity and Smoothness
A fundamental assumption in any differentiable simulators is that the underlying physics system is smooth so that gradients can be well-defined. Equation (
9) contains three possible sources of discontinuities and non-smoothness in the order of their occurrences: determining the contact set
\(\mathcal {I}_n\) , computing
\({\mathbf {J}}_n\) that represents the local contact frames, and choosing between three branches from
\(\mathcal {C}^j_n\) in Equation (
8). Below, we discuss the effects from each of them in detail.
Continuity of branches in contact conditions. First, we empirically demonstrate through an experiment below that switching between the three branches in Equation (
8) does not create discontinuity in Equation (
9). In particular, consider the
nth time step and assume that
\(\mathcal {C}_n^j\) is fixed and that
\({\mathbf {J}}_n\) is a continuous function of
\(({\mathbf {x}}_n, \mathbf {v}_n)\) , if we treat Equation (
9) as a function that takes as input
\(({\mathbf {x}}_n,\mathbf {v}_n)\) and returns
\(({\mathbf {x}}_{n+1},\mathbf {v}_{n+1})\) , we will validate that this function is continuous. In other words, perturbing
\(({\mathbf {x}}_n, \mathbf {v}_n)\) a little will not cause jumps in the resultant
\(({\mathbf {x}}_{n+1},\mathbf {v}_{n+1})\) even though the corresponding
\({\bf r}_{n+1}\) may need to switch between branches during the perturbation. The intuition is that the three branches in Equation (
8) together define a connect set
\(\mathcal {C}_n^j\) in which
\(({\bf r}_{n+1,j},\mathbf {u}_{n+1,j})\) from one branch can smoothly transition to another.
We empirically validate the continuity of branch switching with the following experiment. We simulate a piece of cloth on a rigid, static, and frictional sphere for 200 timesteps. The sphere has one frictional coefficient
\(\mu\) , and we repeat the experiments by varying
\(\mu\) from 0 to 0.35 (Figure
2). When
\(\mu\) is large, all nodes are fixed on the sphere due to their large static friction. When
\(\mu\) is close to 0, the cloth slides on the sphere under gravity and takes off from the sphere near the end of the simulation. As
\(\mu\) changes from 0.35 to 0, each node on the cloth undergoes the transition from sticking to slipping, and eventually takes off. However, since each node has a different contact normal, the turning point for each of them to switch between these branches is different. Overall, when we gradually change
\(\mu\) , the ratio among the numbers of nodes with static friction, dynamic friction, and no friction at the end of the simulation also changes gradually, allowing us to observe how switching between these branches affects the continuity of the physical quantities in simulation.
We summarize the quantitative results from this simulation experiment in Figure
2 (green curves). Specifically, we plot the velocity of three nodes
A,
B, and
C as a function of
\(\mu\) at an intermediate time step (50) and near the end of simulation (200). We select three nodes from the corners, edge centers, and the center of the cloth, respectively. All velocities converge to 0 when
\(\mu\) becomes large, which is as expected, because a large
\(\mu\) leads to static friction that freezes these nodes. We also notice a turning point in the velocity curve for each node, indicating a switch between static and dynamic friction. The turning points are located at slightly different
\(\mu\) values for each node, because their normals on the sphere surface are different. We observe from the figure that the branches in Equation (
8) do not cause discontinuities.
While the above experiment confirms that these branches do not create discontinuities, we note that branch switching does introduce non-smoothness due to corner cases that can be arbitrarily classified into either branch, e.g., when a node is static but about to slip. Gradients at these corner cases are not well-defined, but the subset these corner cases occupy in \(\mathcal {C}^j_n\) has measure zero. Therefore, we still expect gradient-based optimization to be functional, just like we have observed the success of gradient-based optimization in modern deep learning with non-smooth but continuous operators, e.g., ReLU, max pooling, and so on.
Continuity of local frames at contact nodes. A second source of possible discontinuity and non-smoothness comes from computing
\({\mathbf {J}}_n\) , which consists of two steps: determining a contact point on the contact surfaces and calculating the local normal and tangent vectors. Both steps depend on the geometric representation of the contact surfaces. As pointed out by previous papers in rigid body dynamics [Popović et al.
2000; Werling et al.
2021], contact surface discretization causes jumps in surface normals, and therefore they create discontinuities in velocity and position calculation. To confirm this observation in cloth simulation, we repeat the previous experiment by replacing the analytically described sphere with a triangulated one (pink triangulated sphere surface in Figure
2 right). After such replacement, we clearly observe jumps in the intermediate and final velocity from the selected contact nodes (pink curves in Figure
2). Note that the jumps in velocities from the final velocities are less evident than from the intermediate velocities, because the vertical axes have different ranges. This observation agrees with similar experiments from previous papers about rigid body dynamics and suggests that one should favor analytical surfaces in differentiable cloth simulation whenever possible.
We end our discussion on the discontinuities from
\({\mathbf {J}}_n\) with two more remarks. First, we notice the contact node velocity curves in Figure
2 are partitioned into a small number of continuous segments, which is consistent with the result reported by previous work [Popović et al.
2000] discussing contact events on rigid body dynamics. Second, if the scene contains multiple objects the cloth can be in contact with, it is not uncommon to see jumps in the locations of contact events, e.g., from one object to another, even with a continuous representation of each object. Such jumps naturally lead to large discontinuities in simulation. While we do not provide solutions to it in this work, a closely related issue has been extensively studied in differentiable rendering [Li et al.
2018a] from which we may borrow inspirations in the future.
Continuity of contact sets. The last and most common source of discontinuity comes from deciding the contact set at each time step, i.e., whether a node should be added to the contact set or not. Obviously, this selection process is not continuous. It is worth noting that having a constant contact set does not cause too much trouble for gradient computation regardless of its size (Figure
2). Instead, it is the
change in the contact set from time to time that brings in discontinuities, because whenever a new node is put in the contact set, it adds an impulsive force to the right-hand side of Equation (
9).
To better understand the effects of changes in contact sets, we hang a piece of cloth above a static sphere in simulation and let the lower half of the cloth fall and slide on the sphere due to gravity (Figure
3 top). We equip this experiment with a system identification task of the frictional coefficient
\(\mu\) and the stiffness parameter
k of the cloth: given a motion sequence of the cloth generated from a pair of unknown
\(\mu\) and
k, we define a loss function that sums over all time steps the squared distance between each node position in simulation and its corresponding location in the given motion sequence. We repeat the task with four settings of the sphere at different horizontal offsets, leading to a varying frequency of contact events among them.
We plot the landscape of the loss function in Figure
3 (middle) and compare its smoothness among the four settings with different frequencies of contact events. At first glance, it seems that all four landscapes are equally smooth. However, magnifying a small region of each landscape shows that there is a profound distinction between their continuity and smoothness (Figure
3 bottom): as establishing and breaking contact becomes more frequent, the local landscape tends to be bumpier.
Summary. We have discussed the three sources of potential discontinuities and non-smoothness in our differentiable cloth simulator ordered by their damage to the gradients: the branches in the contact conditions only introduce non-smoothness and maintain continuity; contact surface discretization creates discontinuities due to the jumps of normals across adjacent triangles, but we still expect continuity almost everywhere; adding or deleting nodes in the contact set creates frequent and the most severe discontinuities due to the introduction or removal of impulsive forces.
5.4 Evaluation of Iterative Solver in Backpropagation
Another key component in our differentiable cloth simulation is the iterative solver in Equation (
29) that utilizes the prefactorized
\(\mathbf {P}\) in PD. In a standard differentiable simulator, solving Equation (
29) would be done with a sparse matrix solver treating
\((\mathbf {P}- \Delta \mathbf {P}- \Delta \mathbf {R})\) as a whole. To understand the performance of the proposed iterative solver, we design two benchmark tests: a “Wind” test where a hanging napkin moves under synthetic wind and a “Slope” test where a ribbon slides on a slanted plane (Figure
6). These two tests represent two extreme cases in contact handling: the napkin in “Wind” barely has any contact or self-collisions, whereas every single node of the ribbon in “Slope” is in contact with the plane. We then compare the time cost of our iterative solver with a sparse LU solver in both tests. We implement both solvers using Eigen [Guennebaud et al.
2010] and choose LU factorization, because
\((\mathbf {P}- \Delta \mathbf {P}- \Delta \mathbf {R})\) is usually not a symmetric or positive definite matrix, preventing us from using more specialized sparse matrix solvers like Cholesky factorization or Conjugate Gradient methods. For the iterative solver, we report two results from low-precision (1e-4) and high-precision (1e-6) convergence thresholds that control the termination condition in the iterations. We find these thresholds by varying it from 1e-1 to 1e-9 until the gradients computed from the iterative solver start to agree with the direct solver, which we treat as the ground-truth gradients. We repeat the experiments with three mesh resolutions to test the scalability of our method.
We summarize the statistics from both tests in Table
1. Overall, the iterative solver in backpropagation is faster than the direct solver, and the speedup becomes more substantial as we increase the mesh resolution. The speedup is also more evident with low-precision threshold, which is consistent with the results reported in previous PD papers [Bouaziz et al.
2014; Liu et al.
2017; Du et al.
2021]. A further decomposition of time confirms that solving the linear system takes up the majority of backpropagation time, so any improvement in the choice of solver has a dominating positive effect. Although the low-precision results may not match the ground-truth gradients as closely as their high-precision counterparts, their backpropagation is significantly faster and can still benefit gradient-based optimization. This is because even an imperfect gradient can still guide gradient descent algorithms to converge as long as it is along the descending direction. This is confirmed empirically by our experiments in Section
6, in most of which we use low-precision convergence threshold and still observe successful gradient-based optimization results. It is also worth mentioning that contact-related operators, whose time cost is included in the “Other” and “
\(\Delta \mathbf {R}\) ” columns in Table
1, add very little extra overhead to the backpropagation. Finally, we observe uncommon but non-negligible failure cases of the iterative solvers in one experiment (
\(48\times 48\) with 1e-6 as the threshold in Table
1) “Wind.” For the
\(15\%\) failed timesteps, we switch to the sparse LU solver, adding an extra
\(11.5\%\) time in backpropagation.