BUG: dangling dictionary reference for expression BCs

- exposed by the new embedded function handling.

  Requires local copies of dictionary content instead
  (similar to coded BCs handling)

BUG: incorrect formatting for expression function output

ENH: simpler copyDict version taking wordList instead of wordRes

- corresponds to the most common use case at the moment

ENH: expression string writeEntry method

- write as verbatim for better readability
This commit is contained in:
Mark Olesen
2021-12-01 15:45:41 +01:00
parent e09298092d
commit 27e57c29f7
25 changed files with 398 additions and 169 deletions

View File

@ -27,21 +27,18 @@ License
#include "dictionaryContent.H" #include "dictionaryContent.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
Foam::dictionary namespace Foam
Foam::dictionaryContent::copyDict {
template<class UnaryPredicate>
static dictionary copyFilteredDict
( (
const dictionary& input, const dictionary& input,
const wordRes& allow, const UnaryPredicate& pred
const wordRes& deny
) )
{ {
if (allow.empty() && deny.empty())
{
return dictionary(input);
}
dictionary dict; dictionary dict;
dict.name() = input.name(); // rename dict.name() = input.name(); // rename
@ -57,20 +54,9 @@ Foam::dictionaryContent::copyDict
// - could also have a "pruneRegex" flag (for example) // - could also have a "pruneRegex" flag (for example)
accept = true; accept = true;
} }
else if (allow.size())
{
const auto result = allow.matched(key);
accept =
(
result == wordRe::LITERAL
? true
: (result == wordRe::REGEX && !deny.match(key))
);
}
else else
{ {
accept = !deny.match(key); accept = pred(key);
} }
if (accept) if (accept)
@ -82,5 +68,97 @@ Foam::dictionaryContent::copyDict
return dict; 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))
);
}
);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -86,6 +86,19 @@ public:
// Member Functions // 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, //- Copy construct a dictionary,
//- filtered by a combination of allow/deny lists //- filtered by a combination of allow/deny lists
// //
@ -104,10 +117,11 @@ public:
static dictionary copyDict static dictionary copyDict
( (
const dictionary& input, const dictionary& input,
const wordRes& allow = wordRes(), const wordRes& allow,
const wordRes& deny = wordRes() const wordRes& deny = wordRes()
); );
//- Read-access to the content //- Read-access to the content
const dictionary& dict() const noexcept const dictionary& dict() const noexcept
{ {

View File

@ -38,7 +38,7 @@ Foam::Function1Types::Function1Expression<Type>::Function1Expression
) )
: :
Function1<Type>(entryName, dict, obrPtr), Function1<Type>(entryName, dict, obrPtr),
dict_(dict), dict_(dict), // Deep copy
valueExpr_(), valueExpr_(),
driver_(1, dict_) driver_(1, dict_)
{ {
@ -48,8 +48,8 @@ Foam::Function1Types::Function1Expression<Type>::Function1Expression
} }
string expr; string expr;
dict.readEntry("expression", expr); dict_.readEntry("expression", expr);
valueExpr_ = expressions::exprString(expr, dict); valueExpr_ = expressions::exprString(std::move(expr), dict_);
// Basic sanity // Basic sanity
if (valueExpr_.empty()) if (valueExpr_.empty())
@ -70,9 +70,9 @@ Foam::Function1Types::Function1Expression<Type>::Function1Expression
) )
: :
Function1<Type>(rhs), Function1<Type>(rhs),
dict_(rhs.dict_), dict_(rhs.dict_), // Deep copy
valueExpr_(rhs.valueExpr_), valueExpr_(rhs.valueExpr_),
driver_(1, rhs.driver_) driver_(1, rhs.driver_, dict_)
{} {}

View File

@ -124,6 +124,12 @@ public:
//- Copy construct //- Copy construct
explicit Function1Expression(const Function1Expression<Type>& rhs); 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 //- Destructor
virtual ~Function1Expression() = default; virtual ~Function1Expression() = default;

View File

@ -199,10 +199,11 @@ Foam::expressions::exprDriver::exprDriver
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_), result_(rhs.result_),
variableStrings_(rhs.variableStrings_), variableStrings_(rhs.variableStrings_),
variables_(rhs.variables_), variables_(rhs.variables_),

View File

@ -277,16 +277,21 @@ protected:
virtual exprResult getRemoteResult(const exprDriver& other) const; virtual exprResult getRemoteResult(const exprDriver& other) const;
//- No copy assignment
void operator=(const exprDriver&) = delete;
public: public:
//- Runtime type information //- Runtime type information
TypeName("exprDriver"); TypeName("exprDriver");
// Generated Methods
//- No copy construct
exprDriver(const exprDriver&) = delete;
//- No copy assignment
void operator=(const exprDriver&) = delete;
// Constructors // Constructors
//- Default construct, and default construct with search preferences //- Default construct, and default construct with search preferences
@ -296,8 +301,8 @@ public:
const dictionary& dict = dictionary::null const dictionary& dict = dictionary::null
); );
//- Copy construct //- Copy construct with new dictionary reference
exprDriver(const exprDriver& rhs); exprDriver(const exprDriver& rhs, const dictionary& dict);
//- Construct from a dictionary //- Construct from a dictionary
explicit exprDriver(const dictionary& dict); explicit exprDriver(const dictionary& dict);

View File

@ -188,10 +188,7 @@ static void writeFuncsImpl
os.beginBlock(subDictName); os.beginBlock(subDictName);
} }
os.beginBlock(entryName); (*funcPtr).writeData(os);
os.writeEntry("type", (*funcPtr).type());
(*funcPtr).writeEntries(os);
os.endBlock();
} }
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. 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;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -183,6 +183,19 @@ public:
//- Move assign from string. No expansions, no comment stripping //- Move assign from string. No expansions, no comment stripping
inline exprString& operator=(std::string&& str); 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;
}; };

View File

@ -75,11 +75,12 @@ Foam::expressions::fieldExpr::parseDriver::parseDriver
Foam::expressions::fieldExpr::parseDriver::parseDriver Foam::expressions::fieldExpr::parseDriver::parseDriver
( (
const label len, const label len,
const parseDriver& rhs const parseDriver& rhs,
const dictionary& dict
) )
: :
parsing::genericRagelLemonDriver(), parsing::genericRagelLemonDriver(),
expressions::exprDriver(rhs), expressions::exprDriver(rhs, dict),
size_(len) size_(len)
{} {}

View File

@ -82,8 +82,11 @@ protected:
//- The field size //- The field size
label size_; label size_;
public:
// Protected Member Functions ClassName("fieldExpr::driver");
// Generated Methods
// No copy copy construct // No copy copy construct
parseDriver(const parseDriver&) = delete; parseDriver(const parseDriver&) = delete;
@ -92,10 +95,6 @@ protected:
void operator=(const parseDriver&) = delete; void operator=(const parseDriver&) = delete;
public:
ClassName("fieldExpr::driver");
// Constructors // Constructors
//- Default construct (size=1), or with specified size //- Default construct (size=1), or with specified size
@ -104,8 +103,13 @@ public:
//- Construct for specified size with given dictionary //- Construct for specified size with given dictionary
parseDriver(const label len, const dictionary& dict); parseDriver(const label len, const dictionary& dict);
//- Construct for specified size with copy of driver context //- Construct for specified size, copy of driver context
parseDriver(const label len, const parseDriver& rhs); parseDriver
(
const label len,
const parseDriver& rhs,
const dictionary& dict
);
//- Destructor //- Destructor

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -41,7 +41,7 @@ Foam::PatchFunction1Types::PatchExprField<Type>::PatchExprField
) )
: :
PatchFunction1<Type>(pp, entryName, dict, faceValues), PatchFunction1<Type>(pp, entryName, dict, faceValues),
dict_(dict), dict_(dict), // Deep copy
valueExpr_(), valueExpr_(),
driver_(fvPatch::lookupPatch(this->patch()), dict_) driver_(fvPatch::lookupPatch(this->patch()), dict_)
{ {
@ -51,8 +51,8 @@ Foam::PatchFunction1Types::PatchExprField<Type>::PatchExprField
} }
string expr; string expr;
dict.readEntry("expression", expr); dict_.readEntry("expression", expr);
valueExpr_ = expressions::exprString(expr, dict); valueExpr_ = expressions::exprString(std::move(expr), dict_);
// Basic sanity // Basic sanity
if (valueExpr_.empty()) if (valueExpr_.empty())
@ -84,9 +84,9 @@ Foam::PatchFunction1Types::PatchExprField<Type>::PatchExprField
) )
: :
PatchFunction1<Type>(rhs, pp), PatchFunction1<Type>(rhs, pp),
dict_(rhs.dict_), dict_(rhs.dict_), // Deep copy
valueExpr_(rhs.valueExpr_), valueExpr_(rhs.valueExpr_),
driver_(fvPatch::lookupPatch(this->patch()), rhs.driver_) driver_(fvPatch::lookupPatch(this->patch()), rhs.driver_, dict_)
{} {}

View File

@ -110,10 +110,11 @@ Foam::expressions::fvExprDriver::fvExprDriver
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_), globalScopes_(rhs.globalScopes_),
delayedVariables_(rhs.delayedVariables_), delayedVariables_(rhs.delayedVariables_),
storedVariables_(rhs.storedVariables_), storedVariables_(rhs.storedVariables_),

View File

@ -368,8 +368,12 @@ public:
const dictionary& dict = dictionary::null const dictionary& dict = dictionary::null
); );
//- Copy construct //- Copy construct with dictionary reference
fvExprDriver(const fvExprDriver&); explicit fvExprDriver
(
const fvExprDriver& rhs,
const dictionary& dict
);
//- Construct from a dictionary //- Construct from a dictionary
explicit fvExprDriver(const dictionary& dict); explicit fvExprDriver(const dictionary& dict);
@ -396,8 +400,8 @@ public:
const fvMesh& mesh const fvMesh& mesh
); );
//- Clone //- Not generally clonable
virtual autoPtr<fvExprDriver> clone() const = 0; virtual autoPtr<fvExprDriver> clone() = delete;
//- Destructor //- Destructor

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2018 Bernhard Gschaider Copyright (C) 2011-2018 Bernhard Gschaider
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -170,18 +170,10 @@ void Foam::expressions::patchExprFieldBase::write(Ostream& os) const
// Do not emit debug_ value // Do not emit debug_ value
if (!valueExpr_.empty()) // Write expression, but not empty ones
{ valueExpr_.writeEntry("valueExpr", os, false);
os.writeEntry("valueExpr", valueExpr_); gradExpr_.writeEntry("gradientExpr", os, false);
} fracExpr_.writeEntry("fractionExpr", os, false);
if (!gradExpr_.empty())
{
os.writeEntry("gradientExpr", gradExpr_);
}
if (!fracExpr_.empty())
{
os.writeEntry("fractionExpr", fracExpr_);
}
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2009-2018 Bernhard Gschaider Copyright (C) 2009-2018 Bernhard Gschaider
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,6 +27,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "exprFixedValueFvPatchField.H" #include "exprFixedValueFvPatchField.H"
#include "dictionaryContent.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
@ -49,8 +50,9 @@ Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField
const DimensionedField<Type, volMesh>& iF const DimensionedField<Type, volMesh>& iF
) )
: :
fixedValueFvPatchField<Type>(p, iF), parent_bctype(p, iF),
expressions::patchExprFieldBase(), expressions::patchExprFieldBase(),
dict_(),
driver_(this->patch()) driver_(this->patch())
{} {}
@ -58,15 +60,16 @@ Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField
template<class Type> template<class Type>
Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField
( (
const exprFixedValueFvPatchField<Type>& ptf, const exprFixedValueFvPatchField<Type>& rhs,
const fvPatch& p, const fvPatch& p,
const DimensionedField<Type, volMesh>& iF, const DimensionedField<Type, volMesh>& iF,
const fvPatchFieldMapper& mapper const fvPatchFieldMapper& mapper
) )
: :
fixedValueFvPatchField<Type>(ptf, p, iF, mapper), parent_bctype(rhs, p, iF, mapper),
expressions::patchExprFieldBase(ptf), expressions::patchExprFieldBase(rhs),
driver_(this->patch(), ptf.driver_) dict_(rhs.dict_), // Deep copy
driver_(this->patch(), rhs.driver_, dict_)
{ {
setDebug(); setDebug();
DebugInFunction << nl; DebugInFunction << nl;
@ -82,13 +85,27 @@ Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField
const bool valueRequired const bool valueRequired
) )
: :
fixedValueFvPatchField<Type>(p, iF), parent_bctype(p, iF),
expressions::patchExprFieldBase expressions::patchExprFieldBase
( (
dict, dict,
expressions::patchExprFieldBase::expectedTypes::VALUE_TYPE 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(); setDebug();
DebugInFunction << nl; DebugInFunction << nl;
@ -102,7 +119,7 @@ Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField
} }
driver_.readDict(dict); driver_.readDict(dict_);
if (dict.found("value")) if (dict.found("value"))
{ {
@ -134,12 +151,13 @@ Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField
template<class Type> template<class Type>
Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField
( (
const exprFixedValueFvPatchField<Type>& ptf const exprFixedValueFvPatchField<Type>& rhs
) )
: :
fixedValueFvPatchField<Type>(ptf), parent_bctype(rhs),
expressions::patchExprFieldBase(ptf), expressions::patchExprFieldBase(rhs),
driver_(this->patch(), ptf.driver_) dict_(rhs.dict_), // Deep copy
driver_(this->patch(), rhs.driver_, dict_)
{ {
setDebug(); setDebug();
DebugInFunction << nl; DebugInFunction << nl;
@ -149,13 +167,14 @@ Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField
template<class Type> template<class Type>
Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField Foam::exprFixedValueFvPatchField<Type>::exprFixedValueFvPatchField
( (
const exprFixedValueFvPatchField<Type>& ptf, const exprFixedValueFvPatchField<Type>& rhs,
const DimensionedField<Type, volMesh>& iF const DimensionedField<Type, volMesh>& iF
) )
: :
fixedValueFvPatchField<Type>(ptf, iF), parent_bctype(rhs, iF),
expressions::patchExprFieldBase(ptf), expressions::patchExprFieldBase(rhs),
driver_(this->patch(), ptf.driver_) dict_(rhs.dict_), // Deep copy
driver_(this->patch(), rhs.driver_, dict_)
{ {
setDebug(); setDebug();
DebugInFunction << nl; DebugInFunction << nl;
@ -199,14 +218,14 @@ void Foam::exprFixedValueFvPatchField<Type>::updateCoeffs()
} }
} }
fixedValueFvPatchField<Type>::updateCoeffs(); this->parent_bctype::updateCoeffs();
} }
template<class Type> template<class Type>
void Foam::exprFixedValueFvPatchField<Type>::write(Ostream& os) const void Foam::exprFixedValueFvPatchField<Type>::write(Ostream& os) const
{ {
fixedValueFvPatchField<Type>::write(os); this->parent_bctype::write(os);
expressions::patchExprFieldBase::write(os); expressions::patchExprFieldBase::write(os);
driver_.writeCommon(os, this->debug_ || debug); driver_.writeCommon(os, this->debug_ || debug);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -67,10 +67,17 @@ class exprFixedValueFvPatchField
public fixedValueFvPatchField<Type>, public fixedValueFvPatchField<Type>,
public expressions::patchExprFieldBase public expressions::patchExprFieldBase
{ {
//- The parent boundary condition type
typedef fixedValueFvPatchField<Type> parent_bctype;
protected: protected:
// Protected Data // Protected Data
//- Dictionary contents for the boundary condition
dictionary dict_;
//- The expression driver //- The expression driver
expressions::patchExpr::parseDriver driver_; expressions::patchExpr::parseDriver driver_;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2009-2018 Bernhard Gschaider Copyright (C) 2009-2018 Bernhard Gschaider
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -26,6 +26,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "exprMixedFvPatchField.H" #include "exprMixedFvPatchField.H"
#include "dictionaryContent.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
@ -48,8 +49,9 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField
const DimensionedField<Type, volMesh>& iF const DimensionedField<Type, volMesh>& iF
) )
: :
mixedFvPatchField<Type>(p, iF), parent_bctype(p, iF),
expressions::patchExprFieldBase(), expressions::patchExprFieldBase(),
dict_(),
driver_(this->patch()) driver_(this->patch())
{ {
this->refValue() = Zero; this->refValue() = Zero;
@ -61,15 +63,16 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField
template<class Type> template<class Type>
Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField
( (
const exprMixedFvPatchField<Type>& ptf, const exprMixedFvPatchField<Type>& rhs,
const fvPatch& p, const fvPatch& p,
const DimensionedField<Type, volMesh>& iF, const DimensionedField<Type, volMesh>& iF,
const fvPatchFieldMapper& mapper const fvPatchFieldMapper& mapper
) )
: :
mixedFvPatchField<Type>(ptf, p, iF, mapper), parent_bctype(rhs, p, iF, mapper),
expressions::patchExprFieldBase(ptf), expressions::patchExprFieldBase(rhs),
driver_(this->patch(), ptf.driver_) dict_(rhs.dict_), // Deep copy
driver_(this->patch(), rhs.driver_, dict_)
{ {
setDebug(); setDebug();
DebugInFunction << nl; DebugInFunction << nl;
@ -84,13 +87,27 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField
const dictionary& dict const dictionary& dict
) )
: :
mixedFvPatchField<Type>(p, iF), parent_bctype(p, iF),
expressions::patchExprFieldBase expressions::patchExprFieldBase
( (
dict, dict,
expressions::patchExprFieldBase::expectedTypes::MIXED_TYPE 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(); setDebug();
DebugInFunction << nl; DebugInFunction << nl;
@ -144,7 +161,7 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField
} }
driver_.readDict(dict); driver_.readDict(dict_);
// Similar to fvPatchField constructor, which we have bypassed // Similar to fvPatchField constructor, which we have bypassed
dict.readIfPresent("patchType", this->patchType()); dict.readIfPresent("patchType", this->patchType());
@ -217,7 +234,7 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField
// but avoid our own updateCoeffs // but avoid our own updateCoeffs
if (!this->updated()) if (!this->updated())
{ {
this->mixedFvPatchField<Type>::updateCoeffs(); this->parent_bctype::updateCoeffs();
} }
Field<Type>::operator= Field<Type>::operator=
@ -239,12 +256,13 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField
template<class Type> template<class Type>
Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField
( (
const exprMixedFvPatchField<Type>& ptf const exprMixedFvPatchField<Type>& rhs
) )
: :
mixedFvPatchField<Type>(ptf), parent_bctype(rhs),
expressions::patchExprFieldBase(ptf), expressions::patchExprFieldBase(rhs),
driver_(this->patch(), ptf.driver_) dict_(rhs.dict_), // Deep copy
driver_(this->patch(), rhs.driver_, dict_)
{ {
setDebug(); setDebug();
DebugInFunction << nl; DebugInFunction << nl;
@ -254,13 +272,14 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField
template<class Type> template<class Type>
Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField
( (
const exprMixedFvPatchField<Type>& ptf, const exprMixedFvPatchField<Type>& rhs,
const DimensionedField<Type, volMesh>& iF const DimensionedField<Type, volMesh>& iF
) )
: :
mixedFvPatchField<Type>(ptf, iF), parent_bctype(rhs, iF),
expressions::patchExprFieldBase(ptf), expressions::patchExprFieldBase(rhs),
driver_(this->patch(), ptf.driver_) dict_(rhs.dict_), // Deep copy
driver_(this->patch(), rhs.driver_, dict_)
{ {
setDebug(); setDebug();
DebugInFunction << nl; DebugInFunction << nl;
@ -366,14 +385,14 @@ void Foam::exprMixedFvPatchField<Type>::updateCoeffs()
} }
} }
mixedFvPatchField<Type>::updateCoeffs(); this->parent_bctype::updateCoeffs();
} }
template<class Type> template<class Type>
void Foam::exprMixedFvPatchField<Type>::write(Ostream& os) const void Foam::exprMixedFvPatchField<Type>::write(Ostream& os) const
{ {
mixedFvPatchField<Type>::write(os); this->parent_bctype::write(os);
expressions::patchExprFieldBase::write(os); expressions::patchExprFieldBase::write(os);
driver_.writeCommon(os, this->debug_ || debug); driver_.writeCommon(os, this->debug_ || debug);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -73,10 +73,17 @@ class exprMixedFvPatchField
public mixedFvPatchField<Type>, public mixedFvPatchField<Type>,
public expressions::patchExprFieldBase public expressions::patchExprFieldBase
{ {
//- The parent boundary condition type
typedef mixedFvPatchField<Type> parent_bctype;
protected: protected:
// Protected Data // Protected Data
//- Dictionary contents for the boundary condition
dictionary dict_;
//- The expression driver //- The expression driver
expressions::patchExpr::parseDriver driver_; expressions::patchExpr::parseDriver driver_;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2010-2018 Bernhard Gschaider Copyright (C) 2010-2018 Bernhard Gschaider
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,8 +28,8 @@ License
#include "exprValuePointPatchField.H" #include "exprValuePointPatchField.H"
#include "pointPatchFieldMapper.H" #include "pointPatchFieldMapper.H"
#include "typeInfo.H"
#include "facePointPatch.H" #include "facePointPatch.H"
#include "dictionaryContent.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -40,8 +40,9 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField
const DimensionedField<Type, pointMesh>& iF const DimensionedField<Type, pointMesh>& iF
) )
: :
valuePointPatchField<Type>(p, iF), parent_bctype(p, iF),
expressions::patchExprFieldBase(), expressions::patchExprFieldBase(),
dict_(),
driver_ driver_
( (
fvPatch::lookupPatch fvPatch::lookupPatch
@ -55,21 +56,23 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField
template<class Type> template<class Type>
Foam::exprValuePointPatchField<Type>::exprValuePointPatchField Foam::exprValuePointPatchField<Type>::exprValuePointPatchField
( (
const exprValuePointPatchField<Type>& ptf, const exprValuePointPatchField<Type>& rhs,
const pointPatch& p, const pointPatch& p,
const DimensionedField<Type, pointMesh>& iF, const DimensionedField<Type, pointMesh>& iF,
const pointPatchFieldMapper& mapper const pointPatchFieldMapper& mapper
) )
: :
valuePointPatchField<Type>(ptf, p, iF, mapper), parent_bctype(rhs, p, iF, mapper),
expressions::patchExprFieldBase(ptf), expressions::patchExprFieldBase(rhs),
dict_(rhs.dict_), // Deep copy
driver_ driver_
( (
fvPatch::lookupPatch fvPatch::lookupPatch
( (
dynamicCast<const facePointPatch>(this->patch()).patch() dynamicCast<const facePointPatch>(this->patch()).patch()
), ),
ptf.driver_ rhs.driver_,
dict_
) )
{} {}
@ -82,12 +85,26 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField
const dictionary& dict const dictionary& dict
) )
: :
valuePointPatchField<Type>(p, iF), parent_bctype(p, iF),
expressions::patchExprFieldBase expressions::patchExprFieldBase
( (
dict, dict,
expressions::patchExprFieldBase::expectedTypes::VALUE_TYPE, 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_ driver_
( (
@ -95,7 +112,7 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField
( (
dynamicCast<const facePointPatch>(this->patch()).patch() dynamicCast<const facePointPatch>(this->patch()).patch()
), ),
dict dict_
) )
{ {
// Require valueExpr // Require valueExpr
@ -107,7 +124,7 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField
} }
driver_.readDict(dict); driver_.readDict(dict_);
if (dict.found("value")) if (dict.found("value"))
{ {
@ -136,19 +153,21 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField
template<class Type> template<class Type>
Foam::exprValuePointPatchField<Type>::exprValuePointPatchField Foam::exprValuePointPatchField<Type>::exprValuePointPatchField
( (
const exprValuePointPatchField<Type>& ptf, const exprValuePointPatchField<Type>& rhs,
const DimensionedField<Type, pointMesh>& iF const DimensionedField<Type, pointMesh>& iF
) )
: :
valuePointPatchField<Type>(ptf, iF), parent_bctype(rhs, iF),
expressions::patchExprFieldBase(ptf), expressions::patchExprFieldBase(rhs),
dict_(rhs.dict_), // Deep copy
driver_ driver_
( (
fvPatch::lookupPatch fvPatch::lookupPatch
( (
dynamicCast<const facePointPatch>(this->patch()).patch() dynamicCast<const facePointPatch>(this->patch()).patch()
), ),
ptf.driver_ rhs.driver_,
dict_
) )
{} {}
@ -156,18 +175,20 @@ Foam::exprValuePointPatchField<Type>::exprValuePointPatchField
template<class Type> template<class Type>
Foam::exprValuePointPatchField<Type>::exprValuePointPatchField Foam::exprValuePointPatchField<Type>::exprValuePointPatchField
( (
const exprValuePointPatchField<Type>& ptf const exprValuePointPatchField<Type>& rhs
) )
: :
valuePointPatchField<Type>(ptf), parent_bctype(rhs),
expressions::patchExprFieldBase(ptf), expressions::patchExprFieldBase(rhs),
dict_(rhs.dict_), // Deep copy
driver_ driver_
( (
fvPatch::lookupPatch fvPatch::lookupPatch
( (
dynamicCast<const facePointPatch>(this->patch()).patch() 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> template<class Type>
void Foam::exprValuePointPatchField<Type>::write(Ostream& os) const void Foam::exprValuePointPatchField<Type>::write(Ostream& os) const
{ {
valuePointPatchField<Type>::write(os); this->parent_bctype::write(os);
expressions::patchExprFieldBase::write(os); expressions::patchExprFieldBase::write(os);
this->writeEntry("value", os); this->writeEntry("value", os);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -63,10 +63,17 @@ class exprValuePointPatchField
public valuePointPatchField<Type>, public valuePointPatchField<Type>,
public expressions::patchExprFieldBase public expressions::patchExprFieldBase
{ {
//- The parent boundary condition type
typedef valuePointPatchField<Type> parent_bctype;
protected: protected:
// Protected Data // Protected Data
//- Dictionary contents for the boundary condition
dictionary dict_;
//- The expression driver //- The expression driver
expressions::patchExpr::parseDriver driver_; expressions::patchExpr::parseDriver driver_;
@ -129,7 +136,6 @@ public:
); );
} }
//- Construct and return a clone setting internal field reference //- Construct and return a clone setting internal field reference
virtual autoPtr<pointPatchField<Type>> clone virtual autoPtr<pointPatchField<Type>> clone
( (

View File

@ -117,11 +117,12 @@ Foam::expressions::patchExpr::parseDriver::parseDriver
Foam::expressions::patchExpr::parseDriver::parseDriver Foam::expressions::patchExpr::parseDriver::parseDriver
( (
const fvPatch& p, const fvPatch& p,
const parseDriver& rhs const parseDriver& rhs,
const dictionary& dict
) )
: :
parsing::genericRagelLemonDriver(), parsing::genericRagelLemonDriver(),
expressions::fvExprDriver(rhs), expressions::fvExprDriver(rhs, dict),
patch_(p) patch_(p)
{ {
resetTimeReference(nullptr); resetTimeReference(nullptr);

View File

@ -126,6 +126,12 @@ protected:
) const; ) const;
public:
ClassName("patchExpr::driver");
// Generated Methods
// No copy copy construct // No copy copy construct
parseDriver(const parseDriver&) = delete; parseDriver(const parseDriver&) = delete;
@ -133,10 +139,6 @@ protected:
void operator=(const parseDriver&) = delete; void operator=(const parseDriver&) = delete;
public:
ClassName("patchExpr::driver");
// Constructors // Constructors
//- Construct for specified patch, with dictionary information //- Construct for specified patch, with dictionary information
@ -147,7 +149,12 @@ public:
); );
//- Construct for specified patch with copy of driver context //- 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 //- Construct with patchName for the given mesh
parseDriver(const word& patchName, const fvMesh& mesh); parseDriver(const word& patchName, const fvMesh& mesh);
@ -157,14 +164,7 @@ public:
parseDriver(const dictionary& dict, const fvMesh& mesh); parseDriver(const dictionary& dict, const fvMesh& mesh);
//- Clone // Not generally clonable
virtual autoPtr<expressions::fvExprDriver> clone() const
{
return autoPtr<expressions::fvExprDriver>
(
new parseDriver(this->patch_, *this)
);
}
//- Destructor //- Destructor

View File

@ -105,11 +105,12 @@ Foam::expressions::volumeExpr::parseDriver::parseDriver
Foam::expressions::volumeExpr::parseDriver::parseDriver Foam::expressions::volumeExpr::parseDriver::parseDriver
( (
const fvMesh& mesh, const fvMesh& mesh,
const parseDriver& driver const parseDriver& driver,
const dictionary& dict
) )
: :
parsing::genericRagelLemonDriver(), parsing::genericRagelLemonDriver(),
expressions::fvExprDriver(driver), expressions::fvExprDriver(driver, dict),
mesh_(mesh), mesh_(mesh),
resultType_(), resultType_(),
isLogical_(false), isLogical_(false),

View File

@ -165,6 +165,12 @@ protected:
) const; ) const;
public:
ClassName("volumeExpr::driver");
// Generated Methods
// No copy copy construct // No copy copy construct
parseDriver(const parseDriver&) = delete; parseDriver(const parseDriver&) = delete;
@ -172,10 +178,6 @@ protected:
void operator=(const parseDriver&) = delete; void operator=(const parseDriver&) = delete;
public:
ClassName("volumeExpr::driver");
// Constructors // Constructors
//- Construct for specified mesh, with dictionary information //- Construct for specified mesh, with dictionary information
@ -186,7 +188,12 @@ public:
); );
//- Construct for specified mesh with copy of driver context //- 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 //- Construct with meshName for the given mesh
parseDriver(const word& meshName, const fvMesh& mesh); parseDriver(const word& meshName, const fvMesh& mesh);
@ -195,14 +202,7 @@ public:
parseDriver(const dictionary& dict, const fvMesh& mesh); parseDriver(const dictionary& dict, const fvMesh& mesh);
//- Clone // Not generally clonable
virtual autoPtr<expressions::fvExprDriver> clone() const
{
return autoPtr<expressions::fvExprDriver>
(
new parseDriver(this->mesh_, *this)
);
}
//- Destructor //- Destructor