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();
rho = thermo->rho();
rho = thermo.rho();
runTime.write();

View File

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

View File

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

View File

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

View File

@ -34,6 +34,8 @@ Foam::autoPtr<Foam::psiChemistryModel> Foam::psiChemistryModel::New
)
{
word psiChemistryModelType;
word thermoTypeName;
word userSel;
// Enclose the creation of the chemistrtyProperties to ensure it is
// deleted before the chemistrtyProperties is created otherwise the
@ -51,25 +53,41 @@ Foam::autoPtr<Foam::psiChemistryModel> Foam::psiChemistryModel::New
)
);
chemistryPropertiesDict.lookup("psiChemistryModel") >>
psiChemistryModelType;
chemistryPropertiesDict.lookup("psiChemistryModel") >> userSel;
// 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 =
fvMeshConstructorTablePtr_->find(psiChemistryModelType);
if (cstrIter == fvMeshConstructorTablePtr_->end())
{
wordList models = fvMeshConstructorTablePtr_->toc();
forAll(models, i)
{
models[i] = models[i].replace(typeName + ',', "");
}
FatalErrorIn("psiChemistryModelBase::New(const mesh&)")
<< "Unknown psiChemistryModel type " << psiChemistryModelType
<< "Unknown psiChemistryModel type " << userSel
<< nl << nl << "Valid psiChemistryModel types are:" << nl
<< fvMeshConstructorTablePtr_->toc() << nl
<< exit(FatalError);
<< models << nl << exit(FatalError);
}
return autoPtr<psiChemistryModel>(cstrIter()(mesh));
return autoPtr<psiChemistryModel>
(cstrIter()(mesh, typeName, thermoTypeName));
}

View File

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

View File

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

View File

@ -34,6 +34,8 @@ Foam::autoPtr<Foam::rhoChemistryModel> Foam::rhoChemistryModel::New
)
{
word rhoChemistryModelType;
word thermoTypeName;
word userSel;
// Enclose the creation of the chemistrtyProperties to ensure it is
// deleted before the chemistrtyProperties is created otherwise the
@ -51,25 +53,41 @@ Foam::autoPtr<Foam::rhoChemistryModel> Foam::rhoChemistryModel::New
)
);
chemistryPropertiesDict.lookup("rhoChemistryModel") >>
rhoChemistryModelType;
chemistryPropertiesDict.lookup("rhoChemistryModelType") >> userSel;
// 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 =
fvMeshConstructorTablePtr_->find(rhoChemistryModelType);
if (cstrIter == fvMeshConstructorTablePtr_->end())
{
wordList models = fvMeshConstructorTablePtr_->toc();
forAll(models, i)
{
models[i] = models[i].replace(typeName + ',', "");
}
FatalErrorIn("rhoChemistryModelBase::New(const mesh&)")
<< "Unknown rhoChemistryModel type " << rhoChemistryModelType
<< "Unknown rhoChemistryModel type " << userSel
<< nl << nl << "Valid rhoChemistryModel types are:" << nl
<< fvMeshConstructorTablePtr_->toc() << nl
<< exit(FatalError);
<< models << nl << exit(FatalError);
}
return autoPtr<rhoChemistryModel>(cstrIter()(mesh));
return autoPtr<rhoChemistryModel>
(cstrIter()(mesh, typeName, thermoTypeName));
}

View File

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

View File

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

View File

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

View File

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

View File

@ -34,10 +34,12 @@ namespace Foam
template<class CompType, class ThermoType>
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
ODEChemistryModel<CompType, ThermoType>& model_;
//- Name of the chemistry solver
const word name_;
public:
@ -79,22 +82,29 @@ public:
chemistrySolver,
dictionary,
(
ODEChemistryModel<CompType, ThermoType>& model
ODEChemistryModel<CompType, ThermoType>& model,
const word& modelName
),
(model)
(model, modelName)
);
// Constructors
//- Construct from components
chemistrySolver(ODEChemistryModel<CompType, ThermoType>& model);
chemistrySolver
(
ODEChemistryModel<CompType, ThermoType>& model,
const word& modelName
);
//- Selector
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::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 =
dictionaryConstructorTablePtr_->find(chemistrySolverType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
wordList models = dictionaryConstructorTablePtr_->toc();
forAll(models, i)
{
models[i] = models[i].replace
(
'<' + compTypeName + ',' + thermoTypeName + '>',
""
);
}
FatalErrorIn
(
"chemistrySolver::New(const dictionary&, const ODEChemistryModel&)"
) << "Unknown chemistrySolver type " << chemistrySolverType
<< nl << nl
<< "Valid chemistrySolver types are:" << nl
<< dictionaryConstructorTablePtr_->toc() << nl
<< exit(FatalError);
"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));
return autoPtr<chemistrySolver<CompType, ThermoType> >
(cstrIter()(model, modelName));
}

View File

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

View File

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

View File

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

View File

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

View File

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

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,8 +86,17 @@ public:
hReactionThermo(const fvMesh&);
//- Selector
static autoPtr<hReactionThermo> New(const fvMesh&);
// Selectors
//- Standard selection based on fvMesh
static autoPtr<hReactionThermo> New(const fvMesh&);
//- Select and check that package contains 'thermoType'
static autoPtr<hReactionThermo> NewType
(
const fvMesh&,
const word& thermoType
);
//- Destructor

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;
turbulentReaction on;
chemistrySolver ODE;
chemistrySolver ode;
initialChemicalTimeStep 1e-07;
@ -34,7 +36,7 @@ EulerImplicitCoeffs
equilibriumRateLimiter off;
}
ODECoeffs
odeCoeffs
{
ODESolver SIBS;
eps 0.05;

View File

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