ENH: AMI - added new set of field-based AMI operations

This commit is contained in:
Andrew Heather 2024-05-03 16:05:37 +01:00
parent f639538600
commit e44184e626
8 changed files with 705 additions and 0 deletions

View File

@ -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 <http://www.gnu.org/licenses/>.
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 Type, class CombineOp>
class AMIFieldOp
:
public AMIFieldOpBase
{
// Private Data
//- Combine operator, e.g. plusEqOp<Type>()
// 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<value_type>& result,
const UList<value_type>& fld,
const UList<value_type>& /* 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
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
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
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#ifndef AMIFieldOps_H
#define AMIFieldOps_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "ops.H"
#include "AMIFieldOp.H"
#include "AMIMultiplyWeightedOp.H"
#include "LowWeightCorrection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
using AMIMaxOp = AMIFieldOp<Type, maxEqOp<Type>>;
template<class Type>
using AMIMinOp = AMIFieldOp<Type, minEqOp<Type>>;
template<class Type>
using AMICorrectedMultiplyWeightedOp =
LowWeightCorrection<AMIMultiplyWeightedOp<Type>, plusEqOp<Type>>;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#ifndef AMIMultiplyWeightedOp_H
#define AMIMultiplyWeightedOp_H
#include "AMIFieldOpBase.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class AMIMultiplyWeightedOp Declaration
\*---------------------------------------------------------------------------*/
template<class Type, class CombineOp = plusEqOp<Type>>
class AMIMultiplyWeightedOp
:
public AMIFieldOpBase
{
// Private Data
//- Combine operator, e.g. plusEqOp<Type>()
// 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<value_type>& result,
const UList<value_type>& fld,
const UList<value_type>& /* 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
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
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 AMIOpType, class CombineOp>
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<value_type>& 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<value_type>& result,
const UList<value_type>& fld,
const UList<value_type>& defaultValues
) const
{
// Apply AMI interpolator
AMIOpType::operator()(result, fld, UList<value_type>::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<int>(opt_)
<< abort(FatalError);
}
}
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "lowWeightCorrectionBase.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::Enum<Foam::lowWeightCorrectionBase::option>
Foam::lowWeightCorrectionBase::optionNames_
({
{ option::NONE, "none" },
{ option::ASSIGN, "assign" },
{ option::BLEND, "blend" },
});
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::lowWeightCorrectionBase::lowWeightCorrectionBase(const option& opt)
:
opt_(opt)
{}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
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<option> optionNames_;
protected:
// Protected Data
//- Option
option opt_;
public:
//- Constructors
lowWeightCorrectionBase(const option& opt = option::NONE);
//- Destructor
~lowWeightCorrectionBase() = default;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -276,6 +276,7 @@ processorLOD/cellBox/cellBox.C
processorLOD/faceBox/faceBox.C
AMI=AMIInterpolation
$(AMI)/AMIInterpolation/AMIFieldOps/lowWeightCorrectionBase.C
$(AMI)/AMIInterpolation/AMIInterpolation.C
$(AMI)/AMIInterpolation/AMIInterpolationNew.C
$(AMI)/AMIInterpolation/advancingFrontAMI/advancingFrontAMI.C