4.4 Capabilities Required for Simulation
4.4.2 Derivative Operators
As discussed in the section on mass conservation, Section 4.7, we need discrete ver- sions of the divergence and gradient operators. To develop these we utilize Stokes Theorem. For a detailed description of this approach see [31].
of a quantity ω to the integral over the boundary ∂Γ of that quantity, Γdω = ∂Γ ω (4.13)
Stokes’ Theorem is a general version of many well-known specific instances of the theorem including the Fundamental Theorem of Calculus, the Divergence (Gauss) Theorem, and the Curl (Kelvin-Stokes) Theorem. We compute discrete derivatives by finding an average derivative in some discrete region, referred to as the control volume. Recall that the average g of some quantity g(x) over a region Γ with volume V can be computed by
g = 1 V
Γg(x) dx. (4.14)
Equation (4.13) and Equation (4.14) can be used together to estimate an average derivative in some region by first using Equation (4.14) to estimate the average derivative over a control volume Γ. Then the volume integral of the derivative can be converted to a surface integral of the quantity using Stokes’ Theorem, Equation (4.13). To estimate this surface integral we use the discrete values stored on our mesh and perform numerical quadrature. This last step is the only approximation in the procedure. As is often done, in our implementation we use only quadrature points located at the discrete variables locations and integrate over the surface by assuming that this is a good average value of the function over the associated portion of the boundary. One beneficial feature of this general method for computing derivatives is that one could easy modify the implementation to improve the accuracy of the estimation simply by using more quadrature points, interpolating the discrete field as required.
Discrete Divergence
We now show how the generic procedure for deriving average derivatives is used to find the divergence. The average divergence within a tetrahedra, ∇ · u is derived starting from the Divergence (Gauss) theorem,
Γ∇ · u dV = ∂Γ u· dn V ∇ · u = ∂Γ u· dn ∇ · u ≈ 1 V i (ui· sini)Ai ∇ · u ≈ 1 V i siziAi
where Γ is domain of the tetrahedron, ∂Γ is the boundary of the tetrahedron, V is the tetrahedron volume, Ai is the area of the ith face, ni is the face normal, zi is the face normal velocity, and si is ±1 to orient the face normal to point out of the tetrahedron. Here we have approximated the surface integral over the boundary of the tetrahedra using a single quadrature point on each of the tetrahedron’s four faces. The accuracy of this estimate relies on the assumption that the face normal velocity associated with a face is a good representative value for the average normal velocity of the face.
When performing the mass conservation we prefer to compute the volume-weighted divergence, and enforce that it is 0, V (∇ · u) = 0 instead of Equation (4.2) ((∇ · u) = 0). If the divergence-free condition is enforced exactly this would have no effect on the solution, but since we use an iterative solver that is run to some tolerance, weighting by volume encourages larger elements to better conserve mass. This means that a region that is responsible for more mass will be encouraged to make sure that mass is conserved. For
v
n
p
2p
1n
1n
2n
3Figure 4.2: Divergence (left) is estimated by summing the outward-facing face normal velocities. In the figure s2 is negative because n2 points inward; all other s’s are positive. The gradient (right) is estimated by taking the difference between the pressures in the tetrahedra adjoining the face.
cases where elements vary greatly in size over the mesh, this has the potential to create ill-conditioned matrices, as rows are weighted by vastly different numbers. However, we have not observed this problem.
Discrete Gradient
Since we only deal with the face normal velocity, the component of velocity in the direction of the face normal we only need the component of the pressure gradient in the normal direction. To compute this we use the potential theorem (another instance of Stokes Theorem). Let L be the line segment which connects the pressure values p2, p1 which are adjacent to a face f . Let the vector from p1 to p2 be v and the unit length vector in v’s direction is v. The potential theorum computes the component of the gradient in the direction v at face f as
See Figure 4.2 for these and other terms discussed in this section. The average gradient in the line direction is
∇p · v = |v|1
∇p · vdL
= p2− p1 |v|
where |v| is the length of L. We are assuming that the average gradient over the segment is a good approximation of the gradient at the face location. In a Delaunay mesh, the line segment that connects the circumcenters of two adjacent tetrahedra is parallel to the normal of the face that they share. Furthermore the segment passes through the circumcenter of the face. See Figure 4.3, top left. This suggests that a good place for storing the pressure variables is at the circumcenters of tetrahedra; and a good place for storing face normal velocities is at the face circumcenters. This storage scheme was used by Klinger et al. [40] and produced satisfactory results. Unfortunately, the circumcenters can be far from their base object, i.e. a face circumcenter can be far outside the face (although still in the plane defined by the face) and a tetrahedron circumcenter can be far outside the tetrahedron. This has two deleterious effects. When the face circumcenter is far from the face, using the face normal velocity as an average for the outward velocity over the face can be very inaccurate, making the divergence estimate poor. Second, because the tetrahedron circumcenter can be far from the tetrahedra the line segment between two circumcenters might not pass through the face, even though the line does. As a result, the average gradient along the line will be a poor estimate for the gradient at the face. Refer to Figure 4.3 for visual examples of these problems. To alleviate these problems we store the pressures and face normal velocites at the barycenters of the tetrahedra and faces respectively [9]. Barycenters are much better
behaved than circumcenters. The face barycenter is a good location to sample the average quantity over the face and therefore is a good location for estimating the divergence with the face normal velocities. Also, the line segment between two tetrahedra barycenters passes through the shared face, so the average derivative over the line segment is a reasonable estimate for the derivative at the face. Unfortunately, the segment connecting tetrahedra barycenters will not, in general, be parallel to the normal of the shared face nor will it intersect the face at its face barycenter. To compensate for the difference in direction, we modify Equation (4.16) to be
∇p · ¯v ≈ p2− p1
v· n (4.16)
This estimate has works in the examples that we generate but it has errors due to the difference in direction between v and n and the difference between the face barycenter and the face-line segment intersection. One particularly troublesome effect of the error is that the derivative estimate is not linearly consistent and therefore the mass conservation step does not perfectly balance an applied gravity field. As a result a liquid in a container that should remain static (because the gravity forces are perfectly balanced by pressure forces) displays some visible artifacts, the liquid has a slight phantom motion due to the errors.
Discrete Gradient Improvement
To improve the accuracy of the derivative estimate researchers have investigated augmenting the estimate in Equation (4.16) with correction terms [37]. Most methods compute the gradient in the face direction as above and then additionally compute a gradient vector for the face. They use the gradient vector to correct the normal direction gradient based off of how different the line segment direction is from the face’s normal direction. The
Figure 4.3: Top left: If pressures are stored at circumcenters, the line connecting two adjacent pressures passes through the face circumcenter (the edge midpoint in 2D) and is parallel to the face’s normal. Top right: Circumcenters may lie outside of an element such that the line segment between adjacent circumcenters does not intersect the face. Bottom left: In 3D the face circumcenter (dark triangle) is not necessarily in the face, making it a dubious place to locate the face normal velocity for divergence calculation. Bottom right: Storing quantities at barycenters. The line segment connecting adjacent tetrahedra barycenters does not necessarily pass through the face barycenter and is not generally parallel to the face normal.
corrected equation is (from [15]):
∇p · d = p2− p1 v· n +∇p · v 1− 1 n· v (4.17)
where ∇p is an estimate for the gradient vector at the face. To compute the gradient vector at the face, the methods compute gradients vectors at the adjacent tetrahedra and average them. One way that the full gradient for a tetrahedra can be found is by using the
Green-Gauss reconstruction, T ∇pdV = ∂T pndS. (4.18)
With this the tetrahedra full gradient can be estimated as:
∇pj = 1 V 4 i=1 1 2(pj+ pi)nij (4.19)
where pi is the pressure of j’s neighbor, i andnij is the normal of the face between tetrahe- dra i and j. We have obtained pressure values on the faces of the tetrahedra by averaging values from the tetrahedra adjacent to the faces. We have experimented with this aug- mented gradient estimate but the results do not overcome the aforementioned problem with phantom motion in a pool of water effected by gravity or appreciably improve the visual appearance of the simulation. Furthermore, these changes significantly decrease the sparsity of the gradient matrix, thereby increasing both memory use and simulation time. As a result, in our default implementation we do not include this correction.