Discrete Calculus#

This module implements discrete differential operators on simplicial meshes using two complementary approaches:

  1. Discrete Exterior Calculus (DEC) – a rigorous differential-geometry framework based on Desbrun, Hirani, Leok, and Marsden’s work (arXiv:math/0508341). DEC operators use the primal/dual mesh structure (circumcentric dual volumes, Hodge stars) and produce results that satisfy discrete analogues of Stokes’ theorem.

  2. Weighted Least-Squares (LSQ) – a standard CFD/FEM approach that reconstructs derivatives by fitting polynomials to local neighborhoods. LSQ methods are more flexible (they work for any manifold/codimension) and are generally the recommended default.

Both intrinsic (manifold tangent space) and extrinsic (ambient space) derivatives are supported for manifolds embedded in higher-dimensional spaces.

import torch
from physicsnemo.mesh import Mesh
from physicsnemo.mesh.calculus import (
    compute_gradient_points_lsq,
    compute_divergence_points_lsq,
    compute_curl_points_lsq,
)

# Linear scalar field T = x + 2y on a mesh
mesh.point_data["T"] = mesh.points[:, 0] + 2 * mesh.points[:, 1]

# Gradient via the Mesh method (wraps compute_gradient_points_lsq)
mesh = mesh.compute_point_derivatives(keys="T", method="lsq")
grad_T = mesh.point_data["T_gradient"]  # (n_points, n_spatial_dims)

# Divergence and curl via standalone functions
mesh.point_data["velocity"] = mesh.points.clone()
div_v = compute_divergence_points_lsq(mesh, mesh.point_data["velocity"])
curl_v = compute_curl_points_lsq(mesh, mesh.point_data["velocity"])  # 3D only

Key Operators#

  • Gradient: \(\nabla\varphi\) (scalar \(\to\) vector)

  • Divergence: \(\operatorname{div}(\mathbf{v})\) (vector \(\to\) scalar)

  • Curl: \(\operatorname{curl}(\mathbf{v})\) (vector \(\to\) vector, 3D only)

  • Laplacian: \(\Delta\varphi\) (scalar \(\to\) scalar, Laplace-Beltrami)

API Reference#

Discrete calculus operators for simplicial meshes.

This module implements discrete differential operators using both:

  1. Discrete Exterior Calculus (DEC) - rigorous differential geometry framework.

  2. Weighted Least-Squares (LSQ) reconstruction - standard CFD approach.

The DEC implementation follows Desbrun, Hirani, Leok, and Marsden’s seminal work on discrete exterior calculus (arXiv:math/0508341v2).

Key operators:

  • Gradient: \(\nabla \varphi\) (scalar -> vector).

  • Divergence: \(\operatorname{div}(v)\) (vector -> scalar).

  • Curl: \(\operatorname{curl}(v)\) (vector -> vector, 3D only).

  • Laplacian: \(\Delta \varphi\) (scalar -> scalar, Laplace-Beltrami operator).

Both intrinsic (manifold tangent space) and extrinsic (ambient space) derivatives are supported for manifolds embedded in higher-dimensional spaces.