fluid systems: add isIdealGas(phaseIdx) methods

this is primary to allow models to check whether their assumptions are
valid for the given fluidsystem

also add the H2O-Air fluid system to the fluid systems test. this
caught a few issues!
This commit is contained in:
Andreas Lauser
2012-01-27 16:17:41 +00:00
committed by Andreas Lauser
parent 3c12ff1e06
commit 94bc342f6f
21 changed files with 256 additions and 39 deletions

View File

@@ -59,8 +59,7 @@ public:
* Taken from constrelair.hh.
*/
static Scalar molarMass()
{ return 0.02896; // [kg/mole]
; }
{ return 0.02896; /* [kg/mol] */ }
/*!
* \brief Returns the critical temperature \f$\mathrm{[K]}\f$ of \f$AIR\f$.
@@ -72,7 +71,7 @@ public:
* \brief Returns the critical pressure \f$\mathrm{[Pa]}\f$ of \f$AIR\f$.
*/
static Scalar criticalPressure()
{ return 37.86e5; /* [N/m^2] */ }
{ return 37.86e5; /* [Pa] */ }
/*!
* \brief The density of \f$AIR\f$ at a given pressure and temperature [kg/m^3].
@@ -85,17 +84,18 @@ public:
// Assume an ideal gas
return IdealGas::density(molarMass(), temperature, pressure);
}
//TODO: Holle, Doku!!!
static Scalar molarGasDensity(Scalar temperature, Scalar pressure)
{
if(temperature<250.) temperature=250.; /* ACHTUNG Regularisierung */
if(temperature>500.) temperature=500.; /* ACHTUNG Regularisierung */
if(pressure<1e-4) pressure=1e-4; /* ACHTUNG Regularisierung */
if(pressure>1.E8) pressure=1.E8; /* ACHTUNG Regularisierung */
/*!
* \brief Returns true iff the gas phase is assumed to be compressible
*/
static bool gasIsCompressible()
{ return true; }
return (pressure/(8.314*temperature));
}
/*!
* \brief Returns true iff the gas phase is assumed to be ideal
*/
static bool gasIsIdeal()
{ return true; }
/*!
* \brief The pressure of gaseous \f$AIR\f$ at a given density and temperature \f$\mathrm{[Pa]}\f$.
@@ -108,7 +108,6 @@ public:
// Assume an ideal gas
return IdealGas::pressure(temperature, density/molarMass());
}
/*!
* \brief The dynamic viscosity \f$\mathrm{[Pa*s]}\f$ of \f$AIR\f$ at a given pressure and temperature.
*
@@ -188,13 +187,10 @@ public:
/*!
* \brief Specific internal energy of \f$AIR\f$ \f$\mathrm{[J/kg]}\f$.
*
* Definition of enthalpy: \f$h= u + pv = u + p / \rho\f$.
*
* Rearranging for internal energy yields: \f$u = h - pv\f$.
*
* Exploiting the \emph{Ideal Gas} assumption (\f$pv = R_{\textnormal{specific}} T\f$)gives: \f$u = h - R / M T \f$.
*
* The \emph{universal} gas constant can only be used in the case of molar formulations.
* Definition of enthalpy: \f$h= u + pv = u + p / \rho\f$.
* Rearranging for internal energy yields: \f$u = h - pv\f$.
* Exploiting the \emph{Ideal Gas} assumption
* (\f$pv = R_{\textnormal{specific}} T\f$)gives: \f$u = h - R / M T \f$.
*
* \param temperature temperature of component in \f$\mathrm{[K]}\f$
* \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
@@ -203,9 +199,10 @@ public:
Scalar pressure)
{
return
gasEnthalpy(temperature, pressure) -
1/molarMass()* // conversion from [J/(mol K)] to [J/(kg K)]
IdealGas::R*temperature; // = pressure * spec. volume for an ideal gas
gasEnthalpy(temperature, pressure)
-
IdealGas::R * temperature // = pressure * molar volume for an ideal gas
/ molarMass(); // conversion from [J/(mol K)] to [J/(kg K)]
}
};

View File

@@ -261,6 +261,12 @@ public:
static Scalar gasDensity(Scalar temperature, Scalar pressure)
{ return H2O::gasDensity(temperature, pressure); }
/*!
* \brief Returns true iff the gas phase is assumed to be ideal
*/
static bool gasIsIdeal()
{ return H2O::gasIsIdeal(); }
/*!
* \brief The density of pure brine at a given pressure and temperature \f$\mathrm{[kg/m^3]}\f$.
*

View File

@@ -114,6 +114,12 @@ public:
return IdealGas::density(molarMass(), temperature, pressure);
}
/*!
* \brief Returns true iff the gas phase is assumed to be ideal
*/
static bool gasIsIdeal()
{ return true; }
/*!
* \brief The pressure of gaseous \f$CH_4\f$ in \f$\mathrm{[Pa]}\f$ at a given density and temperature.
*

View File

@@ -69,6 +69,12 @@ public:
static bool gasIsCompressible()
{ DUNE_THROW(Dune::NotImplemented, "Component::gasIsCompressible()"); }
/*!
* \brief Returns true iff the gas phase is assumed to be ideal
*/
static bool gasIsIdeal()
{ DUNE_THROW(Dune::NotImplemented, "Component::gasIsCompressible()"); }
/*!
* \brief Returns true iff the liquid phase is assumed to be compressible
*/

View File

@@ -128,6 +128,12 @@ public:
static bool gasIsCompressible()
{ return true; }
/*!
* \brief Returns true iff the gas phase is assumed to be ideal
*/
static bool gasIsIdeal()
{ return true; }
/*!
* \brief The pressure of gaseous \f$H_2\f$ in \f$\mathrm{[Pa]}\f$ at a given density and temperature.
*

View File

@@ -582,6 +582,12 @@ public:
return 1.0/volumeRegion2_(temperature, pressure);
}
/*!
* \brief Returns true iff the gas phase is assumed to be ideal
*/
static bool gasIsIdeal()
{ return false; }
/*!
* \brief The pressure of steam in \f$\mathrm{[Pa]}\f$ at a given density and temperature.
*

View File

@@ -125,12 +125,6 @@ public:
sigma*sigma*sigma*N4))));
}
/*!
* \brief Returns true iff the gas phase is assumed to be compressible
*/
static bool gasIsCompressible()
{ return true; }
/*!
* \brief The density \f$\mathrm{[kg/m^3]}\f$ of \f$N_2\f$ gas at a given pressure and temperature.
*
@@ -143,6 +137,18 @@ public:
return IdealGas::density(molarMass(), temperature, pressure);
}
/*!
* \brief Returns true iff the gas phase is assumed to be compressible
*/
static bool gasIsCompressible()
{ return true; }
/*!
* \brief Returns true iff the gas phase is assumed to be ideal
*/
static bool gasIsIdeal()
{ return true; }
/*!
* \brief The pressure of gaseous \f$N_2\f$ in \f$\mathrm{[Pa]}\f$ at a given density and temperature.
*

View File

@@ -144,6 +144,12 @@ public:
return IdealGas::density(molarMass(), temperature, pressure);
}
/*!
* \brief Returns true iff the gas phase is assumed to be ideal
*/
static bool gasIsIdeal()
{ return true; }
/*!
* \brief The pressure of gaseous \f$O_2\f$ in \f$\mathrm{[Pa]}\f$ at a given density and temperature.
*

View File

@@ -147,6 +147,12 @@ public:
return IdealGas::density(molarMass(), temperature, pressure);
}
/*!
* \brief Returns true iff the gas phase is assumed to be ideal
*/
static bool gasIsIdeal()
{ return true; }
/*!
* \brief The pressure of gaseous \f$CO_2\f$ at a given density and temperature \f$\mathrm{[Pa]}\f$.
*

View File

@@ -127,6 +127,12 @@ public:
pressure);
};
/*!
* \brief Returns true iff the gas phase is assumed to be ideal
*/
static bool gasIsIdeal()
{ return true; }
/*!
* \brief The density of pure TCE at a given pressure and temperature \f$\mathrm{[kg/m^3]}\f$.
*

View File

@@ -207,6 +207,12 @@ public:
return molarMass()*IdealGas::molarDensity(temperature, pressure);
}
/*!
* \brief Returns true iff the gas phase is assumed to be ideal
*/
static bool gasIsIdeal()
{ return true; }
/*!
* \brief The pressure of steam in \f$\mathrm{[Pa]}\f$ at a given density and temperature.
*

View File

@@ -427,6 +427,13 @@ public:
static bool liquidIsCompressible()
{ return RawComponent::liquidIsCompressible(); }
/*!
* \brief Returns true iff the gas phase is assumed to be ideal
*/
static bool gasIsIdeal()
{ return RawComponent::gasIsIdeal(); }
/*!
* \brief The density of gas at a given pressure and temperature
* \f$\mathrm{[kg/m^3]}\f$.

View File

@@ -136,6 +136,20 @@ public:
return true;
}
/*!
* \brief Returns true if and only if a fluid phase is assumed to
* be an ideal gas.
*
* \param phaseIdx The index of the fluid phase to consider
*/
static bool isIdealGas(int phaseIdx)
{
assert(0 <= phaseIdx && phaseIdx < numPhases);
// let the fluid decide
return Fluid::isIdealGas();
}
/****************************************
* Component related static parameters
****************************************/

View File

@@ -150,6 +150,22 @@ public:
return NonwettingPhase::isCompressible();
}
/*!
* \brief Returns true if and only if a fluid phase is assumed to
* be an ideal gas.
*
* \param phaseIdx The index of the fluid phase to consider
*/
static bool isIdealGas(int phaseIdx)
{
assert(0 <= phaseIdx && phaseIdx < numPhases);
// let the fluids decide
if (phaseIdx == wPhaseIdx)
return WettingPhase::isIdealGas();
return NonwettingPhase::isIdealGas();
}
/****************************************
* Component related static parameters
****************************************/

View File

@@ -56,6 +56,12 @@ public:
static bool isCompressible()
{ return Component::gasIsCompressible(); }
/*!
* \brief Returns true iff the fluid is assumed to be an ideal gas
*/
static bool isIdealGas()
{ return Component::gasIsIdeal(); }
/*!
* \brief The mass in [kg] of one mole of the component.
*/

View File

@@ -70,7 +70,7 @@ namespace FluidSystems
SET_PROP(TestDecTwoPTwoCProblem, FluidSystem)
{
typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
typedef Dumux::FluidSystems::H2OAir<Scalar, Dumux::SimpleH2O<Scalar>> type;
typedef Dumux::FluidSystems::H2OAir<Scalar, Dumux::SimpleH2O<Scalar> > type;
};
* Also remember to initialize tabulated components (FluidSystem::init()), while this
@@ -172,6 +172,21 @@ public:
return H2O::liquidIsCompressible();
}
/*!
* \brief Returns true if and only if a fluid phase is assumed to
* be an ideal gas.
*
* \param phaseIdx The index of the fluid phase to consider
*/
static bool isIdealGas(int phaseIdx)
{
assert(0 <= phaseIdx && phaseIdx < numPhases);
// let the fluids decide
if (phaseIdx == gPhaseIdx)
return H2O::gasIsIdeal() && Air::gasIsIdeal();
return false; // not a gas
}
/****************************************
* Component related static parameters
@@ -350,7 +365,16 @@ public:
assert(0 <= phaseIdx && phaseIdx < numPhases);
Scalar T = fluidState.temperature(phaseIdx);
Scalar p = fluidState.pressure(phaseIdx);
Scalar p;
if (isCompressible(phaseIdx))
p = fluidState.pressure(phaseIdx);
else {
// random value which will hopefully cause things to blow
// up if it is used in a calculation!
p = - 1e100;
Valgrind::SetUndefined(p);
}
Scalar sumMoleFrac = 0;
for (int compIdx = 0; compIdx < numComponents; ++compIdx)
@@ -516,6 +540,15 @@ public:
return 1.0;
}
using Base::diffusionCoefficient;
template <class FluidState>
static Scalar diffusionCoefficient(const FluidState &fluidState,
int phaseIdx,
int compIdx)
{
DUNE_THROW(Dune::NotImplemented, "FluidSystems::H2OAir::diffusionCoefficient()");
}
/*!
* \brief Given a phase's composition, temperature and pressure,
* return the binary diffusion coefficient for components
@@ -632,6 +665,36 @@ public:
}
DUNE_THROW(Dune::InvalidStateException, "Invalid phase index " << phaseIdx);
}
/*!
* \brief Thermal conductivity of a fluid phase [W/(m K)].
*
* Use the conductivity of air and water as a first approximation.
* Source:
* http://en.wikipedia.org/wiki/List_of_thermal_conductivities
*/
using Base::thermalConductivity;
template <class FluidState>
static Scalar thermalConductivity(const FluidState &fluidState,
int phaseIdx)
{
DUNE_THROW(Dune::NotImplemented, "FluidSystems::H2OAir::thermalConductivity()");
}
/*!
* \brief Specific isobaric heat capacity of a fluid phase.
* \f$\mathrm{[J/kg]}\f$.
*
* \param params mutable parameters
* \param phaseIdx for which phase to give back the heat capacity
*/
using Base::heatCapacity;
template <class FluidState>
static Scalar heatCapacity(const FluidState &fluidState,
int phaseIdx)
{
DUNE_THROW(Dune::NotImplemented, "FluidSystems::H2OAir::heatCapacity()");
}
};
} // end namepace FluidSystems

View File

@@ -65,18 +65,15 @@ namespace FluidSystems
*/
template <class Scalar, bool useComplexRelations = true>
class H2ON2
: public BaseFluidSystem<Scalar, H2ON2<Scalar, useComplexRelations> >
: public BaseFluidSystem<Scalar, H2ON2<Scalar, useComplexRelations> >
{
typedef H2ON2<Scalar, useComplexRelations> ThisType;
typedef BaseFluidSystem<Scalar, ThisType> Base;
// convenience typedefs
typedef Dumux::IdealGas<Scalar> IdealGas;
typedef Dumux::H2O<Scalar> IapwsH2O;
typedef Dumux::TabulatedComponent<Scalar, IapwsH2O > TabulatedH2O;
typedef Dumux::N2<Scalar> SimpleN2;
public:
@@ -156,13 +153,29 @@ public:
static bool isCompressible(int phaseIdx)
{
assert(0 <= phaseIdx && phaseIdx < numPhases);
// ideal gases are always compressible
// gases are always compressible
if (phaseIdx == gPhaseIdx)
return true;
// the water component decides for the liquid phase...
return H2O::liquidIsCompressible();
}
/*!
* \brief Returns true if and only if a fluid phase is assumed to
* be an ideal gas.
*
* \param phaseIdx The index of the fluid phase to consider
*/
static bool isIdealGas(int phaseIdx)
{
assert(0 <= phaseIdx && phaseIdx < numPhases);
if (phaseIdx == gPhaseIdx)
// let the components decide
return H2O::gasIsIdeal() && N2::gasIsIdeal();
return false; // not a gas
}
/****************************************
* Component related static parameters
****************************************/
@@ -176,7 +189,7 @@ public:
//! The components for pure water
typedef TabulatedH2O H2O;
//typedef SimpleH2O H2O;
// typedef IapwsH2O H2O;
//typedef IapwsH2O H2O;
//! The components for pure nitrogen
typedef SimpleN2 N2;

View File

@@ -57,6 +57,11 @@ public:
static bool isCompressible()
{ return Component::liquidIsCompressible(); }
/*!
* \brief Returns true iff the fluid is assumed to be an ideal gas
*/
static bool isIdealGas()
{ return false; /* we're a liquid! */ }
/*!
* \brief The mass in [kg] of one mole of the component.

View File

@@ -138,6 +138,18 @@ public:
return phaseIdx == wPhaseIdx;
}
/*!
* \brief Returns true if and only if a fluid phase is assumed to
* be an ideal gas.
*
* \param phaseIdx The index of the fluid phase to consider
*/
static bool isIdealGas(int phaseIdx)
{
assert(0 <= phaseIdx && phaseIdx < numPhases);
return false; // gas is not ideal here!
}
/****************************************
* Component related parameters
****************************************/

View File

@@ -294,9 +294,10 @@ void checkFluidSystem()
try { val = FluidSystem::heatCapacity(fs, paramCache, phaseIdx); } catch (...) {};
try { val = FluidSystem::thermalConductivity(fs, paramCache, phaseIdx); } catch (...) {};
fs.allowComposition(!FluidSystem::isIdealMixture(phaseIdx));
for (int compIdx = 0; compIdx < numComponents; ++ compIdx) {
fs.allowComposition(!FluidSystem::isIdealMixture(phaseIdx));
try { val = FluidSystem::fugacityCoefficient(fs, paramCache, phaseIdx, compIdx); } catch (...) {};
fs.allowComposition(true);
try { val = FluidSystem::diffusionCoefficient(fs, paramCache, phaseIdx, compIdx); } catch (...) {};
for (int comp2Idx = 0; comp2Idx < numComponents; ++ comp2Idx) {
try { val = FluidSystem::binaryDiffusionCoefficient(fs, paramCache, phaseIdx, compIdx, comp2Idx); } catch (...) {};
@@ -304,10 +305,11 @@ void checkFluidSystem()
}
}
// test for phaseName() and isLiquid()
// test for phaseName(), isLiquid() and isIdealGas()
for (int phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
std::string __attribute__((unused)) name = FluidSystem::phaseName(phaseIdx);
bool __attribute__((unused)) bVal = FluidSystem::isLiquid(phaseIdx);
bVal = FluidSystem::isIdealGas(phaseIdx);
}
// test for componentName()

View File

@@ -38,6 +38,7 @@
#include <dumux/material/fluidsystems/1pfluidsystem.hh>
#include <dumux/material/fluidsystems/2pimmisciblefluidsystem.hh>
#include <dumux/material/fluidsystems/h2on2fluidsystem.hh>
#include <dumux/material/fluidsystems/h2oairfluidsystem.hh>
// include all fluid states
#include <dumux/material/fluidstates/pressureoverlayfluidstate.hh>
@@ -95,6 +96,27 @@ int main()
{ typedef Dumux::FluidSystems::H2ON2<Scalar, /*enableComplexRelations=*/true> FluidSystem;
checkFluidSystem<Scalar, FluidSystem>(); }
// H2O -- Air
{ typedef Dumux::SimpleH2O<Scalar> H2O;
const bool enableComplexRelations=false;
typedef Dumux::FluidSystems::H2OAir<Scalar, H2O, enableComplexRelations> FluidSystem;
checkFluidSystem<Scalar, FluidSystem>(); }
{ typedef Dumux::SimpleH2O<Scalar> H2O;
const bool enableComplexRelations=true;
typedef Dumux::FluidSystems::H2OAir<Scalar, H2O, enableComplexRelations> FluidSystem;
checkFluidSystem<Scalar, FluidSystem>(); }
{ typedef Dumux::H2O<Scalar> H2O;
const bool enableComplexRelations=false;
typedef Dumux::FluidSystems::H2OAir<Scalar, H2O, enableComplexRelations> FluidSystem;
checkFluidSystem<Scalar, FluidSystem>(); }
{ typedef Dumux::H2O<Scalar> H2O;
const bool enableComplexRelations=true;
typedef Dumux::FluidSystems::H2OAir<Scalar, H2O, enableComplexRelations> FluidSystem;
checkFluidSystem<Scalar, FluidSystem>(); }
// 2p-immiscible
{ typedef Dumux::FluidSystems::TwoPImmiscible<Scalar, Liquid, Liquid> FluidSystem;
checkFluidSystem<Scalar, FluidSystem>(); }