Skip to main content

Module field

Module field 

Source
Expand description

Quantities that vary over space and time.

Continuum physics is fields most of the way down: a temperature field, a velocity field, a stress field, an electromagnetic field. They differ in what they hold and in the equation that governs them, but the three operators used to write those equations — gradient, divergence, Laplacian — are the same three every time. Implementing them once is most of what a kernel owes a continuum domain.

§Values are raw SI numbers, and that is a real limitation

A ScalarField returns f64 and a VectorField returns DVec3, both in SI base units, rather than the dimensioned types from pantometry-units. The dimension varies per field — kelvin here, pascals there — and expressing “the gradient of this field has the field’s dimension divided by a length” needs arithmetic on const generic parameters, which is unstable. So the dimension lives on the concrete type that implements the trait, and is documented rather than checked, at exactly this one boundary.

§The derivatives are finite differences, and the step matters

Central differences, second-order accurate, with the step passed in. There is no good default for it: too large and the truncation error dominates, too small and cancellation in the subtraction does. For a field with curvature scale Lc and values near 1, h ≈ Lc * 1e-5 is a reasonable start, and a field that knows its own analytic derivative should override these methods and skip the question entirely.

Structs§

Analytic
A field from a closure, for the common case where the physics is a formula.
Uniform
The same value everywhere and always. Useful as an ambient condition, and as the thing a finite-difference test should return zero derivatives for.

Traits§

ScalarField
A scalar field: temperature, pressure, concentration, potential.
VectorField
A vector field: velocity, force per volume, electric field, heat flux.