pub fn axpy<T>(
backend: ComputeBackend,
y: &Field<T>,
a: f64,
x: &Field<T>,
) -> Field<T>Expand description
Fused combination c[i] = y[i] + a * x[i] (“axpy”), returning a new field.
This is the single most common shape in a solver timestep — adding a scaled
explicit source, applying an under-relaxed correction, or advancing an
explicit Euler update phi_new = phi + dt * ddt(phi). It is one fused pass,
so the fields are traversed once instead of twice; that matters because these
kernels are memory-bandwidth bound.
Units: y and a*x must be the same physical quantity.
§Panics
Panics if y.len() != x.len().
use outram_foam_basic_lib::compute::ComputeBackend;
use outram_foam_basic_lib::fields::field::Field;
use outram_foam_basic_lib::fields::parallel;
let y = Field::new(vec![1.0, 1.0]);
let x = Field::new(vec![4.0, 6.0]);
let c = parallel::axpy(ComputeBackend::Serial, &y, 0.5, &x);
assert_eq!(c.as_slice(), &[3.0, 4.0]);