diff --git a/src/OpenFOAM/db/dictionary/dictionaryContent/dictionaryContent.C b/src/OpenFOAM/db/dictionary/dictionaryContent/dictionaryContent.C index 4a7e8e6b51a42a2122974a181a5d62e0b58bba6c..f2037f4f143838f7984797737d6df6e9552b9dd1 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryContent/dictionaryContent.C +++ b/src/OpenFOAM/db/dictionary/dictionaryContent/dictionaryContent.C @@ -27,21 +27,18 @@ License #include "dictionaryContent.H" -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // -Foam::dictionary -Foam::dictionaryContent::copyDict +namespace Foam +{ + +template<class UnaryPredicate> +static dictionary copyFilteredDict ( const dictionary& input, - const wordRes& allow, - const wordRes& deny + const UnaryPredicate& pred ) { - if (allow.empty() && deny.empty()) - { - return dictionary(input); - } - dictionary dict; dict.name() = input.name(); // rename @@ -57,20 +54,9 @@ Foam::dictionaryContent::copyDict // - could also have a "pruneRegex" flag (for example) accept = true; } - else if (allow.size()) - { - const auto result = allow.matched(key); - - accept = - ( - result == wordRe::LITERAL - ? true - : (result == wordRe::REGEX && !deny.match(key)) - ); - } else { - accept = !deny.match(key); + accept = pred(key); } if (accept) @@ -82,5 +68,97 @@ Foam::dictionaryContent::copyDict return dict; } +} // End namespace Foam + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +Foam::dictionary +Foam::dictionaryContent::copyDict +( + const dictionary& input, + const wordList& allow, + const wordList& deny +) +{ + if (allow.empty()) + { + if (deny.empty()) + { + // Pass-through + return dictionary(input); + } + + // Deny only + return copyFilteredDict + ( + input, + [&](const std::string& key) { return !deny.found(key); } + ); + } + + // Allow is non-empty + + // No general case with deny as well + return copyFilteredDict + ( + input, + [&](const std::string& key) { return allow.found(key); } + ); +} + + +Foam::dictionary +Foam::dictionaryContent::copyDict +( + const dictionary& input, + const wordRes& allow, + const wordRes& deny +) +{ + if (allow.empty()) + { + if (deny.empty()) + { + // Pass-through + return dictionary(input); + } + + // Deny only + return copyFilteredDict + ( + input, + [&](const std::string& key) { return !deny.match(key); } + ); + } + + // Allow is non-empty + + if (deny.empty()) + { + return copyFilteredDict + ( + input, + [&](const std::string& key) { return allow.match(key); } + ); + } + + // General case - have both deny and allow + return copyFilteredDict + ( + input, + [&](const std::string& key) + { + const auto result = allow.matched(key); + return + ( + result == wordRe::LITERAL + ? true + : (result == wordRe::REGEX && !deny.match(key)) + ); + } + ); +} + // ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/dictionaryContent/dictionaryContent.H b/src/OpenFOAM/db/dictionary/dictionaryContent/dictionaryContent.H index b4c454230c1c14a0974a9ec10c7f3bc6a89d0bd9..c1137f1eef17b14c32cf3689634a101df5be436b 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryContent/dictionaryContent.H +++ b/src/OpenFOAM/db/dictionary/dictionaryContent/dictionaryContent.H @@ -86,6 +86,19 @@ public: // Member Functions + //- Copy construct a dictionary, + //- filtered by simple allow/deny lists + // + // An empty 'allow' list accepts everything not in the 'deny' list. + // + // \return filtered dictionary copy + static dictionary copyDict + ( + const dictionary& input, + const wordList& allow = wordList(), + const wordList& deny = wordList() + ); + //- Copy construct a dictionary, //- filtered by a combination of allow/deny lists // @@ -104,10 +117,11 @@ public: static dictionary copyDict ( const dictionary& input, - const wordRes& allow = wordRes(), + const wordRes& allow, const wordRes& deny = wordRes() ); + //- Read-access to the content const dictionary& dict() const noexcept { diff --git a/src/OpenFOAM/expressions/Function1/Function1Expression.C b/src/OpenFOAM/expressions/Function1/Function1Expression.C index a33c1f01a2ee42572a5dc8fcb690daf720a33f76..a0461b59f669f2c2c6a0043612ae769b0cf41274 100644 --- a/src/OpenFOAM/expressions/Function1/Function1Expression.C +++ b/src/OpenFOAM/expressions/Function1/Function1Expression.C @@ -38,7 +38,7 @@ Foam::Function1Types::Function1Expression<Type>::Function1Expression ) : Function1<Type>(entryName, dict, obrPtr), - dict_(dict), + dict_(dict), // Deep copy valueExpr_(), driver_(1, dict_) { @@ -48,8 +48,8 @@ Foam::Function1Types::Function1Expression<Type>::Function1Expression } string expr; - dict.readEntry("expression", expr); - valueExpr_ = expressions::exprString(expr, dict); + dict_.readEntry("expression", expr); + valueExpr_ = expressions::exprString(std::move(expr), dict_); // Basic sanity if (valueExpr_.empty()) @@ -70,9 +70,9 @@ Foam::Function1Types::Function1Expression<Type>::Function1Expression ) : Function1<Type>(rhs), - dict_(rhs.dict_), + dict_(rhs.dict_), // Deep copy valueExpr_(rhs.valueExpr_), - driver_(1, rhs.driver_) + driver_(1, rhs.driver_, dict_) {} diff --git a/src/OpenFOAM/expressions/Function1/Function1Expression.H b/src/OpenFOAM/expressions/Function1/Function1Expression.H index 824f84312ef2586244f1ce740f7ddfba774eef96..69ecf324246bf27abe368a0dc3101cf5170fffef 100644 --- a/src/OpenFOAM/expressions/Function1/Function1Expression.H +++ b/src/OpenFOAM/expressions/Function1/Function1Expression.H @@ -124,6 +124,12 @@ public: //- Copy construct explicit Function1Expression(const Function1Expression<Type>& rhs); + //- Construct and return a clone + virtual tmp<Function1<Type>> clone() const + { + return tmp<Function1<Type>>(new Function1Expression<Type>(*this)); + } + //- Destructor virtual ~Function1Expression() = default; diff --git a/src/OpenFOAM/expressions/exprDriver/exprDriver.C b/src/OpenFOAM/expressions/exprDriver/exprDriver.C index 9bc1f75b11ca6dc227c1d325685447452e75724a..d28d84d735b2f393a185af74a2fc8a1bf857fad9 100644 --- a/src/OpenFOAM/expressions/exprDriver/exprDriver.C +++ b/src/OpenFOAM/expressions/exprDriver/exprDriver.C @@ -199,10 +199,11 @@ Foam::expressions::exprDriver::exprDriver Foam::expressions::exprDriver::exprDriver ( - const exprDriver& rhs + const exprDriver& rhs, + const dictionary& dict ) : - dict_(rhs.dict_), + dict_(dict), result_(rhs.result_), variableStrings_(rhs.variableStrings_), variables_(rhs.variables_), diff --git a/src/OpenFOAM/expressions/exprDriver/exprDriver.H b/src/OpenFOAM/expressions/exprDriver/exprDriver.H index ccefb049b35f0272fe2f2b2f7b2955857e9b9ed4..11590e51a3b7cf084bd5ca464fdc07f09413308a 100644 --- a/src/OpenFOAM/expressions/exprDriver/exprDriver.H +++ b/src/OpenFOAM/expressions/exprDriver/exprDriver.H @@ -277,16 +277,21 @@ protected: virtual exprResult getRemoteResult(const exprDriver& other) const; - //- No copy assignment - void operator=(const exprDriver&) = delete; - - public: //- Runtime type information TypeName("exprDriver"); + // Generated Methods + + //- No copy construct + exprDriver(const exprDriver&) = delete; + + //- No copy assignment + void operator=(const exprDriver&) = delete; + + // Constructors //- Default construct, and default construct with search preferences @@ -296,8 +301,8 @@ public: const dictionary& dict = dictionary::null ); - //- Copy construct - exprDriver(const exprDriver& rhs); + //- Copy construct with new dictionary reference + exprDriver(const exprDriver& rhs, const dictionary& dict); //- Construct from a dictionary explicit exprDriver(const dictionary& dict); diff --git a/src/OpenFOAM/expressions/exprDriver/exprDriverFunctions.C b/src/OpenFOAM/expressions/exprDriver/exprDriverFunctions.C index 95f90b81ea20cf55164b3dbe71ec97b454092bbf..195eef4301d2232e7bec3c786c8988216fd8c2c5 100644 --- a/src/OpenFOAM/expressions/exprDriver/exprDriverFunctions.C +++ b/src/OpenFOAM/expressions/exprDriver/exprDriverFunctions.C @@ -188,10 +188,7 @@ static void writeFuncsImpl os.beginBlock(subDictName); } - os.beginBlock(entryName); - os.writeEntry("type", (*funcPtr).type()); - (*funcPtr).writeEntries(os); - os.endBlock(); + (*funcPtr).writeData(os); } } diff --git a/src/OpenFOAM/expressions/exprString/exprString.C b/src/OpenFOAM/expressions/exprString/exprString.C index 2d6bd03bc094df7c86cba4e7d3d53ab42d31b599..43cbbb36084bb8048fca597080c382ec2364b995 100644 --- a/src/OpenFOAM/expressions/exprString/exprString.C +++ b/src/OpenFOAM/expressions/exprString/exprString.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -86,4 +86,36 @@ Foam::expressions::exprString::expand } +bool Foam::expressions::exprString::writeEntry +( + const word& keyword, + Ostream& os, + bool writeEmpty +) const +{ + const bool ok = (writeEmpty || !empty()); + + if (ok) + { + if (!keyword.empty()) + { + os.writeKeyword(keyword); + } + + // Write as regular or verbatim string + + token tok(*this); + if (!empty()) + { + tok.setType(token::tokenType::VERBATIM); + } + + os.write(tok); + os.endEntry(); + } + + return ok; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/expressions/exprString/exprString.H b/src/OpenFOAM/expressions/exprString/exprString.H index 9a670930f2bcb6850c73bb9f50cddeb8e111a6b7..f1d5bef94fb03258c836622a53bd044743062339 100644 --- a/src/OpenFOAM/expressions/exprString/exprString.H +++ b/src/OpenFOAM/expressions/exprString/exprString.H @@ -183,6 +183,19 @@ public: //- Move assign from string. No expansions, no comment stripping inline exprString& operator=(std::string&& str); + + + // Write + + //- Dictionary entry for expression string, normally suppressing + //- empty strings. Generally used verbatim output (readability) + // \return true if entry was written + bool writeEntry + ( + const word& keyword, + Ostream& os, + bool writeEmpty = false + ) const; }; diff --git a/src/OpenFOAM/expressions/fields/fieldExprDriver.C b/src/OpenFOAM/expressions/fields/fieldExprDriver.C index 5959596d0c273fa2ab18811e8ed748e575c84fe7..9fd1092bee40e4ddd1dcbb20c8cd32c99b860e09 100644 --- a/src/OpenFOAM/expressions/fields/fieldExprDriver.C +++ b/src/OpenFOAM/expressions/fields/fieldExprDriver.C @@ -75,11 +75,12 @@ Foam::expressions::fieldExpr::parseDriver::parseDriver Foam::expressions::fieldExpr::parseDriver::parseDriver ( const label len, - const parseDriver& rhs + const parseDriver& rhs, + const dictionary& dict ) : parsing::genericRagelLemonDriver(), - expressions::exprDriver(rhs), + expressions::exprDriver(rhs, dict), size_(len) {} diff --git a/src/OpenFOAM/expressions/fields/fieldExprDriver.H b/src/OpenFOAM/expressions/fields/fieldExprDriver.H index c1d7ed04c880f4ad3fb7ce92dad8138a73124ba9..70ae0d2d91bf2c48bbd0e939722c2f0cc009e872 100644 --- a/src/OpenFOAM/expressions/fields/fieldExprDriver.H +++ b/src/OpenFOAM/expressions/fields/fieldExprDriver.H @@ -82,8 +82,11 @@ protected: //- The field size label size_; +public: + + ClassName("fieldExpr::driver"); - // Protected Member Functions + // Generated Methods // No copy copy construct parseDriver(const parseDriver&) = delete; @@ -92,10 +95,6 @@ protected: void operator=(const parseDriver&) = delete; -public: - - ClassName("fieldExpr::driver"); - // Constructors //- Default construct (size=1), or with specified size @@ -104,8 +103,13 @@ public: //- Construct for specified size with given dictionary parseDriver(const label len, const dictionary& dict); - //- Construct for specified size with copy of driver context - parseDriver(const label len, const parseDriver& rhs); + //- Construct for specified size, copy of driver context + parseDriver + ( + const label len, + const parseDriver& rhs, + const dictionary& dict + ); //- Destructor diff --git a/src/finiteVolume/expressions/PatchFunction1/PatchFunction1Expression.C b/src/finiteVolume/expressions/PatchFunction1/PatchFunction1Expression.C index 72211dba9e501bc903fdbc0b0e24ef6312eb6f71..72e19ce8a2237106fd4f128461ee872aec309bc2 100644 --- a/src/finiteVolume/expressions/PatchFunction1/PatchFunction1Expression.C +++ b/src/finiteVolume/expressions/PatchFunction1/PatchFunction1Expression.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,7 +41,7 @@ Foam::PatchFunction1Types::PatchExprField<Type>::PatchExprField ) : PatchFunction1<Type>(pp, entryName, dict, faceValues), - dict_(dict), + dict_(dict), // Deep copy valueExpr_(), driver_(fvPatch::lookupPatch(this->patch()), dict_) { @@ -51,8 +51,8 @@ Foam::PatchFunction1Types::PatchExprField<Type>::PatchExprField } string expr; - dict.readEntry("expression", expr); - valueExpr_ = expressions::exprString(expr, dict); + dict_.readEntry("expression", expr); + valueExpr_ = expressions::exprString(std::move(expr), dict_); // Basic sanity if (valueExpr_.empty()) @@ -84,9 +84,9 @@ Foam::PatchFunction1Types::PatchExprField<Type>::PatchExprField ) : PatchFunction1<Type>(rhs, pp), - dict_(rhs.dict_), + dict_(rhs.dict_), // Deep copy valueExpr_(rhs.valueExpr_), - driver_(fvPatch::lookupPatch(this->patch()), rhs.driver_) + driver_(fvPatch::lookupPatch(this->patch()), rhs.driver_, dict_) {} diff --git a/src/finiteVolume/expressions/base/fvExprDriver.C b/src/finiteVolume/expressions/base/fvExprDriver.C index bbf7f6d80a41bf81b28259a974a0682e38bd0022..a30649c39cddd8dd31107f45cbe1ab402d9a8663 100644 --- a/src/finiteVolume/expressions/base/fvExprDriver.C +++ b/src/finiteVolume/expressions/base/fvExprDriver.C @@ -110,10 +110,11 @@ Foam::expressions::fvExprDriver::fvExprDriver Foam::expressions::fvExprDriver::fvExprDriver ( - const fvExprDriver& rhs + const fvExprDriver& rhs, + const dictionary& dict ) : - expressions::exprDriver(rhs), + expressions::exprDriver(rhs, dict), globalScopes_(rhs.globalScopes_), delayedVariables_(rhs.delayedVariables_), storedVariables_(rhs.storedVariables_), diff --git a/src/finiteVolume/expressions/base/fvExprDriver.H b/src/finiteVolume/expressions/base/fvExprDriver.H index 60b4c41827442840ad0bec5f0275b0fcd13e1ef8..5c4f78f04ea2dd3a7514c1f372c7851eb486800c 100644 --- a/src/finiteVolume/expressions/base/fvExprDriver.H +++ b/src/finiteVolume/expressions/base/fvExprDriver.H @@ -368,8 +368,12 @@ public: const dictionary& dict = dictionary::null ); - //- Copy construct - fvExprDriver(const fvExprDriver&); + //- Copy construct with dictionary reference + explicit fvExprDriver + ( + const fvExprDriver& rhs, + const dictionary& dict + ); //- Construct from a dictionary explicit fvExprDriver(const dictionary& dict); @@ -396,8 +400,8 @@ public: const fvMesh& mesh ); - //- Clone - virtual autoPtr<fvExprDriver> clone() const = 0; + //- Not generally clonable + virtual autoPtr<fvExprDriver> clone() = delete; //- Destructor diff --git a/src/finiteVolume/expressions/fields/base/patchExprFieldBase.C b/src/finiteVolume/expressions/fields/base/patchExprFieldBase.C index 8d0e5e39748980ce9d78ac33f5687fb2eb31adb2..f304e5e5658880ab45b2172ac2aab83a2c36292d 100644 --- a/src/finiteVolume/expressions/fields/base/patchExprFieldBase.C +++ b/src/finiteVolume/expressions/fields/base/patchExprFieldBase.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2018 Bernhard Gschaider - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -170,18 +170,10 @@ void Foam::expressions::patchExprFieldBase::write(Ostream& os) const // Do not emit debug_ value - if (!valueExpr_.empty()) - { - os.writeEntry("valueExpr", valueExpr_); - } - if (!gradExpr_.empty()) - { - os.writeEntry("gradientExpr", gradExpr_); - } - if (!fracExpr_.empty()) - { - os.writeEntry("fractionExpr", fracExpr_); - } + // Write expression, but not empty ones + valueExpr_.writeEntry("valueExpr", os, false); + gradExpr_.writeEntry("gradientExpr", os, false); + fracExpr_.writeEntry("fractionExpr", os, false); } diff --git a/src/finiteVolume/expressions/fields/fvPatchFields/exprFixedValueFvPatchField.C b/src/finiteVolume/expressions/fields/fvPatchFields/exprFixedValueFvPatchField.C index a7d22e0b98d9c5d7efc88733dd1c3b57aa5308c7..71fa7dc3916b47323399e1d20f419f62005410a9 100644 --- a/src/finiteVolume/expressions/fields/fvPatchFields/exprFixedValueFvPatchField.C +++ b/src/finiteVolume/expressions/fields/fvPatchFields/exprFixedValueFvPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2009-2018 Bernhard Gschaider - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,6 +27,7 @@ License \*---------------------------------------------------------------------------*/ #include "exprFixedValueFvPatchField.H" +#include "dictionaryContent.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // @@ -49,8 +50,9 @@ Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField const DimensionedField<Type, volMesh>& iF ) : - fixedValueFvPatchField<Type>(p, iF), + parent_bctype(p, iF), expressions::patchExprFieldBase(), + dict_(), driver_(this->patch()) {} @@ -58,15 +60,16 @@ Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField template<class Type> Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField ( - const exprFixedValueFvPatchField<Type>& ptf, + const exprFixedValueFvPatchField<Type>& rhs, const fvPatch& p, const DimensionedField<Type, volMesh>& iF, const fvPatchFieldMapper& mapper ) : - fixedValueFvPatchField<Type>(ptf, p, iF, mapper), - expressions::patchExprFieldBase(ptf), - driver_(this->patch(), ptf.driver_) + parent_bctype(rhs, p, iF, mapper), + expressions::patchExprFieldBase(rhs), + dict_(rhs.dict_), // Deep copy + driver_(this->patch(), rhs.driver_, dict_) { setDebug(); DebugInFunction << nl; @@ -82,13 +85,27 @@ Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField const bool valueRequired ) : - fixedValueFvPatchField<Type>(p, iF), + parent_bctype(p, iF), expressions::patchExprFieldBase ( dict, expressions::patchExprFieldBase::expectedTypes::VALUE_TYPE ), - driver_(this->patch(), dict) + dict_ + ( + // Copy dictionary without "heavy" data chunks + dictionaryContent::copyDict + ( + dict, + wordList(), // allow + wordList // deny + ({ + "type", // redundant + "value" + }) + ) + ), + driver_(this->patch(), dict_) { setDebug(); DebugInFunction << nl; @@ -102,7 +119,7 @@ Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField } - driver_.readDict(dict); + driver_.readDict(dict_); if (dict.found("value")) { @@ -134,12 +151,13 @@ Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField template<class Type> Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField ( - const exprFixedValueFvPatchField<Type>& ptf + const exprFixedValueFvPatchField<Type>& rhs ) : - fixedValueFvPatchField<Type>(ptf), - expressions::patchExprFieldBase(ptf), - driver_(this->patch(), ptf.driver_) + parent_bctype(rhs), + expressions::patchExprFieldBase(rhs), + dict_(rhs.dict_), // Deep copy + driver_(this->patch(), rhs.driver_, dict_) { setDebug(); DebugInFunction << nl; @@ -149,13 +167,14 @@ Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField template<class Type> Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField ( - const exprFixedValueFvPatchField<Type>& ptf, + const exprFixedValueFvPatchField<Type>& rhs, const DimensionedField<Type, volMesh>& iF ) : - fixedValueFvPatchField<Type>(ptf, iF), - expressions::patchExprFieldBase(ptf), - driver_(this->patch(), ptf.driver_) + parent_bctype(rhs, iF), + expressions::patchExprFieldBase(rhs), + dict_(rhs.dict_), // Deep copy + driver_(this->patch(), rhs.driver_, dict_) { setDebug(); DebugInFunction << nl; @@ -199,14 +218,14 @@ void Foam::exprFixedValueFvPatchField<Type>::updateCoeffs() } } - fixedValueFvPatchField<Type>::updateCoeffs(); + this->parent_bctype::updateCoeffs(); } template<class Type> void Foam::exprFixedValueFvPatchField<Type>::write(Ostream& os) const { - fixedValueFvPatchField<Type>::write(os); + this->parent_bctype::write(os); expressions::patchExprFieldBase::write(os); driver_.writeCommon(os, this->debug_ || debug); diff --git a/src/finiteVolume/expressions/fields/fvPatchFields/exprFixedValueFvPatchField.H b/src/finiteVolume/expressions/fields/fvPatchFields/exprFixedValueFvPatchField.H index 5ef74552ed2db982ccebae9aef2adff8e9771110..fba2f2ed98843da080fc18469ea75d09513de1fd 100644 --- a/src/finiteVolume/expressions/fields/fvPatchFields/exprFixedValueFvPatchField.H +++ b/src/finiteVolume/expressions/fields/fvPatchFields/exprFixedValueFvPatchField.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -67,10 +67,17 @@ class exprFixedValueFvPatchField public fixedValueFvPatchField<Type>, public expressions::patchExprFieldBase { + //- The parent boundary condition type + typedef fixedValueFvPatchField<Type> parent_bctype; + + protected: // Protected Data + //- Dictionary contents for the boundary condition + dictionary dict_; + //- The expression driver expressions::patchExpr::parseDriver driver_; diff --git a/src/finiteVolume/expressions/fields/fvPatchFields/exprMixedFvPatchField.C b/src/finiteVolume/expressions/fields/fvPatchFields/exprMixedFvPatchField.C index e16d95ab671b42a8aecbba782435a16617405b8f..9fd80b6a794920c8f181d96760922939e7050c9f 100644 --- a/src/finiteVolume/expressions/fields/fvPatchFields/exprMixedFvPatchField.C +++ b/src/finiteVolume/expressions/fields/fvPatchFields/exprMixedFvPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2009-2018 Bernhard Gschaider - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,6 +26,7 @@ License \*---------------------------------------------------------------------------*/ #include "exprMixedFvPatchField.H" +#include "dictionaryContent.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // @@ -48,8 +49,9 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField const DimensionedField<Type, volMesh>& iF ) : - mixedFvPatchField<Type>(p, iF), + parent_bctype(p, iF), expressions::patchExprFieldBase(), + dict_(), driver_(this->patch()) { this->refValue() = Zero; @@ -61,15 +63,16 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField template<class Type> Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField ( - const exprMixedFvPatchField<Type>& ptf, + const exprMixedFvPatchField<Type>& rhs, const fvPatch& p, const DimensionedField<Type, volMesh>& iF, const fvPatchFieldMapper& mapper ) : - mixedFvPatchField<Type>(ptf, p, iF, mapper), - expressions::patchExprFieldBase(ptf), - driver_(this->patch(), ptf.driver_) + parent_bctype(rhs, p, iF, mapper), + expressions::patchExprFieldBase(rhs), + dict_(rhs.dict_), // Deep copy + driver_(this->patch(), rhs.driver_, dict_) { setDebug(); DebugInFunction << nl; @@ -84,13 +87,27 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField const dictionary& dict ) : - mixedFvPatchField<Type>(p, iF), + parent_bctype(p, iF), expressions::patchExprFieldBase ( dict, expressions::patchExprFieldBase::expectedTypes::MIXED_TYPE ), - driver_(this->patch(), dict) + dict_ + ( + // Copy dictionary without "heavy" data chunks + dictionaryContent::copyDict + ( + dict, + wordList(), // allow + wordList // deny + ({ + "type", // redundant + "value", "refValue", "refGradient", "valueFraction" + }) + ) + ), + driver_(this->patch(), dict_) { setDebug(); DebugInFunction << nl; @@ -144,7 +161,7 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField } - driver_.readDict(dict); + driver_.readDict(dict_); // Similar to fvPatchField constructor, which we have bypassed dict.readIfPresent("patchType", this->patchType()); @@ -217,7 +234,7 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField // but avoid our own updateCoeffs if (!this->updated()) { - this->mixedFvPatchField<Type>::updateCoeffs(); + this->parent_bctype::updateCoeffs(); } Field<Type>::operator= @@ -239,12 +256,13 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField template<class Type> Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField ( - const exprMixedFvPatchField<Type>& ptf + const exprMixedFvPatchField<Type>& rhs ) : - mixedFvPatchField<Type>(ptf), - expressions::patchExprFieldBase(ptf), - driver_(this->patch(), ptf.driver_) + parent_bctype(rhs), + expressions::patchExprFieldBase(rhs), + dict_(rhs.dict_), // Deep copy + driver_(this->patch(), rhs.driver_, dict_) { setDebug(); DebugInFunction << nl; @@ -254,13 +272,14 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField template<class Type> Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField ( - const exprMixedFvPatchField<Type>& ptf, + const exprMixedFvPatchField<Type>& rhs, const DimensionedField<Type, volMesh>& iF ) : - mixedFvPatchField<Type>(ptf, iF), - expressions::patchExprFieldBase(ptf), - driver_(this->patch(), ptf.driver_) + parent_bctype(rhs, iF), + expressions::patchExprFieldBase(rhs), + dict_(rhs.dict_), // Deep copy + driver_(this->patch(), rhs.driver_, dict_) { setDebug(); DebugInFunction << nl; @@ -366,14 +385,14 @@ void Foam::exprMixedFvPatchField<Type>::updateCoeffs() } } - mixedFvPatchField<Type>::updateCoeffs(); + this->parent_bctype::updateCoeffs(); } template<class Type> void Foam::exprMixedFvPatchField<Type>::write(Ostream& os) const { - mixedFvPatchField<Type>::write(os); + this->parent_bctype::write(os); expressions::patchExprFieldBase::write(os); driver_.writeCommon(os, this->debug_ || debug); diff --git a/src/finiteVolume/expressions/fields/fvPatchFields/exprMixedFvPatchField.H b/src/finiteVolume/expressions/fields/fvPatchFields/exprMixedFvPatchField.H index 0dc8ce7dcef7eaf97cf524ec99f990257ea0bde0..6d395e078fe7d5b4fead1c1342012515d78cb409 100644 --- a/src/finiteVolume/expressions/fields/fvPatchFields/exprMixedFvPatchField.H +++ b/src/finiteVolume/expressions/fields/fvPatchFields/exprMixedFvPatchField.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -73,10 +73,17 @@ class exprMixedFvPatchField public mixedFvPatchField<Type>, public expressions::patchExprFieldBase { + //- The parent boundary condition type + typedef mixedFvPatchField<Type> parent_bctype; + + protected: // Protected Data + //- Dictionary contents for the boundary condition + dictionary dict_; + //- The expression driver expressions::patchExpr::parseDriver driver_; diff --git a/src/finiteVolume/expressions/fields/pointPatchFields/exprValuePointPatchField.C b/src/finiteVolume/expressions/fields/pointPatchFields/exprValuePointPatchField.C index 1ba5e16d834fe4a9fc030527397f5acbab6c6e4b..4b663133c04593cb0f900dad5beb0aba3cd2cd31 100644 --- a/src/finiteVolume/expressions/fields/pointPatchFields/exprValuePointPatchField.C +++ b/src/finiteVolume/expressions/fields/pointPatchFields/exprValuePointPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2010-2018 Bernhard Gschaider - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,8 +28,8 @@ License #include "exprValuePointPatchField.H" #include "pointPatchFieldMapper.H" -#include "typeInfo.H" #include "facePointPatch.H" +#include "dictionaryContent.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -40,8 +40,9 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField const DimensionedField<Type, pointMesh>& iF ) : - valuePointPatchField<Type>(p, iF), + parent_bctype(p, iF), expressions::patchExprFieldBase(), + dict_(), driver_ ( fvPatch::lookupPatch @@ -55,21 +56,23 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField template<class Type> Foam::exprValuePointPatchField<Type>::exprValuePointPatchField ( - const exprValuePointPatchField<Type>& ptf, + const exprValuePointPatchField<Type>& rhs, const pointPatch& p, const DimensionedField<Type, pointMesh>& iF, const pointPatchFieldMapper& mapper ) : - valuePointPatchField<Type>(ptf, p, iF, mapper), - expressions::patchExprFieldBase(ptf), + parent_bctype(rhs, p, iF, mapper), + expressions::patchExprFieldBase(rhs), + dict_(rhs.dict_), // Deep copy driver_ ( fvPatch::lookupPatch ( dynamicCast<const facePointPatch>(this->patch()).patch() ), - ptf.driver_ + rhs.driver_, + dict_ ) {} @@ -82,12 +85,26 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField const dictionary& dict ) : - valuePointPatchField<Type>(p, iF), + parent_bctype(p, iF), expressions::patchExprFieldBase ( dict, expressions::patchExprFieldBase::expectedTypes::VALUE_TYPE, - true // pointValue + true // pointValue + ), + dict_ + ( + // Copy dictionary without "heavy" data chunks + dictionaryContent::copyDict + ( + dict, + wordList(), // allow + wordList // deny + ({ + "type", // redundant + "value" + }) + ) ), driver_ ( @@ -95,7 +112,7 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField ( dynamicCast<const facePointPatch>(this->patch()).patch() ), - dict + dict_ ) { // Require valueExpr @@ -107,7 +124,7 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField } - driver_.readDict(dict); + driver_.readDict(dict_); if (dict.found("value")) { @@ -136,19 +153,21 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField template<class Type> Foam::exprValuePointPatchField<Type>::exprValuePointPatchField ( - const exprValuePointPatchField<Type>& ptf, + const exprValuePointPatchField<Type>& rhs, const DimensionedField<Type, pointMesh>& iF ) : - valuePointPatchField<Type>(ptf, iF), - expressions::patchExprFieldBase(ptf), + parent_bctype(rhs, iF), + expressions::patchExprFieldBase(rhs), + dict_(rhs.dict_), // Deep copy driver_ ( fvPatch::lookupPatch ( dynamicCast<const facePointPatch>(this->patch()).patch() ), - ptf.driver_ + rhs.driver_, + dict_ ) {} @@ -156,18 +175,20 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField template<class Type> Foam::exprValuePointPatchField<Type>::exprValuePointPatchField ( - const exprValuePointPatchField<Type>& ptf + const exprValuePointPatchField<Type>& rhs ) : - valuePointPatchField<Type>(ptf), - expressions::patchExprFieldBase(ptf), + parent_bctype(rhs), + expressions::patchExprFieldBase(rhs), + dict_(rhs.dict_), // Deep copy driver_ ( fvPatch::lookupPatch ( dynamicCast<const facePointPatch>(this->patch()).patch() ), - ptf.driver_ + rhs.driver_, + dict_ ) {} @@ -212,14 +233,14 @@ void Foam::exprValuePointPatchField<Type>::updateCoeffs() } } - valuePointPatchField<Type>::updateCoeffs(); + this->parent_bctype::updateCoeffs(); } template<class Type> void Foam::exprValuePointPatchField<Type>::write(Ostream& os) const { - valuePointPatchField<Type>::write(os); + this->parent_bctype::write(os); expressions::patchExprFieldBase::write(os); this->writeEntry("value", os); diff --git a/src/finiteVolume/expressions/fields/pointPatchFields/exprValuePointPatchField.H b/src/finiteVolume/expressions/fields/pointPatchFields/exprValuePointPatchField.H index 3d6105d6fc7b1a0cd39d87674f974b87d4d29ee1..4ab37195de696ecdf65350cb721fc9c5993c5cf8 100644 --- a/src/finiteVolume/expressions/fields/pointPatchFields/exprValuePointPatchField.H +++ b/src/finiteVolume/expressions/fields/pointPatchFields/exprValuePointPatchField.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -63,10 +63,17 @@ class exprValuePointPatchField public valuePointPatchField<Type>, public expressions::patchExprFieldBase { + //- The parent boundary condition type + typedef valuePointPatchField<Type> parent_bctype; + + protected: // Protected Data + //- Dictionary contents for the boundary condition + dictionary dict_; + //- The expression driver expressions::patchExpr::parseDriver driver_; @@ -129,7 +136,6 @@ public: ); } - //- Construct and return a clone setting internal field reference virtual autoPtr<pointPatchField<Type>> clone ( diff --git a/src/finiteVolume/expressions/patch/patchExprDriver.C b/src/finiteVolume/expressions/patch/patchExprDriver.C index 1263b444860a27a0bfebbb52a536dfb75517411a..e772a7da9e170b2b203e4cec70159b01632ab5e4 100644 --- a/src/finiteVolume/expressions/patch/patchExprDriver.C +++ b/src/finiteVolume/expressions/patch/patchExprDriver.C @@ -117,11 +117,12 @@ Foam::expressions::patchExpr::parseDriver::parseDriver Foam::expressions::patchExpr::parseDriver::parseDriver ( const fvPatch& p, - const parseDriver& rhs + const parseDriver& rhs, + const dictionary& dict ) : parsing::genericRagelLemonDriver(), - expressions::fvExprDriver(rhs), + expressions::fvExprDriver(rhs, dict), patch_(p) { resetTimeReference(nullptr); diff --git a/src/finiteVolume/expressions/patch/patchExprDriver.H b/src/finiteVolume/expressions/patch/patchExprDriver.H index 5a752ccd6e147a7fe6002300e7ae52417661a111..e864b5dd66b21905affe46acd3c3e5dddfdf24f2 100644 --- a/src/finiteVolume/expressions/patch/patchExprDriver.H +++ b/src/finiteVolume/expressions/patch/patchExprDriver.H @@ -126,6 +126,12 @@ protected: ) const; +public: + + ClassName("patchExpr::driver"); + + // Generated Methods + // No copy copy construct parseDriver(const parseDriver&) = delete; @@ -133,10 +139,6 @@ protected: void operator=(const parseDriver&) = delete; -public: - - ClassName("patchExpr::driver"); - // Constructors //- Construct for specified patch, with dictionary information @@ -147,7 +149,12 @@ public: ); //- Construct for specified patch with copy of driver context - parseDriver(const fvPatch& p, const parseDriver& driver); + parseDriver + ( + const fvPatch& p, + const parseDriver& driver, + const dictionary& dict // = dictionary::null + ); //- Construct with patchName for the given mesh parseDriver(const word& patchName, const fvMesh& mesh); @@ -157,14 +164,7 @@ public: parseDriver(const dictionary& dict, const fvMesh& mesh); - //- Clone - virtual autoPtr<expressions::fvExprDriver> clone() const - { - return autoPtr<expressions::fvExprDriver> - ( - new parseDriver(this->patch_, *this) - ); - } + // Not generally clonable //- Destructor diff --git a/src/finiteVolume/expressions/volume/volumeExprDriver.C b/src/finiteVolume/expressions/volume/volumeExprDriver.C index c1e7eccb7050aaaa047c0fc2b135fceb58382806..f41b2b467d17d6185b3c25c13bedf8f01af9d3a1 100644 --- a/src/finiteVolume/expressions/volume/volumeExprDriver.C +++ b/src/finiteVolume/expressions/volume/volumeExprDriver.C @@ -105,11 +105,12 @@ Foam::expressions::volumeExpr::parseDriver::parseDriver Foam::expressions::volumeExpr::parseDriver::parseDriver ( const fvMesh& mesh, - const parseDriver& driver + const parseDriver& driver, + const dictionary& dict ) : parsing::genericRagelLemonDriver(), - expressions::fvExprDriver(driver), + expressions::fvExprDriver(driver, dict), mesh_(mesh), resultType_(), isLogical_(false), diff --git a/src/finiteVolume/expressions/volume/volumeExprDriver.H b/src/finiteVolume/expressions/volume/volumeExprDriver.H index 985b3f27e27dd7235a7f0f62fe1032c3c357df6a..47042f2ad081022f29f3c68dde3deea76fe27623 100644 --- a/src/finiteVolume/expressions/volume/volumeExprDriver.H +++ b/src/finiteVolume/expressions/volume/volumeExprDriver.H @@ -165,6 +165,12 @@ protected: ) const; +public: + + ClassName("volumeExpr::driver"); + + // Generated Methods + // No copy copy construct parseDriver(const parseDriver&) = delete; @@ -172,10 +178,6 @@ protected: void operator=(const parseDriver&) = delete; -public: - - ClassName("volumeExpr::driver"); - // Constructors //- Construct for specified mesh, with dictionary information @@ -186,7 +188,12 @@ public: ); //- Construct for specified mesh with copy of driver context - parseDriver(const fvMesh& mesh, const parseDriver& driver); + parseDriver + ( + const fvMesh& mesh, + const parseDriver& driver, + const dictionary& dict + ); //- Construct with meshName for the given mesh parseDriver(const word& meshName, const fvMesh& mesh); @@ -195,14 +202,7 @@ public: parseDriver(const dictionary& dict, const fvMesh& mesh); - //- Clone - virtual autoPtr<expressions::fvExprDriver> clone() const - { - return autoPtr<expressions::fvExprDriver> - ( - new parseDriver(this->mesh_, *this) - ); - } + // Not generally clonable //- Destructor