Loading...
Searching...
No Matches
GenericOilGasFluidSystem.hpp
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
Copyright 2023 SINTEF Digital, Mathematics and Cybernetics.
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_GENERICOILGASFLUIDSYSTEM_HPP
#define OPM_GENERICOILGASFLUIDSYSTEM_HPP
#include <opm/common/OpmLog/OpmLog.hpp>
#if HAVE_ECL_INPUT
#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
#include <opm/input/eclipse/Schedule/Schedule.hpp>
#endif
#include <opm/material/eos/PengRobinsonMixture.hpp>
#include <opm/material/fluidsystems/BaseFluidSystem.hpp>
#include <opm/material/fluidsystems/PTFlashParameterCache.hpp> // TODO: this is something else need to check
#include <opm/material/viscositymodels/LBC.hpp>
#include <cassert>
#include <cstddef>
#include <string>
#include <string_view>
#include <fmt/format.h>
namespace Opm {
template<class Scalar, int NumComp>
class GenericOilGasFluidSystem : public BaseFluidSystem<Scalar, GenericOilGasFluidSystem<Scalar, NumComp> > {
public:
// TODO: I do not think these should be constant in fluidsystem, will try to make it non-constant later
static constexpr int numPhases = 2;
static constexpr int numComponents = NumComp;
static constexpr int numMisciblePhases = 2;
// \Note: not totally sure when we should distinguish numMiscibleComponents and numComponents.
// Possibly when with a dummy phase like water?
static constexpr int numMiscibleComponents = NumComp;
// TODO: phase location should be more general
static constexpr int waterPhaseIdx = -1;
static constexpr int oilPhaseIdx = 0;
static constexpr int gasPhaseIdx = 1;
static constexpr int waterCompIdx = -1;
static constexpr int oilCompIdx = 0;
static constexpr int gasCompIdx = 1;
static constexpr int compositionSwitchIdx = -1; // equil initializer
template <class ValueType>
using ParameterCache = Opm::PTFlashParameterCache<ValueType, GenericOilGasFluidSystem<Scalar, NumComp>>;
using ViscosityModel = Opm::ViscosityModels<Scalar, GenericOilGasFluidSystem<Scalar, NumComp>>;
using PengRobinsonMixture = Opm::PengRobinsonMixture<Scalar, GenericOilGasFluidSystem<Scalar, NumComp>>;
struct ComponentParam {
std::string name;
Scalar molar_mass; // unit: g/mol
Scalar critic_temp; // unit: K
Scalar critic_pres; // unit: parscal
Scalar critic_vol; // unit: m^3/kmol
Scalar acentric_factor; // unit: dimension less
ComponentParam(const std::string_view name_, const Scalar molar_mass_, const Scalar critic_temp_,
const Scalar critic_pres_, const Scalar critic_vol_, const Scalar acentric_factor_)
: name(name_),
molar_mass(molar_mass_),
critic_temp(critic_temp_),
critic_pres(critic_pres_),
critic_vol(critic_vol_),
acentric_factor(acentric_factor_)
{}
};
static bool phaseIsActive(unsigned phaseIdx)
{
return phaseIdx == oilPhaseIdx || phaseIdx == gasPhaseIdx;
}
template<typename Param>
static void addComponent(const Param& param)
{
// Check if the current size is less than the maximum allowed components.
if (component_param_.size() < numComponents) {
component_param_.push_back(param);
} else {
// Adding another component would exceed the limit.
const std::string msg = fmt::format("The fluid system has reached its maximum capacity of {} components,"
"the component '{}' will not be added.", NumComp, param.name);
OpmLog::note(msg);
// Optionally, throw an exception?
}
}
#if HAVE_ECL_INPUT
static void initFromState(const EclipseState& eclState, const Schedule& /* schedule */)
{
// TODO: we are not considering the EOS region for now
const auto& comp_config = eclState.compositionalConfig();
// how should we utilize the numComps from the CompositionalConfig?
using FluidSystem = GenericOilGasFluidSystem<Scalar, NumComp>;
const std::size_t num_comps = comp_config.numComps();
// const std::size_t num_eos_region = comp_config.
assert(num_comps == NumComp);
const auto& names = comp_config.compName();
// const auto& eos_type = comp_config.eosType(0);
const auto& molar_weight = comp_config.molecularWeights(0);
const auto& acentric_factor = comp_config.acentricFactors(0);
const auto& critic_pressure = comp_config.criticalPressure(0);
const auto& critic_temp = comp_config.criticalTemperature(0);
const auto& critic_volume = comp_config.criticalVolume(0);
FluidSystem::init();
using CompParm = typename FluidSystem::ComponentParam;
for (std::size_t c = 0; c < num_comps; ++c) {
// we use m^3/kmol for the critic volume in the flash calculation, so we multiply 1.e3 for the critic volume
FluidSystem::addComponent(CompParm{names[c], molar_weight[c], critic_temp[c], critic_pressure[c],
critic_volume[c] * 1.e3, acentric_factor[c]});
}
FluidSystem::printComponentParams();
interaction_coefficients_ = comp_config.binaryInteractionCoefficient(0);
}
#endif // HAVE_ECL_INPUT
static void init()
{
component_param_.reserve(numComponents);
}
static Scalar acentricFactor(unsigned compIdx)
{
assert(isConsistent());
assert(compIdx < numComponents);
return component_param_[compIdx].acentric_factor;
}
static Scalar criticalTemperature(unsigned compIdx)
{
assert(isConsistent());
assert(compIdx < numComponents);
return component_param_[compIdx].critic_temp;
}
static Scalar criticalPressure(unsigned compIdx)
{
assert(isConsistent());
assert(compIdx < numComponents);
return component_param_[compIdx].critic_pres;
}
static Scalar criticalVolume(unsigned compIdx)
{
assert(isConsistent());
assert(compIdx < numComponents);
return component_param_[compIdx].critic_vol;
}
static Scalar molarMass(unsigned compIdx)
{
assert(isConsistent());
assert(compIdx < numComponents);
return component_param_[compIdx].molar_mass;
}
static Scalar interactionCoefficient(unsigned comp1Idx, unsigned comp2Idx)
{
assert(isConsistent());
assert(comp1Idx < numComponents);
assert(comp2Idx < numComponents);
if (interaction_coefficients_.empty() || comp2Idx == comp1Idx) {
return 0.0;
}
// make sure row is the bigger value compared to column number
const auto [column, row] = std::minmax(comp1Idx, comp2Idx);
const unsigned index = (row * (row - 1) / 2 + column); // it is the current understanding
return interaction_coefficients_[index];
}
static std::string_view phaseName(unsigned phaseIdx)
{
static const std::string_view name[] = {"o", // oleic phase
"g"}; // gas phase
assert(phaseIdx < numPhases);
return name[phaseIdx];
}
static std::string_view componentName(unsigned compIdx)
{
assert(isConsistent());
assert(compIdx < numComponents);
return component_param_[compIdx].name;
}
template <class FluidState, class LhsEval = typename FluidState::Scalar, class ParamCacheEval = LhsEval>
static LhsEval density(const FluidState& fluidState,
const ParameterCache<ParamCacheEval>& paramCache,
unsigned phaseIdx)
{
assert(isConsistent());
assert(phaseIdx < numPhases);
if (phaseIdx == oilPhaseIdx || phaseIdx == gasPhaseIdx) {
return decay<LhsEval>(fluidState.averageMolarMass(phaseIdx) / paramCache.molarVolume(phaseIdx));
}
return {};
}
template <class FluidState, class LhsEval = typename FluidState::Scalar, class ParamCacheEval = LhsEval>
static LhsEval viscosity(const FluidState& fluidState,
const ParameterCache<ParamCacheEval>& paramCache,
unsigned phaseIdx)
{
assert(isConsistent());
assert(phaseIdx < numPhases);
// Use LBC method to calculate viscosity
return decay<LhsEval>(ViscosityModel::LBC(fluidState, paramCache, phaseIdx));
}
template <class FluidState, class LhsEval = typename FluidState::Scalar, class ParamCacheEval = LhsEval>
static LhsEval fugacityCoefficient(const FluidState& fluidState,
const ParameterCache<ParamCacheEval>& paramCache,
unsigned phaseIdx,
unsigned compIdx)
{
assert(isConsistent());
assert(phaseIdx < numPhases);
assert(compIdx < numComponents);
return decay<LhsEval>(PengRobinsonMixture::computeFugacityCoefficient(fluidState, paramCache, phaseIdx, compIdx));
}
// TODO: the following interfaces are needed by function checkFluidSystem()
static bool isCompressible([[maybe_unused]] unsigned phaseIdx)
{
assert(phaseIdx < numPhases);
return true;
}
static bool isIdealMixture([[maybe_unused]] unsigned phaseIdx)
{
assert(phaseIdx < numPhases);
return false;
}
static bool isLiquid(unsigned phaseIdx)
{
assert(phaseIdx < numPhases);
return (phaseIdx == 0);
}
static bool isIdealGas(unsigned phaseIdx)
{
assert(phaseIdx < numPhases);
return (phaseIdx == 1);
}
private:
static bool isConsistent() {
return component_param_.size() == NumComp;
}
static std::vector<ComponentParam> component_param_;
static std::vector<Scalar> interaction_coefficients_;
public:
static std::string printComponentParams() {
std::string result = "Components Information:\n";
for (const auto& param : component_param_) {
result += fmt::format("Name: {}\n", param.name);
result += fmt::format("Molar Mass: {} g/mol\n", param.molar_mass);
result += fmt::format("Critical Temperature: {} K\n", param.critic_temp);
result += fmt::format("Critical Pressure: {} Pascal\n", param.critic_pres);
result += fmt::format("Critical Volume: {} m^3/kmol\n", param.critic_vol);
result += fmt::format("Acentric Factor: {}\n", param.acentric_factor);
result += "---------------------------------\n";
}
return result;
}
};
template <class Scalar, int NumComp>
std::vector<typename GenericOilGasFluidSystem<Scalar, NumComp>::ComponentParam>
GenericOilGasFluidSystem<Scalar, NumComp>::component_param_;
template <class Scalar, int NumComp>
std::vector<Scalar>
GenericOilGasFluidSystem<Scalar, NumComp>::interaction_coefficients_;
}
#endif // OPM_GENERICOILGASFLUIDSYSTEM_HPP
BaseFluidSystem.hpp
The base class for all fluid systems.
LBC.hpp
PTFlashParameterCache.hpp
Specifies the parameter cache used by the SPE-5 fluid system.
PengRobinsonMixture.hpp
Implements the Peng-Robinson equation of state for a mixture.
Opm::BaseFluidSystem
The base class for all fluid systems.
Definition BaseFluidSystem.hpp:43
Opm::BaseFluidSystem< Scalar, GenericOilGasFluidSystem< Scalar, NumComp > >::Scalar
Scalar Scalar
The type used for scalar quantities.
Definition BaseFluidSystem.hpp:48
Opm::GenericOilGasFluidSystem
A two phase system that can contain NumComp components.
Definition GenericOilGasFluidSystem.hpp:59
Opm::GenericOilGasFluidSystem::isIdealMixture
static bool isIdealMixture(unsigned phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal mixture.
Definition GenericOilGasFluidSystem.hpp:308
Opm::GenericOilGasFluidSystem::fugacityCoefficient
static LhsEval fugacityCoefficient(const FluidState &fluidState, const ParameterCache< ParamCacheEval > &paramCache, unsigned phaseIdx, unsigned compIdx)
Calculate the fugacity coefficient [Pa] of an individual component in a fluid phase.
Definition GenericOilGasFluidSystem.hpp:286
Opm::GenericOilGasFluidSystem::criticalTemperature
static Scalar criticalTemperature(unsigned compIdx)
Critical temperature of a component [K].
Definition GenericOilGasFluidSystem.hpp:176
Opm::GenericOilGasFluidSystem::isCompressible
static bool isCompressible(unsigned phaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition GenericOilGasFluidSystem.hpp:300
Opm::GenericOilGasFluidSystem::criticalVolume
static Scalar criticalVolume(unsigned compIdx)
Critical volume of a component [m3].
Definition GenericOilGasFluidSystem.hpp:200
Opm::GenericOilGasFluidSystem::interactionCoefficient
static Scalar interactionCoefficient(unsigned comp1Idx, unsigned comp2Idx)
Returns the interaction coefficient for two components.
Definition GenericOilGasFluidSystem.hpp:221
Opm::GenericOilGasFluidSystem::criticalPressure
static Scalar criticalPressure(unsigned compIdx)
Critical pressure of a component [Pa].
Definition GenericOilGasFluidSystem.hpp:188
Opm::GenericOilGasFluidSystem::isIdealGas
static bool isIdealGas(unsigned phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal gas.
Definition GenericOilGasFluidSystem.hpp:324
Opm::GenericOilGasFluidSystem::density
static LhsEval density(const FluidState &fluidState, const ParameterCache< ParamCacheEval > &paramCache, unsigned phaseIdx)
Calculate the density [kg/m^3] of a fluid phase.
Definition GenericOilGasFluidSystem.hpp:258
Opm::GenericOilGasFluidSystem::isLiquid
static bool isLiquid(unsigned phaseIdx)
Return whether a phase is liquid.
Definition GenericOilGasFluidSystem.hpp:316
Opm::GenericOilGasFluidSystem::phaseName
static std::string_view phaseName(unsigned phaseIdx)
Return the human readable name of a fluid phase.
Definition GenericOilGasFluidSystem.hpp:236
Opm::GenericOilGasFluidSystem::acentricFactor
static Scalar acentricFactor(unsigned compIdx)
The acentric factor of a component [].
Definition GenericOilGasFluidSystem.hpp:164
Opm::GenericOilGasFluidSystem::molarMass
static Scalar molarMass(unsigned compIdx)
Return the molar mass of a component in [kg/mol].
Definition GenericOilGasFluidSystem.hpp:209
Opm::GenericOilGasFluidSystem::viscosity
static LhsEval viscosity(const FluidState &fluidState, const ParameterCache< ParamCacheEval > &paramCache, unsigned phaseIdx)
Calculate the dynamic viscosity of a fluid phase [Pa*s].
Definition GenericOilGasFluidSystem.hpp:274
Opm::GenericOilGasFluidSystem::componentName
static std::string_view componentName(unsigned compIdx)
Return the human readable name of a component.
Definition GenericOilGasFluidSystem.hpp:246
Opm::PTFlashParameterCache
Specifies the parameter cache used by the SPE-5 fluid system.
Definition PTFlashParameterCache.hpp:48
Opm::PTFlashParameterCache::molarVolume
Scalar molarVolume(unsigned phaseIdx) const
Returns the molar volume of a phase [m^3/mol].
Definition PTFlashParameterCache.hpp:210
Opm::PengRobinsonMixture
Implements the Peng-Robinson equation of state for a mixture.
Definition PengRobinsonMixture.hpp:41
Opm::PengRobinsonMixture::computeFugacityCoefficient
static LhsEval computeFugacityCoefficient(const FluidState &fs, const Params &params, unsigned phaseIdx, unsigned compIdx)
Returns the fugacity coefficient of an individual component in the phase.
Definition PengRobinsonMixture.hpp:74
Opm::ViscosityModels
Definition LBC.hpp:40
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Opm::GenericOilGasFluidSystem::ComponentParam
Definition GenericOilGasFluidSystem.hpp:83