Commit f6dacfb4 authored by Henry Weller's avatar Henry Weller
Browse files

liquidThermo: rhoThermo instantiated on liquidProperties

This allows single, multi-phase and VoF compressible simulations to be performed
with the accurate thermophysical property functions for liquids provided by the
liquidProperty classes.  e.g. in the
multiphase/compressibleInterFoam/laminar/depthCharge2D tutorial water can now be
specified by

thermoType
{
    type            heRhoThermo;
    mixture         pureMixture;
    properties      liquid;
    energy          sensibleInternalEnergy;
}

mixture
{
    H2O;
}

as an alternative to the previous less accurate representation defined by

thermoType
{
    type            heRhoThermo;
    mixture         pureMixture;
    transport       const;
    thermo          hConst;
    equationOfState perfectFluid;
    specie          specie;
    energy          sensibleInternalEnergy;
}

mixture
{
    specie
    {
        molWeight   18.0;
    }
    equationOfState
    {
        R           3000;
        rho0        1027;
    }
    thermodynamics
    {
        Cp          4195;
        Hf          0;
    }
    transport
    {
        mu          3.645e-4;
        Pr          2.289;
    }
}

However the increase in accuracy of the new simpler and more convenient
specification and representation comes at a cost: the NSRDS functions used by
the liquidProperties classes are relatively expensive to evaluate and the
depthCharge2D case takes ~14% longer to run.
parent d2be6454
......@@ -6,6 +6,7 @@ psiThermo/psiThermos.C
rhoThermo/rhoThermo.C
rhoThermo/rhoThermos.C
rhoThermo/liquidThermo.C
derivedFvPatchFields/fixedEnergy/fixedEnergyFvPatchScalarField.C
derivedFvPatchFields/gradientEnergy/gradientEnergyFvPatchScalarField.C
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -449,14 +449,28 @@ Foam::wordList Foam::basicThermo::splitThermoName
{
cmpts[i] = thermoName.substr(beg, end-beg);
cmpts[i++].replaceAll(">","");
// If the number of number of components in the name
// is greater than nCmpt return an empty list
if (i == nCmpt)
{
return wordList::null();
}
}
beg = end + 1;
}
// If the number of number of components in the name is not equal to nCmpt
// return an empty list
if (i + 1 != nCmpt)
{
return wordList::null();
}
if (beg < thermoName.size())
{
cmpts[i] = thermoName.substr(beg, string::npos);
cmpts[i++].replaceAll(">","");
cmpts[i].replaceAll(">","");
}
return cmpts;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -135,6 +135,17 @@ public:
// Selectors
//- Generic lookup for thermodynamics package thermoTypeName
template<class Thermo, class Table>
static typename Table::iterator lookupThermo
(
const dictionary& thermoTypeDict,
Table* tablePtr,
const int nCmpt,
const char* cmptNames[],
const word& thermoTypeName
);
//- Generic lookup for each of the related thermodynamics packages
template<class Thermo, class Table>
static typename Table::iterator lookupThermo
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -30,89 +30,153 @@ License
template<class Thermo, class Table>
typename Table::iterator Foam::basicThermo::lookupThermo
(
const dictionary& thermoDict,
Table* tablePtr
const dictionary& thermoTypeDict,
Table* tablePtr,
const int nCmpt,
const char* cmptNames[],
const word& thermoTypeName
)
{
word thermoTypeName;
// Lookup the thermo package
typename Table::iterator cstrIter = tablePtr->find(thermoTypeName);
if (thermoDict.isDict("thermoType"))
// Print error message if package not found in the table
if (cstrIter == tablePtr->end())
{
const dictionary& thermoTypeDict(thermoDict.subDict("thermoType"));
FatalErrorInFunction
<< "Unknown " << Thermo::typeName << " type " << nl
<< "thermoType" << thermoTypeDict << nl << nl
<< "Valid " << Thermo::typeName << " types are:"
<< nl << nl;
// Get the list of all the suitable thermo packages available
wordList validThermoTypeNames
(
tablePtr->sortedToc()
);
Info<< "Selecting thermodynamics package " << thermoTypeDict << endl;
// Build a table of the thermo packages constituent parts
// Note: row-0 contains the names of constituent parts
List<wordList> validThermoTypeNameCmpts
(
validThermoTypeNames.size() + 1
);
const int nCmpt = 7;
const char* cmptNames[nCmpt] =
validThermoTypeNameCmpts[0].setSize(nCmpt);
forAll(validThermoTypeNameCmpts[0], j)
{
"type",
"mixture",
"transport",
"thermo",
"equationOfState",
"specie",
"energy"
};
// Construct the name of the thermo package from the components
thermoTypeName =
word(thermoTypeDict.lookup("type")) + '<'
+ word(thermoTypeDict.lookup("mixture")) + '<'
+ word(thermoTypeDict.lookup("transport")) + '<'
+ word(thermoTypeDict.lookup("thermo")) + '<'
+ word(thermoTypeDict.lookup("equationOfState")) + '<'
+ word(thermoTypeDict.lookup("specie")) + ">>,"
+ word(thermoTypeDict.lookup("energy")) + ">>>";
// Lookup the thermo package
typename Table::iterator cstrIter = tablePtr->find(thermoTypeName);
validThermoTypeNameCmpts[0][j] = cmptNames[j];
}
// Print error message if package not found in the table
if (cstrIter == tablePtr->end())
// Split the thermo package names into their constituent parts
// Removing incompatible entries from the list
label j = 0;
forAll(validThermoTypeNames, i)
{
FatalErrorInFunction
<< "Unknown " << Thermo::typeName << " type " << nl
<< "thermoType" << thermoTypeDict << nl << nl
<< "Valid " << Thermo::typeName << " types are:" << nl << nl;
// Get the list of all the suitable thermo packages available
wordList validThermoTypeNames
(
tablePtr->sortedToc()
);
// Build a table of the thermo packages constituent parts
// Note: row-0 contains the names of constituent parts
List<wordList> validThermoTypeNameCmpts
wordList names
(
validThermoTypeNames.size() + 1
Thermo::splitThermoName(validThermoTypeNames[i], nCmpt)
);
validThermoTypeNameCmpts[0].setSize(nCmpt);
forAll(validThermoTypeNameCmpts[0], j)
if (names.size())
{
validThermoTypeNameCmpts[0][j] = cmptNames[j];
validThermoTypeNameCmpts[j++] = names;
}
}
validThermoTypeNameCmpts.setSize(j);
// Split the thermo package names into their constituent parts
forAll(validThermoTypeNames, i)
{
validThermoTypeNameCmpts[i+1] =
Thermo::splitThermoName(validThermoTypeNames[i], nCmpt);
}
// Print the table of available packages
// in terms of their constituent parts
printTable(validThermoTypeNameCmpts, FatalError);
FatalError<< exit(FatalError);
}
return cstrIter;
}
template<class Thermo, class Table>
typename Table::iterator Foam::basicThermo::lookupThermo
(
const dictionary& thermoDict,
Table* tablePtr
)
{
if (thermoDict.isDict("thermoType"))
{
const dictionary& thermoTypeDict(thermoDict.subDict("thermoType"));
// Print the table of available packages
// in terms of their constituent parts
printTable(validThermoTypeNameCmpts, FatalError);
Info<< "Selecting thermodynamics package " << thermoTypeDict << endl;
if (thermoTypeDict.found("properties"))
{
const int nCmpt = 4;
const char* cmptNames[nCmpt] =
{
"type",
"mixture",
"properties",
"energy"
};
// Construct the name of the thermo package from the components
const word thermoTypeName
(
word(thermoTypeDict.lookup("type")) + '<'
+ word(thermoTypeDict.lookup("mixture")) + '<'
+ word(thermoTypeDict.lookup("properties")) + ','
+ word(thermoTypeDict.lookup("energy")) + ">>"
);
FatalError<< exit(FatalError);
return lookupThermo<Thermo, Table>
(
thermoTypeDict,
tablePtr,
nCmpt,
cmptNames,
thermoTypeName
);
}
else
{
const int nCmpt = 7;
const char* cmptNames[nCmpt] =
{
"type",
"mixture",
"transport",
"thermo",
"equationOfState",
"specie",
"energy"
};
// Construct the name of the thermo package from the components
const word thermoTypeName
(
word(thermoTypeDict.lookup("type")) + '<'
+ word(thermoTypeDict.lookup("mixture")) + '<'
+ word(thermoTypeDict.lookup("transport")) + '<'
+ word(thermoTypeDict.lookup("thermo")) + '<'
+ word(thermoTypeDict.lookup("equationOfState")) + '<'
+ word(thermoTypeDict.lookup("specie")) + ">>,"
+ word(thermoTypeDict.lookup("energy")) + ">>>"
);
return cstrIter;
return lookupThermo<Thermo, Table>
(
thermoTypeDict,
tablePtr,
nCmpt,
cmptNames,
thermoTypeName
);
}
}
else
{
thermoTypeName = word(thermoDict.lookup("thermoType"));
const word thermoTypeName(thermoDict.lookup("thermoType"));
Info<< "Selecting thermodynamics package " << thermoTypeName << endl;
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "rhoThermo.H"
#include "heRhoThermo.H"
#include "pureMixture.H"
#include "thermo.H"
#include "sensibleEnthalpy.H"
#include "sensibleInternalEnergy.H"
#include "thermophysicalPropertiesSelector.H"
#include "liquidProperties.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/* * * * * * * * * * * * * * * private static data * * * * * * * * * * * * * */
typedef heRhoThermo
<
rhoThermo,
pureMixture
<
species::thermo
<
thermophysicalPropertiesSelector<liquidProperties>,
sensibleInternalEnergy
>
>
> heRhoThermopureMixtureliquidProperties;
defineTemplateTypeNameAndDebugWithName
(
heRhoThermopureMixtureliquidProperties,
"heRhoThermo<pureMixture<liquid,sensibleInternalEnergy>>",
0
);
addToRunTimeSelectionTable
(
basicThermo,
heRhoThermopureMixtureliquidProperties,
fvMesh
);
addToRunTimeSelectionTable
(
fluidThermo,
heRhoThermopureMixtureliquidProperties,
fvMesh
);
addToRunTimeSelectionTable
(
rhoThermo,
heRhoThermopureMixtureliquidProperties,
fvMesh
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
......@@ -31,8 +31,6 @@ License
namespace Foam
{
defineTypeNameAndDebug(H2O, 0);
addToRunTimeSelectionTable(thermophysicalProperties, H2O,);
addToRunTimeSelectionTable(thermophysicalProperties, H2O, dictionary);
addToRunTimeSelectionTable(liquidProperties, H2O,);
addToRunTimeSelectionTable(liquidProperties, H2O, dictionary);
}
......
......@@ -85,7 +85,7 @@ class liquidProperties
public:
TypeName("liquidProperties");
TypeName("liquid");
// Declare run-time constructor selection tables
......@@ -148,6 +148,15 @@ public:
{}
// Static data
//- Is the equation of state is incompressible i.e. rho != f(p)
static const bool incompressible = true;
//- Is the equation of state is isochoric i.e. rho = const
static const bool isochoric = false;
// Member Functions
// Physical constants which define the specie
......
......@@ -72,7 +72,7 @@ class solidProperties
public:
//- Runtime type information
TypeName("solidProperties");
TypeName("solid");
// Declare run-time constructor selection tables
......
......@@ -115,12 +115,6 @@ public:
//- Molecular weight [kg/kmol]
inline scalar W() const;
//- Is the equation of state is incompressible i.e. rho != f(p)
static const bool incompressible = true;
//- Is the equation of state is isochoric i.e. rho = const
static const bool isochoric = false;
//- Limit the temperature to be in the range Tlow_ to Thigh_
inline scalar limit(const scalar T) const;
......
......@@ -23,6 +23,8 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::scalar Foam::thermophysicalProperties::limit(const scalar T) const
{
return T;
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "thermophysicalPropertiesSelector.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ThermophysicalProperties>
Foam::thermophysicalPropertiesSelector<ThermophysicalProperties>::
thermophysicalPropertiesSelector
(
const word& name
)
:
propertiesPtr_(ThermophysicalProperties::New(name))
{}
template<class ThermophysicalProperties>
Foam::thermophysicalPropertiesSelector<ThermophysicalProperties>::
thermophysicalPropertiesSelector
(
const dictionary& dict
)
{
const word name(dict.first()->keyword());
if (dict.isDict(name))
{
propertiesPtr_ = ThermophysicalProperties::New(dict.subDict(name));
}
else
{
propertiesPtr_ = ThermophysicalProperties::New(name);
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::thermophysicalPropertiesSelector
Description
Wrapper class providing run-time selection of thermophysicalProperties
for the templated thermodynamics packages.
SourceFiles
thermophysicalPropertiesSelectorI.H
thermophysicalPropertiesSelector.C
\*---------------------------------------------------------------------------*/
#ifndef thermophysicalPropertiesSelector_H
#define thermophysicalPropertiesSelector_H
#include "thermophysicalProperties.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class thermophysicalPropertiesSelector Declaration
\*---------------------------------------------------------------------------*/
template<class ThermophysicalProperties>
class thermophysicalPropertiesSelector
{
// Private member data
autoPtr<ThermophysicalProperties> propertiesPtr_;
public:
// Constructors
//- Construct from name
thermophysicalPropertiesSelector(const word& name);