Field functions for lerp and clamp. Add clamping as Field methods
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)
Merge request reports
Activity
changed milestone to %v2306
added enhancement label
assigned to @andy
added 1 commit
- bbfea126 - STYLE: lerp and emplace_back to simplify streamline coding
Changes look good - lots of low-level changes -> please test!
@Prashant - can you fire off a test loop?
@Prashant - any updates/regressions noted?
Here is a quick overview of unconfirmed completions and errors (some of them common to develop failures). log.error
A detailed result comparison will follow in an email...
added 42 commits
-
bbfea126...521bdf0f - 31 commits from branch
develop
- 229e171f - COMP: rename field methods clamp() -> clamp_range()
- 90fcadd4 - ENH: use GeometricField clamp_min, clamp_max, clamp_range
- 95f705e6 - ENH: update field function macros and 'reuse' field handling
- c222e182 - EHN: add FieldFunction interface for 0/1 clamping
- 7dae5666 - ENH: define lerp field functions
- 7409c044 - ENH: neg(x) instead of '1 - pos0(x)' for less-than 0 check
- 8c506a7b - ENH: use lerp for valueFraction (mixed BCs) and field relaxation
- 775422d4 - ENH: lerp for patch/neighbour weights
- 1b67b215 - STYLE: use clamp/clamp_range instead of max(min(..., upper), lower)
- 87f8d22c - STYLE: use clamp/clamp_range instead of min(max(..., upper), lower)
- d1254d14 - STYLE: lerp and emplace_back to simplify streamline coding
Toggle commit list-
bbfea126...521bdf0f - 31 commits from branch
@andy The deviation in PDRFoam arises from this (in mixedFvPatch gradientBoundaryCoeffs). clang-14
original code:return ( valueFraction_*this->patch().deltaCoeffs()*refValue_ + (1.0 - valueFraction_)*refGrad_ );
No difference:
return ( (1.0 - valueFraction_)*refGrad_ + valueFraction_*this->patch().deltaCoeffs()*refValue_ );
These however change combustion progress and min(b):
return ( (1.0 - valueFraction_)*refGrad_ + valueFraction_*(this->patch().deltaCoeffs()*refValue_) ); return ( (1.0 - valueFraction_)*refGrad_ + valueFraction_*(refValue_*this->patch().deltaCoeffs()) );
The mixed BC is being harnessed by inletOutlet/outletInlet conditions, so refGrad is identically zero and valueFraction is either 0 or 1 so could argue that grouping and then multiplying by valueFraction should be slightly better (could probably also argue the opposite somehow).
Even with the danger of multiplying even more boundary conditions, there might be a case to be made for having a mixedZeroGradient (as intermediate, probably not selectable) in which the refGrad is kicked out of the calculation (identically zero).
added 23 commits
-
d1254d14...a7d77391 - 12 commits from branch
develop
- 4d7180ae - COMP: rename field methods clamp() -> clamp_range()
- 3d8a6a54 - ENH: use GeometricField clamp_min, clamp_max, clamp_range
- 6f68ce52 - ENH: update field function macros and 'reuse' field handling
- ab10b4a0 - EHN: add FieldFunction interface for 0/1 clamping
- e1a71001 - ENH: define lerp field functions
- 70d526cd - ENH: neg(x) instead of '1 - pos0(x)' for less-than 0 check
- 128516b8 - ENH: use lerp for valueFraction (mixed BCs) and field relaxation
- 4d45cfd5 - ENH: lerp for patch/neighbour weights
- ba6667a3 - STYLE: use clamp/clamp_range instead of max(min(..., upper), lower)
- 1cc72ea7 - STYLE: use clamp/clamp_range instead of min(max(..., upper), lower)
- f180740b - STYLE: lerp and emplace_back to simplify streamline coding
Toggle commit list-
d1254d14...a7d77391 - 12 commits from branch
mentioned in commit 40bdab1c