pub fn vol_integral(backend: ComputeBackend, phi: &VolScalarField) -> f64Expand description
Volume integral over the internal cells,
integral(phi dV) = sum_i phi[i] * V[i].
V[i] is the cell volume in m^3, taken from the field’s own mesh, so the
result carries units [phi] * m^3 — for a density field in kg/m^3 this
is the total mass in kg, which is the conservation check a compressible
solver runs each timestep.
Boundary patches are not included: they carry face values, not cell
values, and have no volume. An empty mesh integrates to 0.0.
§Panics
Panics if the internal field length differs from mesh.n_cells.
§Determinism
Same guarantee as sum: reproducible run to run and independent of thread
count, not bit-identical to a serial left fold.
use std::sync::Arc;
use outram_foam_basic_lib::compute::ComputeBackend;
use outram_foam_basic_lib::fields::parallel;
use outram_foam_basic_lib::fields::vol_field::VolScalarField;
use outram_foam_basic_lib::mesh::fv_mesh::FvMesh;
// 10 cells over a 1 m length, 1 m^2 area => total volume 1 m^3.
let mesh = Arc::new(FvMesh::periodic_1d(10, 1.0, 1.0));
let rho = VolScalarField::uniform("rho", mesh, 1.2); // [kg/m^3]
let mass = parallel::vol_integral(ComputeBackend::CpuMulti, &rho);
assert!((mass - 1.2).abs() < 1e-12); // 1.2 kg