From e8bcf4cb1be2978a04f3266203e25bbc81547b1d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 16 Feb 2023 17:09:17 +0100 Subject: [PATCH] ENH: additional uniform boundary conditions (#2703) - provide uniformMixed conditions for finite-area and finite-volume. These are intended to replace the exprMixed condition but allow the full range of different PatchFunction1 and Function1 types. - add uniformFixedGradient to finite-area for completeness. Note: - still some possible difficulties with the order of evaluation. - eg, using an expression within the 'U' field that depends of the surface 'phi' field before that is constructed. In this case, the 'value' entry is really needed. --- src/finiteArea/Make/files | 2 + .../uniformFixedGradientFaPatchField.C | 161 ++++++++++++ .../uniformFixedGradientFaPatchField.H | 188 ++++++++++++++ .../uniformFixedGradientFaPatchFields.C | 40 +++ .../uniformFixedGradientFaPatchFields.H | 50 ++++ .../uniformFixedValueFaPatchField.C | 6 +- .../uniformMixed/uniformMixedFaPatchField.C | 245 ++++++++++++++++++ .../uniformMixed/uniformMixedFaPatchField.H | 210 +++++++++++++++ .../uniformMixed/uniformMixedFaPatchFields.C | 40 +++ .../uniformMixed/uniformMixedFaPatchFields.H | 50 ++++ src/finiteVolume/Make/files | 1 + .../uniformFixedGradientFvPatchField.C | 31 ++- .../uniformFixedGradientFvPatchField.H | 10 +- .../uniformFixedValueFvPatchField.C | 15 +- .../uniformFixedValueFvPatchField.H | 2 +- .../uniformMixed/uniformMixedFvPatchField.C | 235 +++++++++++++++++ .../uniformMixed/uniformMixedFvPatchField.H | 213 +++++++++++++++ .../uniformMixed/uniformMixedFvPatchFields.C | 39 +++ .../uniformMixed/uniformMixedFvPatchFields.H | 50 ++++ .../uniformFixedValuePointPatchField.C | 23 +- .../rhoPimpleFoam/RAS/TJunctionAverage/0/U | 16 +- 21 files changed, 1589 insertions(+), 38 deletions(-) create mode 100644 src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchField.C create mode 100644 src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchField.H create mode 100644 src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchFields.C create mode 100644 src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchFields.H create mode 100644 src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchField.C create mode 100644 src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchField.H create mode 100644 src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchFields.C create mode 100644 src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchFields.H create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchField.C create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchField.H create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchFields.C create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchFields.H diff --git a/src/finiteArea/Make/files b/src/finiteArea/Make/files index 039386be84..803c8df34f 100644 --- a/src/finiteArea/Make/files +++ b/src/finiteArea/Make/files @@ -68,7 +68,9 @@ $(derivedFaPatchFields)/outletInlet/outletInletFaPatchFields.C $(derivedFaPatchFields)/slip/slipFaPatchFields.C $(derivedFaPatchFields)/edgeNormalFixedValue/edgeNormalFixedValueFaPatchVectorField.C $(derivedFaPatchFields)/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFaPatchFields.C +$(derivedFaPatchFields)/uniformFixedGradient/uniformFixedGradientFaPatchFields.C $(derivedFaPatchFields)/uniformFixedValue/uniformFixedValueFaPatchFields.C +$(derivedFaPatchFields)/uniformMixed/uniformMixedFaPatchFields.C $(derivedFaPatchFields)/ignore/ignoreFaPatchFields.C $(derivedFaPatchFields)/clampedPlate/clampedPlateFaPatchFields.C diff --git a/src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchField.C b/src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchField.C new file mode 100644 index 0000000000..f74667880c --- /dev/null +++ b/src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchField.C @@ -0,0 +1,161 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 "uniformFixedGradientFaPatchField.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::uniformFixedGradientFaPatchField::uniformFixedGradientFaPatchField +( + const faPatch& p, + const DimensionedField& iF +) +: + fixedGradientFaPatchField(p, iF), + refGradFunc_(nullptr) +{} + + +template +Foam::uniformFixedGradientFaPatchField::uniformFixedGradientFaPatchField +( + const faPatch& p, + const DimensionedField& iF, + const Field& fld +) +: + fixedGradientFaPatchField(p, iF, fld), + refGradFunc_(nullptr) +{} + + +template +Foam::uniformFixedGradientFaPatchField::uniformFixedGradientFaPatchField +( + const faPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + fixedGradientFaPatchField(p, iF), // Bypass dictionary constructor + refGradFunc_ + ( + Function1::New + ( + /* p.patch(), */ + "uniformGradient", + dict + ) + ) +{ + this->evaluate(); +} + + +template +Foam::uniformFixedGradientFaPatchField::uniformFixedGradientFaPatchField +( + const uniformFixedGradientFaPatchField& ptf, + const faPatch& p, + const DimensionedField& iF, + const faPatchFieldMapper& mapper +) +: + fixedGradientFaPatchField(ptf, p, iF, mapper), + refGradFunc_(ptf.refGradFunc_.clone(/*p.patch()*/)) +{} + + +template +Foam::uniformFixedGradientFaPatchField::uniformFixedGradientFaPatchField +( + const uniformFixedGradientFaPatchField& ptf +) +: + fixedGradientFaPatchField(ptf), + refGradFunc_(ptf.refGradFunc_.clone(/*p.patch()*/)) +{} + + +template +Foam::uniformFixedGradientFaPatchField::uniformFixedGradientFaPatchField +( + const uniformFixedGradientFaPatchField& ptf, + const DimensionedField& iF +) +: + fixedGradientFaPatchField(ptf, iF), + refGradFunc_(ptf.refGradFunc_.clone(/*this->patch().patch()*/)) +{ + // Evaluate the profile if defined + if (refGradFunc_) + { + this->evaluate(); + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::uniformFixedGradientFaPatchField::updateCoeffs() +{ + if (this->updated()) + { + return; + } + + const scalar t = this->db().time().timeOutputValue(); + + // Extra safety on the evaluation + if (refGradFunc_) + { + this->gradient() = refGradFunc_->value(t); + } + else + { + this->gradient() = Zero; + } + + fixedGradientFaPatchField::updateCoeffs(); +} + + +template +void Foam::uniformFixedGradientFaPatchField::write(Ostream& os) const +{ + fixedGradientFaPatchField::write(os); + if (refGradFunc_) + { + refGradFunc_->writeData(os); + } + faPatchField::writeValueEntry(os); +} + + +// ************************************************************************* // diff --git a/src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchField.H b/src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchField.H new file mode 100644 index 0000000000..52e0f026b6 --- /dev/null +++ b/src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchField.H @@ -0,0 +1,188 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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::uniformFixedGradientFaPatchField + +Group + grpGenericBoundaryConditions + +Description + This boundary condition provides a uniform fixed gradient condition. + +Usage + \table + Property | Description | Required | Default + uniformGradient | uniform gradient | yes | + \endtable + + Example of the boundary condition specification: + \verbatim + + { + type uniformFixedGradient; + uniformGradient constant 0.2; + } + \endverbatim + +Note + The uniformGradient entry is a Function1 type. + The example above gives the usage for supplying a constant value. + +See also + Foam::Function1Types + Foam::fixedGradientFaPatchField + +SourceFiles + uniformFixedGradientFaPatchField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef Foam_uniformFixedGradientFaPatchField_H +#define Foam_uniformFixedGradientFaPatchField_H + +#include "fixedGradientFaPatchField.H" +#include "PatchFunction1.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class uniformFixedGradientFaPatchField Declaration +\*---------------------------------------------------------------------------*/ + +template +class uniformFixedGradientFaPatchField +: + public fixedGradientFaPatchField +{ + // Private Data + + //- Function providing the gradient + autoPtr> refGradFunc_; + + +public: + + //- Runtime type information + TypeName("uniformFixedGradient"); + + + // Constructors + + //- Construct from patch and internal field + uniformFixedGradientFaPatchField + ( + const faPatch&, + const DimensionedField& + ); + + //- Construct from patch and internal field and patch field + uniformFixedGradientFaPatchField + ( + const faPatch&, + const DimensionedField&, + const Field& fld + ); + + //- Construct from patch, internal field and dictionary + uniformFixedGradientFaPatchField + ( + const faPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping onto a new patch + uniformFixedGradientFaPatchField + ( + const uniformFixedGradientFaPatchField&, + const faPatch&, + const DimensionedField&, + const faPatchFieldMapper& + ); + + //- Construct as copy + uniformFixedGradientFaPatchField + ( + const uniformFixedGradientFaPatchField& + ); + + //- Construct and return a clone + virtual tmp> clone() const + { + return tmp> + ( + new uniformFixedGradientFaPatchField(*this) + ); + } + + //- Construct as copy setting internal field reference + uniformFixedGradientFaPatchField + ( + const uniformFixedGradientFaPatchField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp> clone + ( + const DimensionedField& iF + ) const + { + return tmp> + ( + new uniformFixedGradientFaPatchField(*this, iF) + ); + } + + + // Member functions + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + //- Write + virtual void write(Ostream& os) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "uniformFixedGradientFaPatchField.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchFields.C b/src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchFields.C new file mode 100644 index 0000000000..2e6a854e5c --- /dev/null +++ b/src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchFields.C @@ -0,0 +1,40 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 "uniformFixedGradientFaPatchFields.H" +#include "addToRunTimeSelectionTable.H" +#include "areaFields.H" +#include "edgeFields.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + makeFaPatchFields(uniformFixedGradient); +} + +// ************************************************************************* // diff --git a/src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchFields.H b/src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchFields.H new file mode 100644 index 0000000000..7e7a2973d6 --- /dev/null +++ b/src/finiteArea/fields/faPatchFields/derived/uniformFixedGradient/uniformFixedGradientFaPatchFields.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_uniformFixedGradientFaPatchFields_H +#define Foam_uniformFixedGradientFaPatchFields_H + +#include "uniformFixedGradientFaPatchField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +makeFaPatchTypeFieldTypedefs(uniformFixedGradient); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteArea/fields/faPatchFields/derived/uniformFixedValue/uniformFixedValueFaPatchField.C b/src/finiteArea/fields/faPatchFields/derived/uniformFixedValue/uniformFixedValueFaPatchField.C index a02dd23823..804b049a5f 100644 --- a/src/finiteArea/fields/faPatchFields/derived/uniformFixedValue/uniformFixedValueFaPatchField.C +++ b/src/finiteArea/fields/faPatchFields/derived/uniformFixedValue/uniformFixedValueFaPatchField.C @@ -73,11 +73,7 @@ Foam::uniformFixedValueFaPatchField::uniformFixedValueFaPatchField ) ) { - if (this->readValueEntry(dict)) - { - // Full restart - } - else + if (!this->readValueEntry(dict)) { this->evaluate(); } diff --git a/src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchField.C b/src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchField.C new file mode 100644 index 0000000000..82ee838495 --- /dev/null +++ b/src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchField.C @@ -0,0 +1,245 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 "uniformMixedFaPatchField.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::uniformMixedFaPatchField::uniformMixedFaPatchField +( + const faPatch& p, + const DimensionedField& iF +) +: + mixedFaPatchField(p, iF), + refValueFunc_(nullptr), + refGradFunc_(nullptr), + valueFractionFunc_(nullptr) +{} + + +template +Foam::uniformMixedFaPatchField::uniformMixedFaPatchField +( + const faPatch& p, + const DimensionedField& iF, + const Field& fld +) +: + mixedFaPatchField(p, iF, fld), + refValueFunc_(nullptr), + refGradFunc_(nullptr), + valueFractionFunc_(nullptr) +{} + + +template +Foam::uniformMixedFaPatchField::uniformMixedFaPatchField +( + const faPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + mixedFaPatchField(p, iF, dict, IOobjectOption::NO_READ), + refValueFunc_ + ( + Function1::NewIfPresent + ( + /* p.patch(), */ + "uniformValue", + dict + ) + ), + refGradFunc_ + ( + Function1::NewIfPresent + ( + // p.patch(), + "uniformGradient", + dict + ) + ), + valueFractionFunc_(nullptr) +{ + if (refValueFunc_) + { + if (refGradFunc_) + { + // Both value + gradient: needs valueFraction + valueFractionFunc_.reset + ( + Function1::New + ( + /* p.patch(), */ + "uniformValueFraction", + dict + ) + ); + } + } + else if (!refGradFunc_) + { + // Missing both value and gradient: FatalIOError + FatalIOErrorInFunction(dict) + << "For " << this->internalField().name() << " on " + << this->patch().name() << nl + << "Require either or both: uniformValue and uniformGradient" + << " (possibly uniformValueFraction as well)" << nl + << exit(FatalIOError); + } + + // Use restart value if provided... + if (!this->readValueEntry(dict)) + { + this->evaluate(); + } +} + + +template +Foam::uniformMixedFaPatchField::uniformMixedFaPatchField +( + const uniformMixedFaPatchField& ptf, + const faPatch& p, + const DimensionedField& iF, + const faPatchFieldMapper& mapper +) +: + mixedFaPatchField(ptf, p, iF, mapper), + refValueFunc_(ptf.refValueFunc_.clone(/*p.patch()*/)), + refGradFunc_(ptf.refGradFunc_.clone(/*p.patch()*/)), + valueFractionFunc_(ptf.valueFractionFunc_.clone(/*p.patch()*/)) +{} + + +template +Foam::uniformMixedFaPatchField::uniformMixedFaPatchField +( + const uniformMixedFaPatchField& ptf +) +: + mixedFaPatchField(ptf), + refValueFunc_(ptf.refValueFunc_.clone(/*this->patch().patch()*/)), + refGradFunc_(ptf.refGradFunc_.clone(/*this->patch().patch()*/)), + valueFractionFunc_(ptf.valueFractionFunc_.clone(/*this->patch().patch()*/)) +{} + + +template +Foam::uniformMixedFaPatchField::uniformMixedFaPatchField +( + const uniformMixedFaPatchField& ptf, + const DimensionedField& iF +) +: + mixedFaPatchField(ptf, iF), + refValueFunc_(ptf.refValueFunc_.clone(/*this->patch().patch()*/)), + refGradFunc_(ptf.refGradFunc_.clone(/*this->patch().patch()*/)), + valueFractionFunc_(ptf.valueFractionFunc_.clone(/*this->patch().patch()*/)) +{ + // Evaluate the profile if defined + if (ptf.refValueFunc_ || ptf.refGradFunc_) + { + this->evaluate(); + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::uniformMixedFaPatchField::updateCoeffs() +{ + if (this->updated()) + { + return; + } + + const scalar t = this->db().time().timeOutputValue(); + + if (refValueFunc_) + { + this->refValue() = refValueFunc_->value(t); + + if (refGradFunc_) + { + // Both value + gradient: has valueFraction too + this->valueFraction() = valueFractionFunc_->value(t); + } + else + { + // Has value only + this->valueFraction() = 1; + } + } + else + { + this->refValue() = Zero; + this->valueFraction() = 0; + } + if (refGradFunc_) + { + this->refGrad() = refGradFunc_->value(t); + } + else + { + this->refGrad() = Zero; + } + + // Missing both value and gradient is caught as an error in + // dictionary constructor, but treated as zero-gradient here. + + mixedFaPatchField::updateCoeffs(); +} + + +template +void Foam::uniformMixedFaPatchField::write(Ostream& os) const +{ + faPatchField::write(os); + + if (refValueFunc_) + { + refValueFunc_->writeData(os); + } + if (refGradFunc_) + { + refGradFunc_->writeData(os); + } + if (valueFractionFunc_) + { + valueFractionFunc_->writeData(os); + } + + // Eg, for visualisation + faPatchField::writeValueEntry(os); +} + + +// ************************************************************************* // diff --git a/src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchField.H b/src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchField.H new file mode 100644 index 0000000000..bd2819f6f4 --- /dev/null +++ b/src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchField.H @@ -0,0 +1,210 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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::uniformMixedFaPatchField + +Group + grpGenericBoundaryConditions + +Description + This boundary condition provides 'mixed' type boundary condition + that mix a \em uniform fixed value and a \em uniform patch-normal + gradient condition. The term "uniform" is a legacy name since the + prescribed values were previously spatially uniform across that patch. + +Usage + \table + Property | Description | Required | Default + uniformValue | uniform value | partly | 0 + uniformGradient | uniform gradient | partly | 0 + uniformValueFraction | uniform valueFraction | partly | depends + \endtable + + Example of the boundary condition specification: + \verbatim + + { + type uniformMixed; + uniformValue constant 0.2; + uniformGradient constant 0.2; + uniformValueFraction + { + type sine; + ... + } + } + \endverbatim + +Note + This boundary condition allows \em lazier definitions so that either + or both: \c uniformValue and \c uniformGradient must be defined. + If only of these entries is defined, the value fraction is automatically + treated appropriately (ie, 0 with \c uniformGradient and 1 with + uniformValue). + If both \c uniformValue and \c uniformGradient are defined, + the \c uniformValueFraction must also be defined. + +See also + Foam::Function1Types + Foam::mixedFaPatchField + +SourceFiles + uniformMixedFaPatchField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef Foam_uniformMixedFaPatchField_H +#define Foam_uniformMixedFaPatchField_H + +#include "mixedFaPatchField.H" +#include "Function1.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class uniformMixedFaPatchField Declaration +\*---------------------------------------------------------------------------*/ + +template +class uniformMixedFaPatchField +: + public mixedFaPatchField +{ + // Private Data + + //- Function providing the value + autoPtr> refValueFunc_; + + //- Function providing the gradient + autoPtr> refGradFunc_; + + //- Function providing the value-fraction + autoPtr> valueFractionFunc_; + + +public: + + //- Runtime type information + TypeName("uniformMixed"); + + + // Constructors + + //- Construct from patch and internal field + uniformMixedFaPatchField + ( + const faPatch&, + const DimensionedField& + ); + + //- Construct from patch and internal field and patch field + uniformMixedFaPatchField + ( + const faPatch&, + const DimensionedField&, + const Field& fld + ); + + //- Construct from patch, internal field and dictionary + uniformMixedFaPatchField + ( + const faPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping onto a new patch + uniformMixedFaPatchField + ( + const uniformMixedFaPatchField&, + const faPatch&, + const DimensionedField&, + const faPatchFieldMapper& + ); + + //- Construct as copy + uniformMixedFaPatchField + ( + const uniformMixedFaPatchField& + ); + + //- Construct and return a clone + virtual tmp> clone() const + { + return tmp> + ( + new uniformMixedFaPatchField(*this) + ); + } + + //- Construct as copy setting internal field reference + uniformMixedFaPatchField + ( + const uniformMixedFaPatchField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp> clone + ( + const DimensionedField& iF + ) const + { + return tmp> + ( + new uniformMixedFaPatchField(*this, iF) + ); + } + + + // Member Functions + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + //- Write + virtual void write(Ostream& os) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "uniformMixedFaPatchField.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchFields.C b/src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchFields.C new file mode 100644 index 0000000000..d7f518c1a1 --- /dev/null +++ b/src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchFields.C @@ -0,0 +1,40 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 "uniformMixedFaPatchFields.H" +#include "addToRunTimeSelectionTable.H" +#include "areaFields.H" +#include "edgeFields.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + makeFaPatchFields(uniformMixed); +} + +// ************************************************************************* // diff --git a/src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchFields.H b/src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchFields.H new file mode 100644 index 0000000000..4f91619e41 --- /dev/null +++ b/src/finiteArea/fields/faPatchFields/derived/uniformMixed/uniformMixedFaPatchFields.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_uniformMixedFaPatchFields_H +#define Foam_uniformMixedFaPatchFields_H + +#include "uniformMixedFaPatchField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +makeFaPatchTypeFieldTypedefs(uniformMixed); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index aa58f5991c..dca1ff2d9f 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -227,6 +227,7 @@ $(derivedFvPatchFields)/turbulentIntensityKineticEnergyInlet/turbulentIntensityK $(derivedFvPatchFields)/uniformDensityHydrostaticPressure/uniformDensityHydrostaticPressureFvPatchScalarField.C $(derivedFvPatchFields)/uniformFixedGradient/uniformFixedGradientFvPatchFields.C $(derivedFvPatchFields)/uniformFixedValue/uniformFixedValueFvPatchFields.C +$(derivedFvPatchFields)/uniformMixed/uniformMixedFvPatchFields.C $(derivedFvPatchFields)/uniformInletOutlet/uniformInletOutletFvPatchFields.C $(derivedFvPatchFields)/uniformJump/uniformJumpFvPatchFields.C $(derivedFvPatchFields)/uniformJumpAMI/uniformJumpAMIFvPatchFields.C diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedGradient/uniformFixedGradientFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedGradient/uniformFixedGradientFvPatchField.C index 9be8715829..d265cadd19 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedGradient/uniformFixedGradientFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedGradient/uniformFixedGradientFvPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2013-2016 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -38,7 +38,7 @@ Foam::uniformFixedGradientFvPatchField::uniformFixedGradientFvPatchField ) : fixedGradientFvPatchField(p, iF), - uniformGradient_(nullptr) + refGradFunc_(nullptr) {} @@ -51,7 +51,7 @@ Foam::uniformFixedGradientFvPatchField::uniformFixedGradientFvPatchField ) : fixedGradientFvPatchField(p, iF, fld), - uniformGradient_(nullptr) + refGradFunc_(nullptr) {} @@ -64,7 +64,7 @@ Foam::uniformFixedGradientFvPatchField::uniformFixedGradientFvPatchField ) : fixedGradientFvPatchField(p, iF), // Bypass dictionary constructor - uniformGradient_ + refGradFunc_ ( PatchFunction1::New(p.patch(), "uniformGradient", dict) ) @@ -84,7 +84,7 @@ Foam::uniformFixedGradientFvPatchField::uniformFixedGradientFvPatchField ) : fixedGradientFvPatchField(ptf, p, iF, mapper), - uniformGradient_(ptf.uniformGradient_.clone()) + refGradFunc_(ptf.refGradFunc_.clone()) {} @@ -95,7 +95,7 @@ Foam::uniformFixedGradientFvPatchField::uniformFixedGradientFvPatchField ) : fixedGradientFvPatchField(ptf), - uniformGradient_(ptf.uniformGradient_.clone()) + refGradFunc_(ptf.refGradFunc_.clone()) {} @@ -107,10 +107,10 @@ Foam::uniformFixedGradientFvPatchField::uniformFixedGradientFvPatchField ) : fixedGradientFvPatchField(ptf, iF), - uniformGradient_(ptf.uniformGradient_.clone()) + refGradFunc_(ptf.refGradFunc_.clone()) { // Evaluate the profile if defined - if (ptf.uniformGradient_) + if (refGradFunc_) { this->evaluate(); } @@ -128,7 +128,15 @@ void Foam::uniformFixedGradientFvPatchField::updateCoeffs() } const scalar t = this->db().time().timeOutputValue(); - this->gradient() = uniformGradient_->value(t); + // Extra safety on the evaluation + if (refGradFunc_) + { + this->gradient() = refGradFunc_->value(t); + } + else + { + this->gradient() = Zero; + } fixedGradientFvPatchField::updateCoeffs(); } @@ -138,7 +146,10 @@ template void Foam::uniformFixedGradientFvPatchField::write(Ostream& os) const { fixedGradientFvPatchField::write(os); - uniformGradient_->writeData(os); + if (refGradFunc_) + { + refGradFunc_->writeData(os); + } fvPatchField::writeValueEntry(os); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedGradient/uniformFixedGradientFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedGradient/uniformFixedGradientFvPatchField.H index 0cce531299..34bdbb50a0 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedGradient/uniformFixedGradientFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedGradient/uniformFixedGradientFvPatchField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2013-2016 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -62,8 +62,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef uniformFixedGradientFvPatchField_H -#define uniformFixedGradientFvPatchField_H +#ifndef Foam_uniformFixedGradientFvPatchField_H +#define Foam_uniformFixedGradientFvPatchField_H #include "fixedGradientFvPatchFields.H" #include "PatchFunction1.H" @@ -84,8 +84,8 @@ class uniformFixedGradientFvPatchField { // Private Data - //- Gradient - autoPtr> uniformGradient_; + //- Function providing the gradient + autoPtr> refGradFunc_; public: diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.C index c1ba993d44..4e876b1a07 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.C @@ -134,12 +134,12 @@ void Foam::uniformFixedValueFvPatchField::autoMap if (refValueFunc_) { refValueFunc_().autoMap(mapper); - } - if (refValueFunc_().constant()) - { - // If mapper is not dependent on time we're ok to evaluate - this->evaluate(); + if (refValueFunc_().constant()) + { + // If mapper is not dependent on time we're ok to evaluate + this->evaluate(); + } } } @@ -156,7 +156,7 @@ void Foam::uniformFixedValueFvPatchField::rmap const uniformFixedValueFvPatchField& tiptf = refCast(ptf); - if (refValueFunc_) + if (refValueFunc_ && tiptf.refValueFunc_) { refValueFunc_().rmap(tiptf.refValueFunc_(), addr); } @@ -172,6 +172,7 @@ void Foam::uniformFixedValueFvPatchField::updateCoeffs() } const scalar t = this->db().time().timeOutputValue(); + fvPatchField::operator==(refValueFunc_->value(t)); fixedValueFvPatchField::updateCoeffs(); } @@ -181,12 +182,10 @@ template void Foam::uniformFixedValueFvPatchField::write(Ostream& os) const { fvPatchField::write(os); - if (refValueFunc_) { refValueFunc_->writeData(os); } - fvPatchField::writeValueEntry(os); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.H index f36be7f976..fa5f8a3442 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchField.C new file mode 100644 index 0000000000..c73934f4ec --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchField.C @@ -0,0 +1,235 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 "uniformMixedFvPatchField.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::uniformMixedFvPatchField::uniformMixedFvPatchField +( + const fvPatch& p, + const DimensionedField& iF +) +: + mixedFvPatchField(p, iF), + refValueFunc_(nullptr), + refGradFunc_(nullptr), + valueFractionFunc_(nullptr) +{} + + +template +Foam::uniformMixedFvPatchField::uniformMixedFvPatchField +( + const fvPatch& p, + const DimensionedField& iF, + const Field& fld +) +: + mixedFvPatchField(p, iF, fld), + refValueFunc_(nullptr), + refGradFunc_(nullptr), + valueFractionFunc_(nullptr) +{} + + +template +Foam::uniformMixedFvPatchField::uniformMixedFvPatchField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + mixedFvPatchField(p, iF, dict, IOobjectOption::NO_READ), + refValueFunc_ + ( + PatchFunction1::NewIfPresent(p.patch(), "uniformValue", dict) + ), + refGradFunc_ + ( + PatchFunction1::NewIfPresent(p.patch(), "uniformGradient", dict) + ), + valueFractionFunc_(nullptr) +{ + if (refValueFunc_) + { + if (refGradFunc_) + { + // Both value + gradient: needs valueFraction + valueFractionFunc_.reset + ( + PatchFunction1::New + ( + p.patch(), + "uniformValueFraction", + dict + ) + ); + } + } + else if (!refGradFunc_) + { + // Missing both value and gradient: FatalIOError + FatalIOErrorInFunction(dict) + << "For " << this->internalField().name() << " on " + << this->patch().name() << nl + << "Require either or both: uniformValue and uniformGradient" + << " (possibly uniformValueFraction as well)" << nl + << exit(FatalIOError); + } + + // Use restart value if provided... + if (!this->readValueEntry(dict)) + { + this->evaluate(); + } +} + + +template +Foam::uniformMixedFvPatchField::uniformMixedFvPatchField +( + const uniformMixedFvPatchField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + mixedFvPatchField(ptf, p, iF, mapper), + refValueFunc_(ptf.refValueFunc_.clone(p.patch())), + refGradFunc_(ptf.refGradFunc_.clone(p.patch())), + valueFractionFunc_(ptf.valueFractionFunc_.clone(p.patch())) +{} + + +template +Foam::uniformMixedFvPatchField::uniformMixedFvPatchField +( + const uniformMixedFvPatchField& ptf +) +: + mixedFvPatchField(ptf), + refValueFunc_(ptf.refValueFunc_.clone(this->patch().patch())), + refGradFunc_(ptf.refGradFunc_.clone(this->patch().patch())), + valueFractionFunc_(ptf.valueFractionFunc_.clone(this->patch().patch())) +{} + + +template +Foam::uniformMixedFvPatchField::uniformMixedFvPatchField +( + const uniformMixedFvPatchField& ptf, + const DimensionedField& iF +) +: + mixedFvPatchField(ptf, iF), + refValueFunc_(ptf.refValueFunc_.clone(this->patch().patch())), + refGradFunc_(ptf.refGradFunc_.clone(this->patch().patch())), + valueFractionFunc_(ptf.valueFractionFunc_.clone(this->patch().patch())) +{ + // Evaluate the profile if defined + if (ptf.refValueFunc_ || ptf.refGradFunc_) + { + this->evaluate(); + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::uniformMixedFvPatchField::updateCoeffs() +{ + if (this->updated()) + { + return; + } + + const scalar t = this->db().time().timeOutputValue(); + + if (refValueFunc_) + { + this->refValue() = refValueFunc_->value(t); + + if (refGradFunc_) + { + // Both value + gradient: has valueFraction too + this->valueFraction() = valueFractionFunc_->value(t); + } + else + { + // Has value only + this->valueFraction() = 1; + } + } + else + { + this->refValue() = Zero; + this->valueFraction() = 0; + } + if (refGradFunc_) + { + this->refGrad() = refGradFunc_->value(t); + } + else + { + this->refGrad() = Zero; + } + + // Missing both value and gradient is caught as an error in + // dictionary constructor, but treated as zero-gradient here. + + mixedFvPatchField::updateCoeffs(); +} + + +template +void Foam::uniformMixedFvPatchField::write(Ostream& os) const +{ + fvPatchField::write(os); + + if (refValueFunc_) + { + refValueFunc_->writeData(os); + } + if (refGradFunc_) + { + refGradFunc_->writeData(os); + } + if (valueFractionFunc_) + { + valueFractionFunc_->writeData(os); + } + + // Eg, for visualisation + fvPatchField::writeValueEntry(os); +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchField.H new file mode 100644 index 0000000000..ccaa055b31 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchField.H @@ -0,0 +1,213 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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::uniformMixedFvPatchField + +Group + grpGenericBoundaryConditions + +Description + This boundary condition provides 'mixed' type boundary condition + that mix a \em uniform fixed value and a \em uniform patch-normal + gradient condition. The term "uniform" is a legacy name since the + prescribed values were previously spatially uniform across that patch. + + In the meantime, a PatchFunction1 is used, which can have both + spatial and temporal dependencies. + +Usage + \table + Property | Description | Required | Default + uniformValue | uniform value | partly | 0 + uniformGradient | uniform gradient | partly | 0 + uniformValueFraction | uniform valueFraction | partly | depends + \endtable + + Example of the boundary condition specification: + \verbatim + + { + type uniformMixed; + uniformValue constant 0.2; + uniformGradient constant 0.2; + uniformValueFraction + { + type sine; + ... + } + } + \endverbatim + +Note + This boundary condition allows \em lazier definitions so that either + or both: \c uniformValue and \c uniformGradient must be defined. + If only of these entries is defined, the value fraction is automatically + treated appropriately (ie, 0 with \c uniformGradient and 1 with + uniformValue). + If both \c uniformValue and \c uniformGradient are defined, + the \c uniformValueFraction must also be defined. + +See also + Foam::Function1Types + Foam::mixedFvPatchField + +SourceFiles + uniformMixedFvPatchField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef Foam_uniformMixedFvPatchField_H +#define Foam_uniformMixedFvPatchField_H + +#include "mixedFvPatchField.H" +#include "PatchFunction1.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class uniformMixedFvPatchField Declaration +\*---------------------------------------------------------------------------*/ + +template +class uniformMixedFvPatchField +: + public mixedFvPatchField +{ + // Private Data + + //- Function providing the value + autoPtr> refValueFunc_; + + //- Function providing the gradient + autoPtr> refGradFunc_; + + //- Function providing the value-fraction + autoPtr> valueFractionFunc_; + + +public: + + //- Runtime type information + TypeName("uniformMixed"); + + + // Constructors + + //- Construct from patch and internal field + uniformMixedFvPatchField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct from patch and internal field and patch field + uniformMixedFvPatchField + ( + const fvPatch&, + const DimensionedField&, + const Field& fld + ); + + //- Construct from patch, internal field and dictionary + uniformMixedFvPatchField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping onto a new patch + uniformMixedFvPatchField + ( + const uniformMixedFvPatchField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + uniformMixedFvPatchField + ( + const uniformMixedFvPatchField& + ); + + //- Construct and return a clone + virtual tmp> clone() const + { + return tmp> + ( + new uniformMixedFvPatchField(*this) + ); + } + + //- Construct as copy setting internal field reference + uniformMixedFvPatchField + ( + const uniformMixedFvPatchField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp> clone + ( + const DimensionedField& iF + ) const + { + return tmp> + ( + new uniformMixedFvPatchField(*this, iF) + ); + } + + + // Member Functions + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + //- Write + virtual void write(Ostream& os) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "uniformMixedFvPatchField.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchFields.C new file mode 100644 index 0000000000..e307da0c65 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchFields.C @@ -0,0 +1,39 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 "uniformMixedFvPatchFields.H" +#include "addToRunTimeSelectionTable.H" +#include "volFields.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + makePatchFields(uniformMixed); +} + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchFields.H b/src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchFields.H new file mode 100644 index 0000000000..25eac16d84 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformMixed/uniformMixedFvPatchFields.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_uniformMixedFvPatchFields_H +#define Foam_uniformMixedFvPatchFields_H + +#include "uniformMixedFvPatchField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +makePatchTypeFieldTypedefs(uniformMixed); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/meshTools/fields/pointPatchFields/uniformFixedValue/uniformFixedValuePointPatchField.C b/src/meshTools/fields/pointPatchFields/uniformFixedValue/uniformFixedValuePointPatchField.C index 5708eab900..2f291298c0 100644 --- a/src/meshTools/fields/pointPatchFields/uniformFixedValue/uniformFixedValuePointPatchField.C +++ b/src/meshTools/fields/pointPatchFields/uniformFixedValue/uniformFixedValuePointPatchField.C @@ -152,12 +152,16 @@ void Foam::uniformFixedValuePointPatchField::autoMap ) { fixedValuePointPatchField::autoMap(mapper); - refValueFunc_().autoMap(mapper); - if (refValueFunc_().constant()) + if (refValueFunc_) { - // If mapper is not dependent on time we're ok to evaluate - this->evaluate(); + refValueFunc_().autoMap(mapper); + + if (refValueFunc_().constant()) + { + // If mapper is not dependent on time we're ok to evaluate + this->evaluate(); + } } } @@ -174,7 +178,10 @@ void Foam::uniformFixedValuePointPatchField::rmap const uniformFixedValuePointPatchField& tiptf = refCast(ptf); - refValueFunc_().rmap(tiptf.refValueFunc_(), addr); + if (refValueFunc_ && tiptf.refValueFunc_) + { + refValueFunc_().rmap(tiptf.refValueFunc_(), addr); + } } @@ -186,6 +193,7 @@ void Foam::uniformFixedValuePointPatchField::updateCoeffs() return; } const scalar t = this->db().time().timeOutputValue(); + fixedValuePointPatchField::operator==(refValueFunc_->value(t)); fixedValuePointPatchField::updateCoeffs(); } @@ -197,7 +205,10 @@ write(Ostream& os) const { // Note: write value fixedValuePointPatchField::write(os); - refValueFunc_->writeData(os); + if (refValueFunc_) + { + refValueFunc_->writeData(os); + } } diff --git a/tutorials/compressible/rhoPimpleFoam/RAS/TJunctionAverage/0/U b/tutorials/compressible/rhoPimpleFoam/RAS/TJunctionAverage/0/U index 6f72b041f0..10a031b688 100644 --- a/tutorials/compressible/rhoPimpleFoam/RAS/TJunctionAverage/0/U +++ b/tutorials/compressible/rhoPimpleFoam/RAS/TJunctionAverage/0/U @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2212 | +| \\ / O peration | Version: v2306 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -35,9 +35,19 @@ boundaryField outlet2 { - type inletOutlet; - inletValue uniform (0 0 0); + // A do-it-yourself inletOutlet (for demonstration purposes) + // Need 'value' entry to avoid evaluation (with phi) on startup + type uniformMixed; value uniform (0 0 0); + + uniformValue zero; + uniformGradient zero; + + uniformValueFraction + { + type expression; + expression "neg(phi)"; + } } defaultFaces