Commit 9ef33017 authored by Henry's avatar Henry
Browse files

Thermodynamics: Added phaseName option to the constructors and selectors of all thermo packages

parent d0d6ef50
......@@ -13,5 +13,5 @@ LIB_LIBS = \
-lfiniteVolume \
-lsampling \
-lmeshTools \
-lsolidThermo \
/*-lsolidThermo*/ \
-lcompressibleTurbulenceModel
......@@ -34,16 +34,56 @@ namespace Foam
defineRunTimeSelectionTable(basicThermo, fvMesh);
}
const Foam::word Foam::basicThermo::dictName("thermophysicalProperties");
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::basicThermo::basicThermo(const fvMesh& mesh)
Foam::volScalarField& Foam::basicThermo::lookupOrConstruct
(
const fvMesh& mesh,
const char* name
) const
{
if (!mesh.objectRegistry::foundObject<volScalarField>(name))
{
volScalarField* fPtr
(
new volScalarField
(
IOobject
(
name,
mesh.time().timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
)
);
// Transfer ownership of this object to the objectRegistry
fPtr->store(fPtr);
}
return const_cast<volScalarField&>
(
mesh.objectRegistry::lookupObject<volScalarField>(name)
);
}
Foam::basicThermo::basicThermo
(
const fvMesh& mesh,
const word& phaseName
)
:
IOdictionary
(
IOobject
(
"thermophysicalProperties",
phasePropertyName(dictName, phaseName),
mesh.time().constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
......@@ -51,24 +91,15 @@ Foam::basicThermo::basicThermo(const fvMesh& mesh)
)
),
p_
(
IOobject
(
"p",
mesh.time().timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
),
phaseName_(phaseName),
p_(lookupOrConstruct(mesh, "p")),
T_
(
IOobject
(
"T",
phasePropertyName("T"),
mesh.time().timeName(),
mesh,
IOobject::MUST_READ,
......@@ -81,7 +112,7 @@ Foam::basicThermo::basicThermo(const fvMesh& mesh)
(
IOobject
(
"alpha",
phasePropertyName("alpha"),
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
......@@ -98,14 +129,15 @@ Foam::basicThermo::basicThermo(const fvMesh& mesh)
Foam::basicThermo::basicThermo
(
const fvMesh& mesh,
const dictionary& dict
const dictionary& dict,
const word& phaseName
)
:
IOdictionary
(
IOobject
(
"thermophysicalProperties",
phasePropertyName(dictName, phaseName),
mesh.time().constant(),
mesh,
IOobject::NO_READ,
......@@ -114,24 +146,15 @@ Foam::basicThermo::basicThermo
dict
),
p_
(
IOobject
(
"p",
mesh.time().timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
),
phaseName_(phaseName),
p_(lookupOrConstruct(mesh, "p")),
T_
(
IOobject
(
"T",
phasePropertyName("T"),
mesh.time().timeName(),
mesh,
IOobject::MUST_READ,
......@@ -144,7 +167,7 @@ Foam::basicThermo::basicThermo
(
IOobject
(
"alpha",
phasePropertyName("alpha"),
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
......@@ -160,10 +183,11 @@ Foam::basicThermo::basicThermo
Foam::autoPtr<Foam::basicThermo> Foam::basicThermo::New
(
const fvMesh& mesh
const fvMesh& mesh,
const word& phaseName
)
{
return New<basicThermo>(mesh);
return New<basicThermo>(mesh, phaseName);
}
......@@ -175,16 +199,52 @@ Foam::basicThermo::~basicThermo()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::basicThermo& Foam::basicThermo::lookupThermo
(
const fvPatchScalarField& pf
)
{
if (pf.db().foundObject<basicThermo>(dictName))
{
return pf.db().lookupObject<basicThermo>(dictName);
}
else
{
HashTable<const basicThermo*> thermos =
pf.db().lookupClass<basicThermo>();
for
(
HashTable<const basicThermo*>::iterator iter = thermos.begin();
iter != thermos.end();
++iter
)
{
if
(
&(iter()->he().dimensionedInternalField())
== &(pf.dimensionedInternalField())
)
{
return *iter();
}
}
}
return pf.db().lookupObject<basicThermo>(dictName);
}
void Foam::basicThermo::validate
(
const word& app,
const word& a
) const
{
if (!(he().name() == a))
if (!(he().name() == phasePropertyName(a)))
{
FatalErrorIn(app)
<< "Supported energy type is " << a
<< "Supported energy type is " << phasePropertyName(a)
<< ", thermodynamics package provides " << he().name()
<< exit(FatalError);
}
......@@ -197,10 +257,17 @@ void Foam::basicThermo::validate
const word& b
) const
{
if (!(he().name() == a || he().name() == b))
if
(
!(
he().name() == phasePropertyName(a)
|| he().name() == phasePropertyName(b)
)
)
{
FatalErrorIn(app)
<< "Supported energy types are " << a << " and " << b
<< "Supported energy types are " << phasePropertyName(a)
<< " and " << phasePropertyName(b)
<< ", thermodynamics package provides " << he().name()
<< exit(FatalError);
}
......@@ -217,14 +284,16 @@ void Foam::basicThermo::validate
if
(
!(
he().name() == a
|| he().name() == b
|| he().name() == c
he().name() == phasePropertyName(a)
|| he().name() == phasePropertyName(b)
|| he().name() == phasePropertyName(c)
)
)
{
FatalErrorIn(app)
<< "Supported energy types are " << a << ", " << b << " and " << c
<< "Supported energy types are " << phasePropertyName(a)
<< ", " << phasePropertyName(b)
<< " and " << phasePropertyName(c)
<< ", thermodynamics package provides " << he().name()
<< exit(FatalError);
}
......@@ -242,16 +311,18 @@ void Foam::basicThermo::validate
if
(
!(
he().name() == a
|| he().name() == b
|| he().name() == c
|| he().name() == d
he().name() == phasePropertyName(a)
|| he().name() == phasePropertyName(b)
|| he().name() == phasePropertyName(c)
|| he().name() == phasePropertyName(d)
)
)
{
FatalErrorIn(app)
<< "Supported energy types are " << a << ", " << b
<< ", " << c << " and " << d
<< "Supported energy types are " << phasePropertyName(a)
<< ", " << phasePropertyName(b)
<< ", " << phasePropertyName(c)
<< " and " << phasePropertyName(d)
<< ", thermodynamics package provides " << he().name()
<< exit(FatalError);
}
......
......@@ -59,10 +59,14 @@ protected:
// Protected data
//- Phase-name
const word& phaseName_;
// Fields
//- Pressure [Pa]
volScalarField p_;
volScalarField& p_;
//- Temperature [K]
volScalarField T_;
......@@ -76,6 +80,12 @@ protected:
//- Construct as copy (not implemented)
basicThermo(const basicThermo&);
volScalarField& lookupOrConstruct
(
const fvMesh& mesh,
const char* name
) const;
public:
......@@ -89,18 +99,27 @@ public:
autoPtr,
basicThermo,
fvMesh,
(const fvMesh& mesh),
(mesh)
(const fvMesh& mesh, const word& phaseName),
(mesh, phaseName)
);
// Constructors
//- Construct from mesh
basicThermo(const fvMesh&);
//- Construct from mesh and phase name
basicThermo
(
const fvMesh&,
const word& phaseName
);
//- Construct from mesh
basicThermo(const fvMesh&, const dictionary&);
//- Construct from mesh, dictionary and phase name
basicThermo
(
const fvMesh&,
const dictionary&,
const word& phaseName
);
// Selectors
......@@ -115,14 +134,27 @@ public:
//- Generic New for each of the related thermodynamics packages
template<class Thermo>
static autoPtr<Thermo> New(const fvMesh&);
static autoPtr<Thermo> New
(
const fvMesh&,
const word& phaseName=word::null
);
//- Generic New for each of the related thermodynamics packages
template<class Thermo>
static autoPtr<Thermo> New(const fvMesh&, const dictionary&);
static autoPtr<Thermo> New
(
const fvMesh&,
const dictionary&,
const word& phaseName=word::null
);
//- Specialisation of the Generic New for basicThermo
static autoPtr<basicThermo> New(const fvMesh&);
static autoPtr<basicThermo> New
(
const fvMesh&,
const word& phaseName=word::null
);
//- Destructor
......@@ -131,6 +163,24 @@ public:
// Member functions
static const word dictName;
static word phasePropertyName
(
const word& name,
const word& phaseName
)
{
return name + phaseName;
}
word phasePropertyName(const word& name) const
{
return basicThermo::phasePropertyName(name, phaseName_);
}
static const basicThermo& lookupThermo(const fvPatchScalarField& pf);
//- Check that the thermodynamics package is consistent
// with energy forms supported by the application
void validate
......@@ -356,7 +406,7 @@ public:
) const = 0;
//- Read thermophysicalProperties dictionary
//- Read thermophysical properties dictionary
virtual bool read();
};
......
......@@ -136,14 +136,15 @@ typename Table::iterator Foam::basicThermo::lookupThermo
template<class Thermo>
Foam::autoPtr<Thermo> Foam::basicThermo::New
(
const fvMesh& mesh
const fvMesh& mesh,
const word& phaseName
)
{
IOdictionary thermoDict
(
IOobject
(
"thermophysicalProperties",
phasePropertyName(dictName, phaseName),
mesh.time().constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
......@@ -159,7 +160,7 @@ Foam::autoPtr<Thermo> Foam::basicThermo::New
Thermo::fvMeshConstructorTablePtr_
);
return autoPtr<Thermo>(cstrIter()(mesh));
return autoPtr<Thermo>(cstrIter()(mesh, phaseName));
}
......@@ -167,7 +168,8 @@ template<class Thermo>
Foam::autoPtr<Thermo> Foam::basicThermo::New
(
const fvMesh& mesh,
const dictionary& dict
const dictionary& dict,
const word& phaseName
)
{
typename Thermo::dictionaryConstructorTable::iterator cstrIter =
......@@ -177,7 +179,7 @@ Foam::autoPtr<Thermo> Foam::basicThermo::New
Thermo::dictionaryConstructorTablePtr_
);
return autoPtr<Thermo>(cstrIter()(mesh, dict));
return autoPtr<Thermo>(cstrIter()(mesh, dict, phaseName));
}
......
......@@ -101,9 +101,7 @@ void Foam::energyJumpFvPatchScalarField::updateCoeffs()
if (this->cyclicPatch().owner())
{
const basicThermo& thermo =
db().lookupObject<basicThermo>("thermophysicalProperties");
const basicThermo& thermo = basicThermo::lookupThermo(*this);
label patchID = patch().index();
const scalarField& pp = thermo.p().boundaryField()[patchID];
......
......@@ -101,9 +101,7 @@ void Foam::energyJumpAMIFvPatchScalarField::updateCoeffs()
if (this->cyclicAMIPatch().owner())
{
const basicThermo& thermo =
db().lookupObject<basicThermo>("thermophysicalProperties");
const basicThermo& thermo = basicThermo::lookupThermo(*this);
label patchID = patch().index();
const scalarField& pp = thermo.p().boundaryField()[patchID];
......
......@@ -97,12 +97,7 @@ void Foam::fixedEnergyFvPatchScalarField::updateCoeffs()
return;
}
const basicThermo& thermo = db().lookupObject<basicThermo>
(
"thermophysicalProperties"
);
const basicThermo& thermo = basicThermo::lookupThermo(*this);
const label patchi = patch().index();
const scalarField& pw = thermo.p().boundaryField()[patchi];
......
......@@ -97,9 +97,7 @@ void Foam::gradientEnergyFvPatchScalarField::updateCoeffs()
return;
}
const basicThermo& thermo =
db().lookupObject<basicThermo>("thermophysicalProperties");
const basicThermo& thermo = basicThermo::lookupThermo(*this);
const label patchi = patch().index();
const scalarField& pw = thermo.p().boundaryField()[patchi];
......
......@@ -102,11 +102,7 @@ void Foam::mixedEnergyFvPatchScalarField::updateCoeffs()
return;
}
const basicThermo& thermo = db().lookupObject<basicThermo>
(
"thermophysicalProperties"
);
const basicThermo& thermo = basicThermo::lookupThermo(*this);
const label patchi = patch().index();
const scalarField& pw = thermo.p().boundaryField()[patchi];
......
......@@ -149,11 +149,7 @@ void Foam::wallHeatTransferFvPatchScalarField::updateCoeffs()
return;
}
const basicThermo& thermo = db().lookupObject<basicThermo>
(
"thermophysicalProperties"
);
const basicThermo& thermo = basicThermo::lookupThermo(*this);
const label patchi = patch().index();
const scalarField& pw = thermo.p().boundaryField()[patchi];
......
......@@ -36,16 +36,21 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fluidThermo::fluidThermo(const fvMesh& mesh)
Foam::fluidThermo::fluidThermo(const fvMesh& mesh, const word& phaseName)
:
basicThermo(mesh)
basicThermo(mesh, phaseName)
{}
Foam::fluidThermo::fluidThermo(const fvMesh& mesh, const dictionary& dict)
Foam::fluidThermo::fluidThermo
(
const fvMesh& mesh,
const dictionary& dict,
const word& phaseName
)
:
basicThermo(mesh, dict)
basicThermo(mesh, dict, phaseName)
{}
......@@ -53,10 +58,11 @@ Foam::fluidThermo::fluidThermo(const fvMesh& mesh, const dictionary& dict)
Foam::autoPtr<Foam::fluidThermo> Foam::fluidThermo::New
(
const fvMesh& mesh
const fvMesh& mesh,
const word& phaseName
)
{
return basicThermo::New<fluidThermo>(mesh);
return basicThermo::New<fluidThermo>(mesh, phaseName);
}
......
......@@ -63,21 +63,34 @@ public:
autoPtr,
fluidThermo,
fvMesh,
(const fvMesh& mesh),
(mesh)
(const fvMesh& mesh, const word& phaseName),
(mesh, phaseName)
);
// Constructors
//- Construct from mesh
fluidThermo(const fvMesh&);
//- Construct from mesh and phase name
fluidThermo
(
const fvMesh&,