From 94df19a93a49fdb2812d230e5dc5fb830223500e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 3 Mar 2023 18:12:29 +0100 Subject: [PATCH] ENH: add finiteArea outletInlet patch type STYLE: use readValueEntry and Field assign to simplify code --- src/finiteArea/Make/files | 1 + .../inletOutlet/inletOutletFaPatchField.C | 19 +- .../inletOutlet/inletOutletFaPatchField.H | 66 +++--- .../inletOutlet/inletOutletFaPatchFields.C | 12 +- .../outletInlet/outletInletFaPatchField.C | 139 +++++++++++++ .../outletInlet/outletInletFaPatchField.H | 190 ++++++++++++++++++ .../outletInlet/outletInletFaPatchFields.C | 41 ++++ .../outletInlet/outletInletFaPatchFields.H | 50 +++++ .../inletOutlet/inletOutletFvPatchField.C | 11 +- .../inletOutlet/inletOutletFvPatchField.H | 6 +- .../outletInlet/outletInletFvPatchField.C | 11 +- .../outletInlet/outletInletFvPatchField.H | 6 +- 12 files changed, 483 insertions(+), 69 deletions(-) create mode 100644 src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchField.C create mode 100644 src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchField.H create mode 100644 src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchFields.C create mode 100644 src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchFields.H diff --git a/src/finiteArea/Make/files b/src/finiteArea/Make/files index 3743ff8522..a929066eed 100644 --- a/src/finiteArea/Make/files +++ b/src/finiteArea/Make/files @@ -62,6 +62,7 @@ $(constraintFaPatchFields)/symmetry/symmetryFaPatchFields.C derivedFaPatchFields = $(faPatchFields)/derived $(derivedFaPatchFields)/fixedValueOutflow/fixedValueOutflowFaPatchFields.C $(derivedFaPatchFields)/inletOutlet/inletOutletFaPatchFields.C +$(derivedFaPatchFields)/outletInlet/outletInletFaPatchFields.C $(derivedFaPatchFields)/slip/slipFaPatchFields.C $(derivedFaPatchFields)/edgeNormalFixedValue/edgeNormalFixedValueFaPatchVectorField.C $(derivedFaPatchFields)/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFaPatchFields.C diff --git a/src/finiteArea/fields/faPatchFields/derived/inletOutlet/inletOutletFaPatchField.C b/src/finiteArea/fields/faPatchFields/derived/inletOutlet/inletOutletFaPatchField.C index 9c9749be92..001faa1012 100644 --- a/src/finiteArea/fields/faPatchFields/derived/inletOutlet/inletOutletFaPatchField.C +++ b/src/finiteArea/fields/faPatchFields/derived/inletOutlet/inletOutletFaPatchField.C @@ -40,8 +40,8 @@ Foam::inletOutletFaPatchField::inletOutletFaPatchField mixedFaPatchField(p, iF), phiName_("phi") { - this->refValue() = pTraits::zero; - this->refGrad() = pTraits::zero; + this->refValue() = Zero; + this->refGrad() = Zero; this->valueFraction() = 0.0; } @@ -71,21 +71,16 @@ Foam::inletOutletFaPatchField::inletOutletFaPatchField mixedFaPatchField(p, iF), phiName_(dict.getOrDefault("phi", "phi")) { - this->refValue() = Field("inletValue", dict, p.size()); + faPatchFieldBase::readDict(dict); - if (dict.found("value")) - { - faPatchField::operator= - ( - Field("value", dict, p.size()) - ); - } - else + this->refValue().assign("inletValue", dict, p.size()); + + if (!this->readValueEntry(dict)) { faPatchField::operator=(this->refValue()); } - this->refGrad() = pTraits::zero; + this->refGrad() = Zero; this->valueFraction() = 0.0; } diff --git a/src/finiteArea/fields/faPatchFields/derived/inletOutlet/inletOutletFaPatchField.H b/src/finiteArea/fields/faPatchFields/derived/inletOutlet/inletOutletFaPatchField.H index 669b0b5078..85e2c34108 100644 --- a/src/finiteArea/fields/faPatchFields/derived/inletOutlet/inletOutletFaPatchField.H +++ b/src/finiteArea/fields/faPatchFields/derived/inletOutlet/inletOutletFaPatchField.H @@ -27,19 +27,52 @@ License Class Foam::inletOutletFaPatchField -Description +Group + grpOutletBoundaryConditions -Author - Zeljko Tukovic, FMENA - Hrvoje Jasak, Wikki Ltd. +Description + This boundary condition provides a generic outflow condition, with + specified inflow for the case of return flow. + +Usage + \table + Property | Description | Required | Default value + phi | Flux field name | no | phi + inletValue | Inlet value for reverse flow | yes | + \endtable + + Example of the boundary condition specification: + \verbatim + + { + type inletOutlet; + phi phi; + inletValue uniform 0; + value uniform 0; + } + \endverbatim + + The mode of operation is determined by the sign of the flux across the + patch edges. + + +Note + Sign conventions: + - Positive flux (out of domain): apply zero-gradient condition + - Negative flux (into domain): apply the "inletValue" fixed-value + +See also + Foam::mixedFaPatchField + Foam::zeroGradientFaPatchField + Foam::outletInletFaPatchField SourceFiles inletOutletFaPatchField.C \*---------------------------------------------------------------------------*/ -#ifndef inletOutletFaPatchField_H -#define inletOutletFaPatchField_H +#ifndef Foam_inletOutletFaPatchField_H +#define Foam_inletOutletFaPatchField_H #include "mixedFaPatchField.H" @@ -57,11 +90,11 @@ class inletOutletFaPatchField : public mixedFaPatchField { - protected: - // Protected data + // Protected Data + //- Name of flux field word phiName_; @@ -136,22 +169,7 @@ public: virtual ~inletOutletFaPatchField() = default; - // Member functions - - // Access - - //- Return the name of phi - const word& phiName() const - { - return phiName_; - } - - //- Return reference to the name of phi to allow adjustment - word& phiName() - { - return phiName_; - } - + // Member Functions //- Update the coefficients associated with the patch field virtual void updateCoeffs(); diff --git a/src/finiteArea/fields/faPatchFields/derived/inletOutlet/inletOutletFaPatchFields.C b/src/finiteArea/fields/faPatchFields/derived/inletOutlet/inletOutletFaPatchFields.C index 8e775f4376..73132add95 100644 --- a/src/finiteArea/fields/faPatchFields/derived/inletOutlet/inletOutletFaPatchFields.C +++ b/src/finiteArea/fields/faPatchFields/derived/inletOutlet/inletOutletFaPatchFields.C @@ -30,17 +30,11 @@ License #include "inletOutletFaPatchFields.H" #include "addToRunTimeSelectionTable.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -makeFaPatchFields(inletOutlet); - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam + makeFaPatchFields(inletOutlet); +} // ************************************************************************* // diff --git a/src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchField.C b/src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchField.C new file mode 100644 index 0000000000..be919d76fb --- /dev/null +++ b/src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchField.C @@ -0,0 +1,139 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2023 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 "outletInletFaPatchField.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::outletInletFaPatchField::outletInletFaPatchField +( + const faPatch& p, + const DimensionedField& iF +) +: + mixedFaPatchField(p, iF), + phiName_("phi") +{ + this->refValue() = *this; + this->refGrad() = Zero; + this->valueFraction() = 0.0; +} + + +template +Foam::outletInletFaPatchField::outletInletFaPatchField +( + const outletInletFaPatchField& ptf, + const faPatch& p, + const DimensionedField& iF, + const faPatchFieldMapper& mapper +) +: + mixedFaPatchField(ptf, p, iF, mapper), + phiName_(ptf.phiName_) +{} + + +template +Foam::outletInletFaPatchField::outletInletFaPatchField +( + const faPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + mixedFaPatchField(p, iF), + phiName_(dict.getOrDefault("phi", "phi")) +{ + faPatchFieldBase::readDict(dict); + + this->refValue().assign("outletValue", dict, p.size()); + + if (!this->readValueEntry(dict)) + { + faPatchField::operator=(this->refValue()); + } + + this->refGrad() = Zero; + this->valueFraction() = 0.0; +} + + +template +Foam::outletInletFaPatchField::outletInletFaPatchField +( + const outletInletFaPatchField& ptf +) +: + mixedFaPatchField(ptf), + phiName_(ptf.phiName_) +{} + + +template +Foam::outletInletFaPatchField::outletInletFaPatchField +( + const outletInletFaPatchField& ptf, + const DimensionedField& iF +) +: + mixedFaPatchField(ptf, iF), + phiName_(ptf.phiName_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::outletInletFaPatchField::updateCoeffs() +{ + if (this->updated()) + { + return; + } + + const Field& phip = + this->patch().template lookupPatchField(phiName_); + + this->valueFraction() = pos0(phip); + + mixedFaPatchField::updateCoeffs(); +} + + +template +void Foam::outletInletFaPatchField::write(Ostream& os) const +{ + faPatchField::write(os); + os.writeEntryIfDifferent("phi", "phi", phiName_); + this->refValue().writeEntry("outletValue", os); + faPatchField::writeValueEntry(os); +} + + +// ************************************************************************* // diff --git a/src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchField.H b/src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchField.H new file mode 100644 index 0000000000..47ba41fba7 --- /dev/null +++ b/src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchField.H @@ -0,0 +1,190 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2023 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::outletInletFaPatchField + +Group + grpInletBoundaryConditions + +Description + This boundary condition provides a generic inflow condition, with + specified outflow for the case of reverse flow. + +Usage + \table + Property | Description | Required | Default value + phi | Flux field name | no | phi + outletValue | Outlet value for reverse flow | yes | + \endtable + + Example of the boundary condition specification: + \verbatim + + { + type outletInlet; + phi phi; + outletValue uniform 0; + value uniform 0; + } + \endverbatim + + The mode of operation is determined by the sign of the flux across the + patch edges. + +Note + Sign conventions: + - Positive flux (out of domain): apply the "outletValue" fixed-value + - Negative flux (into domain): apply zero-gradient condition + +See also + Foam::mixedFaPatchField + Foam::zeroGradientFaPatchField + Foam::inletOutletFaPatchField + +SourceFiles + outletInletFaPatchField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef Foam_outletInletFaPatchField_H +#define Foam_outletInletFaPatchField_H + +#include "mixedFaPatchField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class outletInletFaPatch Declaration +\*---------------------------------------------------------------------------*/ + +template +class outletInletFaPatchField +: + public mixedFaPatchField +{ +protected: + + // Protected Data + + //- Name of flux field + word phiName_; + + +public: + + //- Runtime type information + TypeName("outletInlet"); + + + // Constructors + + //- Construct from patch and internal field + outletInletFaPatchField + ( + const faPatch&, + const DimensionedField& + ); + + //- Construct from patch, internal field and dictionary + outletInletFaPatchField + ( + const faPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given outletInletFaPatchField onto a new patch + outletInletFaPatchField + ( + const outletInletFaPatchField&, + const faPatch&, + const DimensionedField&, + const faPatchFieldMapper& + ); + + //- Construct as copy + outletInletFaPatchField + ( + const outletInletFaPatchField& + ); + + //- Construct and return a clone + virtual tmp> clone() const + { + return tmp> + ( + new outletInletFaPatchField(*this) + ); + } + + //- Construct as copy setting internal field reference + outletInletFaPatchField + ( + const outletInletFaPatchField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp> clone + ( + const DimensionedField& iF + ) const + { + return tmp> + ( + new outletInletFaPatchField(*this, iF) + ); + } + + + // Member Functions + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "outletInletFaPatchField.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchFields.C b/src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchFields.C new file mode 100644 index 0000000000..95741aeeea --- /dev/null +++ b/src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchFields.C @@ -0,0 +1,41 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2023 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 "areaFields.H" +#include "edgeFields.H" +#include "outletInletFaPatchFields.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + makeFaPatchFields(outletInlet); +} + + +// ************************************************************************* // diff --git a/src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchFields.H b/src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchFields.H new file mode 100644 index 0000000000..66a88dbfbe --- /dev/null +++ b/src/finiteArea/fields/faPatchFields/derived/outletInlet/outletInletFaPatchFields.H @@ -0,0 +1,50 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2023 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 Foam_outletInletFaPatchFields_H +#define Foam_outletInletFaPatchFields_H + +#include "outletInletFaPatchField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +makeFaPatchTypeFieldTypedefs(outletInlet); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/inletOutlet/inletOutletFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/inletOutlet/inletOutletFvPatchField.C index 459620bf6b..c926569410 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/inletOutlet/inletOutletFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/inletOutlet/inletOutletFvPatchField.C @@ -73,16 +73,9 @@ Foam::inletOutletFvPatchField::inletOutletFvPatchField { fvPatchFieldBase::readDict(dict); - this->refValue() = Field("inletValue", dict, p.size()); + this->refValue().assign("inletValue", dict, p.size()); - if (dict.found("value")) - { - fvPatchField::operator= - ( - Field("value", dict, p.size()) - ); - } - else + if (!this->readValueEntry(dict)) { fvPatchField::operator=(this->refValue()); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/inletOutlet/inletOutletFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/inletOutlet/inletOutletFvPatchField.H index a1d1e522a4..0462c6bc0e 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/inletOutlet/inletOutletFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/inletOutlet/inletOutletFvPatchField.H @@ -57,7 +57,7 @@ Usage Note Sign conventions: - Positive flux (out of domain): apply zero-gradient condition - - Negative flux (into of domain): apply the "inletValue" fixed-value + - Negative flux (into domain): apply the "inletValue" fixed-value See also Foam::mixedFvPatchField @@ -69,8 +69,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef inletOutletFvPatchField_H -#define inletOutletFvPatchField_H +#ifndef Foam_inletOutletFvPatchField_H +#define Foam_inletOutletFvPatchField_H #include "mixedFvPatchField.H" diff --git a/src/finiteVolume/fields/fvPatchFields/derived/outletInlet/outletInletFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/outletInlet/outletInletFvPatchField.C index 8c621154a3..37455d8f86 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/outletInlet/outletInletFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/outletInlet/outletInletFvPatchField.C @@ -73,16 +73,9 @@ Foam::outletInletFvPatchField::outletInletFvPatchField { fvPatchFieldBase::readDict(dict); - this->refValue() = Field("outletValue", dict, p.size()); + this->refValue().assign("outletValue", dict, p.size()); - if (dict.found("value")) - { - fvPatchField::operator= - ( - Field("value", dict, p.size()) - ); - } - else + if (!this->readValueEntry(dict)) { fvPatchField::operator=(this->refValue()); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/outletInlet/outletInletFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/outletInlet/outletInletFvPatchField.H index 3da5df5604..1d192b571b 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/outletInlet/outletInletFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/outletInlet/outletInletFvPatchField.H @@ -57,7 +57,7 @@ Usage Note Sign conventions: - Positive flux (out of domain): apply the "outletValue" fixed-value - - Negative flux (into of domain): apply zero-gradient condition + - Negative flux (into domain): apply zero-gradient condition See also Foam::mixedFvPatchField @@ -69,8 +69,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef outletInletFvPatchField_H -#define outletInletFvPatchField_H +#ifndef Foam_outletInletFvPatchField_H +#define Foam_outletInletFvPatchField_H #include "mixedFvPatchField.H"