Skip to main content

add_vol

Function add_vol 

Source
pub fn add_vol<T>(
    backend: ComputeBackend,
    a: &VolField<T>,
    b: &VolField<T>,
) -> VolField<T>
where T: Copy + Default + Send + Sync + Add<Output = T>,
Expand description

Sum of two volume fields — internal field and every boundary patch.

The result takes a’s name, a’s mesh, and a’s per-patch boundary conditions, exactly like the serial std::ops::Add impl on VolField.

The name is copied, never composed. See the module docs: composing names here produces 2^step string growth in a solver loop.

Units: both operands are the same physical quantity.

§Panics

Panics if the internal fields or any patch pair differ in length.

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;

let mesh = Arc::new(FvMesh::periodic_1d(8, 1.0, 1.0));
let a = VolScalarField::uniform("rho", mesh.clone(), 1.0);
let b = VolScalarField::uniform("drho", mesh, 0.25);
let c = parallel::add_vol(ComputeBackend::CpuMulti, &a, &b);
assert_eq!(c.name, "rho");                 // NOT "(rho + drho)"
assert!((c.internal[0] - 1.25).abs() < 1e-15);