Skip to main content

add

Function add 

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

Element-wise sum c[i] = a[i] + b[i], returning a new field.

Generic over the element type: works for Field<f64>, Field<Vector3>, Field<Tensor> and Field<SymmTensor>, all of which are Copy.

Units: both operands must carry the same physical quantity (this layer stores bare numbers and cannot check that); the result carries it too.

Every output element is computed by the same expression as the serial std::ops::Add impl on Field, so the result is bit-identical to ComputeBackend::Serial on any backend and any thread count.

ยงPanics

Panics if a.len() != b.len(), matching the serial operator.

use outram_foam_basic_lib::compute::ComputeBackend;
use outram_foam_basic_lib::fields::field::Field;
use outram_foam_basic_lib::fields::parallel;

let a = Field::new(vec![1.0, 2.0, 3.0]);
let b = Field::new(vec![10.0, 20.0, 30.0]);
let c = parallel::add(ComputeBackend::CpuMulti, &a, &b);
assert_eq!(c.as_slice(), &[11.0, 22.0, 33.0]);