diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index e5c33e8ec4..4bb64471bc 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -776,6 +776,7 @@ $(Fields)/fieldTypes.C pointPatchFields = fields/pointPatchFields +$(pointPatchFields)/pointPatchField/pointPatchFieldBase.C $(pointPatchFields)/pointPatchField/pointPatchFields.C basicPointPatchFields = $(pointPatchFields)/basic diff --git a/src/OpenFOAM/fields/pointPatchFields/basic/calculated/calculatedPointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/basic/calculated/calculatedPointPatchField.C index 34002cc383..eee6cf809a 100644 --- a/src/OpenFOAM/fields/pointPatchFields/basic/calculated/calculatedPointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/basic/calculated/calculatedPointPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,7 +33,7 @@ License template const Foam::word& Foam::pointPatchField::calculatedType() { - return calculatedPointPatchField::typeName; + return Foam::calculatedPointPatchField::typeName; } @@ -94,7 +94,7 @@ Foam::pointPatchField::NewCalculatedType const pointPatchField& pf ) { - auto* patchTypeCtor = pointPatchConstructorTable(pf.patch().type()); + auto* patchTypeCtor = patchConstructorTable(pf.patch().type()); if (patchTypeCtor) { diff --git a/src/OpenFOAM/fields/pointPatchFields/basic/zeroGradient/zeroGradientPointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/basic/zeroGradient/zeroGradientPointPatchField.C index 1cc3430ddc..9e01a4df9f 100644 --- a/src/OpenFOAM/fields/pointPatchFields/basic/zeroGradient/zeroGradientPointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/basic/zeroGradient/zeroGradientPointPatchField.C @@ -27,6 +27,15 @@ License #include "zeroGradientPointPatchField.H" +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +const Foam::word& Foam::pointPatchField::zeroGradientType() +{ + return Foam::zeroGradientPointPatchField::typeName; +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template diff --git a/src/OpenFOAM/fields/pointPatchFields/basic/zeroGradient/zeroGradientPointPatchField.H b/src/OpenFOAM/fields/pointPatchFields/basic/zeroGradient/zeroGradientPointPatchField.H index 3b6dbfdb6c..2a9e712375 100644 --- a/src/OpenFOAM/fields/pointPatchFields/basic/zeroGradient/zeroGradientPointPatchField.H +++ b/src/OpenFOAM/fields/pointPatchFields/basic/zeroGradient/zeroGradientPointPatchField.H @@ -34,8 +34,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef zeroGradientPointPatchField_H -#define zeroGradientPointPatchField_H +#ifndef Foam_zeroGradientPointPatchField_H +#define Foam_zeroGradientPointPatchField_H #include "pointPatchField.H" @@ -53,7 +53,6 @@ class zeroGradientPointPatchField : public pointPatchField { - public: //- Runtime type information diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C index 1ec83dd17a..69ae3130c7 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,10 +39,8 @@ Foam::pointPatchField::pointPatchField const DimensionedField& iF ) : - patch_(p), - internalField_(iF), - updated_(false), - patchType_() + pointPatchFieldBase(p), + internalField_(iF) {} @@ -54,13 +52,9 @@ Foam::pointPatchField::pointPatchField const dictionary& dict ) : - patch_(p), - internalField_(iF), - updated_(false), - patchType_() -{ - dict.readIfPresent("patchType", patchType_, keyType::LITERAL); -} + pointPatchFieldBase(p, dict), + internalField_(iF) +{} template @@ -72,10 +66,8 @@ Foam::pointPatchField::pointPatchField const pointPatchFieldMapper& ) : - patch_(p), - internalField_(iF), - updated_(false), - patchType_(ptf.patchType_) + pointPatchFieldBase(ptf, p), + internalField_(iF) {} @@ -85,10 +77,8 @@ Foam::pointPatchField::pointPatchField const pointPatchField& ptf ) : - patch_(ptf.patch_), - internalField_(ptf.internalField_), - updated_(false), - patchType_(ptf.patchType_) + pointPatchFieldBase(ptf), + internalField_(ptf.internalField_) {} @@ -99,30 +89,21 @@ Foam::pointPatchField::pointPatchField const DimensionedField& iF ) : - patch_(ptf.patch_), - internalField_(iF), - updated_(false), - patchType_(ptf.patchType_) + pointPatchFieldBase(ptf), + internalField_(iF) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template -const Foam::objectRegistry& Foam::pointPatchField::db() const -{ - return patch_.boundaryMesh().mesh()(); -} - - template void Foam::pointPatchField::write(Ostream& os) const { os.writeEntry("type", type()); - if (!patchType_.empty()) + if (!patchType().empty()) { - os.writeEntry("patchType", patchType_); + os.writeEntry("patchType", patchType()); } } @@ -293,15 +274,22 @@ void Foam::pointPatchField::setInInternalField } +template +void Foam::pointPatchField::updateCoeffs() +{ + pointPatchFieldBase::setUpdated(true); +} + + template void Foam::pointPatchField::evaluate(const Pstream::commsTypes) { - if (!updated_) + if (!updated()) { updateCoeffs(); } - updated_ = false; + pointPatchFieldBase::setUpdated(false); } diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H index 61dbe49d53..8ea1f2f63f 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H @@ -55,7 +55,6 @@ namespace Foam { // Forward Declarations - class objectRegistry; class dictionary; class pointPatchFieldMapper; @@ -67,6 +66,116 @@ template class calculatedPointPatchField; template Ostream& operator<<(Ostream&, const pointPatchField&); +/*---------------------------------------------------------------------------*\ + Class pointPatchFieldBase Declaration +\*---------------------------------------------------------------------------*/ + +//- Template invariant parts for pointPatchField +class pointPatchFieldBase +{ + // Private Data + + //- Reference to patch + const pointPatch& patch_; + + //- Update index used so that updateCoeffs is called only once during + //- the construction of the matrix + bool updated_; + + //- Optional patch type + // Used to allow specified boundary conditions to be applied + // to constraint patches by providing the constraint + // patch type as 'patchType' + word patchType_; + + +protected: + + // Protected Member Functions + + //- Read dictionary entries. + // Useful when initially constructed without a dictionary + virtual void readDict(const dictionary& dict); + + //- Set updated state + void setUpdated(bool state) noexcept + { + updated_ = state; + } + + +public: + + //- Debug switch to disallow the use of generic pointPatchField + static int disallowGenericPatchField; + + //- Runtime type information + TypeName("pointPatchField"); + + + // Constructors + + //- Construct from patch + explicit pointPatchFieldBase(const pointPatch& p); + + //- Construct from patch and patch type + pointPatchFieldBase(const pointPatch& p, const word& patchType); + + //- Construct from patch and dictionary + pointPatchFieldBase(const pointPatch& p, const dictionary& dict); + + //- Copy construct with new patch + pointPatchFieldBase(const pointPatchFieldBase&, const pointPatch& p); + + //- Copy construct + pointPatchFieldBase(const pointPatchFieldBase&); + + + //- Destructor + virtual ~pointPatchFieldBase() = default; + + + // Member Functions + + // Access + + //- The associated objectRegistry + const objectRegistry& db() const; + + //- Return the patch + const pointPatch& patch() const noexcept + { + return patch_; + } + + //- The optional patch type + const word& patchType() const noexcept + { + return patchType_; + } + + //- The optional patch type + word& patchType() noexcept + { + return patchType_; + } + + + // Solution + + //- True if the boundary condition has already been updated + bool updated() const noexcept + { + return updated_; + } + + + // Check + + //- Check that patches are identical + void checkPatch(const pointPatchFieldBase& rhs) const; +}; + /*---------------------------------------------------------------------------*\ Class pointPatchField Declaration @@ -74,24 +183,14 @@ Ostream& operator<<(Ostream&, const pointPatchField&); template class pointPatchField +: + public pointPatchFieldBase { // Private Data - //- Reference to patch - const pointPatch& patch_; - //- Reference to internal field const DimensionedField& internalField_; - //- Update index used so that updateCoeffs is called only once during - // the construction of the matrix - bool updated_; - - //- Optional patch type, used to allow specified boundary conditions - // to be applied to constraint patches by providing the constraint - // patch type as 'patchType' - word patchType_; - public: @@ -108,20 +207,13 @@ public: typedef calculatedPointPatchField Calculated; - //- Runtime type information - TypeName("pointPatchField"); - - //- Debug switch to disallow the use of genericPointPatchField - static int disallowGenericPointPatchField; - - // Declare run-time constructor selection tables declareRunTimeSelectionTable ( autoPtr, pointPatchField, - pointPatch, + patch, ( const pointPatch& p, const DimensionedField& iF @@ -186,9 +278,6 @@ public: //- Construct as copy pointPatchField(const pointPatchField&); - //- Construct and return a clone - virtual autoPtr> clone() const = 0; - //- Construct as copy setting internal field reference pointPatchField ( @@ -196,6 +285,9 @@ public: const DimensionedField& ); + //- Construct and return a clone + virtual autoPtr> clone() const = 0; + //- Construct and return a clone setting internal field reference virtual autoPtr> clone ( @@ -257,69 +349,58 @@ public: //- Destructor - virtual ~pointPatchField() = default; + virtual ~pointPatchField() = default; - // Member functions + // Member Functions - // Access + //- The type name for calculated patch fields + static const word& calculatedType(); - //- Return local objectRegistry - const objectRegistry& db() const; + //- The type name for zeroGradient patch fields + static const word& zeroGradientType(); - //- Return size - label size() const - { - return patch().size(); - } - //- Return patch - const pointPatch& patch() const - { - return patch_; - } + // Attributes - //- Return dimensioned internal field reference - const DimensionedField& - internalField() const - { - return internalField_; - } - - //- Return internal field reference - const Field& primitiveField() const - { - return internalField_; - } - - //- Optional patch type - const word& patchType() const - { - return patchType_; - } - - //- Optional patch type - word& patchType() - { - return patchType_; - } - - //- Return true if this patch field fixes a value + //- True if this patch field fixes a value virtual bool fixesValue() const { return false; } - //- Return true if this patch field is coupled + //- True if this patch field is coupled virtual bool coupled() const { return false; } - //- Return true if the boundary condition has already been updated - bool updated() const + //- The constraint type this pointPatchField implements. + virtual const word& constraintType() const { - return updated_; + return word::null; + } + + + // Access + + //- Return the patch size + label size() const + { + return patch().size(); + } + + //- Return dimensioned internal field reference + const DimensionedField& internalField() + const noexcept + { + return internalField_; + } + + //- Return internal field reference + const Field& primitiveField() const noexcept + { + return internalField_; } //- Return field created from appropriate internal field values @@ -380,17 +461,8 @@ public: const Field& pF ) const; - //- Return the type of the calculated form of pointPatchField - static const word& calculatedType(); - //- Return the constraint type this pointPatchField implements. - virtual const word& constraintType() const - { - return word::null; - } - - - // Mapping functions + // Mapping Functions //- Map (and resize as needed) from self given a mapping object virtual void autoMap @@ -408,14 +480,11 @@ public: {} - // Evaluation functions + // Evaluation Functions //- Update the coefficients associated with the patch field // Sets Updated to true - virtual void updateCoeffs() - { - updated_ = true; - } + virtual void updateCoeffs(); //- Initialise evaluation of the patch field (do nothing) virtual void initEvaluate @@ -470,7 +539,7 @@ public: virtual void operator==(const Type&){} - // Ostream operator + // Ostream Operator friend Ostream& operator<< ( @@ -513,15 +582,19 @@ const pointPatchField& operator+ #ifdef NoRepository #include "pointPatchField.C" #include "calculatedPointPatchField.H" + #include "zeroGradientPointPatchField.H" #endif +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Runtime selection macros + #define addToPointPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \ addToRunTimeSelectionTable \ ( \ PatchTypeField, \ typePatchTypeField, \ - pointPatch \ + patch \ ); \ addToRunTimeSelectionTable \ ( \ @@ -574,7 +647,7 @@ const pointPatchField& operator+ ( \ pointPatchTensorField, \ type##PointPatchTensorField \ -); + ); #define makePointPatchFieldsTypeName(type) \ diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFieldBase.C b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFieldBase.C new file mode 100644 index 0000000000..3ecd9e583c --- /dev/null +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFieldBase.C @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 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 "pointPatchField.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(pointPatchFieldBase, 0); +} + +int Foam::pointPatchFieldBase::disallowGenericPatchField +( + Foam::debug::debugSwitch("disallowGenericPointPatchField", 0) +); + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::pointPatchFieldBase::pointPatchFieldBase(const pointPatch& p) +: + patch_(p), + updated_(false), + patchType_() +{} + + +Foam::pointPatchFieldBase::pointPatchFieldBase +( + const pointPatch& p, + const word& patchType +) +: + pointPatchFieldBase(p) +{ + patchType_ = patchType; +} + + +Foam::pointPatchFieldBase::pointPatchFieldBase +( + const pointPatch& p, + const dictionary& dict +) +: + pointPatchFieldBase(p) +{ + pointPatchFieldBase::readDict(dict); +} + + +Foam::pointPatchFieldBase::pointPatchFieldBase +( + const pointPatchFieldBase& rhs, + const pointPatch& p +) +: + patch_(p), + updated_(false), + patchType_(rhs.patchType_) +{} + + +Foam::pointPatchFieldBase::pointPatchFieldBase(const pointPatchFieldBase& rhs) +: + patch_(rhs.patch_), + updated_(false), + patchType_(rhs.patchType_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::pointPatchFieldBase::readDict(const dictionary& dict) +{ + dict.readIfPresent("patchType", patchType_, keyType::LITERAL); +} + + +const Foam::objectRegistry& Foam::pointPatchFieldBase::db() const +{ + return patch_.boundaryMesh().mesh()(); +} + + +void Foam::pointPatchFieldBase::checkPatch(const pointPatchFieldBase& rhs) const +{ + if (&patch_ != &(rhs.patch_)) + { + FatalErrorInFunction + << "Different patches for pointPatchField" + << abort(FatalError); + } +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFieldNew.C b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFieldNew.C index 4c47084577..d054fb4ac8 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFieldNew.C +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFieldNew.C @@ -42,28 +42,28 @@ Foam::autoPtr> Foam::pointPatchField::New << " [" << actualPatchType << "] : " << p.type() << " name = " << p.name() << endl; - auto* ctorPtr = pointPatchConstructorTable(patchFieldType); + auto* ctorPtr = patchConstructorTable(patchFieldType); if (!ctorPtr) { FatalErrorInLookup ( - "patchFieldType", + "patchField", patchFieldType, - *pointPatchConstructorTablePtr_ + *patchConstructorTablePtr_ ) << exit(FatalError); } - autoPtr> pfPtr(ctorPtr(p, iF)); + autoPtr> tpfld(ctorPtr(p, iF)); if (actualPatchType.empty() || actualPatchType != p.type()) { - if (pfPtr().constraintType() != p.constraintType()) + if (tpfld().constraintType() != p.constraintType()) { // Incompatible (constraint-wise) with the patch type // - use default constraint type - auto* patchTypeCtor = pointPatchConstructorTable(p.type()); + auto* patchTypeCtor = patchConstructorTable(p.type()); if (!patchTypeCtor) { @@ -79,13 +79,13 @@ Foam::autoPtr> Foam::pointPatchField::New } else { - if (pointPatchConstructorTablePtr_->found(p.type())) + if (patchConstructorTablePtr_->found(p.type())) { - pfPtr().patchType() = actualPatchType; + tpfld.ref().patchType() = actualPatchType; } } - return pfPtr; + return tpfld; } @@ -123,7 +123,7 @@ Foam::autoPtr> Foam::pointPatchField::New if (!ctorPtr) { - if (!disallowGenericPointPatchField) + if (!pointPatchFieldBase::disallowGenericPatchField) { ctorPtr = dictionaryConstructorTable("generic"); } @@ -140,11 +140,11 @@ Foam::autoPtr> Foam::pointPatchField::New } // Construct (but not necessarily returned) - autoPtr> pfPtr(ctorPtr(p, iF, dict)); + autoPtr> tpfld(ctorPtr(p, iF, dict)); if (actualPatchType.empty() || actualPatchType != p.type()) { - if (pfPtr().constraintType() != p.constraintType()) + if (tpfld().constraintType() != p.constraintType()) { // Incompatible (constraint-wise) with the patch type // - use default constraint type @@ -164,7 +164,7 @@ Foam::autoPtr> Foam::pointPatchField::New } } - return pfPtr; + return tpfld; } diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFields.C b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFields.C index 97c0ea9009..7a9d947842 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFields.C +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFields.C @@ -36,13 +36,7 @@ namespace Foam #define makePointPatchField(pointPatchTypeField) \ \ -defineNamedTemplateTypeNameAndDebug(pointPatchTypeField, 0); \ -template<> \ -int pointPatchTypeField::disallowGenericPointPatchField \ -( \ - debug::debugSwitch("disallowGenericPointPatchField", 0) \ -); \ -defineTemplateRunTimeSelectionTable(pointPatchTypeField, pointPatch); \ +defineTemplateRunTimeSelectionTable(pointPatchTypeField, patch); \ defineTemplateRunTimeSelectionTable(pointPatchTypeField, patchMapper); \ defineTemplateRunTimeSelectionTable(pointPatchTypeField, dictionary); diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFields.H b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFields.H index ecc152d71e..e00a9b32a8 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFields.H +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFields.H @@ -25,8 +25,8 @@ License \*---------------------------------------------------------------------------*/ -#ifndef pointPatchFields_H -#define pointPatchFields_H +#ifndef Foam_pointPatchFields_H +#define Foam_pointPatchFields_H #include "pointPatchField.H" #include "pointPatchFieldsFwd.H" diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFieldsFwd.H b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFieldsFwd.H index 5ab10b3819..2f0b23bb5e 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFieldsFwd.H +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchFieldsFwd.H @@ -25,8 +25,8 @@ License \*---------------------------------------------------------------------------*/ -#ifndef pointPatchFieldsFwd_H -#define pointPatchFieldsFwd_H +#ifndef Foam_pointPatchFieldsFwd_H +#define Foam_pointPatchFieldsFwd_H #include "fieldTypes.H" diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C index 61be272817..081c7d0f83 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -100,7 +100,7 @@ Foam::polyPatch::polyPatch faceCellsPtr_(nullptr), mePtr_(nullptr) { - if (!patchType.empty() && constraintType(patchType)) + if (constraintType(patchType)) { inGroups().appendUniq(patchType); } @@ -156,7 +156,7 @@ Foam::polyPatch::polyPatch faceCellsPtr_(nullptr), mePtr_(nullptr) { - if (!patchType.empty() && constraintType(patchType)) + if (constraintType(patchType)) { inGroups().appendUniq(patchType); } @@ -274,12 +274,13 @@ Foam::polyPatch::~polyPatch() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::polyPatch::constraintType(const word& pt) +bool Foam::polyPatch::constraintType(const word& patchType) { return ( - pointPatchField::pointPatchConstructorTablePtr_ - && pointPatchField::pointPatchConstructorTablePtr_->found(pt) + !patchType.empty() + && pointPatchField::patchConstructorTablePtr_ + && pointPatchField::patchConstructorTablePtr_->found(patchType) ); } @@ -300,7 +301,7 @@ Foam::wordList Foam::polyPatch::constraintTypes() } } - cTypes.setSize(i); + cTypes.resize(i); return cTypes; } diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H index bccfc2f78c..e704fbc8c5 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H @@ -384,7 +384,7 @@ public: } //- Return true if the given type is a constraint type - static bool constraintType(const word& pt); + static bool constraintType(const word& patchType); //- Return a list of all the constraint patch types static wordList constraintTypes(); diff --git a/src/finiteArea/Make/files b/src/finiteArea/Make/files index cca8e340e9..18a6e9abf3 100644 --- a/src/finiteArea/Make/files +++ b/src/finiteArea/Make/files @@ -37,6 +37,7 @@ $(faMeshMapper)/faEdgeMapper.C $(faMeshMapper)/faPatchMapper.C faPatchFields = fields/faPatchFields +$(faPatchFields)/faPatchField/faPatchFieldBase.C $(faPatchFields)/faPatchField/faPatchFields.C basicFaPatchFields = $(faPatchFields)/basic @@ -68,6 +69,7 @@ $(derivedFaPatchFields)/timeVaryingUniformFixedValue/timeVaryingUniformFixedValu $(derivedFaPatchFields)/clampedPlate/clampedPlateFaPatchFields.C faePatchFields = fields/faePatchFields +$(faePatchFields)/faePatchField/faePatchFieldBase.C $(faePatchFields)/faePatchField/faePatchFields.C basicFaePatchFields = $(faePatchFields)/basic diff --git a/src/finiteArea/faMesh/faPatches/faPatch/faPatch.C b/src/finiteArea/faMesh/faPatches/faPatch/faPatch.C index f87e82d8aa..8430af7597 100644 --- a/src/finiteArea/faMesh/faPatches/faPatch/faPatch.C +++ b/src/finiteArea/faMesh/faPatches/faPatch/faPatch.C @@ -111,7 +111,7 @@ Foam::faPatch::faPatch pointLabelsPtr_(nullptr), pointEdgesPtr_(nullptr) { - if (!patchType.empty() && constraintType(patchType)) + if (constraintType(patchType)) { inGroups().appendUniq(patchType); } @@ -135,7 +135,7 @@ Foam::faPatch::faPatch pointLabelsPtr_(nullptr), pointEdgesPtr_(nullptr) { - if (!patchType.empty() && constraintType(patchType)) + if (constraintType(patchType)) { inGroups().appendUniq(patchType); } diff --git a/src/finiteArea/faMesh/faPatches/faPatch/faPatch.H b/src/finiteArea/faMesh/faPatches/faPatch/faPatch.H index 73b55bf598..2dece99662 100644 --- a/src/finiteArea/faMesh/faPatches/faPatch/faPatch.H +++ b/src/finiteArea/faMesh/faPatches/faPatch/faPatch.H @@ -264,7 +264,7 @@ public: // Static Member Functions //- Return true if the given type is a constraint type - static bool constraintType(const word& pt); + static bool constraintType(const word& patchType); //- Return a list of all the constraint patch types static wordList constraintTypes(); diff --git a/src/finiteArea/fields/faPatchFields/basic/calculated/calculatedFaPatchField.C b/src/finiteArea/fields/faPatchFields/basic/calculated/calculatedFaPatchField.C index 0ec6a8bdaa..2a26313135 100644 --- a/src/finiteArea/fields/faPatchFields/basic/calculated/calculatedFaPatchField.C +++ b/src/finiteArea/fields/faPatchFields/basic/calculated/calculatedFaPatchField.C @@ -34,7 +34,7 @@ License template const Foam::word& Foam::faPatchField::calculatedType() { - return calculatedFaPatchField::typeName; + return Foam::calculatedFaPatchField::typeName; } diff --git a/src/finiteArea/fields/faPatchFields/basic/zeroGradient/zeroGradientFaPatchField.C b/src/finiteArea/fields/faPatchFields/basic/zeroGradient/zeroGradientFaPatchField.C index 7d96cfeff6..862d37c85a 100644 --- a/src/finiteArea/fields/faPatchFields/basic/zeroGradient/zeroGradientFaPatchField.C +++ b/src/finiteArea/fields/faPatchFields/basic/zeroGradient/zeroGradientFaPatchField.C @@ -28,6 +28,15 @@ License #include "zeroGradientFaPatchField.H" #include "faPatchFieldMapper.H" +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +const Foam::word& Foam::faPatchField::zeroGradientType() +{ + return Foam::zeroGradientFaPatchField::typeName; +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template diff --git a/src/finiteArea/fields/faPatchFields/basic/zeroGradient/zeroGradientFaPatchField.H b/src/finiteArea/fields/faPatchFields/basic/zeroGradient/zeroGradientFaPatchField.H index 163596a22b..bbb1493097 100644 --- a/src/finiteArea/fields/faPatchFields/basic/zeroGradient/zeroGradientFaPatchField.H +++ b/src/finiteArea/fields/faPatchFields/basic/zeroGradient/zeroGradientFaPatchField.H @@ -57,7 +57,6 @@ class zeroGradientFaPatchField : public faPatchField { - public: //- Runtime type information @@ -126,10 +125,6 @@ public: } - //- Destructor - virtual ~zeroGradientFaPatchField() = default; - - // Member functions // Evaluation functions diff --git a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.C b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.C index e2376aef73..dc7a42400d 100644 --- a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.C +++ b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 Wikki Ltd - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -38,11 +38,9 @@ Foam::faPatchField::faPatchField const DimensionedField& iF ) : + faPatchFieldBase(p), Field(p.size()), - patch_(p), - internalField_(iF), - updated_(false), - patchType_() + internalField_(iF) {} @@ -54,11 +52,9 @@ Foam::faPatchField::faPatchField const Field& f ) : + faPatchFieldBase(p), Field(f), - patch_(p), - internalField_(iF), - updated_(false), - patchType_() + internalField_(iF) {} @@ -71,11 +67,9 @@ Foam::faPatchField::faPatchField const faPatchFieldMapper& mapper ) : + faPatchFieldBase(ptf, p), Field(ptf, mapper), - patch_(p), - internalField_(iF), - updated_(false), - patchType_() + internalField_(iF) {} @@ -88,14 +82,10 @@ Foam::faPatchField::faPatchField const bool valueRequired ) : + faPatchFieldBase(p, dict), Field(p.size()), - patch_(p), - internalField_(iF), - updated_(false), - patchType_() + internalField_(iF) { - dict.readIfPresent("patchType", patchType_, keyType::LITERAL); - /// if (valueRequired) - not yet needed. Already a lazy evaluation const auto* eptr = dict.findEntry("value", keyType::LITERAL); @@ -117,11 +107,9 @@ Foam::faPatchField::faPatchField const faPatchField& ptf ) : + faPatchFieldBase(ptf), Field(ptf), - patch_(ptf.patch_), - internalField_(ptf.internalField_), - updated_(false), - patchType_(ptf.patchType_) + internalField_(ptf.internalField_) {} @@ -132,11 +120,9 @@ Foam::faPatchField::faPatchField const DimensionedField& iF ) : + faPatchFieldBase(ptf), Field(ptf), - patch_(ptf.patch_), - internalField_(iF), - updated_(false), - patchType_(ptf.patchType_) + internalField_(iF) {} @@ -151,21 +137,16 @@ const Foam::objectRegistry& Foam::faPatchField::db() const template -void Foam::faPatchField::check(const faPatchField& ptf) const +void Foam::faPatchField::check(const faPatchField& rhs) const { - if (&patch_ != &(ptf.patch_)) - { - FatalErrorInFunction - << "different patches for faPatchFields" - << abort(FatalError); - } + faPatchFieldBase::checkPatch(rhs); } template Foam::tmp> Foam::faPatchField::snGrad() const { - return (*this - patchInternalField())*patch_.deltaCoeffs(); + return (*this - patchInternalField())*patch().deltaCoeffs(); } @@ -173,7 +154,7 @@ template Foam::tmp> Foam::faPatchField::patchInternalField() const { - return patch_.patchInternalField(internalField_); + return patch().patchInternalField(internalField_); } @@ -195,15 +176,22 @@ void Foam::faPatchField::rmap } +template +void Foam::faPatchField::updateCoeffs() +{ + faPatchFieldBase::setUpdated(true); +} + + template void Foam::faPatchField::evaluate(const Pstream::commsTypes) { - if (!updated_) + if (!updated()) { updateCoeffs(); } - updated_ = false; + faPatchFieldBase::setUpdated(false); } @@ -212,9 +200,9 @@ void Foam::faPatchField::write(Ostream& os) const { os.writeEntry("type", type()); - if (!patchType_.empty()) + if (!patchType().empty()) { - os.writeEntry("patchType", patchType_); + os.writeEntry("patchType", patchType()); } } @@ -237,7 +225,7 @@ void Foam::faPatchField::operator= const faPatchField& ptf ) { - check(ptf); + faPatchFieldBase::checkPatch(ptf); Field::operator=(ptf); } @@ -248,7 +236,7 @@ void Foam::faPatchField::operator+= const faPatchField& ptf ) { - check(ptf); + faPatchFieldBase::checkPatch(ptf); Field::operator+=(ptf); } @@ -259,7 +247,7 @@ void Foam::faPatchField::operator-= const faPatchField& ptf ) { - check(ptf); + faPatchFieldBase::checkPatch(ptf); Field::operator-=(ptf); } @@ -270,13 +258,7 @@ void Foam::faPatchField::operator*= const faPatchField& ptf ) { - if (&patch_ != &ptf.patch()) - { - FatalErrorInFunction - << "incompatible patches for patch fields" - << abort(FatalError); - } - + faPatchFieldBase::checkPatch(ptf); Field::operator*=(ptf); } @@ -287,13 +269,7 @@ void Foam::faPatchField::operator/= const faPatchField& ptf ) { - if (&patch_ != &ptf.patch()) - { - FatalErrorInFunction - << " incompatible patches for patch fields" - << abort(FatalError); - } - + faPatchFieldBase::checkPatch(ptf); Field::operator/=(ptf); } diff --git a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.H b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.H index a6cf3cb170..de98d4ebef 100644 --- a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.H +++ b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.H @@ -41,7 +41,8 @@ Author SourceFiles faPatchField.C - newPatchField.C + faPatchFieldBase.C + faPatchFieldNew.C \*---------------------------------------------------------------------------*/ @@ -57,21 +58,128 @@ namespace Foam { // Forward Declarations - class objectRegistry; class dictionary; class faPatchFieldMapper; class areaMesh; -template -class faPatchField; - -template -class calculatedFaPatchField; +template class faPatchField; +template class calculatedFaPatchField; template Ostream& operator<<(Ostream&, const faPatchField&); +/*---------------------------------------------------------------------------*\ + Class faPatchFieldBase Declaration +\*---------------------------------------------------------------------------*/ + +//- Template invariant parts for faPatchField +class faPatchFieldBase +{ + // Private Data + + //- Reference to patch + const faPatch& patch_; + + //- Update index used so that updateCoeffs is called only once during + //- the construction of the matrix + bool updated_; + + //- Optional patch type + // Used to allow specified boundary conditions to be applied + // to constraint patches by providing the constraint + // patch type as 'patchType' + word patchType_; + + +protected: + + // Protected Member Functions + + //- Read dictionary entries. + // Useful when initially constructed without a dictionary + virtual void readDict(const dictionary& dict); + + //- Set updated state + void setUpdated(bool state) noexcept + { + updated_ = state; + } + + +public: + + //- Debug switch to disallow the use of generic faPatchField + static int disallowGenericPatchField; + + //- Runtime type information + TypeName("faPatchField"); + + + // Constructors + + //- Construct from patch + explicit faPatchFieldBase(const faPatch& p); + + //- Construct from patch and patch type + explicit faPatchFieldBase(const faPatch& p, const word& patchType); + + //- Construct from patch and dictionary + faPatchFieldBase(const faPatch& p, const dictionary& dict); + + //- Copy construct with new patch + faPatchFieldBase(const faPatchFieldBase& rhs, const faPatch& p); + + //- Copy construct + faPatchFieldBase(const faPatchFieldBase& rhs); + + + //- Destructor + virtual ~faPatchFieldBase() = default; + + + // Member Functions + + // Access + + //- The associated objectRegistry + /// const objectRegistry& db() const; + + //- Return the patch + const faPatch& patch() const noexcept + { + return patch_; + } + + //- The optional patch type + const word& patchType() const noexcept + { + return patchType_; + } + + //- The optional patch type + word& patchType() noexcept + { + return patchType_; + } + + + // Solution + + //- True if the boundary condition has already been updated + bool updated() const noexcept + { + return updated_; + } + + + // Check + + //- Check that patches are identical + void checkPatch(const faPatchFieldBase& rhs) const; +}; + + /*---------------------------------------------------------------------------*\ Class faPatchField Declaration \*---------------------------------------------------------------------------*/ @@ -79,25 +187,14 @@ Ostream& operator<<(Ostream&, const faPatchField&); template class faPatchField : + public faPatchFieldBase, public Field { // Private Data - //- Reference to a patch - const faPatch& patch_; - //- Reference to internal field const DimensionedField& internalField_; - //- Update index used so that updateCoeffs is called only once during - // the construction of the matrix - bool updated_; - - //- Optional patch type, used to allow specified boundary conditions - //- to be applied to constraint patches by providing the constraint - //- patch type as 'patchType' - word patchType_; - public: @@ -111,13 +208,6 @@ public: typedef calculatedFaPatchField Calculated; - //- Runtime type information - TypeName("faPatchField"); - - //- Debug switch to disallow the use of - static int disallowGenericFaPatchField; - - // Declare run-time constructor selection tables declareRunTimeSelectionTable @@ -198,12 +288,6 @@ public: //- Construct as copy faPatchField(const faPatchField&); - //- Construct and return a clone - virtual tmp> clone() const - { - return tmp>(new faPatchField(*this)); - } - //- Construct as copy setting internal field reference faPatchField ( @@ -211,6 +295,12 @@ public: const DimensionedField& ); + //- Construct and return a clone + virtual tmp> clone() const + { + return tmp>(new faPatchField(*this)); + } + //- Construct and return a clone setting internal field reference virtual tmp> clone ( @@ -273,50 +363,21 @@ public: //- Destructor - virtual ~faPatchField() = default; + virtual ~faPatchField() = default; // Member Functions - // Access + //- The type name for calculated patch fields + static const word& calculatedType(); - //- Return local objectRegistry - const objectRegistry& db() const; + //- The type name for zeroGradient patch fields + static const word& zeroGradientType(); - //- Return patch - const faPatch& patch() const - { - return patch_; - } - //- Return dimensioned internal field reference - const DimensionedField& internalField() const - { - return internalField_; - } + // Attributes - //- Return internal field reference - const Field& primitiveField() const - { - return internalField_; - } - - //- Optional patch type - const word& patchType() const - { - return patchType_; - } - - //- Optional patch type - word& patchType() - { - return patchType_; - } - - //- Return the type of the calculated for of faPatchField - static const word& calculatedType(); - - //- Return true if this patch field fixes a value. + //- True if this patch field fixes a value. // Needed to check if a level has to be specified while solving // Poissons equations. virtual bool fixesValue() const @@ -324,16 +385,29 @@ public: return false; } - //- Return true if this patch field is coupled + //- True if this patch field is coupled virtual bool coupled() const { return false; } - //- Return true if the boundary condition has already been updated - bool updated() const + + // Access + + //- Return local objectRegistry + const objectRegistry& db() const; + + //- Return dimensioned internal field reference + const DimensionedField& + internalField() const noexcept { - return updated_; + return internalField_; + } + + //- Return internal field reference + const Field& primitiveField() const noexcept + { + return internalField_; } @@ -358,13 +432,6 @@ public: //- Return patch-normal gradient virtual tmp> snGrad() const; - //- Update the coefficients associated with the patch field - // Sets Updated to true - virtual void updateCoeffs() - { - updated_ = true; - } - //- Return internal field next to patch as patch field virtual tmp> patchInternalField() const; @@ -375,6 +442,10 @@ public: return *this; } + //- Update the coefficients associated with the patch field + // Sets Updated to true + virtual void updateCoeffs(); + //- Initialise the evaluation of the patch field virtual void initEvaluate ( @@ -471,7 +542,7 @@ public: virtual void operator==(const Type&); - // Ostream operator + // Ostream Operator friend Ostream& operator<< (Ostream&, const faPatchField&); }; @@ -486,9 +557,13 @@ public: #ifdef NoRepository #include "faPatchField.C" #include "calculatedFaPatchField.H" + #include "zeroGradientFaPatchField.H" #endif +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Runtime selection macros + #define addToFaPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \ \ addToRunTimeSelectionTable \ diff --git a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFieldBase.C b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFieldBase.C new file mode 100644 index 0000000000..8edc4781b2 --- /dev/null +++ b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFieldBase.C @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 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 "faPatchField.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(faPatchFieldBase, 0); +} + +int Foam::faPatchFieldBase::disallowGenericPatchField +( + Foam::debug::debugSwitch("disallowGenericFaPatchField", 0) +); + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::faPatchFieldBase::faPatchFieldBase(const faPatch& p) +: + patch_(p), + updated_(false), + patchType_() +{} + + +Foam::faPatchFieldBase::faPatchFieldBase +( + const faPatch& p, + const word& patchType +) +: + faPatchFieldBase(p) +{ + patchType_ = patchType; +} + + +Foam::faPatchFieldBase::faPatchFieldBase +( + const faPatch& p, + const dictionary& dict +) +: + faPatchFieldBase(p) +{ + faPatchFieldBase::readDict(dict); +} + + +Foam::faPatchFieldBase::faPatchFieldBase +( + const faPatchFieldBase& rhs, + const faPatch& p +) +: + patch_(p), + updated_(false), + patchType_(rhs.patchType_) +{} + + +Foam::faPatchFieldBase::faPatchFieldBase(const faPatchFieldBase& rhs) +: + patch_(rhs.patch_), + updated_(false), + patchType_(rhs.patchType_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::faPatchFieldBase::readDict(const dictionary& dict) +{ + dict.readIfPresent("patchType", patchType_, keyType::LITERAL); +} + + +// const Foam::objectRegistry& Foam::faPatchFieldBase::db() const +// { +// return patch_.boundaryMesh().mesh().thisDb(); +// } + + +void Foam::faPatchFieldBase::checkPatch(const faPatchFieldBase& rhs) const +{ + if (&patch_ != &(rhs.patch_)) + { + FatalErrorInFunction + << "Different patches for faPatchField" + << abort(FatalError); + } +} + + +// ************************************************************************* // diff --git a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFieldNew.C b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFieldNew.C index 80bc3721dd..d0c97d232b 100644 --- a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFieldNew.C +++ b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFieldNew.C @@ -69,14 +69,14 @@ Foam::tmp> Foam::faPatchField::New } - tmp> tfap = ctorPtr(p, iF); + tmp> tpfld(ctorPtr(p, iF)); - // Check if constraint type override and store patchType if so + // If constraint type: override and store patchType if (patchTypeCtor) { - tfap.ref().patchType() = actualPatchType; + tpfld.ref().patchType() = actualPatchType; } - return tfap; + return tpfld; } @@ -114,7 +114,7 @@ Foam::tmp> Foam::faPatchField::New if (!ctorPtr) { - if (!disallowGenericFaPatchField) + if (!faPatchFieldBase::disallowGenericPatchField) { ctorPtr = dictionaryConstructorTable("generic"); } diff --git a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFields.C b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFields.C index 72a2cd3597..1cfadb9c9c 100644 --- a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFields.C +++ b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFields.C @@ -37,13 +37,6 @@ namespace Foam #define makeFaPatchField(faPatchTypeField) \ \ -defineNamedTemplateTypeNameAndDebug(faPatchTypeField, 0); \ -template<> \ -int \ -faPatchTypeField::disallowGenericFaPatchField \ -( \ - debug::debugSwitch("disallowGenericFaPatchField", 0) \ -); \ defineTemplateRunTimeSelectionTable(faPatchTypeField, patch); \ defineTemplateRunTimeSelectionTable(faPatchTypeField, patchMapper); \ defineTemplateRunTimeSelectionTable(faPatchTypeField, dictionary); diff --git a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFields.H b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFields.H index ca7512c607..21acf6ab74 100644 --- a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFields.H +++ b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchFields.H @@ -25,8 +25,8 @@ License \*---------------------------------------------------------------------------*/ -#ifndef faPatchFields_H -#define faPatchFields_H +#ifndef Foam_faPatchFields_H +#define Foam_faPatchFields_H #include "faPatchField.H" #include "faPatchFieldsFwd.H" diff --git a/src/finiteArea/fields/faePatchFields/basic/calculated/calculatedFaePatchField.C b/src/finiteArea/fields/faePatchFields/basic/calculated/calculatedFaePatchField.C index f1424829e3..93e3b6ccf4 100644 --- a/src/finiteArea/fields/faePatchFields/basic/calculated/calculatedFaePatchField.C +++ b/src/finiteArea/fields/faePatchFields/basic/calculated/calculatedFaePatchField.C @@ -34,7 +34,7 @@ License template const Foam::word& Foam::faePatchField::calculatedType() { - return calculatedFaePatchField::typeName; + return Foam::calculatedFaePatchField::typeName; } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // diff --git a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.C b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.C index 673bea130a..2c84b4ed5b 100644 --- a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.C +++ b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 Wikki Ltd + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,8 +38,8 @@ Foam::faePatchField::faePatchField const DimensionedField& iF ) : + faePatchFieldBase(p), Field(p.size()), - patch_(p), internalField_(iF) {} @@ -51,8 +52,8 @@ Foam::faePatchField::faePatchField const Field& f ) : + faePatchFieldBase(p), Field(f), - patch_(p), internalField_(iF) {} @@ -66,8 +67,8 @@ Foam::faePatchField::faePatchField const faPatchFieldMapper& mapper ) : + faePatchFieldBase(ptf, p), Field(ptf, mapper), - patch_(p), internalField_(iF) {} @@ -80,8 +81,8 @@ Foam::faePatchField::faePatchField const dictionary& dict ) : + faePatchFieldBase(p, dict), Field(p.size()), - patch_(p), internalField_(iF) { const auto* eptr = dict.findEntry("value", keyType::LITERAL); @@ -103,8 +104,8 @@ Foam::faePatchField::faePatchField const faePatchField& ptf ) : + faePatchFieldBase(ptf), Field(ptf), - patch_(ptf.patch_), internalField_(ptf.internalField_) {} @@ -116,8 +117,8 @@ Foam::faePatchField::faePatchField const DimensionedField& iF ) : + faePatchFieldBase(ptf), Field(ptf), - patch_(ptf.patch_), internalField_(iF) {} @@ -133,14 +134,9 @@ const Foam::objectRegistry& Foam::faePatchField::db() const template -void Foam::faePatchField::check(const faePatchField& ptf) const +void Foam::faePatchField::check(const faePatchField& rhs) const { - if (&patch_ != &(ptf.patch_)) - { - FatalErrorInFunction - << "different patches for faePatchFields" - << abort(FatalError); - } + faePatchFieldBase::checkPatch(rhs); } @@ -170,9 +166,9 @@ void Foam::faePatchField::write(Ostream& os) const { os.writeEntry("type", type()); - // if (!patchType_.empty()) + // if (!patchType().empty()) // { - // os.writeEntry("patchType", patchType_); + // os.writeEntry("patchType", patchType()); // } } @@ -195,7 +191,7 @@ void Foam::faePatchField::operator= const faePatchField& ptf ) { - check(ptf); + faePatchFieldBase::checkPatch(ptf); Field::operator=(ptf); } @@ -206,7 +202,7 @@ void Foam::faePatchField::operator+= const faePatchField& ptf ) { - check(ptf); + faePatchFieldBase::checkPatch(ptf); Field::operator+=(ptf); } @@ -217,7 +213,7 @@ void Foam::faePatchField::operator-= const faePatchField& ptf ) { - check(ptf); + faePatchFieldBase::checkPatch(ptf); Field::operator-=(ptf); } @@ -228,13 +224,7 @@ void Foam::faePatchField::operator*= const faePatchField& ptf ) { - if (&patch_ != &ptf.patch()) - { - FatalErrorInFunction - << "incompatible patches for patch fields" - << abort(FatalError); - } - + faePatchFieldBase::checkPatch(ptf); Field::operator*=(ptf); } @@ -245,13 +235,7 @@ void Foam::faePatchField::operator/= const faePatchField& ptf ) { - if (&patch_ != &ptf.patch()) - { - FatalErrorInFunction - << " incompatible patches for patch fields" - << abort(FatalError); - } - + faePatchFieldBase::checkPatch(ptf); Field::operator/=(ptf); } diff --git a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.H b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.H index 679bebca54..950f9d5de1 100644 --- a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.H +++ b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.H @@ -41,7 +41,8 @@ Author SourceFiles faePatchField.C - newPatchField.C + faePatchFieldBase.C + faePatchFieldNew.C \*---------------------------------------------------------------------------*/ @@ -63,16 +64,86 @@ class dictionary; class faPatchFieldMapper; class edgeMesh; -template -class faePatchField; - -template -class calculatedFaePatchField; +template class faePatchField; +template class calculatedFaePatchField; template Ostream& operator<<(Ostream&, const faePatchField&); +/*---------------------------------------------------------------------------*\ + Class faePatchFieldBase Declaration +\*---------------------------------------------------------------------------*/ + +//- Template invariant parts for faePatchField +class faePatchFieldBase +{ + // Private Data + + //- Reference to patch + const faPatch& patch_; + +protected: + + // Protected Member Functions + + //- Read dictionary entries. + // Useful when initially constructed without a dictionary + virtual void readDict(const dictionary& dict); + + +public: + + //- Debug switch to disallow the use of generic faePatchField + static int disallowGenericPatchField; + + //- Runtime type information + TypeName("faePatchField"); + + + // Constructors + + //- Construct from patch + explicit faePatchFieldBase(const faPatch& p); + + //- Construct from patch and patch type + explicit faePatchFieldBase(const faPatch& p, const word& patchType); + + //- Construct from patch and dictionary + faePatchFieldBase(const faPatch& p, const dictionary& dict); + + //- Copy construct with new patch + faePatchFieldBase(const faePatchFieldBase& rhs, const faPatch& p); + + //- Copy construct + faePatchFieldBase(const faePatchFieldBase& rhs); + + + //- Destructor + virtual ~faePatchFieldBase() = default; + + + // Member Functions + + // Access + + //- The associated objectRegistry + /// const objectRegistry& db() const; + + //- Return the patch + const faPatch& patch() const noexcept + { + return patch_; + } + + + // Check + + //- Check that patches are identical + void checkPatch(const faePatchFieldBase& rhs) const; +}; + + /*---------------------------------------------------------------------------*\ Class faePatchField Declaration \*---------------------------------------------------------------------------*/ @@ -80,13 +151,11 @@ Ostream& operator<<(Ostream&, const faePatchField&); template class faePatchField : + public faePatchFieldBase, public Field { // Private Data - //- Reference to a patch - const faPatch& patch_; - //- Reference to internal field const DimensionedField& internalField_; @@ -103,13 +172,6 @@ public: typedef calculatedFaePatchField Calculated; - //- Runtime type information - TypeName("faePatchField"); - - //- Debug switch to disallow the use of - static int disallowGenericFaePatchField; - - // Declare run-time constructor selection tables declareRunTimeSelectionTable @@ -189,12 +251,6 @@ public: //- Construct as copy faePatchField(const faePatchField&); - //- Construct and return a clone - virtual tmp> clone() const - { - return tmp>(new faePatchField(*this)); - } - //- Construct as copy setting internal field reference faePatchField ( @@ -202,6 +258,12 @@ public: const DimensionedField& ); + //- Construct and return a clone + virtual tmp> clone() const + { + return tmp>(new faePatchField(*this)); + } + //- Construct and return a clone setting internal field reference virtual tmp> clone ( @@ -271,35 +333,15 @@ public: ); - // Member functions + // Member Functions - // Access + //- The type name for calculated patch fields + static const word& calculatedType(); - //- Return local objectRegistry - const objectRegistry& db() const; - //- Return patch - const faPatch& patch() const - { - return patch_; - } + // Attributes - //- Return dimensioned internal field reference - const DimensionedField& internalField() const - { - return internalField_; - } - - //- Return internal field reference - const Field& primitiveField() const - { - return internalField_; - } - - //- Return the type of the calculated for of faePatchField - static const word& calculatedType(); - - //- Return true if this patch field fixes a value. + //- True if this patch field fixes a value. // Needed to check if a level has to be specified while solving // Poissons equations. virtual bool fixesValue() const @@ -307,14 +349,33 @@ public: return false; } - //- Return true if this patch field is coupled + //- True if this patch field is coupled virtual bool coupled() const { return false; } - // Mapping functions + // Access + + //- Return local objectRegistry + const objectRegistry& db() const; + + //- Return dimensioned internal field reference + const DimensionedField& internalField() + const noexcept + { + return internalField_; + } + + //- Return internal field reference + const Field& primitiveField() const noexcept + { + return internalField_; + } + + + // Mapping //- Map (and resize as needed) from self given a mapping object virtual void autoMap @@ -334,13 +395,13 @@ public: virtual void write(Ostream&) const; - // Check + // Check - //- Check faePatchField against given faePatchField - void check(const faePatchField&) const; + //- Check faePatchField against given faePatchField + void check(const faePatchField&) const; - // Member operators + // Member Operators virtual void operator=(const UList&); @@ -370,7 +431,7 @@ public: virtual void operator==(const Type&); - // Ostream operator + // Ostream Operator friend Ostream& operator<< (Ostream&, const faePatchField&); }; @@ -388,6 +449,9 @@ public: #endif +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Runtime selection macros + #define makeFaePatchTypeFieldTypeName(typePatchTypeField) \ \ defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0); diff --git a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFieldBase.C b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFieldBase.C new file mode 100644 index 0000000000..8dcd03a3ae --- /dev/null +++ b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFieldBase.C @@ -0,0 +1,113 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 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 "faePatchField.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(faePatchFieldBase, 0); +} + +int Foam::faePatchFieldBase::disallowGenericPatchField +( + Foam::debug::debugSwitch("disallowGenericFaePatchField", 0) +); + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::faePatchFieldBase::faePatchFieldBase(const faPatch& p) +: + patch_(p) +{} + + +Foam::faePatchFieldBase::faePatchFieldBase +( + const faPatch& p, + const word& patchType +) +: + faePatchFieldBase(p) +{} + + +Foam::faePatchFieldBase::faePatchFieldBase +( + const faPatch& p, + const dictionary& dict +) +: + faePatchFieldBase(p) +{ + faePatchFieldBase::readDict(dict); +} + + +Foam::faePatchFieldBase::faePatchFieldBase +( + const faePatchFieldBase& rhs, + const faPatch& p +) +: + patch_(p) +{} + + +Foam::faePatchFieldBase::faePatchFieldBase(const faePatchFieldBase& rhs) +: + patch_(rhs.patch_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::faePatchFieldBase::readDict(const dictionary& dict) +{} + + +// const Foam::objectRegistry& Foam::faePatchFieldBase::db() const +// { +// return patch_.boundaryMesh().mesh().thisDb(); +// } + + +void Foam::faePatchFieldBase::checkPatch(const faePatchFieldBase& rhs) const +{ + if (&patch_ != &(rhs.patch_)) + { + FatalErrorInFunction + << "Different patches for faePatchField" + << abort(FatalError); + } +} + + +// ************************************************************************* // diff --git a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFieldNew.C b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFieldNew.C index e6a7b36022..0fda52c942 100644 --- a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFieldNew.C +++ b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFieldNew.C @@ -106,7 +106,7 @@ Foam::tmp> Foam::faePatchField::New if (!ctorPtr) { - if (!disallowGenericFaePatchField) + if (!faePatchFieldBase::disallowGenericPatchField) { ctorPtr = dictionaryConstructorTable("generic"); } diff --git a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFields.C b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFields.C index 99c429b924..29dcc54e3c 100644 --- a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFields.C +++ b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFields.C @@ -37,13 +37,6 @@ namespace Foam #define makeFaePatchField(faePatchTypeField) \ \ -defineNamedTemplateTypeNameAndDebug(faePatchTypeField, 0); \ -template<> \ -int \ -faePatchTypeField::disallowGenericFaePatchField \ -( \ - debug::debugSwitch("disallowGenericFaPatchField", 0) \ -); \ defineTemplateRunTimeSelectionTable(faePatchTypeField, patch); \ defineTemplateRunTimeSelectionTable(faePatchTypeField, patchMapper); \ defineTemplateRunTimeSelectionTable(faePatchTypeField, dictionary); diff --git a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFields.H b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFields.H index 12edc12738..f3bc8dc854 100644 --- a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFields.H +++ b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchFields.H @@ -31,8 +31,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef faePatchFields_H -#define faePatchFields_H +#ifndef Foam_faePatchFields_H +#define Foam_faePatchFields_H #include "faePatchField.H" #include "faePatchFieldsFwd.H" diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 023d56d8ce..4821d19fea 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -121,6 +121,7 @@ functionObjects/fieldSelections/volFieldSelection/volFieldSelection.C functionObjects/fieldSelections/solverFieldSelection/solverFieldSelection.C fvPatchFields = fields/fvPatchFields +$(fvPatchFields)/fvPatchField/fvPatchFieldBase.C $(fvPatchFields)/fvPatchField/fvPatchFields.C basicFvPatchFields = $(fvPatchFields)/basic @@ -254,6 +255,7 @@ $(derivedFvPatchFields)/mappedField/Sampled/makeSampledPatchFunction1s.C $(derivedFvPatchFields)/mappedField/mappedMixedFieldFvPatchField/mappedMixedFieldFvPatchFields.C fvsPatchFields = fields/fvsPatchFields +$(fvsPatchFields)/fvsPatchField/fvsPatchFieldBase.C $(fvsPatchFields)/fvsPatchField/fvsPatchFields.C basicFvsPatchFields = $(fvsPatchFields)/basic diff --git a/src/finiteVolume/fields/fvPatchFields/basic/calculated/calculatedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/basic/calculated/calculatedFvPatchField.C index 47a1c224b2..520c50d258 100644 --- a/src/finiteVolume/fields/fvPatchFields/basic/calculated/calculatedFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/basic/calculated/calculatedFvPatchField.C @@ -34,7 +34,7 @@ License template const Foam::word& Foam::fvPatchField::calculatedType() { - return calculatedFvPatchField::typeName; + return Foam::calculatedFvPatchField::typeName; } diff --git a/src/finiteVolume/fields/fvPatchFields/basic/zeroGradient/zeroGradientFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/basic/zeroGradient/zeroGradientFvPatchField.C index 7eed327cd9..7cbadacb8f 100644 --- a/src/finiteVolume/fields/fvPatchFields/basic/zeroGradient/zeroGradientFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/basic/zeroGradient/zeroGradientFvPatchField.C @@ -28,6 +28,16 @@ License #include "zeroGradientFvPatchField.H" #include "fvPatchFieldMapper.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +const Foam::word& Foam::fvPatchField::zeroGradientType() +{ + return zeroGradientFvPatchField::typeName; +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C index ded2e52eb7..29eca05a69 100644 --- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C @@ -41,13 +41,9 @@ Foam::fvPatchField::fvPatchField const DimensionedField& iF ) : + fvPatchFieldBase(p), Field(p.size()), - patch_(p), - internalField_(iF), - updated_(false), - manipulatedMatrix_(false), - useImplicit_(false), - patchType_() + internalField_(iF) {} @@ -59,13 +55,9 @@ Foam::fvPatchField::fvPatchField const Type& value ) : + fvPatchFieldBase(p), Field(p.size(), value), - patch_(p), - internalField_(iF), - updated_(false), - manipulatedMatrix_(false), - useImplicit_(false), - patchType_() + internalField_(iF) {} @@ -77,13 +69,9 @@ Foam::fvPatchField::fvPatchField const word& patchType ) : + fvPatchFieldBase(p, patchType), Field(p.size()), - patch_(p), - internalField_(iF), - updated_(false), - manipulatedMatrix_(false), - useImplicit_(false), - patchType_(patchType) + internalField_(iF) {} @@ -95,13 +83,9 @@ Foam::fvPatchField::fvPatchField const Field& f ) : + fvPatchFieldBase(p), Field(f), - patch_(p), - internalField_(iF), - updated_(false), - manipulatedMatrix_(false), - useImplicit_(false), - patchType_() + internalField_(iF) {} @@ -114,17 +98,10 @@ Foam::fvPatchField::fvPatchField const bool valueRequired ) : + fvPatchFieldBase(p, dict), Field(p.size()), - patch_(p), - internalField_(iF), - updated_(false), - manipulatedMatrix_(false), - useImplicit_(false), - patchType_() + internalField_(iF) { - dict.readIfPresent("useImplicit", useImplicit_, keyType::LITERAL); - dict.readIfPresent("patchType", patchType_, keyType::LITERAL); - if (valueRequired) { const auto* eptr = dict.findEntry("value", keyType::LITERAL); @@ -153,13 +130,9 @@ Foam::fvPatchField::fvPatchField const fvPatchFieldMapper& mapper ) : + fvPatchFieldBase(ptf, p), Field(p.size()), - patch_(p), - internalField_(iF), - updated_(false), - manipulatedMatrix_(false), - useImplicit_(ptf.useImplicit_), - patchType_(ptf.patchType_) + internalField_(iF) { // For unmapped faces set to internal field value (zero-gradient) if (notNull(iF) && mapper.hasUnmapped()) @@ -176,13 +149,9 @@ Foam::fvPatchField::fvPatchField const fvPatchField& ptf ) : + fvPatchFieldBase(ptf), Field(ptf), - patch_(ptf.patch_), - internalField_(ptf.internalField_), - updated_(false), - manipulatedMatrix_(false), - useImplicit_(ptf.useImplicit_), - patchType_(ptf.patchType_) + internalField_(ptf.internalField_) {} @@ -193,41 +162,25 @@ Foam::fvPatchField::fvPatchField const DimensionedField& iF ) : + fvPatchFieldBase(ptf), Field(ptf), - patch_(ptf.patch_), - internalField_(iF), - updated_(false), - manipulatedMatrix_(false), - useImplicit_(ptf.useImplicit_), - patchType_(ptf.patchType_) + internalField_(iF) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -const Foam::objectRegistry& Foam::fvPatchField::db() const +void Foam::fvPatchField::check(const fvPatchField& rhs) const { - return patch_.boundaryMesh().mesh(); -} - - -template -void Foam::fvPatchField::check(const fvPatchField& ptf) const -{ - if (&patch_ != &(ptf.patch_)) - { - FatalErrorInFunction - << "different patches for fvPatchFields" - << abort(FatalError); - } + fvPatchFieldBase::checkPatch(rhs); } template Foam::tmp> Foam::fvPatchField::snGrad() const { - return patch_.deltaCoeffs()*(*this - patchInternalField()); + return patch().deltaCoeffs()*(*this - patchInternalField()); } @@ -235,14 +188,14 @@ template Foam::tmp> Foam::fvPatchField::patchInternalField() const { - return patch_.patchInternalField(internalField_); + return patch().patchInternalField(internalField_); } template void Foam::fvPatchField::patchInternalField(Field& pif) const { - patch_.patchInternalField(internalField_, pif); + patch().patchInternalField(internalField_, pif); } @@ -323,7 +276,7 @@ void Foam::fvPatchField::rmap template void Foam::fvPatchField::updateCoeffs() { - updated_ = true; + fvPatchFieldBase::setUpdated(true); } @@ -331,11 +284,11 @@ template void Foam::fvPatchField::updateWeightedCoeffs(const scalarField& weights) { // Default behaviour ignores the weights - if (!updated_) + if (!updated()) { updateCoeffs(); - updated_ = true; + fvPatchFieldBase::setUpdated(true); } } @@ -343,20 +296,20 @@ void Foam::fvPatchField::updateWeightedCoeffs(const scalarField& weights) template void Foam::fvPatchField::evaluate(const Pstream::commsTypes) { - if (!updated_) + if (!updated()) { updateCoeffs(); } - updated_ = false; - manipulatedMatrix_ = false; + fvPatchFieldBase::setUpdated(false); + fvPatchFieldBase::setManipulated(false); } template void Foam::fvPatchField::manipulateMatrix(fvMatrix& matrix) { - manipulatedMatrix_ = true; + fvPatchFieldBase::setManipulated(true); } @@ -367,7 +320,7 @@ void Foam::fvPatchField::manipulateMatrix const scalarField& weights ) { - manipulatedMatrix_ = true; + fvPatchFieldBase::setManipulated(true); } @@ -379,7 +332,7 @@ void Foam::fvPatchField::manipulateMatrix const direction cmp ) { - manipulatedMatrix_ = true; + fvPatchFieldBase::setManipulated(true); } @@ -388,15 +341,14 @@ void Foam::fvPatchField::write(Ostream& os) const { os.writeEntry("type", type()); - if (useImplicit_) + if (!patchType().empty()) + { + os.writeEntry("patchType", patchType()); + } + if (useImplicit()) { os.writeEntry("useImplicit", "true"); } - - if (!patchType_.empty()) - { - os.writeEntry("patchType", patchType_); - } } @@ -418,7 +370,7 @@ void Foam::fvPatchField::operator= const fvPatchField& ptf ) { - check(ptf); + fvPatchFieldBase::checkPatch(ptf); Field::operator=(ptf); } @@ -429,7 +381,7 @@ void Foam::fvPatchField::operator+= const fvPatchField& ptf ) { - check(ptf); + fvPatchFieldBase::checkPatch(ptf); Field::operator+=(ptf); } @@ -440,7 +392,7 @@ void Foam::fvPatchField::operator-= const fvPatchField& ptf ) { - check(ptf); + fvPatchFieldBase::checkPatch(ptf); Field::operator-=(ptf); } @@ -451,13 +403,7 @@ void Foam::fvPatchField::operator*= const fvPatchField& ptf ) { - if (&patch_ != &ptf.patch()) - { - FatalErrorInFunction - << "incompatible patches for patch fields" - << abort(FatalError); - } - + fvPatchFieldBase::checkPatch(ptf); Field::operator*=(ptf); } @@ -468,12 +414,7 @@ void Foam::fvPatchField::operator/= const fvPatchField& ptf ) { - if (&patch_ != &ptf.patch()) - { - FatalErrorInFunction - << abort(FatalError); - } - + fvPatchFieldBase::checkPatch(ptf); Field::operator/=(ptf); } diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H index 4db51f93a4..976d9e778d 100644 --- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H @@ -40,6 +40,7 @@ Description SourceFiles fvPatchField.C + fvPatchFieldBase.C fvPatchFieldNew.C \*---------------------------------------------------------------------------*/ @@ -58,7 +59,6 @@ namespace Foam { // Forward Declarations - class objectRegistry; class dictionary; class fvPatchFieldMapper; @@ -73,22 +73,17 @@ Ostream& operator<<(Ostream&, const fvPatchField&); /*---------------------------------------------------------------------------*\ - Class fvPatchField Declaration + Class fvPatchFieldBase Declaration \*---------------------------------------------------------------------------*/ -template -class fvPatchField -: - public Field +//- Template invariant parts for fvPatchField +class fvPatchFieldBase { // Private Data //- Reference to patch const fvPatch& patch_; - //- Reference to internal field - const DimensionedField& internalField_; - //- Update index used so that updateCoeffs is called only once during //- the construction of the matrix bool updated_; @@ -100,12 +95,143 @@ class fvPatchField //- Use implicit formulation bool useImplicit_; - //- Optional patch type, used to allow specified boundary conditions - // to be applied to constraint patches by providing the constraint + //- Optional patch type + // Used to allow specified boundary conditions to be applied + // to constraint patches by providing the constraint // patch type as 'patchType' word patchType_; +protected: + + // Protected Member Functions + + //- Read dictionary entries. + // Useful when initially constructed without a dictionary + virtual void readDict(const dictionary& dict); + + //- Set updated state + void setUpdated(bool state) noexcept + { + updated_ = state; + } + + //- Set matrix manipulated state + void setManipulated(bool state) noexcept + { + manipulatedMatrix_ = state; + } + +public: + + //- Debug switch to disallow the use of generic fvPatchField + static int disallowGenericPatchField; + + //- Runtime type information + TypeName("fvPatchField"); + + + // Constructors + + //- Construct from patch + explicit fvPatchFieldBase(const fvPatch& p); + + //- Construct from patch and patch type + explicit fvPatchFieldBase(const fvPatch& p, const word& patchType); + + //- Construct from patch and dictionary + fvPatchFieldBase(const fvPatch& p, const dictionary& dict); + + //- Copy construct with new patch + fvPatchFieldBase(const fvPatchFieldBase& rhs, const fvPatch& p); + + //- Copy construct + fvPatchFieldBase(const fvPatchFieldBase& rhs); + + + //- Destructor + virtual ~fvPatchFieldBase() = default; + + + // Member Functions + + // Access + + //- The associated objectRegistry + const objectRegistry& db() const; + + //- Return the patch + const fvPatch& patch() const noexcept + { + return patch_; + } + + //- The optional patch type + const word& patchType() const noexcept + { + return patchType_; + } + + //- The optional patch type + word& patchType() noexcept + { + return patchType_; + } + + + // Solution + + //- True if the boundary condition has already been updated + bool updated() const noexcept + { + return updated_; + } + + //- True if the matrix has already been manipulated + bool manipulatedMatrix() const noexcept + { + return manipulatedMatrix_; + } + + //- Use implicit formulation for coupled patches only + bool useImplicit() const noexcept + { + return useImplicit_; + } + + //- Set useImplicit on/off + // \return old value + bool useImplicit(bool on) noexcept + { + bool old(useImplicit_); + useImplicit_ = on; + return old; + } + + + // Check + + //- Check that patches are identical + void checkPatch(const fvPatchFieldBase& rhs) const; +}; + + +/*---------------------------------------------------------------------------*\ + Class fvPatchField Declaration +\*---------------------------------------------------------------------------*/ + +template +class fvPatchField +: + public fvPatchFieldBase, + public Field +{ + // Private Data + + //- Reference to internal field + const DimensionedField& internalField_; + + public: //- The internal field type associated with the patch field @@ -118,13 +244,6 @@ public: typedef calculatedFvPatchField Calculated; - //- Runtime type information - TypeName("fvPatchField"); - - //- Debug switch to disallow the use of genericFvPatchField - static int disallowGenericFvPatchField; - - // Declare run-time constructor selection tables declareRunTimeSelectionTable @@ -221,12 +340,6 @@ public: //- Construct as copy fvPatchField(const fvPatchField&); - //- Construct and return a clone - virtual tmp> clone() const - { - return tmp>::New(*this); - } - //- Construct as copy setting internal field reference fvPatchField ( @@ -234,6 +347,12 @@ public: const DimensionedField& ); + //- Construct and return a clone + virtual tmp> clone() const + { + return tmp>::New(*this); + } + //- Construct and return a clone setting internal field reference virtual tmp> clone ( @@ -304,35 +423,21 @@ public: //- Destructor - virtual ~fvPatchField() = default; + virtual ~fvPatchField() = default; // Member Functions - // Implicit Functions + //- The type name for calculated patch fields + static const word& calculatedType(); - //- Use implicit formulation for coupled patches only - bool useImplicit() const noexcept - { - return useImplicit_; - } - - //- Set useImplicit on/off - // \return old value - bool useImplicit(bool on) noexcept - { - bool old(useImplicit_); - useImplicit_ = on; - return old; - } + //- The type name for zeroGradient patch fields + static const word& zeroGradientType(); // Attributes - //- Return the type of the calculated for of fvPatchField - static const word& calculatedType(); - - //- Return true if this patch field fixes a value. + //- True if this patch field fixes a value. // Needed to check if a level has to be specified while solving // Poissons equations. virtual bool fixesValue() const @@ -340,14 +445,14 @@ public: return false; } - //- Return true if the value of the patch field - // is altered by assignment (the default) + //- True if the value of the patch field + //- is altered by assignment (the default) virtual bool assignable() const { return true; } - //- Return true if this patch field is coupled + //- True if this patch field is coupled virtual bool coupled() const { return false; @@ -356,51 +461,19 @@ public: // Access - //- Return local objectRegistry - const objectRegistry& db() const; - - //- Return patch - const fvPatch& patch() const - { - return patch_; - } - //- Return dimensioned internal field reference - const DimensionedField& internalField() const + const DimensionedField& internalField() + const noexcept { return internalField_; } //- Return internal field reference - const Field& primitiveField() const + const Field& primitiveField() const noexcept { return internalField_; } - //- Optional patch type - const word& patchType() const - { - return patchType_; - } - - //- Optional patch type - word& patchType() - { - return patchType_; - } - - //- Return true if the boundary condition has already been updated - bool updated() const - { - return updated_; - } - - //- Return true if the matrix has already been manipulated - bool manipulatedMatrix() const - { - return manipulatedMatrix_; - } - // Mapping Functions @@ -597,7 +670,7 @@ public: virtual void operator==(const Type&); - // Ostream operator + // Ostream Operator friend Ostream& operator<< (Ostream&, const fvPatchField&); }; @@ -612,22 +685,21 @@ public: #ifdef NoRepository #include "fvPatchField.C" #include "calculatedFvPatchField.H" + #include "zeroGradientFvPatchField.H" #endif +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Runtime selection macros + #define makeFvPatchField(fvPatchTypeField) \ \ -defineNamedTemplateTypeNameAndDebug(fvPatchTypeField, 0); \ -template<> \ -int fvPatchTypeField::disallowGenericFvPatchField \ -( \ - debug::debugSwitch("disallowGenericFvPatchField", 0) \ -); \ defineTemplateRunTimeSelectionTable(fvPatchTypeField, patch); \ defineTemplateRunTimeSelectionTable(fvPatchTypeField, patchMapper); \ defineTemplateRunTimeSelectionTable(fvPatchTypeField, dictionary); +#undef addToPatchFieldRunTimeSelection #define addToPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \ addToRunTimeSelectionTable \ ( \ @@ -650,6 +722,7 @@ defineTemplateRunTimeSelectionTable(fvPatchTypeField, dictionary); // Use with caution +#undef addRemovableToPatchFieldRunTimeSelection #define addRemovableToPatchFieldRunTimeSelection\ (PatchTypeField, typePatchTypeField) \ \ diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFieldBase.C b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFieldBase.C new file mode 100644 index 0000000000..f075ada6ec --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFieldBase.C @@ -0,0 +1,130 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 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 "fvPatchField.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(fvPatchFieldBase, 0); +} + +int Foam::fvPatchFieldBase::disallowGenericPatchField +( + Foam::debug::debugSwitch("disallowGenericFvPatchField", 0) +); + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::fvPatchFieldBase::fvPatchFieldBase(const fvPatch& p) +: + patch_(p), + updated_(false), + manipulatedMatrix_(false), + useImplicit_(false), + patchType_() +{} + + +Foam::fvPatchFieldBase::fvPatchFieldBase +( + const fvPatch& p, + const word& patchType +) +: + fvPatchFieldBase(p) +{ + patchType_ = patchType; +} + + +Foam::fvPatchFieldBase::fvPatchFieldBase +( + const fvPatch& p, + const dictionary& dict +) +: + fvPatchFieldBase(p) +{ + fvPatchFieldBase::readDict(dict); +} + + +Foam::fvPatchFieldBase::fvPatchFieldBase +( + const fvPatchFieldBase& rhs, + const fvPatch& p +) +: + patch_(p), + updated_(false), + manipulatedMatrix_(false), + useImplicit_(rhs.useImplicit_), + patchType_(rhs.patchType_) +{} + + +Foam::fvPatchFieldBase::fvPatchFieldBase(const fvPatchFieldBase& rhs) +: + patch_(rhs.patch_), + updated_(false), + manipulatedMatrix_(false), + useImplicit_(rhs.useImplicit_), + patchType_(rhs.patchType_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::fvPatchFieldBase::readDict(const dictionary& dict) +{ + dict.readIfPresent("patchType", patchType_, keyType::LITERAL); + dict.readIfPresent("useImplicit", useImplicit_, keyType::LITERAL); +} + + +const Foam::objectRegistry& Foam::fvPatchFieldBase::db() const +{ + return patch_.boundaryMesh().mesh(); +} + + +void Foam::fvPatchFieldBase::checkPatch(const fvPatchFieldBase& rhs) const +{ + if (&patch_ != &(rhs.patch_)) + { + FatalErrorInFunction + << "Different patches for fvPatchField" + << abort(FatalError); + } +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFieldNew.C b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFieldNew.C index 7a220be7f6..eb7d4054f9 100644 --- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFieldNew.C +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFieldNew.C @@ -69,14 +69,14 @@ Foam::tmp> Foam::fvPatchField::New } - tmp> tfvp = ctorPtr(p, iF); + tmp> tpfld(ctorPtr(p, iF)); - // Check if constraint type override and store patchType if so + // If constraint type: override and store patchType if (patchTypeCtor) { - tfvp.ref().patchType() = actualPatchType; + tpfld.ref().patchType() = actualPatchType; } - return tfvp; + return tpfld; } @@ -114,7 +114,7 @@ Foam::tmp> Foam::fvPatchField::New if (!ctorPtr) { - if (!disallowGenericFvPatchField) + if (!fvPatchFieldBase::disallowGenericPatchField) { ctorPtr = dictionaryConstructorTable("generic"); } diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFields.H b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFields.H index f134e55089..0881910bdf 100644 --- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFields.H +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFields.H @@ -25,8 +25,8 @@ License \*---------------------------------------------------------------------------*/ -#ifndef fvPatchFields_H -#define fvPatchFields_H +#ifndef Foam_fvPatchFields_H +#define Foam_fvPatchFields_H #include "fvPatchField.H" #include "fvPatchFieldsFwd.H" diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFieldsFwd.H b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFieldsFwd.H index ef333653e0..4e22a76e5e 100644 --- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFieldsFwd.H +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchFieldsFwd.H @@ -25,8 +25,8 @@ License \*---------------------------------------------------------------------------*/ -#ifndef fvPatchFieldsFwd_H -#define fvPatchFieldsFwd_H +#ifndef Foam_fvPatchFieldsFwd_H +#define Foam_fvPatchFieldsFwd_H #include "fieldTypes.H" diff --git a/src/finiteVolume/fields/fvsPatchFields/basic/calculated/calculatedFvsPatchField.C b/src/finiteVolume/fields/fvsPatchFields/basic/calculated/calculatedFvsPatchField.C index f3d2a56818..210db114ac 100644 --- a/src/finiteVolume/fields/fvsPatchFields/basic/calculated/calculatedFvsPatchField.C +++ b/src/finiteVolume/fields/fvsPatchFields/basic/calculated/calculatedFvsPatchField.C @@ -34,7 +34,7 @@ License template const Foam::word& Foam::fvsPatchField::calculatedType() { - return calculatedFvsPatchField::typeName; + return Foam::calculatedFvsPatchField::typeName; } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.C b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.C index b4c20b8c92..dfeb9b5da3 100644 --- a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.C +++ b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.C @@ -41,8 +41,8 @@ Foam::fvsPatchField::fvsPatchField const DimensionedField& iF ) : + fvsPatchFieldBase(p), Field(p.size()), - patch_(p), internalField_(iF) {} @@ -55,8 +55,8 @@ Foam::fvsPatchField::fvsPatchField const Field& f ) : + fvsPatchFieldBase(p), Field(f), - patch_(p), internalField_(iF) {} @@ -70,8 +70,8 @@ Foam::fvsPatchField::fvsPatchField const fvPatchFieldMapper& mapper ) : + fvsPatchFieldBase(ptf, p), Field(ptf, mapper), - patch_(p), internalField_(iF) {} @@ -85,8 +85,8 @@ Foam::fvsPatchField::fvsPatchField const bool valueRequired ) : + fvsPatchFieldBase(p, dict), Field(p.size()), - patch_(p), internalField_(iF) { if (valueRequired) @@ -111,8 +111,8 @@ Foam::fvsPatchField::fvsPatchField template Foam::fvsPatchField::fvsPatchField(const fvsPatchField& ptf) : + fvsPatchFieldBase(ptf), Field(ptf), - patch_(ptf.patch_), internalField_(ptf.internalField_) {} @@ -124,30 +124,18 @@ Foam::fvsPatchField::fvsPatchField const DimensionedField& iF ) : + fvsPatchFieldBase(ptf), Field(ptf), - patch_(ptf.patch_), internalField_(iF) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template -const Foam::objectRegistry& Foam::fvsPatchField::db() const -{ - return patch_.boundaryMesh().mesh(); -} - - template void Foam::fvsPatchField::check(const fvsPatchField& ptf) const { - if (&patch_ != &(ptf.patch_)) - { - FatalErrorInFunction - << "different patches for fvsPatchFields" - << abort(FatalError); - } + fvsPatchFieldBase::checkPatch(ptf); } @@ -196,7 +184,7 @@ void Foam::fvsPatchField::operator= const fvsPatchField& ptf ) { - check(ptf); + fvsPatchFieldBase::checkPatch(ptf); Field::operator=(ptf); } @@ -207,7 +195,7 @@ void Foam::fvsPatchField::operator+= const fvsPatchField& ptf ) { - check(ptf); + fvsPatchFieldBase::checkPatch(ptf); Field::operator+=(ptf); } @@ -218,7 +206,7 @@ void Foam::fvsPatchField::operator-= const fvsPatchField& ptf ) { - check(ptf); + fvsPatchFieldBase::checkPatch(ptf); Field::operator-=(ptf); } @@ -229,13 +217,7 @@ void Foam::fvsPatchField::operator*= const fvsPatchField& ptf ) { - if (&patch_ != &ptf.patch()) - { - FatalErrorInFunction - << "incompatible patches for patch fields" - << abort(FatalError); - } - + fvsPatchFieldBase::checkPatch(ptf); Field::operator*=(ptf); } @@ -246,12 +228,7 @@ void Foam::fvsPatchField::operator/= const fvsPatchField& ptf ) { - if (&patch_ != &ptf.patch()) - { - FatalErrorInFunction - << abort(FatalError); - } - + fvsPatchFieldBase::checkPatch(ptf); Field::operator/=(ptf); } diff --git a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.H b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.H index 0ac5952136..1542e9a743 100644 --- a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.H +++ b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.H @@ -56,7 +56,6 @@ namespace Foam { // Forward Declarations - class objectRegistry; class dictionary; class fvPatchFieldMapper; @@ -70,19 +69,87 @@ Ostream& operator<<(Ostream&, const fvsPatchField&); /*---------------------------------------------------------------------------*\ - Class patch Declaration + Class fvsPatchFieldBase Declaration \*---------------------------------------------------------------------------*/ -template -class fvsPatchField -: - public Field +//- Template invariant parts for fvsPatchField +class fvsPatchFieldBase { // Private Data //- Reference to patch const fvPatch& patch_; +protected: + + // Protected Member Functions + + //- Read dictionary entries. + // Useful when initially constructed without a dictionary + virtual void readDict(const dictionary& dict); + + +public: + + //- Debug switch to disallow the use of generic fvsPatchField + static int disallowGenericPatchField; + + //- Runtime type information + TypeName("fvsPatchField"); + + + // Constructors + + //- Construct from patch + explicit fvsPatchFieldBase(const fvPatch& p); + + //- Construct from patch and dictionary (unused) + fvsPatchFieldBase(const fvPatch& p, const dictionary& dict); + + //- Copy construct with new patch + fvsPatchFieldBase(const fvsPatchFieldBase& rhs, const fvPatch& p); + + //- Copy construct + fvsPatchFieldBase(const fvsPatchFieldBase& rhs); + + + //- Destructor + virtual ~fvsPatchFieldBase() = default; + + + // Member Functions + + // Access + + //- The associated objectRegistry + const objectRegistry& db() const; + + //- Return the patch + const fvPatch& patch() const noexcept + { + return patch_; + } + + + // Check + + //- Check that patches are identical + void checkPatch(const fvsPatchFieldBase& rhs) const; +}; + + +/*---------------------------------------------------------------------------*\ + Class fvsPatchField Declaration +\*---------------------------------------------------------------------------*/ + +template +class fvsPatchField +: + public fvsPatchFieldBase, + public Field +{ + // Private Data + //- Reference to internal field const DimensionedField& internalField_; @@ -99,13 +166,6 @@ public: typedef calculatedFvsPatchField Calculated; - //- Runtime type information - TypeName("fvsPatchField"); - - //- Debug switch to disallow the use of genericFvsPatchField - static int disallowGenericFvsPatchField; - - // Declare run-time constructor selection tables declareRunTimeSelectionTable @@ -186,12 +246,6 @@ public: //- Construct as copy fvsPatchField(const fvsPatchField&); - //- Construct and return a clone - virtual tmp> clone() const - { - return tmp>::New(*this); - } - //- Construct as copy setting internal field reference fvsPatchField ( @@ -199,6 +253,12 @@ public: const DimensionedField& ); + //- Construct and return a clone + virtual tmp> clone() const + { + return tmp>::New(*this); + } + //- Construct and return a clone setting internal field reference virtual tmp> clone ( @@ -269,38 +329,18 @@ public: //- Destructor - virtual ~fvsPatchField() = default; + virtual ~fvsPatchField() = default; - // Member functions + // Member Functions - // Access + //- The type name for calculated patch fields + static const word& calculatedType(); - //- Return local objectRegistry - const objectRegistry& db() const; - //- Return patch - const fvPatch& patch() const - { - return patch_; - } + // Attributes - //- Return dimensioned internal field reference - const DimensionedField& internalField() const - { - return internalField_; - } - - //- Return internal field reference - const Field& primitiveField() const - { - return internalField_; - } - - //- Return the type of the calculated for of fvsPatchField - static const word& calculatedType(); - - //- Return true if this patch field fixes a value. + //- True if this patch field fixes a value. // Needed to check if a level has to be specified while solving // Poissons equations. virtual bool fixesValue() const @@ -308,14 +348,30 @@ public: return false; } - //- Return true if this patch field is coupled + //- True if this patch field is coupled virtual bool coupled() const { return false; } - // Mapping functions + // Access + + //- Return dimensioned internal field reference + const DimensionedField& internalField() + const noexcept + { + return internalField_; + } + + //- Return internal field reference + const Field& primitiveField() const noexcept + { + return internalField_; + } + + + // Mapping Functions //- Map (and resize as needed) from self given a mapping object virtual void autoMap @@ -341,7 +397,7 @@ public: void check(const fvsPatchField&) const; - // Member operators + // Member Operators virtual void operator=(const UList&); @@ -371,7 +427,7 @@ public: virtual void operator==(const Type&); - // Ostream operator + // Ostream Operator friend Ostream& operator<< (Ostream&, const fvsPatchField&); }; @@ -389,6 +445,9 @@ public: #endif +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Runtime selection macros + #define makeFvsPatchTypeFieldTypeName(type) \ \ defineNamedTemplateTypeNameAndDebug(type, 0); diff --git a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldBase.C b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldBase.C new file mode 100644 index 0000000000..3abe281ccf --- /dev/null +++ b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldBase.C @@ -0,0 +1,101 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 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 "fvsPatchField.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(fvsPatchFieldBase, 0); +} + +int Foam::fvsPatchFieldBase::disallowGenericPatchField +( + Foam::debug::debugSwitch("disallowGenericFvsPatchField", 0) +); + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::fvsPatchFieldBase::fvsPatchFieldBase(const fvPatch& p) +: + patch_(p) +{} + + +Foam::fvsPatchFieldBase::fvsPatchFieldBase +( + const fvPatch& p, + const dictionary& dict +) +: + patch_(p) +{} + + +Foam::fvsPatchFieldBase::fvsPatchFieldBase +( + const fvsPatchFieldBase& rhs, + const fvPatch& p +) +: + patch_(p) +{} + + +Foam::fvsPatchFieldBase::fvsPatchFieldBase(const fvsPatchFieldBase& rhs) +: + patch_(rhs.patch_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::fvsPatchFieldBase::readDict(const dictionary& dict) +{} + + +const Foam::objectRegistry& Foam::fvsPatchFieldBase::db() const +{ + return patch_.boundaryMesh().mesh(); +} + + +void Foam::fvsPatchFieldBase::checkPatch(const fvsPatchFieldBase& rhs) const +{ + if (&patch_ != &(rhs.patch_)) + { + FatalErrorInFunction + << "Different patches for fvsPatchField" + << abort(FatalError); + } +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldNew.C b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldNew.C index 854857339e..6c39051c70 100644 --- a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldNew.C +++ b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldNew.C @@ -102,7 +102,7 @@ Foam::tmp> Foam::fvsPatchField::New if (!ctorPtr) { - if (!disallowGenericFvsPatchField) + if (!fvsPatchFieldBase::disallowGenericPatchField) { ctorPtr = dictionaryConstructorTable("generic"); } diff --git a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFields.C b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFields.C index 804de5295f..bd696c9ec1 100644 --- a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFields.C +++ b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFields.C @@ -36,12 +36,6 @@ namespace Foam #define makeFvsPatchField(fvsPatchTypeField) \ \ -defineNamedTemplateTypeNameAndDebug(fvsPatchTypeField, 0); \ -template<> \ -int fvsPatchTypeField::disallowGenericFvsPatchField \ -( \ - debug::debugSwitch("disallowGenericFvsPatchField", 0) \ -); \ defineTemplateRunTimeSelectionTable(fvsPatchTypeField, patch); \ defineTemplateRunTimeSelectionTable(fvsPatchTypeField, patchMapper); \ defineTemplateRunTimeSelectionTable(fvsPatchTypeField, dictionary); diff --git a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFields.H b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFields.H index 86ee4fb525..6f1990822f 100644 --- a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFields.H +++ b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFields.H @@ -30,8 +30,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef fvsPatchFields_H -#define fvsPatchFields_H +#ifndef Foam_fvsPatchFields_H +#define Foam_fvsPatchFields_H #include "fvsPatchField.H" #include "fvsPatchFieldsFwd.H" diff --git a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldsFwd.H b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldsFwd.H index 1f03140186..3f3629e682 100644 --- a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldsFwd.H +++ b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFieldsFwd.H @@ -30,8 +30,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef fvsPatchFieldsFwd_H -#define fvsPatchFieldsFwd_H +#ifndef Foam_fvsPatchFieldsFwd_H +#define Foam_fvsPatchFieldsFwd_H #include "fieldTypes.H" diff --git a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.C b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.C index 6d85301a44..4d30c3baaa 100644 --- a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.C +++ b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020-2021 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -78,12 +78,13 @@ Foam::fvPatch::~fvPatch() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::fvPatch::constraintType(const word& pt) +bool Foam::fvPatch::constraintType(const word& patchType) { return ( - fvPatchField::patchConstructorTablePtr_ - && fvPatchField::patchConstructorTablePtr_->found(pt) + !patchType.empty() + && fvPatchField::patchConstructorTablePtr_ + && fvPatchField::patchConstructorTablePtr_->found(patchType) ); } @@ -104,7 +105,7 @@ Foam::wordList Foam::fvPatch::constraintTypes() } } - cTypes.setSize(i); + cTypes.resize(i); return cTypes; } diff --git a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H index b184dd0ec6..5ee1cefb04 100644 --- a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H +++ b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H @@ -195,7 +195,7 @@ public: } //- Return true if the given type is a constraint type - static bool constraintType(const word& pt); + static bool constraintType(const word& patchType); //- Return a list of all the constraint patch types static wordList constraintTypes(); diff --git a/src/overset/oversetPolyPatch/oversetPointPatchFields.C b/src/overset/oversetPolyPatch/oversetPointPatchFields.C index 874e39aeaa..4ac0ae810f 100644 --- a/src/overset/oversetPolyPatch/oversetPointPatchFields.C +++ b/src/overset/oversetPolyPatch/oversetPointPatchFields.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2017 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,35 +40,35 @@ addNamedToRunTimeSelectionTable ( pointPatchScalarField, slipPointPatchScalarField, - pointPatch, + patch, overset ); addNamedToRunTimeSelectionTable ( pointPatchVectorField, slipPointPatchVectorField, - pointPatch, + patch, overset ); addNamedToRunTimeSelectionTable ( pointPatchSphericalTensorField, slipPointPatchSphericalTensorField, - pointPatch, + patch, overset ); addNamedToRunTimeSelectionTable ( pointPatchSymmTensorField, slipPointPatchSymmTensorField, - pointPatch, + patch, overset ); addNamedToRunTimeSelectionTable ( pointPatchTensorField, slipPointPatchTensorField, - pointPatch, + patch, overset ); diff --git a/tutorials/compressible/rhoPorousSimpleFoam/angledDuct/implicit/system/sampling b/tutorials/compressible/rhoPorousSimpleFoam/angledDuct/implicit/system/sampling index f269fc0514..f11505626d 100644 --- a/tutorials/compressible/rhoPorousSimpleFoam/angledDuct/implicit/system/sampling +++ b/tutorials/compressible/rhoPorousSimpleFoam/angledDuct/implicit/system/sampling @@ -41,7 +41,7 @@ cellZoneID fieldName, mesh, dimless, - zeroGradientFvPatchField::typeName + fvPatchScalarField::zeroGradientType() ) ); diff --git a/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system/relVelocity b/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system/relVelocity index 32fcce76f4..544ac846ef 100644 --- a/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system/relVelocity +++ b/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system/relVelocity @@ -91,7 +91,7 @@ relVelocity "relVelocity", mesh(), dimensionedVector(dimVelocity, Zero), - "zeroGradient" + fvPatchVectorField::zeroGradientType() ); auto& relVel = trelVel.ref(); auto& relVelField = relVel.primitiveFieldRef();