diff --git a/src/OpenFOAM/db/dynamicLibrary/codedBase/CodedBase.H b/src/OpenFOAM/db/dynamicLibrary/codedBase/CodedBase.H index af4ccc9448..774a7b9000 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codedBase/CodedBase.H +++ b/src/OpenFOAM/db/dynamicLibrary/codedBase/CodedBase.H @@ -103,7 +103,7 @@ public: // Member Functions //- Name of the dynamically generated CodedType - const word& codeName() const; + virtual const word& codeName() const; //- Get the dictionary to initialize the codeContext virtual const dictionary& codeDict() const; diff --git a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C index 67f2c03206..97207b942d 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C +++ b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C @@ -280,12 +280,10 @@ void Foam::codedBase::createLibrary // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // -void Foam::codedBase::updateLibrary -( - const word& name -) const +void Foam::codedBase::updateLibrary() const { - const dictionary& dict = this->codeDict(); + const word& name = codeName(); + const dictionary& dict = codeDict(); dynamicCode::checkSecurity ( diff --git a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H index 62888f1ed4..f6dff47696 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H +++ b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H @@ -86,23 +86,26 @@ class codedBase protected: //- Update library as required - void updateLibrary(const word& name) const; + void updateLibrary() const; - //- Adapt the context for the current object - virtual void prepare(dynamicCode&, const dynamicCodeContext&) const = 0; + //- Name of the dynamically generated CodedType + virtual const word& codeName() const = 0; //- Return a description (type + name) for the output virtual string description() const = 0; - //- Clear any redirected objects - virtual void clearRedirect() const = 0; - //- Get the dictionary to initialize the codeContext virtual const dictionary& codeDict() const = 0; //- Get the keywords associated with source code virtual const wordList& codeKeys() const = 0; + //- Adapt the context for the current object + virtual void prepare(dynamicCode&, const dynamicCodeContext&) const = 0; + + //- Clear any redirected objects + virtual void clearRedirect() const = 0; + public: diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C index 0307f3fec2..4bdae14b1b 100644 --- a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C @@ -29,77 +29,9 @@ License #include "pointFields.H" #include "dynamicCode.H" #include "dynamicCodeContext.H" -#include "stringOps.H" - -// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * // - -template -const Foam::wordList Foam::codedFixedValuePointPatchField::codeKeys_ = - {"code", "codeInclude", "localCode"}; - - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -template -const Foam::word Foam::codedFixedValuePointPatchField::codeTemplateC = - "fixedValuePointPatchFieldTemplate.C"; - -template -const Foam::word Foam::codedFixedValuePointPatchField::codeTemplateH = - "fixedValuePointPatchFieldTemplate.H"; - - -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // - -template -void Foam::codedFixedValuePointPatchField::setFieldTemplates -( - dynamicCode& dynCode -) -{ - word fieldType(pTraits::typeName); - - // Template type for pointPatchField - dynCode.setFilterVariable("TemplateType", fieldType); - - // Name for pointPatchField - eg, ScalarField, VectorField, ... - fieldType[0] = toupper(fieldType[0]); - dynCode.setFilterVariable("FieldType", fieldType + "Field"); -} - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -template -const Foam::IOdictionary& Foam::codedFixedValuePointPatchField::dict() -const -{ - const objectRegistry& obr = this->db(); - - if (obr.foundObject("codeDict")) - { - return obr.lookupObject("codeDict"); - } - else - { - return obr.store - ( - new IOdictionary - ( - IOobject - ( - "codeDict", - this->db().time().system(), - this->db(), - IOobject::MUST_READ_IF_MODIFIED, - IOobject::NO_WRITE - ) - ) - ); - } -} - - template void Foam::codedFixedValuePointPatchField::prepare ( @@ -107,12 +39,19 @@ void Foam::codedFixedValuePointPatchField::prepare const dynamicCodeContext& context ) const { - // Take no chances - typeName must be identical to name_ - dynCode.setFilterVariable("typeName", name_); + // Take no chances - typeName must be identical to codeName() + dynCode.setFilterVariable("typeName", codeName()); // Set TemplateType and FieldType filter variables // (for pointPatchField) - setFieldTemplates(dynCode); + word fieldType(pTraits::typeName); + + // Template type for pointPatchField + dynCode.setFilterVariable("TemplateType", fieldType); + + // Name for pointPatchField - eg, ScalarField, VectorField, ... + fieldType[0] = toupper(fieldType[0]); + dynCode.setFilterVariable("FieldType", fieldType + "Field"); // Compile filtered C template dynCode.addCompileFile(codeTemplateC); @@ -120,59 +59,29 @@ void Foam::codedFixedValuePointPatchField::prepare // Copy filtered H template dynCode.addCopyFile(codeTemplateH); - // Debugging: make BC verbose - // dynCode.setFilterVariable("verbose", "true"); - // Info<<"compile " << name_ << " sha1: " - // << context.sha1() << endl; + if (debug) + { + // Debugging: make BC verbose + dynCode.setFilterVariable("verbose", "true"); + Info<<"compile " << codeName() << " sha1: " + << context.sha1() << endl; + } // Define Make/options dynCode.setMakeOptions - ( - "EXE_INC = -g \\\n" - "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n" - + context.options() - + "\n\nLIB_LIBS = \\\n" - + " -lOpenFOAM \\\n" - + " -lfiniteVolume \\\n" - + context.libs() - ); -} - - -template -const Foam::dictionary& -Foam::codedFixedValuePointPatchField::codeDict() const -{ - // Use system/codeDict or in-line - return ( - dict_.found("code") - ? dict_ - : this->dict().subDict(name_) + "EXE_INC = -g \\\n" + "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n" + + context.options() + + "\n\nLIB_LIBS = \\\n" + + " -lOpenFOAM \\\n" + + " -lfiniteVolume \\\n" + + context.libs() ); } -template -const Foam::wordList& -Foam::codedFixedValuePointPatchField::codeKeys() const -{ - return codeKeys_; -} - - -template -Foam::string Foam::codedFixedValuePointPatchField::description() const -{ - return - "patch " - + this->patch().name() - + " on field " - + this->internalField().name(); -} - - template void Foam::codedFixedValuePointPatchField::clearRedirect() const { @@ -191,7 +100,7 @@ Foam::codedFixedValuePointPatchField::codedFixedValuePointPatchField ) : fixedValuePointPatchField(p, iF), - codedBase(), + CodedBase(), redirectPatchFieldPtr_() {} @@ -206,9 +115,7 @@ Foam::codedFixedValuePointPatchField::codedFixedValuePointPatchField ) : fixedValuePointPatchField(ptf, p, iF, mapper), - codedBase(), - dict_(ptf.dict_), - name_(ptf.name_), + CodedBase(ptf), redirectPatchFieldPtr_() {} @@ -222,17 +129,10 @@ Foam::codedFixedValuePointPatchField::codedFixedValuePointPatchField ) : fixedValuePointPatchField(p, iF, dict), - codedBase(), - dict_(dict), - name_ - ( - dict.found("redirectType") - ? dict.lookup("redirectType") - : dict.lookup("name") - ), + CodedBase(dict), redirectPatchFieldPtr_() { - updateLibrary(name_); + updateLibrary(); } @@ -243,9 +143,7 @@ Foam::codedFixedValuePointPatchField::codedFixedValuePointPatchField ) : fixedValuePointPatchField(ptf), - codedBase(), - dict_(ptf.dict_), - name_(ptf.name_), + CodedBase(ptf), redirectPatchFieldPtr_() {} @@ -258,9 +156,7 @@ Foam::codedFixedValuePointPatchField::codedFixedValuePointPatchField ) : fixedValuePointPatchField(ptf, iF), - codedBase(), - dict_(ptf.dict_), - name_(ptf.name_), + CodedBase(ptf), redirectPatchFieldPtr_() {} @@ -273,11 +169,8 @@ Foam::codedFixedValuePointPatchField::redirectPatchField() const { if (!redirectPatchFieldPtr_.valid()) { - // Construct a patch - // Make sure to construct the patchfield with up-to-date value - OStringStream os; - writeEntry(os, "type", name_); + writeEntry(os, "type", codeName()); writeEntry(os, "value", static_cast&>(*this)); IStringStream is(os.str()); dictionary dict(is); @@ -292,6 +185,7 @@ Foam::codedFixedValuePointPatchField::redirectPatchField() const ).ptr() ); } + return redirectPatchFieldPtr_(); } @@ -305,7 +199,7 @@ void Foam::codedFixedValuePointPatchField::updateCoeffs() } // Make sure library containing user-defined pointPatchField is up-to-date - updateLibrary(name_); + updateLibrary(); const pointPatchField& fvp = redirectPatchField(); @@ -325,7 +219,7 @@ void Foam::codedFixedValuePointPatchField::evaluate ) { // Make sure library containing user-defined pointPatchField is up-to-date - updateLibrary(name_); + updateLibrary(); const pointPatchField& fvp = redirectPatchField(); @@ -339,42 +233,7 @@ template void Foam::codedFixedValuePointPatchField::write(Ostream& os) const { fixedValuePointPatchField::write(os); - writeEntry(os, "name", name_); - - if (dict_.found("codeInclude")) - { - writeKeyword(os, "codeInclude"); - os.write(verbatimString(dict_["codeInclude"])) - << token::END_STATEMENT << nl; - } - - if (dict_.found("localCode")) - { - writeKeyword(os, "localCode"); - os.write(verbatimString(dict_["localCode"])) - << token::END_STATEMENT << nl; - } - - if (dict_.found("code")) - { - writeKeyword(os, "code"); - os.write(verbatimString(dict_["code"])) - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeOptions")) - { - writeKeyword(os, "codeOptions"); - os.write(verbatimString(dict_["codeOptions"])) - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeLibs")) - { - writeKeyword(os, "codeLibs"); - os.write(verbatimString(dict_["codeLibs"])) - << token::END_STATEMENT << nl; - } + writeCode(os); } diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.H b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.H index 83b847e6d3..d3e6d5acf4 100644 --- a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.H +++ b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.H @@ -83,15 +83,24 @@ SourceFiles #define codedFixedValuePointPatchField_H #include "fixedValuePointPatchFields.H" -#include "codedBase.H" +#include "CodedBase.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -// Forward declaration of classes -class IOdictionary; +/*---------------------------------------------------------------------------*\ + Class codedFixedValueFvPatchFieldBase Declaration +\*---------------------------------------------------------------------------*/ + +class codedFixedValuePointPatchFieldBase +{ +public: + + ClassNameNoDebug("fixedValuePointPatchField"); +}; + /*---------------------------------------------------------------------------*\ Class codedFixedValuePointPatchField Declaration @@ -101,58 +110,24 @@ template class codedFixedValuePointPatchField : public fixedValuePointPatchField, - public codedBase + public CodedBase { - // Private static data - - //- The keywords associated with source code - static const wordList codeKeys_; - - // Private Data - //- Dictionary contents for the boundary condition - mutable dictionary dict_; - - const word name_; - mutable autoPtr> redirectPatchFieldPtr_; // Private Member Functions - const IOdictionary& dict() const; - - //- Set the rewrite vars controlling the Type - static void setFieldTemplates(dynamicCode& dynCode); - //- Adapt the context for the current object virtual void prepare(dynamicCode&, const dynamicCodeContext&) const; - //- Return a description (type + name) for the output - virtual string description() const; - //- Clear the ptr to the redirected object virtual void clearRedirect() const; - //- Get the dictionary to initialize the codeContext - virtual const dictionary& codeDict() const; - - //- Get the keywords associated with source code - virtual const wordList& codeKeys() const; - public: - // Static Data Members - - //- Name of the C code template to be used - static const word codeTemplateC; - - //- Name of the H code template to be used - static const word codeTemplateH; - - //- Runtime type information TypeName("codedFixedValue"); diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchFields.C b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchFields.C index 7160aad6c3..a156a44fd6 100644 --- a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchFields.C +++ b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,20 +24,26 @@ License \*---------------------------------------------------------------------------*/ #include "codedFixedValuePointPatchFields.H" -#include "pointPatchFields.H" #include "addToRunTimeSelectionTable.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ +#include "pointPatchFields.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -makePointPatchFields(codedFixedValue); +defineTypeName(Foam::codedFixedValuePointPatchFieldBase); -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +template<> +const Foam::wordList +Foam::CodedBase::codeKeys_ = +{ + "code", + "codeInclude", + "localCode" +}; + +namespace Foam +{ + makePointPatchFields(codedFixedValue); +} -} // End namespace Foam // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C index 5f07d8fe7a..1a8e5ccfc4 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C +++ b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1.C @@ -91,7 +91,7 @@ template Foam::autoPtr> Foam::Function1s::Coded::compileNew() { - this->updateLibrary(codeName()); + this->updateLibrary(); dictionary redirectDict(codeDict()); redirectDict.set(codeName(), codeName()); diff --git a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1I.H b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1I.H index 3d8ed2931e..86b297e061 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1I.H +++ b/src/OpenFOAM/primitives/functions/Function1/Coded/CodedFunction1I.H @@ -31,7 +31,7 @@ template inline Type Foam::Function1s::Coded::value(const scalar x) const { // Make sure library containing user-defined Function1 is up-to-date - this->updateLibrary(codeName()); + this->updateLibrary(); return redirectFunction1Ptr_->value(x); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C index 1d54921f86..7e94b7c678 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C @@ -29,7 +29,6 @@ License #include "volFields.H" #include "dynamicCode.H" #include "dynamicCodeContext.H" -#include "stringOps.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -131,7 +130,7 @@ Foam::codedFixedValueFvPatchField::codedFixedValueFvPatchField CodedBase(dict), redirectPatchFieldPtr_() { - updateLibrary(codeName()); + updateLibrary(); } @@ -168,9 +167,6 @@ Foam::codedFixedValueFvPatchField::redirectPatchField() const { if (!redirectPatchFieldPtr_.valid()) { - // Construct a patch - // Make sure to construct the patchfield with up-to-date value - OStringStream os; writeEntry(os, "type", codeName()); writeEntry(os, "value", *this); @@ -201,7 +197,7 @@ void Foam::codedFixedValueFvPatchField::updateCoeffs() } // Make sure library containing user-defined fvPatchField is up-to-date - updateLibrary(codeName()); + updateLibrary(); const fvPatchField& fvp = redirectPatchField(); @@ -221,7 +217,7 @@ void Foam::codedFixedValueFvPatchField::evaluate ) { // Make sure library containing user-defined fvPatchField is up-to-date - updateLibrary(codeName()); + updateLibrary(); const fvPatchField& fvp = redirectPatchField(); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.H index c05f01d406..052ac9e74e 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.H @@ -117,9 +117,6 @@ class codedFixedValueFvPatchField // Private Member Functions - //- Set the rewrite vars controlling the Type - static void setFieldTemplates(dynamicCode& dynCode); - //- Adapt the context for the current object virtual void prepare(dynamicCode&, const dynamicCodeContext&) const; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchFields.C index ccb2fb8b02..8e9a12dc8e 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchFields.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchFields.C @@ -27,7 +27,7 @@ License #include "addToRunTimeSelectionTable.H" #include "volFields.H" -// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // defineTypeName(Foam::codedFixedValueFvPatchFieldBase); @@ -40,18 +40,10 @@ Foam::CodedBase::codeKeys_ = "localCode" }; - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - namespace Foam { + makePatchFields(codedFixedValue); +} -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -makePatchFields(codedFixedValue); - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam // ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C index d24f297e4b..19f182a98b 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C @@ -29,76 +29,9 @@ License #include "volFields.H" #include "dynamicCode.H" #include "dynamicCodeContext.H" -#include "stringOps.H" - -// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * // - -template -const Foam::wordList Foam::codedMixedFvPatchField::codeKeys_ = - {"code", "codeInclude", "localCode"}; - - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -template -const Foam::word Foam::codedMixedFvPatchField::codeTemplateC = - "mixedFvPatchFieldTemplate.C"; - -template -const Foam::word Foam::codedMixedFvPatchField::codeTemplateH = - "mixedFvPatchFieldTemplate.H"; - - -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // - -template -void Foam::codedMixedFvPatchField::setFieldTemplates -( - dynamicCode& dynCode -) -{ - word fieldType(pTraits::typeName); - - // template type for fvPatchField - dynCode.setFilterVariable("TemplateType", fieldType); - - // Name for fvPatchField - eg, ScalarField, VectorField, ... - fieldType[0] = toupper(fieldType[0]); - dynCode.setFilterVariable("FieldType", fieldType + "Field"); -} - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -template -const Foam::IOdictionary& Foam::codedMixedFvPatchField::dict() const -{ - const objectRegistry& obr = this->db(); - - if (obr.foundObject("codeDict")) - { - return obr.lookupObject("codeDict"); - } - else - { - return obr.store - ( - new IOdictionary - ( - IOobject - ( - "codeDict", - this->db().time().system(), - this->db(), - IOobject::MUST_READ_IF_MODIFIED, - IOobject::NO_WRITE - ) - ) - ); - } -} - - template void Foam::codedMixedFvPatchField::prepare ( @@ -106,75 +39,51 @@ void Foam::codedMixedFvPatchField::prepare const dynamicCodeContext& context ) const { - // take no chances - typeName must be identical to name_ - dynCode.setFilterVariable("typeName", name_); + dynCode.setFilterVariable("typeName", codeName()); - // set TemplateType and FieldType filter variables + // Set TemplateType and FieldType filter variables // (for fvPatchField) - setFieldTemplates(dynCode); + word fieldType(pTraits::typeName); - // compile filtered C template + // Template type for fvPatchField + dynCode.setFilterVariable("TemplateType", fieldType); + + // Name for fvPatchField - eg, ScalarField, VectorField, ... + fieldType[0] = toupper(fieldType[0]); + dynCode.setFilterVariable("FieldType", fieldType + "Field"); + + // Compile filtered C template dynCode.addCompileFile(codeTemplateC); - // copy filtered H template + // Copy filtered H template dynCode.addCopyFile(codeTemplateH); + // Debugging: make BC verbose + if (debug) + { + dynCode.setFilterVariable("verbose", "true"); + Info<<"compile " << codeName() << " sha1: " + << context.sha1() << endl; + } - // debugging: make BC verbose - // dynCode.setFilterVariable("verbose", "true"); - // Info<<"compile " << name_ << " sha1: " - // << context.sha1() << endl; - - // define Make/options + // Define Make/options dynCode.setMakeOptions - ( - "EXE_INC = -g \\\n" - "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n" - + context.options() - + "\n\nLIB_LIBS = \\\n" - + " -lOpenFOAM \\\n" - + " -lfiniteVolume \\\n" - + context.libs() - ); -} - - -template -const Foam::dictionary& Foam::codedMixedFvPatchField::codeDict() -const -{ - // use system/codeDict or in-line - return ( - dict_.found("code") - ? dict_ - : this->dict().subDict(name_) + "EXE_INC = -g \\\n" + "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n" + + context.options() + + "\n\nLIB_LIBS = \\\n" + + " -lOpenFOAM \\\n" + + " -lfiniteVolume \\\n" + + context.libs() ); } -template -const Foam::wordList& Foam::codedMixedFvPatchField::codeKeys() const -{ - return codeKeys_; -} - - -template -Foam::string Foam::codedMixedFvPatchField::description() const -{ - return - "patch " - + this->patch().name() - + " on field " - + this->internalField().name(); -} - - template void Foam::codedMixedFvPatchField::clearRedirect() const { - // remove instantiation of fvPatchField provided by library + // Remove instantiation of fvPatchField provided by library redirectPatchFieldPtr_.clear(); } @@ -189,7 +98,7 @@ Foam::codedMixedFvPatchField::codedMixedFvPatchField ) : mixedFvPatchField(p, iF), - codedBase(), + CodedBase(), redirectPatchFieldPtr_() {} @@ -204,9 +113,7 @@ Foam::codedMixedFvPatchField::codedMixedFvPatchField ) : mixedFvPatchField(ptf, p, iF, mapper), - codedBase(), - dict_(ptf.dict_), - name_(ptf.name_), + CodedBase(ptf), redirectPatchFieldPtr_() {} @@ -220,17 +127,10 @@ Foam::codedMixedFvPatchField::codedMixedFvPatchField ) : mixedFvPatchField(p, iF, dict), - codedBase(), - dict_(dict), - name_ - ( - dict.found("redirectType") - ? dict.lookup("redirectType") - : dict.lookup("name") - ), + CodedBase(dict), redirectPatchFieldPtr_() { - updateLibrary(name_); + updateLibrary(); } @@ -241,9 +141,7 @@ Foam::codedMixedFvPatchField::codedMixedFvPatchField ) : mixedFvPatchField(ptf), - codedBase(), - dict_(ptf.dict_), - name_(ptf.name_), + CodedBase(ptf), redirectPatchFieldPtr_() {} @@ -256,9 +154,7 @@ Foam::codedMixedFvPatchField::codedMixedFvPatchField ) : mixedFvPatchField(ptf, iF), - codedBase(), - dict_(ptf.dict_), - name_(ptf.name_), + CodedBase(ptf), redirectPatchFieldPtr_() {} @@ -271,19 +167,14 @@ Foam::codedMixedFvPatchField::redirectPatchField() const { if (!redirectPatchFieldPtr_.valid()) { - // Construct a patch - // Make sure to construct the patchfield with up-to-date value - - // Write the data from the mixed b.c. OStringStream os; mixedFvPatchField::write(os); IStringStream is(os.str()); - // Construct dictionary from it. dictionary dict(is); // Override the type to enforce the fvPatchField::New constructor // to choose our type - dict.set("type", name_); + dict.set("type", codeName()); redirectPatchFieldPtr_.set ( @@ -298,6 +189,7 @@ Foam::codedMixedFvPatchField::redirectPatchField() const ) ); } + return redirectPatchFieldPtr_(); } @@ -311,7 +203,7 @@ void Foam::codedMixedFvPatchField::updateCoeffs() } // Make sure library containing user-defined fvPatchField is up-to-date - updateLibrary(name_); + updateLibrary(); const mixedFvPatchField& fvp = redirectPatchField(); @@ -333,7 +225,7 @@ void Foam::codedMixedFvPatchField::evaluate ) { // Make sure library containing user-defined fvPatchField is up-to-date - updateLibrary(name_); + updateLibrary(); const mixedFvPatchField& fvp = redirectPatchField(); @@ -350,42 +242,7 @@ template void Foam::codedMixedFvPatchField::write(Ostream& os) const { mixedFvPatchField::write(os); - writeEntry(os, "name", name_); - - if (dict_.found("codeInclude")) - { - writeKeyword(os, "codeInclude"); - os.write(verbatimString(dict_["codeInclude"])) - << token::END_STATEMENT << nl; - } - - if (dict_.found("localCode")) - { - writeKeyword(os, "localCode"); - os.write(verbatimString(dict_["localCode"])) - << token::END_STATEMENT << nl; - } - - if (dict_.found("code")) - { - writeKeyword(os, "code"); - os.write(verbatimString(dict_["code"])) - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeOptions")) - { - writeKeyword(os, "codeOptions"); - os.write(verbatimString(dict_["codeOptions"])) - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeLibs")) - { - writeKeyword(os, "codeLibs"); - os.write(verbatimString(dict_["codeLibs"])) - << token::END_STATEMENT << nl; - } + writeCode(os); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.H index 77f00bbb72..ee9a443688 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.H @@ -91,15 +91,24 @@ SourceFiles #define codedMixedFvPatchField_H #include "mixedFvPatchFields.H" -#include "codedBase.H" +#include "CodedBase.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -// Forward declaration of classes -class IOdictionary; +/*---------------------------------------------------------------------------*\ + Class codedMixedFvPatchFieldBase Declaration +\*---------------------------------------------------------------------------*/ + +class codedMixedFvPatchFieldBase +{ +public: + + ClassNameNoDebug("mixedFvPatchField"); +}; + /*---------------------------------------------------------------------------*\ Class codedMixedFvPatchField Declaration @@ -109,58 +118,24 @@ template class codedMixedFvPatchField : public mixedFvPatchField, - public codedBase + public CodedBase { - // Private static data - - //- The keywords associated with source code - static const wordList codeKeys_; - - // Private Data - //- Dictionary contents for the boundary condition - mutable dictionary dict_; - - const word name_; - mutable autoPtr> redirectPatchFieldPtr_; // Private Member Functions - const IOdictionary& dict() const; - - //- Set the rewrite vars controlling the Type - static void setFieldTemplates(dynamicCode& dynCode); - //- Adapt the context for the current object virtual void prepare(dynamicCode&, const dynamicCodeContext&) const; - //- Return a description (type + name) for the output - virtual string description() const; - //- Clear the ptr to the redirected object virtual void clearRedirect() const; - //- Get the dictionary to initialize the codeContext - virtual const dictionary& codeDict() const; - - //- Get the keywords associated with source code - virtual const wordList& codeKeys() const; - public: - // Static Data Members - - //- Name of the C code template to be used - static const word codeTemplateC; - - //- Name of the H code template to be used - static const word codeTemplateH; - - //- Runtime type information TypeName("codedMixed"); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchFields.C index a000df3927..3bd2005849 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchFields.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,17 +27,23 @@ License #include "addToRunTimeSelectionTable.H" #include "volFields.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +defineTypeName(Foam::codedMixedFvPatchFieldBase); + +template<> +const Foam::wordList +Foam::CodedBase::codeKeys_ = +{ + "code", + "codeInclude", + "localCode" +}; namespace Foam { + makePatchFields(codedMixed); +} -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -makePatchFields(codedMixed); - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam // ************************************************************************* // diff --git a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C index 45dc60796d..31f6840406 100644 --- a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C +++ b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C @@ -154,28 +154,28 @@ Foam::functionObject& Foam::codedFunctionObject::redirectFunctionObject() const bool Foam::codedFunctionObject::execute() { - updateLibrary(codeName()); + updateLibrary(); return redirectFunctionObject().execute(); } bool Foam::codedFunctionObject::write() { - updateLibrary(codeName()); + updateLibrary(); return redirectFunctionObject().write(); } bool Foam::codedFunctionObject::end() { - updateLibrary(codeName()); + updateLibrary(); return redirectFunctionObject().end(); } bool Foam::codedFunctionObject::read(const dictionary& dict) { - updateLibrary(codeName()); + updateLibrary(); return redirectFunctionObject().read(dict); } diff --git a/src/fvOptions/sources/general/codedSource/CodedSource.C b/src/fvOptions/sources/general/codedSource/CodedSource.C index 79cb60b554..ad8021baf6 100644 --- a/src/fvOptions/sources/general/codedSource/CodedSource.C +++ b/src/fvOptions/sources/general/codedSource/CodedSource.C @@ -33,7 +33,13 @@ License template const Foam::wordList Foam::fv::CodedSource::codeKeys_ = - {"codeAddSup", "codeCorrect", "codeInclude", "codeSetValue", "localCode"}; +{ + "codeAddSup", + "codeCorrect", + "codeInclude", + "codeSetValue", + "localCode" +}; // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // @@ -160,7 +166,7 @@ void Foam::fv::CodedSource::correct << ">::correct for source " << name_ << endl; } - updateLibrary(name_); + updateLibrary(); redirectFvOption().correct(field); } @@ -178,7 +184,7 @@ void Foam::fv::CodedSource::addSup << ">::addSup for source " << name_ << endl; } - updateLibrary(name_); + updateLibrary(); redirectFvOption().addSup(eqn, fieldi); } @@ -197,7 +203,7 @@ void Foam::fv::CodedSource::addSup << ">::addSup for source " << name_ << endl; } - updateLibrary(name_); + updateLibrary(); redirectFvOption().addSup(rho, eqn, fieldi); } @@ -215,7 +221,7 @@ void Foam::fv::CodedSource::constrain << ">::constrain for source " << name_ << endl; } - updateLibrary(name_); + updateLibrary(); redirectFvOption().constrain(eqn, fieldi); } diff --git a/src/fvOptions/sources/general/codedSource/CodedSource.H b/src/fvOptions/sources/general/codedSource/CodedSource.H index 23ab872254..65f15414f5 100644 --- a/src/fvOptions/sources/general/codedSource/CodedSource.H +++ b/src/fvOptions/sources/general/codedSource/CodedSource.H @@ -149,6 +149,12 @@ protected: //- Adapt the context for the current object virtual void prepare(dynamicCode&, const dynamicCodeContext&) const; + //- Name of the dynamically generated CodedType + virtual const word& codeName() const + { + return name_; + } + //- Return a description (type + name) for the output virtual string description() const; diff --git a/src/fvOptions/sources/general/codedSource/CodedSourceIO.C b/src/fvOptions/sources/general/codedSource/CodedSourceIO.C index 2b5a60357d..e69fbf66fb 100644 --- a/src/fvOptions/sources/general/codedSource/CodedSourceIO.C +++ b/src/fvOptions/sources/general/codedSource/CodedSourceIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -47,7 +47,7 @@ bool Foam::fv::CodedSource::read(const dictionary& dict) dict.lookup("name"); // <-- generate error message with "name" in it } - updateLibrary(name_); + updateLibrary(); return true; }