Skip to content

Field functions for lerp and clamp. Add clamping as Field methods

Mark OLESEN requested to merge feature-field-functions-SIMD into develop

To improve data locality and simplify calling code, now have lerp() and clamp() as free functions working on fields. Both can be composed as a SIMD type of operation (with three operands) and applied within the fields loops instead of being composed as separate field operations.

  • Having lerp turns out to only be moderately useful, since most of the schemes have already unrolled the operation inside. However, it is still quite convenient when composing (for example) mixed boundary conditions or combining patch internal and neighbour values.
  • The clamp method is used in several more places, quite commonly in multi-phase routines to enforce a strict 0-1 boundness.

Since clamping of field values is a quite useful property, in-place clamping has been added as field methods directly:

  • clamp_min(...), clamp_max(...), clamp_range(...)

The frequently required 0-1 bounding can be use succinctly with the zero_one dispatch tag. For example,

alpha.clamp_range(zero_one{});

Tip: with flow switching (eg, inlet/outlet) the lerp function can be combined with pos0 to define a selector. Eg,

lerp(a, b, pos0(phi))

// vs.
a*neg(phi) + b * pos0(phi)
Edited by Mark OLESEN

Merge request reports