Skip to main content

axpy_assign

Function axpy_assign 

Source
pub fn axpy_assign<T>(
    backend: ComputeBackend,
    y: &mut Field<T>,
    a: f64,
    x: &Field<T>,
)
where T: Copy + Send + Sync + Add<Output = T> + Mul<f64, Output = T>,
Expand description

In-place fused combination y[i] += a * x[i] (“axpy”). Allocation-free.

The hot-loop form of axpy: one traversal, no allocation. This is the shape an explicit transient update takes every timestep.

Units: y and a*x are 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;
use outram_foam_basic_lib::primitives::Vector3;

let mut u = Field::uniform(3, Vector3::new(1.0, 0.0, 0.0));   // [m/s]
let du = Field::uniform(3, Vector3::new(0.0, 2.0, 0.0));      // [m/s^2]
parallel::axpy_assign(ComputeBackend::CpuMulti, &mut u, 0.5, &du);  // dt = 0.5 s
assert_eq!(u[0], Vector3::new(1.0, 1.0, 0.0));