diff --git a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C index d6c4f935d6..aad851509e 100644 --- a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C +++ b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.C @@ -147,7 +147,7 @@ ${typeName}FvOption${SourceType}::addSup Info<< "${typeName}FvOption${SourceType}::addSup()\n"; } -//{{{ begin code +//{{{ begin code - warn/fatal if not implemented? ${codeAddSup} //}}} end code } @@ -163,11 +163,11 @@ ${typeName}FvOption${SourceType}::addSup { if (${verbose:-false}) { - Info<< "${typeName}FvOption${SourceType}::addSup()\n"; + Info<< "${typeName}FvOption${SourceType}::addSup(rho)\n"; } -//{{{ begin code - ${codeAddSup} +//{{{ begin code - warn/fatal if not implemented? + ${codeAddSupRho} //}}} end code } diff --git a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H index e252336236..b38b4e92f6 100644 --- a/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H +++ b/etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H @@ -35,7 +35,14 @@ Description codeAddSup ( - fvMatrix& eqn, + fvMatrix& eqn, + const label fieldi + ) + + codeAddSupRho + ( + const volScalarField& rho, + fvMatrix& eqn, const label fieldi ) diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C index 2a6a25d5aa..f83e260887 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C @@ -100,6 +100,12 @@ bool Foam::dynamicCodeContext::valid() const noexcept } +const Foam::entry* Foam::dynamicCodeContext::findEntry(const word& key) const +{ + return this->dict().findEntry(key, keyType::LITERAL); +} + + bool Foam::dynamicCodeContext::readEntry ( const word& key, diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H index 91e4441337..95f527dd12 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H @@ -176,6 +176,9 @@ public: // Reading + //- Locate literal dictionary entry, nullptr if not found + const entry* findEntry(const word& key) const; + //- Read string entry from context dictionary //- append content to SHA1 hashing and add line number etc. // diff --git a/src/fvOptions/sources/general/codedSource/CodedFvSource.C b/src/fvOptions/sources/general/codedSource/CodedFvSource.C index 969cb79374..1799249345 100644 --- a/src/fvOptions/sources/general/codedSource/CodedFvSource.C +++ b/src/fvOptions/sources/general/codedSource/CodedFvSource.C @@ -79,9 +79,30 @@ void Foam::fv::CodedSource::prepare //dynCode.removeFilterVariable("code"); dynCode.setFilterVariable("codeCorrect", codeCorrect_); - dynCode.setFilterVariable("codeAddSup", codeAddSup_); dynCode.setFilterVariable("codeConstrain", codeConstrain_); + // Missing codeAddSup or codeAddSupRho handled on input, + // but also check for empty() and inject "NotImplemented" to avoid + // cases where the user has specified or used the wrong one + // (ie, compresssible vs incompressible) + + if (codeAddSup_.empty()) + { + dynCode.setFilterVariable("codeAddSup", "NotImplemented"); + } + else + { + dynCode.setFilterVariable("codeAddSup", codeAddSup_); + } + if (codeAddSupRho_.empty()) + { + dynCode.setFilterVariable("codeAddSupRho", "NotImplemented"); + } + else + { + dynCode.setFilterVariable("codeAddSupRho", codeAddSupRho_); + } + // Compile filtered C template dynCode.addCompileFile(codeTemplateC); @@ -154,7 +175,18 @@ bool Foam::fv::CodedSource::read(const dictionary& dict) auto& ctx = codedBase::codeContext(); ctx.readEntry("codeCorrect", codeCorrect_); - ctx.readEntry("codeAddSup", codeAddSup_); + + // Need one or both codeAddSup/codeAddSupRho. + // - do precheck and let the usual mechanism fail + + const bool mandatory = + ( + !ctx.findEntry("codeAddSup") + && !ctx.findEntry("codeAddSupRho") + ); + + ctx.readEntry("codeAddSup", codeAddSup_, mandatory); + ctx.readEntry("codeAddSupRho", codeAddSupRho_, mandatory); // ctx.readEntry("codeConstrain", codeConstrain_); ctx.readEntry // Compatibility @@ -233,7 +265,7 @@ void Foam::fv::CodedSource::addSup { DebugInfo << "fv::CodedSource<" << pTraits::typeName - << ">::addSup for source " << name_ << endl; + << ">::addSup(rho) for source " << name_ << endl; updateLibrary(name_); redirectOption().addSup(rho, eqn, fieldi); diff --git a/src/fvOptions/sources/general/codedSource/CodedFvSource.H b/src/fvOptions/sources/general/codedSource/CodedFvSource.H index 2f1606df96..8bb4114f77 100644 --- a/src/fvOptions/sources/general/codedSource/CodedFvSource.H +++ b/src/fvOptions/sources/general/codedSource/CodedFvSource.H @@ -43,13 +43,20 @@ Description codeAddSup ( - fvMatrix& eqn, + fvMatrix& eqn, + const label fieldi + ) + + codeAddSupRho + ( + const volScalarField& rho, + fvMatrix& eqn, const label fieldi ) codeConstrain ( - fvMatrix& eqn, + fvMatrix& eqn, const label fieldi ) \endverbatim @@ -141,6 +148,7 @@ protected: string codeCorrect_; string codeAddSup_; + string codeAddSupRho_; string codeConstrain_; //- Underlying code