simplifying i-o for chemistry models + thermo

This commit is contained in:
andy
2009-06-12 13:28:02 +01:00
parent 5116bfe732
commit 0929b48698
25 changed files with 320 additions and 67 deletions

View File

@ -113,7 +113,7 @@ int main(int argc, char *argv[])
turbulence->correct(); turbulence->correct();
rho = thermo->rho(); rho = thermo.rho();
runTime.write(); runTime.write();

View File

@ -33,10 +33,12 @@ License
template<class CompType, class ThermoType> template<class CompType, class ThermoType>
Foam::ODEChemistryModel<CompType, ThermoType>::ODEChemistryModel Foam::ODEChemistryModel<CompType, ThermoType>::ODEChemistryModel
( (
const fvMesh& mesh const fvMesh& mesh,
const word& compTypeName,
const word& thermoTypeName
) )
: :
CompType(mesh), CompType(mesh, thermoTypeName),
ODE(), ODE(),
@ -55,7 +57,15 @@ Foam::ODEChemistryModel<CompType, ThermoType>::ODEChemistryModel
nSpecie_(Y_.size()), nSpecie_(Y_.size()),
nReaction_(reactions_.size()), nReaction_(reactions_.size()),
solver_(chemistrySolver<CompType, ThermoType>::New(*this)), solver_
(
chemistrySolver<CompType, ThermoType>::New
(
*this,
compTypeName,
thermoTypeName
)
),
RR_(nSpecie_) RR_(nSpecie_)
{ {

View File

@ -110,7 +110,12 @@ public:
// Constructors // Constructors
//- Construct from components //- Construct from components
ODEChemistryModel(const fvMesh& mesh); ODEChemistryModel
(
const fvMesh& mesh,
const word& compTypeName,
const word& thermoTypeName
);
//- Destructor //- Destructor

View File

@ -57,9 +57,7 @@ Foam::basicChemistryModel::basicChemistryModel(const fvMesh& mesh)
mesh.nCells(), mesh.nCells(),
readScalar(lookup("initialChemicalTimeStep")) readScalar(lookup("initialChemicalTimeStep"))
) )
{ {}
Info<< "basicChemistryModel(const fvMesh&)" << endl;
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

View File

@ -34,6 +34,8 @@ Foam::autoPtr<Foam::psiChemistryModel> Foam::psiChemistryModel::New
) )
{ {
word psiChemistryModelType; word psiChemistryModelType;
word thermoTypeName;
word userSel;
// Enclose the creation of the chemistrtyProperties to ensure it is // Enclose the creation of the chemistrtyProperties to ensure it is
// deleted before the chemistrtyProperties is created otherwise the // deleted before the chemistrtyProperties is created otherwise the
@ -51,25 +53,41 @@ Foam::autoPtr<Foam::psiChemistryModel> Foam::psiChemistryModel::New
) )
); );
chemistryPropertiesDict.lookup("psiChemistryModel") >> chemistryPropertiesDict.lookup("psiChemistryModel") >> userSel;
psiChemistryModelType;
// construct chemistry model type name by inserting first template
// argument
label tempOpen = userSel.find('<');
label tempClose = userSel.find('>');
word className = userSel(0, tempOpen);
thermoTypeName = userSel(tempOpen + 1, tempClose - tempOpen - 1);
psiChemistryModelType =
className + '<' + typeName + ',' + thermoTypeName + '>';
} }
Info<< "Selecting psiChemistryModel " << psiChemistryModelType << endl; Info<< "Selecting psiChemistryModel " << userSel << endl;
fvMeshConstructorTable::iterator cstrIter = fvMeshConstructorTable::iterator cstrIter =
fvMeshConstructorTablePtr_->find(psiChemistryModelType); fvMeshConstructorTablePtr_->find(psiChemistryModelType);
if (cstrIter == fvMeshConstructorTablePtr_->end()) if (cstrIter == fvMeshConstructorTablePtr_->end())
{ {
FatalErrorIn("psiChemistryModelBase::New(const mesh&)") wordList models = fvMeshConstructorTablePtr_->toc();
<< "Unknown psiChemistryModel type " << psiChemistryModelType forAll(models, i)
<< nl << nl << "Valid psiChemistryModel types are:" << nl {
<< fvMeshConstructorTablePtr_->toc() << nl models[i] = models[i].replace(typeName + ',', "");
<< exit(FatalError);
} }
return autoPtr<psiChemistryModel>(cstrIter()(mesh)); FatalErrorIn("psiChemistryModelBase::New(const mesh&)")
<< "Unknown psiChemistryModel type " << userSel
<< nl << nl << "Valid psiChemistryModel types are:" << nl
<< models << nl << exit(FatalError);
}
return autoPtr<psiChemistryModel>
(cstrIter()(mesh, typeName, thermoTypeName));
} }

View File

@ -38,10 +38,14 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::psiChemistryModel::psiChemistryModel(const fvMesh& mesh) Foam::psiChemistryModel::psiChemistryModel
(
const fvMesh& mesh,
const word& thermoTypeName
)
: :
basicChemistryModel(mesh), basicChemistryModel(mesh),
thermo_(hCombustionThermo::New(mesh)) thermo_(hCombustionThermo::NewType(mesh, thermoTypeName))
{} {}

View File

@ -89,16 +89,18 @@ public:
psiChemistryModel, psiChemistryModel,
fvMesh, fvMesh,
( (
const fvMesh& mesh const fvMesh& mesh,
const word& compTypeName,
const word& thermoTypeName
), ),
(mesh) (mesh, compTypeName, thermoTypeName)
); );
// Constructors // Constructors
//- Construct from mesh //- Construct from mesh
psiChemistryModel(const fvMesh& mesh); psiChemistryModel(const fvMesh& mesh, const word& thermoTypeName);
//- Selector //- Selector

View File

@ -34,6 +34,8 @@ Foam::autoPtr<Foam::rhoChemistryModel> Foam::rhoChemistryModel::New
) )
{ {
word rhoChemistryModelType; word rhoChemistryModelType;
word thermoTypeName;
word userSel;
// Enclose the creation of the chemistrtyProperties to ensure it is // Enclose the creation of the chemistrtyProperties to ensure it is
// deleted before the chemistrtyProperties is created otherwise the // deleted before the chemistrtyProperties is created otherwise the
@ -51,25 +53,41 @@ Foam::autoPtr<Foam::rhoChemistryModel> Foam::rhoChemistryModel::New
) )
); );
chemistryPropertiesDict.lookup("rhoChemistryModel") >> chemistryPropertiesDict.lookup("rhoChemistryModelType") >> userSel;
rhoChemistryModelType;
// construct chemistry model type name by inserting first template
// argument
label tempOpen = userSel.find('<');
label tempClose = userSel.find('>');
word className = userSel(0, tempOpen);
thermoTypeName = userSel(tempOpen + 1, tempClose - tempOpen - 1);
rhoChemistryModelType =
className + '<' + typeName + ',' + thermoTypeName + '>';
} }
Info<< "Selecting rhoChemistryModel " << rhoChemistryModelType << endl; Info<< "Selecting rhoChemistryModel " << userSel << endl;
fvMeshConstructorTable::iterator cstrIter = fvMeshConstructorTable::iterator cstrIter =
fvMeshConstructorTablePtr_->find(rhoChemistryModelType); fvMeshConstructorTablePtr_->find(rhoChemistryModelType);
if (cstrIter == fvMeshConstructorTablePtr_->end()) if (cstrIter == fvMeshConstructorTablePtr_->end())
{ {
FatalErrorIn("rhoChemistryModelBase::New(const mesh&)") wordList models = fvMeshConstructorTablePtr_->toc();
<< "Unknown rhoChemistryModel type " << rhoChemistryModelType forAll(models, i)
<< nl << nl << "Valid rhoChemistryModel types are:" << nl {
<< fvMeshConstructorTablePtr_->toc() << nl models[i] = models[i].replace(typeName + ',', "");
<< exit(FatalError);
} }
return autoPtr<rhoChemistryModel>(cstrIter()(mesh)); FatalErrorIn("rhoChemistryModelBase::New(const mesh&)")
<< "Unknown rhoChemistryModel type " << userSel
<< nl << nl << "Valid rhoChemistryModel types are:" << nl
<< models << nl << exit(FatalError);
}
return autoPtr<rhoChemistryModel>
(cstrIter()(mesh, typeName, thermoTypeName));
} }

View File

@ -38,10 +38,14 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::rhoChemistryModel::rhoChemistryModel(const fvMesh& mesh) Foam::rhoChemistryModel::rhoChemistryModel
(
const fvMesh& mesh,
const word& thermoTypeName
)
: :
basicChemistryModel(mesh), basicChemistryModel(mesh),
thermo_(hReactionThermo::New(mesh)) thermo_(hReactionThermo::NewType(mesh, thermoTypeName))
{} {}

View File

@ -89,16 +89,18 @@ public:
rhoChemistryModel, rhoChemistryModel,
fvMesh, fvMesh,
( (
const fvMesh& mesh const fvMesh& mesh,
const word& compTypeName,
const word& thermoTypeName
), ),
(mesh) (mesh, compTypeName, thermoTypeName)
); );
// Constructors // Constructors
//- Construct from mesh //- Construct from mesh
rhoChemistryModel(const fvMesh& mesh); rhoChemistryModel(const fvMesh& mesh, const word& thermoTypeName);
//- Selector //- Selector

View File

@ -33,11 +33,12 @@ License
template<class CompType, class ThermoType> template<class CompType, class ThermoType>
Foam::EulerImplicit<CompType, ThermoType>::EulerImplicit Foam::EulerImplicit<CompType, ThermoType>::EulerImplicit
( (
ODEChemistryModel<CompType, ThermoType>& model ODEChemistryModel<CompType, ThermoType>& model,
const word& modelName
) )
: :
chemistrySolver<CompType, ThermoType>(model), chemistrySolver<CompType, ThermoType>(model, modelName),
coeffsDict_(model.subDict(typeName + "Coeffs")), coeffsDict_(model.subDict(modelName + "Coeffs")),
cTauChem_(readScalar(coeffsDict_.lookup("cTauChem"))), cTauChem_(readScalar(coeffsDict_.lookup("cTauChem"))),
equil_(coeffsDict_.lookup("equilibriumRateLimiter")) equil_(coeffsDict_.lookup("equilibriumRateLimiter"))
{} {}

View File

@ -75,7 +75,11 @@ public:
// Constructors // Constructors
//- Construct from components //- Construct from components
EulerImplicit(ODEChemistryModel<CompType, ThermoType>& chemistry); EulerImplicit
(
ODEChemistryModel<CompType, ThermoType>& model,
const word& modelName
);
//- Destructor //- Destructor

View File

@ -34,10 +34,12 @@ namespace Foam
template<class CompType, class ThermoType> template<class CompType, class ThermoType>
Foam::chemistrySolver<CompType, ThermoType>::chemistrySolver Foam::chemistrySolver<CompType, ThermoType>::chemistrySolver
( (
ODEChemistryModel<CompType, ThermoType>& model ODEChemistryModel<CompType, ThermoType>& model,
const word& modelName
) )
: :
model_(model) model_(model),
name_(modelName)
{} {}

View File

@ -65,6 +65,9 @@ protected:
//- Reference to the chemistry model //- Reference to the chemistry model
ODEChemistryModel<CompType, ThermoType>& model_; ODEChemistryModel<CompType, ThermoType>& model_;
//- Name of the chemistry solver
const word name_;
public: public:
@ -79,22 +82,29 @@ public:
chemistrySolver, chemistrySolver,
dictionary, dictionary,
( (
ODEChemistryModel<CompType, ThermoType>& model ODEChemistryModel<CompType, ThermoType>& model,
const word& modelName
), ),
(model) (model, modelName)
); );
// Constructors // Constructors
//- Construct from components //- Construct from components
chemistrySolver(ODEChemistryModel<CompType, ThermoType>& model); chemistrySolver
(
ODEChemistryModel<CompType, ThermoType>& model,
const word& modelName
);
//- Selector //- Selector
static autoPtr<chemistrySolver> New static autoPtr<chemistrySolver> New
( (
ODEChemistryModel<CompType, ThermoType>& model ODEChemistryModel<CompType, ThermoType>& model,
const word& compTypeName,
const word& thermoTypeName
); );

View File

@ -32,27 +32,48 @@ template<class CompType, class ThermoType>
Foam::autoPtr<Foam::chemistrySolver<CompType, ThermoType> > Foam::autoPtr<Foam::chemistrySolver<CompType, ThermoType> >
Foam::chemistrySolver<CompType, ThermoType>::New Foam::chemistrySolver<CompType, ThermoType>::New
( (
ODEChemistryModel<CompType, ThermoType>& model ODEChemistryModel<CompType, ThermoType>& model,
const word& compTypeName,
const word& thermoTypeName
) )
{ {
word chemistrySolverType(model.CompType::lookup("chemistrySolver")); word modelName(model.lookup("chemistrySolver"));
word chemistrySolverType =
modelName + '<' + compTypeName + ',' + thermoTypeName + '>';
Info<< "Selecting chemistrySolver " << modelName << endl;
typename dictionaryConstructorTable::iterator cstrIter = typename dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(chemistrySolverType); dictionaryConstructorTablePtr_->find(chemistrySolverType);
if (cstrIter == dictionaryConstructorTablePtr_->end()) if (cstrIter == dictionaryConstructorTablePtr_->end())
{ {
FatalErrorIn wordList models = dictionaryConstructorTablePtr_->toc();
forAll(models, i)
{
models[i] = models[i].replace
( (
"chemistrySolver::New(const dictionary&, const ODEChemistryModel&)" '<' + compTypeName + ',' + thermoTypeName + '>',
) << "Unknown chemistrySolver type " << chemistrySolverType ""
<< nl << nl );
<< "Valid chemistrySolver types are:" << nl
<< dictionaryConstructorTablePtr_->toc() << nl
<< exit(FatalError);
} }
return autoPtr<chemistrySolver<CompType, ThermoType> >(cstrIter()(model)); FatalErrorIn
(
"chemistrySolver::New"
"("
"const ODEChemistryModel&, "
"const word&, "
"const word&"
")"
) << "Unknown chemistrySolver type " << modelName
<< nl << nl << "Valid chemistrySolver types are:" << nl
<< models << nl << exit(FatalError);
}
return autoPtr<chemistrySolver<CompType, ThermoType> >
(cstrIter()(model, modelName));
} }

View File

@ -32,11 +32,12 @@ License
template<class CompType, class ThermoType> template<class CompType, class ThermoType>
Foam::ode<CompType, ThermoType>::ode Foam::ode<CompType, ThermoType>::ode
( (
ODEChemistryModel<CompType, ThermoType>& model ODEChemistryModel<CompType, ThermoType>& model,
const word& modelName
) )
: :
chemistrySolver<CompType, ThermoType>(model), chemistrySolver<CompType, ThermoType>(model, modelName),
coeffsDict_(model.subDict(typeName + "Coeffs")), coeffsDict_(model.subDict(modelName + "Coeffs")),
solverName_(coeffsDict_.lookup("ODESolver")), solverName_(coeffsDict_.lookup("ODESolver")),
odeSolver_(ODESolver::New(solverName_, model)), odeSolver_(ODESolver::New(solverName_, model)),
eps_(readScalar(coeffsDict_.lookup("eps"))), eps_(readScalar(coeffsDict_.lookup("eps"))),

View File

@ -78,7 +78,11 @@ public:
// Constructors // Constructors
//- Construct from components //- Construct from components
ode(ODEChemistryModel<CompType, ThermoType>& model); ode
(
ODEChemistryModel<CompType, ThermoType>& model,
const word& modelName
);
//- Destructor //- Destructor

View File

@ -32,11 +32,12 @@ License
template<class CompType, class ThermoType> template<class CompType, class ThermoType>
Foam::sequential<CompType, ThermoType>::sequential Foam::sequential<CompType, ThermoType>::sequential
( (
ODEChemistryModel<CompType, ThermoType>& model ODEChemistryModel<CompType, ThermoType>& model,
const word& modelName
) )
: :
chemistrySolver<CompType, ThermoType>(model), chemistrySolver<CompType, ThermoType>(model, modelName),
coeffsDict_(model.subDict(typeName + "Coeffs")), coeffsDict_(model.subDict(modelName + "Coeffs")),
cTauChem_(readScalar(coeffsDict_.lookup("cTauChem"))), cTauChem_(readScalar(coeffsDict_.lookup("cTauChem"))),
equil_(coeffsDict_.lookup("equilibriumRateLimiter")) equil_(coeffsDict_.lookup("equilibriumRateLimiter"))
{} {}

View File

@ -78,7 +78,11 @@ public:
//- Construct from components //- Construct from components
sequential(ODEChemistryModel<CompType, ThermoType>& model); sequential
(
ODEChemistryModel<CompType, ThermoType>& model,
const word& modelName
);
//- Destructor //- Destructor

View File

@ -86,9 +86,18 @@ public:
hCombustionThermo(const fvMesh&); hCombustionThermo(const fvMesh&);
//- Selector // Selectors
//- Standard selection based on fvMesh
static autoPtr<hCombustionThermo> New(const fvMesh&); static autoPtr<hCombustionThermo> New(const fvMesh&);
//- Select and check that package contains 'thermoType'
static autoPtr<hCombustionThermo> NewType
(
const fvMesh&,
const word& thermoType
);
//- Destructor //- Destructor
virtual ~hCombustionThermo(); virtual ~hCombustionThermo();

View File

@ -75,4 +75,66 @@ Foam::autoPtr<Foam::hCombustionThermo> Foam::hCombustionThermo::New
} }
Foam::autoPtr<Foam::hCombustionThermo> Foam::hCombustionThermo::NewType
(
const fvMesh& mesh,
const word& thermoType
)
{
word hCombustionThermoTypeName;
// Enclose the creation of the thermophysicalProperties to ensure it is
// deleted before the turbulenceModel is created otherwise the dictionary
// is entered in the database twice
{
IOdictionary thermoDict
(
IOobject
(
"thermophysicalProperties",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
thermoDict.lookup("thermoType") >> hCombustionThermoTypeName;
if (hCombustionThermoTypeName.find(thermoType) == string::npos)
{
FatalErrorIn
(
"autoPtr<hCombustionThermo> hCombustionThermo::NewType"
"("
"const fvMesh&, "
"const word&"
")"
) << "Inconsistent thermo package selected:" << nl << nl
<< hCombustionThermoTypeName << nl << nl << "Please select a "
<< "thermo package based on " << thermoType << nl << nl
<< exit(FatalError);
}
}
Info<< "Selecting thermodynamics package " << hCombustionThermoTypeName
<< endl;
fvMeshConstructorTable::iterator cstrIter =
fvMeshConstructorTablePtr_->find(hCombustionThermoTypeName);
if (cstrIter == fvMeshConstructorTablePtr_->end())
{
FatalErrorIn("hCombustionThermo::New(const fvMesh&)")
<< "Unknown hCombustionThermo type "
<< hCombustionThermoTypeName << nl << nl
<< "Valid hCombustionThermo types are:" << nl
<< fvMeshConstructorTablePtr_->toc() << nl
<< exit(FatalError);
}
return autoPtr<hCombustionThermo>(cstrIter()(mesh));
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -86,9 +86,18 @@ public:
hReactionThermo(const fvMesh&); hReactionThermo(const fvMesh&);
//- Selector // Selectors
//- Standard selection based on fvMesh
static autoPtr<hReactionThermo> New(const fvMesh&); static autoPtr<hReactionThermo> New(const fvMesh&);
//- Select and check that package contains 'thermoType'
static autoPtr<hReactionThermo> NewType
(
const fvMesh&,
const word& thermoType
);
//- Destructor //- Destructor
virtual ~hReactionThermo(); virtual ~hReactionThermo();

View File

@ -75,4 +75,66 @@ Foam::autoPtr<Foam::hReactionThermo> Foam::hReactionThermo::New
} }
Foam::autoPtr<Foam::hReactionThermo> Foam::hReactionThermo::NewType
(
const fvMesh& mesh,
const word& thermoType
)
{
word hReactionThermoTypeName;
// Enclose the creation of the thermophysicalProperties to ensure it is
// deleted before the turbulenceModel is created otherwise the dictionary
// is entered in the database twice
{
IOdictionary thermoDict
(
IOobject
(
"thermophysicalProperties",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
thermoDict.lookup("thermoType") >> hReactionThermoTypeName;
if (hReactionThermoTypeName.find(thermoType) == string::npos)
{
FatalErrorIn
(
"autoPtr<hReactionThermo> hReactionThermo::NewType"
"("
"const fvMesh&, "
"const word&"
")"
) << "Inconsistent thermo package selected:" << nl << nl
<< hReactionThermoTypeName << nl << nl << "Please select a "
<< "thermo package based on " << thermoType << nl << nl
<< exit(FatalError);
}
}
Info<< "Selecting thermodynamics package " << hReactionThermoTypeName
<< endl;
fvMeshConstructorTable::iterator cstrIter =
fvMeshConstructorTablePtr_->find(hReactionThermoTypeName);
if (cstrIter == fvMeshConstructorTablePtr_->end())
{
FatalErrorIn("hReactionThermo::New(const fvMesh&)")
<< "Unknown hReactionThermo type "
<< hReactionThermoTypeName << nl << nl
<< "Valid hReactionThermo types are:" << nl
<< fvMeshConstructorTablePtr_->toc() << nl
<< exit(FatalError);
}
return autoPtr<hReactionThermo>(cstrIter()(mesh));
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -15,11 +15,13 @@ FoamFile
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
psiChemistryModel ODEChemistryModel<gasThermoPhysics>;
chemistry on; chemistry on;
turbulentReaction on; turbulentReaction on;
chemistrySolver ODE; chemistrySolver ode;
initialChemicalTimeStep 1e-07; initialChemicalTimeStep 1e-07;
@ -34,7 +36,7 @@ EulerImplicitCoeffs
equilibriumRateLimiter off; equilibriumRateLimiter off;
} }
ODECoeffs odeCoeffs
{ {
ODESolver SIBS; ODESolver SIBS;
eps 0.05; eps 0.05;

View File

@ -15,7 +15,7 @@ FoamFile
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
thermoType hMixtureThermo<reactingMixture>; thermoType hPsiMixtureThermo<reactingMixture<gasThermoPhysics>>;
chemistryReader foamChemistryReader; chemistryReader foamChemistryReader;