diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files index ac70390ecd..2e19e13910 100644 --- a/src/functionObjects/field/Make/files +++ b/src/functionObjects/field/Make/files @@ -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 diff --git a/src/functionObjects/field/limitFields/limitFields.C b/src/functionObjects/field/limitFields/limitFields.C new file mode 100644 index 0000000000..c89d230848 --- /dev/null +++ b/src/functionObjects/field/limitFields/limitFields.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#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(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("min"); + Info<< " Imposing lower limit " << min_ << nl; + } + + if (limit_ & MAX) + { + max_ = dict.get("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(fieldName) + || limitField(fieldName) + || limitField(fieldName) + || limitField(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(fieldName).write(); + } + + return true; +} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/limitFields/limitFields.H b/src/functionObjects/field/limitFields/limitFields.H new file mode 100644 index 0000000000..9a8e9dec37 --- /dev/null +++ b/src/functionObjects/field/limitFields/limitFields.H @@ -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 . + +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 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 + 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 + +// ************************************************************************* // diff --git a/src/functionObjects/field/limitFields/limitFieldsTemplates.C b/src/functionObjects/field/limitFields/limitFieldsTemplates.C new file mode 100644 index 0000000000..3e1bc00483 --- /dev/null +++ b/src/functionObjects/field/limitFields/limitFieldsTemplates.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#include "limitFields.H" +#include "volFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +bool Foam::functionObjects::limitFields::limitField(const word& fieldName) +{ + typedef GeometricField VolFieldType; + + auto* fieldPtr = getObjectPtr(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; +} + + +// ************************************************************************* //