Gyredocs
Depth Practice
API

Gyre/Mathematics & Numerical Methods

Curvilinear elements and metric terms

In one minuteElements are curved with the same polynomial technology as the solution. Metric terms are computed so that a uniform flow stays exactly uniform on any mesh, and they are evaluated inside the differentiated code so that shape derivatives come for free.

Written at L2 Practice goes to L4 Theory 1148 words Markdown

High-order accuracy near curved walls needs curved elements: a straight-sided mesh limits the whole solution to second order regardless of pp, and its kinks generate spurious entropy. Each Gyre element carries (pg+1)d(p_g+1)^d geometry nodes on an LGL lattice (degree pgp_g, default 4) that define its polynomial mapping x(ξ)\mathbf x(\boldsymbol\xi). Geometry nodes on shared faces are shared, so any smooth displacement of the global node array keeps the mesh watertight — which is how surface design variables enter.

On a curved element the divergence of a constant flux is discretised as ∑aDa (Jaa)⋅Fconst\sum_a \mathbf D_a\,(J\mathbf a^a)\cdot\mathbf F_\text{const}. It vanishes only if the discrete metric identities

∑a=1dDa (Jaba)=0(b=1,…,d)\sum_{a=1}^{d} \mathbf D_a\,(J a^a_b) = 0 \qquad (b = 1,\dots,d)

hold. If they do not, a uniform flow generates spurious waves at every curved element. Gyre satisfies the identities to round-off in 2-D and 3-D, including with viscous terms:

Uniform-flow residual on warped meshesFree-stream preservation on curved meshes
dimelementspgeometry degreeviscousmin J / max Jmax |Rw|surface closure
2-D6x534no0.4510471.3492e-153.0531e-16
2-D6x534yes0.4510471.3368e-153.0531e-16
2-D4x454no0.4535562.8560e-154.9960e-16
2-D4x454yes0.4535562.9091e-154.9960e-16
3-D3x3x322no0.2761592.6316e-163.4694e-17
3-D3x3x322yes0.2761592.6316e-163.4694e-17
3-D3x3x333no0.4170893.2526e-166.9823e-17
3-D3x3x333yes0.4170893.2823e-166.9823e-17

gyre 0.4.0 · 39979fcf90 · · cpu · quick suite · record (JSON)Same code as this build

The geometry is first interpolated from the geometry nodes to the solution nodes (degree pp), then differentiated with the same D\mathbf D used for the solution.

Two dimensions. The cross-product form is already divergence-free discretely:

Ja1=(yη, −xη),Ja2=(−yξ,  xξ),J=xξyη−xηyξ.J\mathbf a^1 = (y_\eta,\,-x_\eta), \qquad J\mathbf a^2 = (-y_\xi,\; x_\xi), \qquad J = x_\xi y_\eta - x_\eta y_\xi .

Three dimensions. Products such as yηzζy_\eta z_\zeta are of degree 2p2p and their derivatives no longer commute after interpolation, so the cross-product form violates the identities. Gyre uses Kopriva’s conservative curl form,

Jani=−x^i⋅∇ξ×(Ip ⁣(Xl ∇ξXm)),(n,m,l) cyclic,J a^i_n = -\hat{\mathbf x}_i\cdot\nabla_\xi \times \left( I^p\!\left( X_l\,\nabla_\xi X_m \right) \right), \qquad (n, m, l)\ \text{cyclic},

where IpI^p is nodal interpolation at degree pp. Being the discrete curl of a polynomial, each contravariant vector is discretely divergence-free by construction.

Outward face normals and surface Jacobians are the face values of the same arrays: n sJ=±Jaa\mathbf n\, s_J = \pm J\mathbf a^a on the two faces normal to ξa\xi_a, which makes the normals of two elements sharing a face exactly opposite — a requirement for conservation.

Metric terms are not precomputed constants: Discretization.geometry(X) is an ordinary JAX function of the global node coordinates X\mathbf X. The residual is R(U,X,θ)\mathbf R(\mathbf U, \mathbf X, \theta) and the chain

surface displacement d  →deformation  X(d)  →metrics  (J,Ja,n,sJ)  →operator  R, J\text{surface displacement } \mathbf d \;\xrightarrow{\text{deformation}}\; \mathbf X(\mathbf d) \;\xrightarrow{\text{metrics}}\; (J, J\mathbf a, \mathbf n, s_J) \;\xrightarrow{\text{operator}}\; \mathbf R,\, J

is differentiated end-to-end by reverse-mode AD. There is no separate “mesh sensitivity” code to keep consistent with the solver. The verification study on mesh deformation checks the derivative of a geometric integral through this chain against finite differences.

PassedDifferentiable mesh deformation9 of 9 checks passed · 2.45 s · quick suite

Surface displacements are propagated to all high-order geometry nodes by inverse-distance weighting. The study deforms a NACA 0012 O-mesh with a thickness bump of increasing amplitude and checks that elements stay valid, that wall nodes follow the prescription exactly while far-field nodes stay fixed, and that the derivative of a geometric quantity through deformation and metric evaluation matches finite differences.

  • scale 0.0: mesh valid (min J > 0)4.33e-05expected > 0pass
  • scale 0.0: surface/far-field prescription defect0expected < 1e-13pass
  • scale 0.5: mesh valid (min J > 0)4.33e-05expected > 0pass
  • scale 0.5: surface/far-field prescription defect0expected < 1e-13pass
  • scale 1.0: mesh valid (min J > 0)4.33e-05expected > 0pass
  • scale 1.0: surface/far-field prescription defect0expected < 1e-13pass
  • scale 2.0: mesh valid (min J > 0)4.33e-05expected > 0pass
  • scale 2.0: surface/far-field prescription defect0expected < 1e-13pass
  • d(weighted area)/d(surface displacement): AD vs FD1.08e-08expected < 1e-7pass

gyre 0.4.0 · 39979fcf90 · · cpu · quick suite · record (JSON)Same code as this build

The coarsest p-multigrid level uses one node per element. Differentiating a one-point “polynomial” gives no metrics, so this level takes its geometry from the degree-pgp_g description by exact reduction: the cell Jacobian is the mean ∑wJ/2d\sum w J / 2^d, face normals are the face integrals ∫n dS\int \mathbf n\,\mathrm dS divided by the reference face area. For the inviscid terms the resulting scheme is a first-order finite-volume method on the curved cell whose faces close exactly (geometric conservation), verified in test_finite_volume_geometry_reduction. The viscous terms keep only the face-normal two-point difference at this level (penalty parameter).

All built-in generators evaluate a smooth mapping on the LGL lattice, so elements are curved to degree pgp_g:

generator topology notes
airfoil_omesh O-mesh around a NACA 4-digit section or a spline fit of coordinate data sharp trailing edge and leading edge at element vertices; wall-normal lines from a smoothed normal field; geometric wall-normal growth from a first cell of the requested height
annulus O-mesh between two circles cylinder flows
bump_channel channel with a Gaussian bump smooth-wall verification
box Cartesian block, 2-D or 3-D optional smooth warp that preserves periodicity

A detail worth knowing: classical cosine clustering along the chord has zero parametric speed at the trailing edge, which makes the Jacobian vanish at the trailing-edge vertex. The aerofoil generator uses x=sin⁡2(cπ2v)/sin⁡2(cπ2)x = \sin^2(\tfrac{c\pi}{2} v)/\sin^2(\tfrac{c\pi}{2}) with c<1c < 1, which keeps the smooth x\sqrt{x} behaviour at the nose but a finite tangent at the trailing edge.

A mesh read from a file (mesh.generator: file) becomes the same global node array and element lattice as a generated one, so everything on this page applies unchanged. For a Gmsh file the reader maps Gmsh’s node ordering of each element onto the tensor-product lattice, re-orients left-handed elements, and interpolates the equispaced Gmsh nodes to the Legendre–Gauss–Lobatto distribution of the same degree (the identity up to degree 2). Lattice nodes are numbered topologically (a vertex by its file node, an edge or face node by the vertices of that edge or face and its position on it), so neighbouring elements share nodes exactly and nodes that merely coincide in space, at a slit or a periodic pair, stay distinct. Elements may meet in any relative orientation. A mesh is refused if the Jacobian determinant is not positive at every geometry node. The imported-mesh study tests these steps.

    ↑ ↓ moveEnter open[ ] change depthResults show section and depth level