ENH: distinguish between compressible/incompressible coded source

- previously had codeAddSup used for both incompressible and
  compressible source terms. However, it was not actually possible to
  use it for compressible sources since any references to the 'rho'
  parameter would cause a compilation error for the incompressible case.

  Added 'codeAddSupRho' to distinguish the compressible case.
  User must supply one or both of them on input.
This commit is contained in:
Mark Olesen 2021-10-25 16:01:18 +02:00
parent 8638d82325
commit fd82f3e47a
6 changed files with 66 additions and 10 deletions

View File

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

View File

@ -35,7 +35,14 @@ Description
codeAddSup
(
fvMatrix<Type}>& eqn,
fvMatrix<Type>& eqn,
const label fieldi
)
codeAddSupRho
(
const volScalarField& rho,
fvMatrix<Type>& eqn,
const label fieldi
)

View File

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

View File

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

View File

@ -79,9 +79,30 @@ void Foam::fv::CodedSource<Type>::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<Type>::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<Type>::addSup
{
DebugInfo
<< "fv::CodedSource<" << pTraits<Type>::typeName
<< ">::addSup for source " << name_ << endl;
<< ">::addSup(rho) for source " << name_ << endl;
updateLibrary(name_);
redirectOption().addSup(rho, eqn, fieldi);

View File

@ -43,13 +43,20 @@ Description
codeAddSup
(
fvMatrix<Type}>& eqn,
fvMatrix<Type>& eqn,
const label fieldi
)
codeAddSupRho
(
const volScalarField& rho,
fvMatrix<Type>& eqn,
const label fieldi
)
codeConstrain
(
fvMatrix<Type}>& eqn,
fvMatrix<Type>& eqn,
const label fieldi
)
\endverbatim
@ -141,6 +148,7 @@ protected:
string codeCorrect_;
string codeAddSup_;
string codeAddSupRho_;
string codeConstrain_;
//- Underlying code