diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/AMIFieldOp.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/AMIFieldOp.H new file mode 100644 index 0000000000..dee2566a27 --- /dev/null +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/AMIFieldOp.H @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2024 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::AMIFieldOP + +Description + General template for AMI field operations + +\*---------------------------------------------------------------------------*/ + +#ifndef AMIFieldOp_H +#define AMIFieldOp_H + +#include "AMIFieldOpBase.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class AMIFieldOp Declaration +\*---------------------------------------------------------------------------*/ + +template +class AMIFieldOp +: + public AMIFieldOpBase +{ + // Private Data + + //- Combine operator, e.g. plusEqOp() + // Note: must be null-constructed + CombineOp cop_; + + +public: + + typedef Type value_type; + + //- Constructor + AMIFieldOp(const AMIInterpolation& ami, bool toSource) + : + AMIFieldOpBase(ami, toSource), + cop_() + {} + + //- Destructor + ~AMIFieldOp() = default; + + + //- Apply the op + // Note: does not use default values + void operator() + ( + List& result, + const UList& fld, + const UList& /* unused defaultValues */ + ) const + { + const auto& address = this->address(); + + forAll(result, facei) + { + const labelList& faceSlots = address[facei]; + + forAll(faceSlots, i) + { + if (i == 0) + { + result[facei] = fld[faceSlots[i]]; + } + else + { + cop_(result[facei], fld[faceSlots[i]]); + } + } + } + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // \ No newline at end of file diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/AMIFieldOpBase.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/AMIFieldOpBase.H new file mode 100644 index 0000000000..c1f15b70fc --- /dev/null +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/AMIFieldOpBase.H @@ -0,0 +1,105 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2024 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::AMIFieldOpBase + +Description + Base class for AMI field operations + +\*---------------------------------------------------------------------------*/ + +#ifndef AMIFieldOpsBase_H +#define AMIFieldOpsBase_H + +#include "AMIInterpolation.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class AMIFieldOpBase Declaration +\*---------------------------------------------------------------------------*/ + +class AMIFieldOpBase +{ +protected: + + //- Reference to the AMI + const AMIInterpolation& ami_; + + //- Interpolation to source; false=interpolate to target + const bool toSource_; + + +public: + + //- Constructor + AMIFieldOpBase(const AMIInterpolation& ami, const bool toSource) + : + ami_(ami), + toSource_(toSource) + {} + + + // Member Functions + + //- Return the 'toSource' flag + bool toSource() const + { + return toSource_; + } + + //- Return the AMI addressing + const labelListList& address() const + { + return toSource_ ? ami_.srcAddress() : ami_.tgtAddress(); + } + + //- Return the AMI weights + const scalarListList& weights() const + { + return toSource_ ? ami_.srcWeights() : ami_.tgtWeights(); + } + + //- Return the AMI sum of weights + const scalarList& weightsSum() const + { + return toSource_ ? ami_.srcWeightsSum() : ami_.tgtWeightsSum(); + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // \ No newline at end of file diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/AMIFieldOps.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/AMIFieldOps.H new file mode 100644 index 0000000000..dbd6403add --- /dev/null +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/AMIFieldOps.H @@ -0,0 +1,58 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2024 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#ifndef AMIFieldOps_H +#define AMIFieldOps_H + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "ops.H" +#include "AMIFieldOp.H" +#include "AMIMultiplyWeightedOp.H" +#include "LowWeightCorrection.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +template +using AMIMaxOp = AMIFieldOp>; + +template +using AMIMinOp = AMIFieldOp>; + +template +using AMICorrectedMultiplyWeightedOp = + LowWeightCorrection, plusEqOp>; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // \ No newline at end of file diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/AMIMultiplyWeightedOp.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/AMIMultiplyWeightedOp.H new file mode 100644 index 0000000000..207be20ccf --- /dev/null +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/AMIMultiplyWeightedOp.H @@ -0,0 +1,112 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2024 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#ifndef AMIMultiplyWeightedOp_H +#define AMIMultiplyWeightedOp_H + +#include "AMIFieldOpBase.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class AMIMultiplyWeightedOp Declaration +\*---------------------------------------------------------------------------*/ + +template> +class AMIMultiplyWeightedOp +: + public AMIFieldOpBase +{ + // Private Data + + //- Combine operator, e.g. plusEqOp() + // Note: must be null-constructed + CombineOp cop_; + + +public: + + typedef Type value_type; + + + //- Constructor + AMIMultiplyWeightedOp + ( + const AMIInterpolation& ami, + const bool toSource + ) + : + AMIFieldOpBase(ami, toSource), + cop_() + {} + + + //- Multiply-weighted op + // Note: does not use default values + void operator() + ( + List& result, + const UList& fld, + const UList& /* unused defaultValues */ + ) const + { + const auto& address = this->address(); + const auto& weights = this->weights(); + + forAll(result, facei) + { + const labelList& faceSlots = address[facei]; + const scalarList& faceWeights = weights[facei]; + + forAll(faceSlots, i) + { + if (i == 0) + { + result[facei] = faceWeights[i]*fld[faceSlots[i]]; + } + else + { + cop_(result[facei], faceWeights[i]*fld[faceSlots[i]]); + } + } + } + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // \ No newline at end of file diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/LowWeightCorrection.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/LowWeightCorrection.H new file mode 100644 index 0000000000..bc4d082c63 --- /dev/null +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/LowWeightCorrection.H @@ -0,0 +1,176 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2024 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::LowWeightCorrection + +Description + Wrapper around the AMI field op + +\*---------------------------------------------------------------------------*/ + +#ifndef LowWeightCorrection_H +#define LowWeightCorrection_H + +#include "lowWeightCorrectionBase.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class LowWeightCorrection Declaration +\*---------------------------------------------------------------------------*/ + +template +class LowWeightCorrection +: + public lowWeightCorrectionBase, + public AMIOpType +{ + typedef typename AMIOpType::value_type value_type; + +public: + + //- Constructor + LowWeightCorrection + ( + const AMIInterpolation& ami, + const bool toSource, + const lowWeightCorrectionBase::option& opt = + lowWeightCorrectionBase::option::NONE + ) + : + lowWeightCorrectionBase(opt), + AMIOpType(ami, toSource) + {} + + + // Member Functions + + //- Helper function to ensure default value field is valid + bool validDefaults(const UList& defaultValues) const + { + const auto& ami = AMIOpType::ami_; + + if (ami.lowWeightCorrection() > 0) + { + const auto& weightsSum = this->weightsSum(); + + if (defaultValues.size() != weightsSum.size()) + { + FatalErrorInFunction + << "Employing default values when sum of weights " + << "falls below " << ami.lowWeightCorrection() + << " but number of default values is not equal to " + << "addressing size" << nl + << " default values size = " + << defaultValues.size() << nl + << " addressing size = " + << weightsSum.size() << nl + << abort(FatalError); + } + + return true; + } + + return false; + } + + + //- Correction operator + void operator() + ( + List& result, + const UList& fld, + const UList& defaultValues + ) const + { + // Apply AMI interpolator + AMIOpType::operator()(result, fld, UList::null()); + + if (!validDefaults(defaultValues)) return; + + switch (opt_) + { + case option::NONE: + { + break; + } + case option::ASSIGN: + { + const auto& ami = AMIOpType::ami_; + const auto& weightsSum = this->weightsSum(); + + forAll(result, facei) + { + if (weightsSum[facei] < ami.lowWeightCorrection()) + { + // Assign default value + result[facei] = defaultValues[facei]; + } + } + + break; + } + case option::BLEND: + { + const auto& ami = AMIOpType::ami_; + const auto& weightsSum = this->weightsSum(); + + forAll(result, facei) + { + if (weightsSum[facei] < ami.lowWeightCorrection()) + { + // Already have 'weightSum' contribution in result + // - blend 'missing' contribution into result + const scalar w = min(1, max(0, weightsSum[facei])); + result[facei] += (1 - w)*defaultValues[facei]; + } + } + + break; + } + default: + { + FatalErrorInFunction + << "Unhandled enumeration " << static_cast(opt_) + << abort(FatalError); + } + } + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // \ No newline at end of file diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/lowWeightCorrectionBase.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/lowWeightCorrectionBase.C new file mode 100644 index 0000000000..62e34004f6 --- /dev/null +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/lowWeightCorrectionBase.C @@ -0,0 +1,49 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2024 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "lowWeightCorrectionBase.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +const Foam::Enum +Foam::lowWeightCorrectionBase::optionNames_ +({ + { option::NONE, "none" }, + { option::ASSIGN, "assign" }, + { option::BLEND, "blend" }, +}); + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::lowWeightCorrectionBase::lowWeightCorrectionBase(const option& opt) +: + opt_(opt) +{} + + +// ************************************************************************* // \ No newline at end of file diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/lowWeightCorrectionBase.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/lowWeightCorrectionBase.H new file mode 100644 index 0000000000..bb46a9d8e4 --- /dev/null +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIFieldOps/lowWeightCorrectionBase.H @@ -0,0 +1,90 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2024 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::lowWeightCorrectionBase + +Description + Base class for AMI low weight corrections + + +\*---------------------------------------------------------------------------*/ + +#ifndef lowWeightCorrectionBase_H +#define lowWeightCorrectionBase_H + +#include "Enum.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class lowWeightCorrectionBase Declaration +\*---------------------------------------------------------------------------*/ + +class lowWeightCorrectionBase +{ + +public: + + enum class option + { + NONE, + ASSIGN, + BLEND + }; + + static const Enum