codedMixedFvPatchField, codedFixedValuePointPatchField: Updated and simplified using the new CodedBase class
reducing code duplication and maintenance overhead.
This commit is contained in:
@ -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;
|
||||
|
||||
@ -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
|
||||
(
|
||||
|
||||
@ -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:
|
||||
|
||||
|
||||
@ -29,77 +29,9 @@ License
|
||||
#include "pointFields.H"
|
||||
#include "dynamicCode.H"
|
||||
#include "dynamicCodeContext.H"
|
||||
#include "stringOps.H"
|
||||
|
||||
// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
const Foam::wordList Foam::codedFixedValuePointPatchField<Type>::codeKeys_ =
|
||||
{"code", "codeInclude", "localCode"};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
const Foam::word Foam::codedFixedValuePointPatchField<Type>::codeTemplateC =
|
||||
"fixedValuePointPatchFieldTemplate.C";
|
||||
|
||||
template<class Type>
|
||||
const Foam::word Foam::codedFixedValuePointPatchField<Type>::codeTemplateH =
|
||||
"fixedValuePointPatchFieldTemplate.H";
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::codedFixedValuePointPatchField<Type>::setFieldTemplates
|
||||
(
|
||||
dynamicCode& dynCode
|
||||
)
|
||||
{
|
||||
word fieldType(pTraits<Type>::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<class Type>
|
||||
const Foam::IOdictionary& Foam::codedFixedValuePointPatchField<Type>::dict()
|
||||
const
|
||||
{
|
||||
const objectRegistry& obr = this->db();
|
||||
|
||||
if (obr.foundObject<IOdictionary>("codeDict"))
|
||||
{
|
||||
return obr.lookupObject<IOdictionary>("codeDict");
|
||||
}
|
||||
else
|
||||
{
|
||||
return obr.store
|
||||
(
|
||||
new IOdictionary
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"codeDict",
|
||||
this->db().time().system(),
|
||||
this->db(),
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::codedFixedValuePointPatchField<Type>::prepare
|
||||
(
|
||||
@ -107,12 +39,19 @@ void Foam::codedFixedValuePointPatchField<Type>::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<Type>::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<Type>::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<class Type>
|
||||
const Foam::dictionary&
|
||||
Foam::codedFixedValuePointPatchField<Type>::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<class Type>
|
||||
const Foam::wordList&
|
||||
Foam::codedFixedValuePointPatchField<Type>::codeKeys() const
|
||||
{
|
||||
return codeKeys_;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::string Foam::codedFixedValuePointPatchField<Type>::description() const
|
||||
{
|
||||
return
|
||||
"patch "
|
||||
+ this->patch().name()
|
||||
+ " on field "
|
||||
+ this->internalField().name();
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::codedFixedValuePointPatchField<Type>::clearRedirect() const
|
||||
{
|
||||
@ -191,7 +100,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField
|
||||
)
|
||||
:
|
||||
fixedValuePointPatchField<Type>(p, iF),
|
||||
codedBase(),
|
||||
CodedBase<codedFixedValuePointPatchFieldBase>(),
|
||||
redirectPatchFieldPtr_()
|
||||
{}
|
||||
|
||||
@ -206,9 +115,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField
|
||||
)
|
||||
:
|
||||
fixedValuePointPatchField<Type>(ptf, p, iF, mapper),
|
||||
codedBase(),
|
||||
dict_(ptf.dict_),
|
||||
name_(ptf.name_),
|
||||
CodedBase<codedFixedValuePointPatchFieldBase>(ptf),
|
||||
redirectPatchFieldPtr_()
|
||||
{}
|
||||
|
||||
@ -222,17 +129,10 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField
|
||||
)
|
||||
:
|
||||
fixedValuePointPatchField<Type>(p, iF, dict),
|
||||
codedBase(),
|
||||
dict_(dict),
|
||||
name_
|
||||
(
|
||||
dict.found("redirectType")
|
||||
? dict.lookup("redirectType")
|
||||
: dict.lookup("name")
|
||||
),
|
||||
CodedBase<codedFixedValuePointPatchFieldBase>(dict),
|
||||
redirectPatchFieldPtr_()
|
||||
{
|
||||
updateLibrary(name_);
|
||||
updateLibrary();
|
||||
}
|
||||
|
||||
|
||||
@ -243,9 +143,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField
|
||||
)
|
||||
:
|
||||
fixedValuePointPatchField<Type>(ptf),
|
||||
codedBase(),
|
||||
dict_(ptf.dict_),
|
||||
name_(ptf.name_),
|
||||
CodedBase<codedFixedValuePointPatchFieldBase>(ptf),
|
||||
redirectPatchFieldPtr_()
|
||||
{}
|
||||
|
||||
@ -258,9 +156,7 @@ Foam::codedFixedValuePointPatchField<Type>::codedFixedValuePointPatchField
|
||||
)
|
||||
:
|
||||
fixedValuePointPatchField<Type>(ptf, iF),
|
||||
codedBase(),
|
||||
dict_(ptf.dict_),
|
||||
name_(ptf.name_),
|
||||
CodedBase<codedFixedValuePointPatchFieldBase>(ptf),
|
||||
redirectPatchFieldPtr_()
|
||||
{}
|
||||
|
||||
@ -273,11 +169,8 @@ Foam::codedFixedValuePointPatchField<Type>::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<const Field<Type>&>(*this));
|
||||
IStringStream is(os.str());
|
||||
dictionary dict(is);
|
||||
@ -292,6 +185,7 @@ Foam::codedFixedValuePointPatchField<Type>::redirectPatchField() const
|
||||
).ptr()
|
||||
);
|
||||
}
|
||||
|
||||
return redirectPatchFieldPtr_();
|
||||
}
|
||||
|
||||
@ -305,7 +199,7 @@ void Foam::codedFixedValuePointPatchField<Type>::updateCoeffs()
|
||||
}
|
||||
|
||||
// Make sure library containing user-defined pointPatchField is up-to-date
|
||||
updateLibrary(name_);
|
||||
updateLibrary();
|
||||
|
||||
const pointPatchField<Type>& fvp = redirectPatchField();
|
||||
|
||||
@ -325,7 +219,7 @@ void Foam::codedFixedValuePointPatchField<Type>::evaluate
|
||||
)
|
||||
{
|
||||
// Make sure library containing user-defined pointPatchField is up-to-date
|
||||
updateLibrary(name_);
|
||||
updateLibrary();
|
||||
|
||||
const pointPatchField<Type>& fvp = redirectPatchField();
|
||||
|
||||
@ -339,42 +233,7 @@ template<class Type>
|
||||
void Foam::codedFixedValuePointPatchField<Type>::write(Ostream& os) const
|
||||
{
|
||||
fixedValuePointPatchField<Type>::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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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 Type>
|
||||
class codedFixedValuePointPatchField
|
||||
:
|
||||
public fixedValuePointPatchField<Type>,
|
||||
public codedBase
|
||||
public CodedBase<codedFixedValuePointPatchFieldBase>
|
||||
{
|
||||
// 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<pointPatchField<Type>> 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");
|
||||
|
||||
|
||||
@ -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<Foam::codedFixedValuePointPatchFieldBase>::codeKeys_ =
|
||||
{
|
||||
"code",
|
||||
"codeInclude",
|
||||
"localCode"
|
||||
};
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
makePointPatchFields(codedFixedValue);
|
||||
}
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -91,7 +91,7 @@ template<class Type>
|
||||
Foam::autoPtr<Foam::Function1<Type>>
|
||||
Foam::Function1s::Coded<Type>::compileNew()
|
||||
{
|
||||
this->updateLibrary(codeName());
|
||||
this->updateLibrary();
|
||||
|
||||
dictionary redirectDict(codeDict());
|
||||
redirectDict.set(codeName(), codeName());
|
||||
|
||||
@ -31,7 +31,7 @@ template<class Type>
|
||||
inline Type Foam::Function1s::Coded<Type>::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);
|
||||
}
|
||||
|
||||
@ -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<Type>::codedFixedValueFvPatchField
|
||||
CodedBase<codedFixedValueFvPatchFieldBase>(dict),
|
||||
redirectPatchFieldPtr_()
|
||||
{
|
||||
updateLibrary(codeName());
|
||||
updateLibrary();
|
||||
}
|
||||
|
||||
|
||||
@ -168,9 +167,6 @@ Foam::codedFixedValueFvPatchField<Type>::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<Type>::updateCoeffs()
|
||||
}
|
||||
|
||||
// Make sure library containing user-defined fvPatchField is up-to-date
|
||||
updateLibrary(codeName());
|
||||
updateLibrary();
|
||||
|
||||
const fvPatchField<Type>& fvp = redirectPatchField();
|
||||
|
||||
@ -221,7 +217,7 @@ void Foam::codedFixedValueFvPatchField<Type>::evaluate
|
||||
)
|
||||
{
|
||||
// Make sure library containing user-defined fvPatchField is up-to-date
|
||||
updateLibrary(codeName());
|
||||
updateLibrary();
|
||||
|
||||
const fvPatchField<Type>& fvp = redirectPatchField();
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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<Foam::codedFixedValueFvPatchFieldBase>::codeKeys_ =
|
||||
"localCode"
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
makePatchFields(codedFixedValue);
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
makePatchFields(codedFixedValue);
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -29,76 +29,9 @@ License
|
||||
#include "volFields.H"
|
||||
#include "dynamicCode.H"
|
||||
#include "dynamicCodeContext.H"
|
||||
#include "stringOps.H"
|
||||
|
||||
// * * * * * * * * * * * * Private Static Data Members * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
const Foam::wordList Foam::codedMixedFvPatchField<Type>::codeKeys_ =
|
||||
{"code", "codeInclude", "localCode"};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
const Foam::word Foam::codedMixedFvPatchField<Type>::codeTemplateC =
|
||||
"mixedFvPatchFieldTemplate.C";
|
||||
|
||||
template<class Type>
|
||||
const Foam::word Foam::codedMixedFvPatchField<Type>::codeTemplateH =
|
||||
"mixedFvPatchFieldTemplate.H";
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::codedMixedFvPatchField<Type>::setFieldTemplates
|
||||
(
|
||||
dynamicCode& dynCode
|
||||
)
|
||||
{
|
||||
word fieldType(pTraits<Type>::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<class Type>
|
||||
const Foam::IOdictionary& Foam::codedMixedFvPatchField<Type>::dict() const
|
||||
{
|
||||
const objectRegistry& obr = this->db();
|
||||
|
||||
if (obr.foundObject<IOdictionary>("codeDict"))
|
||||
{
|
||||
return obr.lookupObject<IOdictionary>("codeDict");
|
||||
}
|
||||
else
|
||||
{
|
||||
return obr.store
|
||||
(
|
||||
new IOdictionary
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"codeDict",
|
||||
this->db().time().system(),
|
||||
this->db(),
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::codedMixedFvPatchField<Type>::prepare
|
||||
(
|
||||
@ -106,75 +39,51 @@ void Foam::codedMixedFvPatchField<Type>::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<Type>::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<class Type>
|
||||
const Foam::dictionary& Foam::codedMixedFvPatchField<Type>::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<class Type>
|
||||
const Foam::wordList& Foam::codedMixedFvPatchField<Type>::codeKeys() const
|
||||
{
|
||||
return codeKeys_;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::string Foam::codedMixedFvPatchField<Type>::description() const
|
||||
{
|
||||
return
|
||||
"patch "
|
||||
+ this->patch().name()
|
||||
+ " on field "
|
||||
+ this->internalField().name();
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::codedMixedFvPatchField<Type>::clearRedirect() const
|
||||
{
|
||||
// remove instantiation of fvPatchField provided by library
|
||||
// Remove instantiation of fvPatchField provided by library
|
||||
redirectPatchFieldPtr_.clear();
|
||||
}
|
||||
|
||||
@ -189,7 +98,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField
|
||||
)
|
||||
:
|
||||
mixedFvPatchField<Type>(p, iF),
|
||||
codedBase(),
|
||||
CodedBase<codedMixedFvPatchFieldBase>(),
|
||||
redirectPatchFieldPtr_()
|
||||
{}
|
||||
|
||||
@ -204,9 +113,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField
|
||||
)
|
||||
:
|
||||
mixedFvPatchField<Type>(ptf, p, iF, mapper),
|
||||
codedBase(),
|
||||
dict_(ptf.dict_),
|
||||
name_(ptf.name_),
|
||||
CodedBase<codedMixedFvPatchFieldBase>(ptf),
|
||||
redirectPatchFieldPtr_()
|
||||
{}
|
||||
|
||||
@ -220,17 +127,10 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField
|
||||
)
|
||||
:
|
||||
mixedFvPatchField<Type>(p, iF, dict),
|
||||
codedBase(),
|
||||
dict_(dict),
|
||||
name_
|
||||
(
|
||||
dict.found("redirectType")
|
||||
? dict.lookup("redirectType")
|
||||
: dict.lookup("name")
|
||||
),
|
||||
CodedBase<codedMixedFvPatchFieldBase>(dict),
|
||||
redirectPatchFieldPtr_()
|
||||
{
|
||||
updateLibrary(name_);
|
||||
updateLibrary();
|
||||
}
|
||||
|
||||
|
||||
@ -241,9 +141,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField
|
||||
)
|
||||
:
|
||||
mixedFvPatchField<Type>(ptf),
|
||||
codedBase(),
|
||||
dict_(ptf.dict_),
|
||||
name_(ptf.name_),
|
||||
CodedBase<codedMixedFvPatchFieldBase>(ptf),
|
||||
redirectPatchFieldPtr_()
|
||||
{}
|
||||
|
||||
@ -256,9 +154,7 @@ Foam::codedMixedFvPatchField<Type>::codedMixedFvPatchField
|
||||
)
|
||||
:
|
||||
mixedFvPatchField<Type>(ptf, iF),
|
||||
codedBase(),
|
||||
dict_(ptf.dict_),
|
||||
name_(ptf.name_),
|
||||
CodedBase<codedMixedFvPatchFieldBase>(ptf),
|
||||
redirectPatchFieldPtr_()
|
||||
{}
|
||||
|
||||
@ -271,19 +167,14 @@ Foam::codedMixedFvPatchField<Type>::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<Type>::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<Type>::redirectPatchField() const
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return redirectPatchFieldPtr_();
|
||||
}
|
||||
|
||||
@ -311,7 +203,7 @@ void Foam::codedMixedFvPatchField<Type>::updateCoeffs()
|
||||
}
|
||||
|
||||
// Make sure library containing user-defined fvPatchField is up-to-date
|
||||
updateLibrary(name_);
|
||||
updateLibrary();
|
||||
|
||||
const mixedFvPatchField<Type>& fvp = redirectPatchField();
|
||||
|
||||
@ -333,7 +225,7 @@ void Foam::codedMixedFvPatchField<Type>::evaluate
|
||||
)
|
||||
{
|
||||
// Make sure library containing user-defined fvPatchField is up-to-date
|
||||
updateLibrary(name_);
|
||||
updateLibrary();
|
||||
|
||||
const mixedFvPatchField<Type>& fvp = redirectPatchField();
|
||||
|
||||
@ -350,42 +242,7 @@ template<class Type>
|
||||
void Foam::codedMixedFvPatchField<Type>::write(Ostream& os) const
|
||||
{
|
||||
mixedFvPatchField<Type>::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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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 Type>
|
||||
class codedMixedFvPatchField
|
||||
:
|
||||
public mixedFvPatchField<Type>,
|
||||
public codedBase
|
||||
public CodedBase<codedMixedFvPatchFieldBase>
|
||||
{
|
||||
// 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<mixedFvPatchField<Type>> 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");
|
||||
|
||||
|
||||
@ -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<Foam::codedMixedFvPatchFieldBase>::codeKeys_ =
|
||||
{
|
||||
"code",
|
||||
"codeInclude",
|
||||
"localCode"
|
||||
};
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
makePatchFields(codedMixed);
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
makePatchFields(codedMixed);
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -33,7 +33,13 @@ License
|
||||
|
||||
template<class Type>
|
||||
const Foam::wordList Foam::fv::CodedSource<Type>::codeKeys_ =
|
||||
{"codeAddSup", "codeCorrect", "codeInclude", "codeSetValue", "localCode"};
|
||||
{
|
||||
"codeAddSup",
|
||||
"codeCorrect",
|
||||
"codeInclude",
|
||||
"codeSetValue",
|
||||
"localCode"
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
@ -160,7 +166,7 @@ void Foam::fv::CodedSource<Type>::correct
|
||||
<< ">::correct for source " << name_ << endl;
|
||||
}
|
||||
|
||||
updateLibrary(name_);
|
||||
updateLibrary();
|
||||
redirectFvOption().correct(field);
|
||||
}
|
||||
|
||||
@ -178,7 +184,7 @@ void Foam::fv::CodedSource<Type>::addSup
|
||||
<< ">::addSup for source " << name_ << endl;
|
||||
}
|
||||
|
||||
updateLibrary(name_);
|
||||
updateLibrary();
|
||||
redirectFvOption().addSup(eqn, fieldi);
|
||||
}
|
||||
|
||||
@ -197,7 +203,7 @@ void Foam::fv::CodedSource<Type>::addSup
|
||||
<< ">::addSup for source " << name_ << endl;
|
||||
}
|
||||
|
||||
updateLibrary(name_);
|
||||
updateLibrary();
|
||||
redirectFvOption().addSup(rho, eqn, fieldi);
|
||||
}
|
||||
|
||||
@ -215,7 +221,7 @@ void Foam::fv::CodedSource<Type>::constrain
|
||||
<< ">::constrain for source " << name_ << endl;
|
||||
}
|
||||
|
||||
updateLibrary(name_);
|
||||
updateLibrary();
|
||||
redirectFvOption().constrain(eqn, fieldi);
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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<Type>::read(const dictionary& dict)
|
||||
dict.lookup("name"); // <-- generate error message with "name" in it
|
||||
}
|
||||
|
||||
updateLibrary(name_);
|
||||
updateLibrary();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user