Loading...
Searching...
No Matches
FluidStateCompositionModules.hpp
Go to the documentation of this file.
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
This file is part of the Open Porous Media project (OPM).
OPM 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 2 of the License, or
(at your option) any later version.
OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
#ifndef OPM_FLUID_STATE_COMPOSITION_MODULES_HPP
#define OPM_FLUID_STATE_COMPOSITION_MODULES_HPP
#include <opm/material/common/Valgrind.hpp>
#include <opm/material/common/MathToolbox.hpp>
#include <algorithm>
#include <array>
#include <cmath>
namespace Opm {
template <class Scalar,
class FluidSystem,
class Implementation>
class FluidStateExplicitCompositionModule
{
enum { numPhases = FluidSystem::numPhases };
enum { numComponents = FluidSystem::numComponents };
public:
FluidStateExplicitCompositionModule()
{
for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
for (int compIdx = 0; compIdx < numComponents; ++compIdx)
moleFraction_[phaseIdx][compIdx] = 0.0;
Valgrind::SetDefined(moleFraction_);
Valgrind::SetUndefined(averageMolarMass_);
Valgrind::SetUndefined(sumMoleFractions_);
}
const Scalar& moleFraction(unsigned phaseIdx, unsigned compIdx) const
{ return moleFraction_[phaseIdx][compIdx]; }
Scalar massFraction(unsigned phaseIdx, unsigned compIdx) const
{
return
abs(sumMoleFractions_[phaseIdx])
*moleFraction_[phaseIdx][compIdx]
*FluidSystem::molarMass(compIdx)
/ max(1e-40, abs(averageMolarMass_[phaseIdx]));
}
const Scalar& averageMolarMass(unsigned phaseIdx) const
{ return averageMolarMass_[phaseIdx]; }
Scalar molarity(unsigned phaseIdx, unsigned compIdx) const
{ return asImp_().molarDensity(phaseIdx)*moleFraction(phaseIdx, compIdx); }
void setMoleFraction(unsigned phaseIdx, unsigned compIdx, const Scalar& value)
{
Valgrind::CheckDefined(value);
Valgrind::SetUndefined(sumMoleFractions_[phaseIdx]);
Valgrind::SetUndefined(averageMolarMass_[phaseIdx]);
Valgrind::SetUndefined(moleFraction_[phaseIdx][compIdx]);
moleFraction_[phaseIdx][compIdx] = value;
// re-calculate the mean molar mass
sumMoleFractions_[phaseIdx] = 0.0;
averageMolarMass_[phaseIdx] = 0.0;
for (unsigned compJIdx = 0; compJIdx < numComponents; ++compJIdx) {
sumMoleFractions_[phaseIdx] += moleFraction_[phaseIdx][compJIdx];
averageMolarMass_[phaseIdx] += moleFraction_[phaseIdx][compJIdx]*FluidSystem::molarMass(compJIdx);
}
}
void setCompressFactor(unsigned phaseIdx, const Scalar& value) {
Valgrind::CheckDefined(value);
Z_[phaseIdx] = value;
}
Scalar compressFactor(unsigned phaseIdx) const {
return Z_[phaseIdx];
}
template <class FluidState>
void assign(const FluidState& fs)
{
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
averageMolarMass_[phaseIdx] = 0;
sumMoleFractions_[phaseIdx] = 0;
for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
moleFraction_[phaseIdx][compIdx] =
decay<Scalar>(fs.moleFraction(phaseIdx, compIdx));
averageMolarMass_[phaseIdx] += moleFraction_[phaseIdx][compIdx]*FluidSystem::molarMass(compIdx);
sumMoleFractions_[phaseIdx] += moleFraction_[phaseIdx][compIdx];
}
}
}
void checkDefined() const
{
Valgrind::CheckDefined(moleFraction_);
Valgrind::CheckDefined(averageMolarMass_);
Valgrind::CheckDefined(sumMoleFractions_);
Valgrind::CheckDefined(K_);
Valgrind::CheckDefined(L_);
}
const Scalar& K(unsigned compIdx) const
{
return K_[compIdx];
}
void setKvalue(unsigned compIdx, const Scalar& value)
{
K_[compIdx] = value;
}
const Scalar& L() const
{
return L_;
}
void setLvalue(const Scalar& value)
{
L_ = value;
}
Scalar wilsonK_(unsigned compIdx) const
{
const auto& acf = FluidSystem::acentricFactor(compIdx);
const auto& T_crit = FluidSystem::criticalTemperature(compIdx);
const auto& T = asImp_().temperature(0);
const auto& p_crit = FluidSystem::criticalPressure(compIdx);
const auto& p = asImp_().pressure(0); //for now assume no capillary pressure
const auto tmp = exp(5.37 * (1+acf) * (1-T_crit/T)) * (p_crit/p);
return tmp;
}
protected:
const Implementation& asImp_() const
{
return *static_cast<const Implementation*>(this);
}
std::array<std::array<Scalar,numComponents>,numPhases> moleFraction_{};
std::array<Scalar,numPhases> averageMolarMass_{};
std::array<Scalar,numPhases> sumMoleFractions_{};
std::array<Scalar,numPhases> Z_{};
std::array<Scalar,numComponents> K_{};
Scalar L_{};
};
template <class Scalar,
class FluidSystem,
class Implementation>
class FluidStateImmiscibleCompositionModule
{
enum { numPhases = FluidSystem::numPhases };
public:
enum { numComponents = FluidSystem::numComponents };
static_assert(static_cast<int>(numPhases) == static_cast<int>(numComponents),
"The number of phases must be the same as the number of (pseudo-) components if you assume immiscibility");
FluidStateImmiscibleCompositionModule() = default;
Scalar moleFraction(unsigned phaseIdx, unsigned compIdx) const
{ return (phaseIdx == compIdx)?1.0:0.0; }
Scalar massFraction(unsigned phaseIdx, unsigned compIdx) const
{ return (phaseIdx == compIdx)?1.0:0.0; }
Scalar averageMolarMass(unsigned phaseIdx) const
{ return FluidSystem::molarMass(/*compIdx=*/phaseIdx); }
Scalar molarity(unsigned phaseIdx, unsigned compIdx) const
{ return asImp_().molarDensity(phaseIdx)*moleFraction(phaseIdx, compIdx); }
template <class FluidState>
void assign(const FluidState& /* fs */)
{ }
void checkDefined() const
{ }
protected:
const Implementation& asImp_() const
{ return *static_cast<const Implementation*>(this); }
};
template <class Scalar>
class FluidStateNullCompositionModule
{
public:
enum { numComponents = 0 };
FluidStateNullCompositionModule() = default;
Scalar moleFraction(unsigned /* phaseIdx */, unsigned /* compIdx */) const
{ throw std::logic_error("Mole fractions are not provided by this fluid state"); }
Scalar massFraction(unsigned /* phaseIdx */, unsigned /* compIdx */) const
{ throw std::logic_error("Mass fractions are not provided by this fluid state"); }
Scalar averageMolarMass(unsigned /* phaseIdx */) const
{ throw std::logic_error("Mean molar masses are not provided by this fluid state"); }
Scalar molarity(unsigned /* phaseIdx */, unsigned /* compIdx */) const
{ throw std::logic_error("Molarities are not provided by this fluid state"); }
void checkDefined() const
{ }
};
} // namespace Opm
#endif
MathToolbox.hpp
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
Valgrind.hpp
Some templates to wrap the valgrind client request macros.
Opm::FluidStateExplicitCompositionModule
Module for the modular fluid state which stores the phase compositions explicitly in terms of mole fr...
Definition FluidStateCompositionModules.hpp:48
Opm::FluidStateExplicitCompositionModule::setLvalue
void setLvalue(const Scalar &value)
Set the L value [-].
Definition FluidStateCompositionModules.hpp:198
Opm::FluidStateExplicitCompositionModule::molarity
Scalar molarity(unsigned phaseIdx, unsigned compIdx) const
The concentration of a component in a phase [mol/m^3].
Definition FluidStateCompositionModules.hpp:102
Opm::FluidStateExplicitCompositionModule::L
const Scalar & L() const
The L value of a composition [-].
Definition FluidStateCompositionModules.hpp:190
Opm::FluidStateExplicitCompositionModule::wilsonK_
Scalar wilsonK_(unsigned compIdx) const
Wilson formula to calculate K.
Definition FluidStateCompositionModules.hpp:207
Opm::FluidStateExplicitCompositionModule::assign
void assign(const FluidState &fs)
Retrieve all parameters from an arbitrary fluid state.
Definition FluidStateCompositionModules.hpp:142
Opm::FluidStateExplicitCompositionModule::averageMolarMass
const Scalar & averageMolarMass(unsigned phaseIdx) const
The mean molar mass of a fluid phase [kg/mol].
Definition FluidStateCompositionModules.hpp:90
Opm::FluidStateExplicitCompositionModule::moleFraction
const Scalar & moleFraction(unsigned phaseIdx, unsigned compIdx) const
The mole fraction of a component in a phase [].
Definition FluidStateCompositionModules.hpp:67
Opm::FluidStateExplicitCompositionModule::setMoleFraction
void setMoleFraction(unsigned phaseIdx, unsigned compIdx, const Scalar &value)
Set the mole fraction of a component in a phase [] and update the average molar mass [kg/mol] accordi...
Definition FluidStateCompositionModules.hpp:110
Opm::FluidStateExplicitCompositionModule::setKvalue
void setKvalue(unsigned compIdx, const Scalar &value)
Set the K value of a component [-].
Definition FluidStateCompositionModules.hpp:182
Opm::FluidStateExplicitCompositionModule::massFraction
Scalar massFraction(unsigned phaseIdx, unsigned compIdx) const
The mass fraction of a component in a phase [].
Definition FluidStateCompositionModules.hpp:73
Opm::FluidStateExplicitCompositionModule::checkDefined
void checkDefined() const
Make sure that all attributes are defined.
Definition FluidStateCompositionModules.hpp:165
Opm::FluidStateImmiscibleCompositionModule
Module for the modular fluid state which provides the phase compositions assuming immiscibility.
Definition FluidStateCompositionModules.hpp:241
Opm::FluidStateImmiscibleCompositionModule::massFraction
Scalar massFraction(unsigned phaseIdx, unsigned compIdx) const
The mass fraction of a component in a phase [].
Definition FluidStateCompositionModules.hpp:260
Opm::FluidStateImmiscibleCompositionModule::molarity
Scalar molarity(unsigned phaseIdx, unsigned compIdx) const
The concentration of a component in a phase [mol/m^3].
Definition FluidStateCompositionModules.hpp:283
Opm::FluidStateImmiscibleCompositionModule::checkDefined
void checkDefined() const
Make sure that all attributes are defined.
Definition FluidStateCompositionModules.hpp:302
Opm::FluidStateImmiscibleCompositionModule::assign
void assign(const FluidState &)
Retrieve all parameters from an arbitrary fluid state.
Definition FluidStateCompositionModules.hpp:291
Opm::FluidStateImmiscibleCompositionModule::moleFraction
Scalar moleFraction(unsigned phaseIdx, unsigned compIdx) const
The mole fraction of a component in a phase [].
Definition FluidStateCompositionModules.hpp:254
Opm::FluidStateImmiscibleCompositionModule::averageMolarMass
Scalar averageMolarMass(unsigned phaseIdx) const
The mean molar mass of a fluid phase [kg/mol].
Definition FluidStateCompositionModules.hpp:271
Opm::FluidStateNullCompositionModule
Module for the modular fluid state which does not store the compositions but throws std::logic_error ...
Definition FluidStateCompositionModules.hpp:316
Opm::FluidStateNullCompositionModule::moleFraction
Scalar moleFraction(unsigned, unsigned) const
The mole fraction of a component in a phase [].
Definition FluidStateCompositionModules.hpp:325
Opm::FluidStateNullCompositionModule::averageMolarMass
Scalar averageMolarMass(unsigned) const
The mean molar mass of a fluid phase [kg/mol].
Definition FluidStateCompositionModules.hpp:342
Opm::FluidStateNullCompositionModule::molarity
Scalar molarity(unsigned, unsigned) const
The concentration of a component in a phase [mol/m^3].
Definition FluidStateCompositionModules.hpp:354
Opm::FluidStateNullCompositionModule::checkDefined
void checkDefined() const
Make sure that all attributes are defined.
Definition FluidStateCompositionModules.hpp:365
Opm::FluidStateNullCompositionModule::massFraction
Scalar massFraction(unsigned, unsigned) const
The mass fraction of a component in a phase [].
Definition FluidStateCompositionModules.hpp:331
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30