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"
// * * * * * * * * * * * * * 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))
);
}
);
}
// ************************************************************************* //

View File

@ -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
{

View File

@ -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_)
{}

View File

@ -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;

View File

@ -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_),

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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;
}
// ************************************************************************* //

View File

@ -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;
};

View File

@ -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)
{}

View File

@ -82,8 +82,11 @@ protected:
//- The field size
label size_;
public:
// Protected Member Functions
ClassName("fieldExpr::driver");
// 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

View File

@ -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_)
{}

View File

@ -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_),

View File

@ -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

View File

@ -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);
}

View File

@ -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);

View File

@ -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_;

View File

@ -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);

View File

@ -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_;

View File

@ -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);

View File

@ -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
(

View File

@ -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);

View File

@ -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

View File

@ -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),

View File

@ -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