Merge branch 'feature-limitFields-FO' into 'develop'

ENH: Added new limitFields function object

See merge request Development/openfoam!304
This commit is contained in:
Mark Olesen
2019-12-13 20:04:05 +00:00
4 changed files with 459 additions and 0 deletions

View File

@ -27,6 +27,8 @@ heatTransferCoeff/heatTransferCoeffModels/fixedReferenceTemperature/fixedReferen
heatTransferCoeff/heatTransferCoeffModels/localReferenceTemperature/localReferenceTemperature.C
heatTransferCoeff/heatTransferCoeffModels/ReynoldsAnalogy/ReynoldsAnalogy.C
limitFields/limitFields.C
nearWallFields/nearWallFields.C
nearWallFields/findCellParticle.C
nearWallFields/findCellParticleCloud.C

View File

@ -0,0 +1,183 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 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 "limitFields.H"
#include "fieldTypes.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(limitFields, 0);
addToRunTimeSelectionTable(functionObject, limitFields, dictionary);
}
}
const Foam::Enum
<
Foam::functionObjects::limitFields::limitType
>
Foam::functionObjects::limitFields::limitTypeNames_
({
{ limitType::MIN, "min" },
{ limitType::MAX, "max" },
{ limitType::BOTH, "both" },
});
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::limitFields::limitScalarField
(
const word& fieldName
)
{
auto* fieldPtr = obr_.getObjectPtr<volScalarField>(fieldName);
if (!fieldPtr)
{
return false;
}
auto& field = *fieldPtr;
if (limit_ & MIN)
{
Log << ": min(" << gMin(field) << ")";
field.max(dimensionedScalar("", field.dimensions(), min_));
}
if (limit_ & MAX)
{
Log << ": max(" << gMax(field) << ")";
field.min(dimensionedScalar("", field.dimensions(), max_));
}
return true;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::limitFields::limitFields
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
limit_(MIN),
fieldSet_(mesh_),
min_(-VGREAT),
max_(VGREAT)
{
read(dict);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::limitFields::read(const dictionary& dict)
{
if (fvMeshFunctionObject::read(dict))
{
Info<< type() << " " << name() << ":" << nl;
limit_ = limitTypeNames_.get("limit", dict);
if (limit_ & MIN)
{
min_ = dict.get<scalar>("min");
Info<< " Imposing lower limit " << min_ << nl;
}
if (limit_ & MAX)
{
max_ = dict.get<scalar>("max");
Info<< " Imposing upper limit " << max_ << nl;
}
fieldSet_.read(dict);
Info<< endl;
return true;
}
return false;
}
bool Foam::functionObjects::limitFields::execute()
{
fieldSet_.updateSelection();
Log << type() << " " << name() << ":" << nl;
label count = 0;
for (const word& fieldName : fieldSet_.selectionNames())
{
if
(
limitScalarField(fieldName)
|| limitField<vector>(fieldName)
|| limitField<sphericalTensor>(fieldName)
|| limitField<symmTensor>(fieldName)
|| limitField<tensor>(fieldName)
)
{
++count;
}
}
if (debug)
{
Log << " - limited " << count << '/'
<< fieldSet_.selectionNames().size() << " fields";
}
Log << endl;
return true;
}
bool Foam::functionObjects::limitFields::write()
{
for (const word& fieldName : fieldSet_.selectionNames())
{
lookupObject<regIOobject>(fieldName).write();
}
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,200 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 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::functionObjects::limitFields
Group
grpFieldFunctionObjects
Description
Limits fields to user-specified min and max bounds
Note
For non-scalar field types, the user limit is used to create a
scaling factor using the field magnitudes.
Usage
Example of function object specification:
\verbatim
limitFields1
{
type limitFields;
libs ("libfieldFunctionObjects.so");
...
fields (U);
limit max;
max 100;
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default
type | type name: limitFields | yes |
fields | list of fields to process | yes |
limit | bound to limit - see below | yes |
min | min limit value | partly |
max | max limit value | partly |
\endtable
The \c limit entry can take the value:
- \c min : specify a minimum value
- \c max : specify a maximum value
- \c both : specify a minimum value and a maximum value
See also
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
limitFields.C
limitFieldsTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_limitFields_H
#define functionObjects_limitFields_H
#include "Enum.H"
#include "fvMeshFunctionObject.H"
#include "volFieldSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class limitFields Declaration
\*---------------------------------------------------------------------------*/
class limitFields
:
public fvMeshFunctionObject
{
public:
// Public Enumerations
enum limitType : unsigned
{
MIN = 0x1, //!< limit by minimum value
MAX = 0x2, //!< limit by maximum value
BOTH = (MIN | MAX) //!< limit by both minimum and maximum values
};
protected:
// Protected Data
//- Limit type names
static const Enum<limitType> limitTypeNames_;
//- Limiting type
limitType limit_;
//- Fields to limit
volFieldSelection fieldSet_;
//- Minimum limit
scalar min_;
//- Maximum limit
scalar max_;
// Protected Member Functions
//- Limit a scalar field.
// \return true if field of this type was found.
bool limitScalarField(const word& fieldName);
//- Limit a field.
// \return true if field of this type was found.
template<class Type>
bool limitField(const word& fieldName);
//- No copy construct
limitFields(const limitFields&) = delete;
//- No copy assignment
void operator=(const limitFields&) = delete;
public:
//- Runtime type information
TypeName("limitFields");
// Constructors
//- Construct from Time and dictionary
limitFields
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~limitFields() = default;
// Member Functions
//- Read the field min/max data
virtual bool read(const dictionary& dict);
//- Execute, currently does nothing
virtual bool execute();
//- Write the limitFields
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "limitFieldsTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,74 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 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 "limitFields.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::limitFields::limitField(const word& fieldName)
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
auto* fieldPtr = getObjectPtr<VolFieldType>(fieldName);
if (!fieldPtr)
{
return false;
}
auto& field = *fieldPtr;
Log << " Limiting field " << fieldName << ":";
const dimensionedScalar eps("eps", field.dimensions(), ROOTVSMALL);
if (limit_ & MIN)
{
volScalarField mField(typeName + ":mag" + field.name(), mag(field));
Log << " min(|" << gMin(mField) << "|)";
//field.normalise();
field /= mag(field) + eps;
mField.max(dimensionedScalar("min", field.dimensions(), min_));
field *= mField;
}
if (limit_ & MAX)
{
volScalarField mField(typeName + ":mag" + field.name(), mag(field));
Log << " max(|" << gMax(mField) << "|)";
//field.normalise();
field /= mag(field) + eps;
mField.min(dimensionedScalar("max", field.dimensions(), max_));
field *= mField;
}
return true;
}
// ************************************************************************* //