cartan

Divergence

apply_divergence and apply_tensor_divergence compute the discrete covariant divergence of vector and tensor fields using the DEC operator .

Summary

FunctionInputOutput
apply_divergenceedge 1-form (vector field)vertex 0-form (scalar)
apply_tensor_divergenceedge 1-form (tensor field)edge 1-form (vector)

Formula

The codifferential (up to sign) gives the formal adjoint of the exterior derivative:

This is the discrete covariant divergence of a 1-form (vector field) to a 0-form (scalar field): .

Code Examples

Vector field divergence

use cartan_dec::{Mesh, ExteriorDerivative, HodgeStar, apply_divergence};
use nalgebra::DVector;
 
let mesh  = Mesh::unit_square_grid(4);
let ext   = ExteriorDerivative::from_mesh(&mesh);
let hodge = HodgeStar::from_mesh(&mesh);
 
// Vector field u at vertices: interleaved [u_x[0..n_v], u_y[0..n_v]] - 2*n_v entries
let nv = mesh.n_vertices();
let u = DVector::from_element(2 * nv, 1.0_f64);
let div_u = apply_divergence(&mesh, &ext, &hodge, &u);
 
// div(constant field) = 0 at interior vertices
assert_eq!(div_u.len(), mesh.n_vertices());

Tensor divergence (for Q-tensor PDEs)

use cartan_dec::apply_tensor_divergence;
 
// q: edge 1-form (n_e entries)
let ne = mesh.n_edges();
let q  = DVector::from_element(ne, 0.1_f64);
let div_q = apply_tensor_divergence(&mesh, &ext, &hodge, &q);
assert_eq!(div_q.len(), mesh.n_edges());

Numerical Notes

The divergence operator is the negative adjoint of . On a closed mesh (no boundary), holds exactly.

Boundary behavior: at boundary vertices, the divergence includes contributions from boundary edges. Apply masking if you need purely interior divergence values.

Applications

  • Active stress term: in volterra
  • Incompressibility enforcement: in fluid solvers
  • Discrete Hodge decomposition: component of