Loading...
Searching...
No Matches
flashmodel.hh
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 EWOMS_FLASH_MODEL_HH
#define EWOMS_FLASH_MODEL_HH
#include <opm/material/constraintsolvers/NcpFlash.hpp>
#include <opm/material/densead/Math.hpp>
#include <opm/material/fluidmatrixinteractions/MaterialTraits.hpp>
#include <opm/material/fluidmatrixinteractions/NullMaterial.hpp>
#include <opm/models/common/energymodule.hh>
#include <opm/models/common/multiphasebasemodel.hh>
#include <opm/models/flash/flashboundaryratevector.hh>
#include <opm/models/flash/flashextensivequantities.hh>
#include <opm/models/flash/flashindices.hh>
#include <opm/models/flash/flashintensivequantities.hh>
#include <opm/models/flash/flashlocalresidual.hh>
#include <opm/models/flash/flashparameters.hh>
#include <opm/models/flash/flashprimaryvariables.hh>
#include <opm/models/flash/flashproperties.hh>
#include <opm/models/flash/flashratevector.hh>
#include <opm/models/io/vtkcompositionmodule.hpp>
#include <opm/models/io/vtkdiffusionmodule.hpp>
#include <opm/models/io/vtkenergymodule.hpp>
#include <cassert>
#include <memory>
#include <sstream>
#include <string>
#include <tuple>
namespace Opm {
template <class TypeTag>
class FlashModel;
}
namespace Opm::Properties {
namespace TTag {
struct FlashModel
{ using InheritsFrom = std::tuple<MultiPhaseBaseModel>; };
} // namespace TTag
template<class TypeTag>
struct LocalResidual<TypeTag, TTag::FlashModel>
{ using type = FlashLocalResidual<TypeTag>; };
template<class TypeTag>
struct FlashSolver<TypeTag, TTag::FlashModel>
{
using type = NcpFlash<GetPropType<TypeTag, Properties::Scalar>,
GetPropType<TypeTag, Properties::FluidSystem>>;
};
template<class TypeTag>
struct Model<TypeTag, TTag::FlashModel>
{ using type = FlashModel<TypeTag>; };
template<class TypeTag>
struct PrimaryVariables<TypeTag, TTag::FlashModel>
{ using type = FlashPrimaryVariables<TypeTag>; };
template<class TypeTag>
struct RateVector<TypeTag, TTag::FlashModel>
{ using type = FlashRateVector<TypeTag>; };
template<class TypeTag>
struct BoundaryRateVector<TypeTag, TTag::FlashModel>
{ using type = FlashBoundaryRateVector<TypeTag>; };
template<class TypeTag>
struct IntensiveQuantities<TypeTag, TTag::FlashModel>
{ using type = FlashIntensiveQuantities<TypeTag>; };
template<class TypeTag>
struct ExtensiveQuantities<TypeTag, TTag::FlashModel>
{ using type = FlashExtensiveQuantities<TypeTag>; };
template<class TypeTag>
struct Indices<TypeTag, TTag::FlashModel>
{ using type = FlashIndices<TypeTag, /*PVIdx=*/0>; };
// disable molecular diffusion by default
template<class TypeTag>
struct EnableDiffusion<TypeTag, TTag::FlashModel>
{ static constexpr bool value = false; };
template<class TypeTag>
struct EnableEnergy<TypeTag, TTag::FlashModel>
{ static constexpr bool value = false; };
} // namespace Opm::Properties
namespace Opm {
template <class TypeTag>
class FlashModel
: public MultiPhaseBaseModel<TypeTag>
{
using ParentType = MultiPhaseBaseModel<TypeTag>;
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
using Indices = GetPropType<TypeTag, Properties::Indices>;
enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
enum { enableDiffusion = getPropValue<TypeTag, Properties::EnableDiffusion>() };
enum { enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>() };
using EnergyModule = ::Opm::EnergyModule<TypeTag, enableEnergy>;
public:
explicit FlashModel(Simulator& simulator)
: ParentType(simulator)
{}
static void registerParameters()
{
ParentType::registerParameters();
// register runtime parameters of the VTK output modules
VtkCompositionModule<TypeTag>::registerParameters();
if constexpr (enableDiffusion) {
VtkDiffusionModule<TypeTag>::registerParameters();
}
if constexpr (enableEnergy) {
VtkEnergyModule<TypeTag>::registerParameters();
}
Parameters::Register<Parameters::FlashTolerance<Scalar>>
("The maximum tolerance for the flash solver to "
"consider the solution converged");
// The updates of intensive quantities tend to be _very_ expensive for this
// model, so let's try to minimize the number of required ones
Parameters::SetDefault<Parameters::EnableIntensiveQuantityCache>(true);
// since thermodynamic hints are basically free if the cache for intensive quantities is
// enabled, and this model usually shows quite a performance improvment if they are
// enabled, let's enable them by default.
Parameters::SetDefault<Parameters::EnableThermodynamicHints>(true);
}
static std::string name()
{ return "flash"; }
std::string primaryVarName(unsigned pvIdx) const
{
const std::string& tmp = EnergyModule::primaryVarName(pvIdx);
if (!tmp.empty()) {
return tmp;
}
if (Indices::cTot0Idx <= pvIdx && pvIdx < Indices::cTot0Idx + numComponents) {
std::ostringstream oss;
oss << "c_tot," << FluidSystem::componentName(/*compIdx=*/pvIdx - Indices::cTot0Idx);
return oss.str();
}
else {
assert(false);
return "";
}
}
std::string eqName(unsigned eqIdx) const
{
const std::string& tmp = EnergyModule::eqName(eqIdx);
if (!tmp.empty()) {
return tmp;
}
if (Indices::conti0EqIdx <= eqIdx && eqIdx < Indices::conti0EqIdx + numComponents) {
const unsigned compIdx = eqIdx - Indices::conti0EqIdx;
std::ostringstream oss;
oss << "continuity^" << FluidSystem::componentName(compIdx);
return oss.str();
}
else {
assert(false);
return "";
}
}
Scalar primaryVarWeight(unsigned globalDofIdx, unsigned pvIdx) const
{
const Scalar tmp = EnergyModule::primaryVarWeight(*this, globalDofIdx, pvIdx);
if (tmp > 0) {
return tmp;
}
const unsigned compIdx = pvIdx - Indices::cTot0Idx;
// make all kg equal. also, divide the weight of all total
// compositions by 100 to make the relative errors more
// comparable to the ones of the other models (at 10% porosity
// the medium is fully saturated with water at atmospheric
// conditions if 100 kg/m^3 are present!)
return FluidSystem::molarMass(compIdx) / 100.0;
}
Scalar eqWeight(unsigned globalDofIdx, unsigned eqIdx) const
{
const Scalar tmp = EnergyModule::eqWeight(*this, globalDofIdx, eqIdx);
if (tmp > 0) {
return tmp;
}
const unsigned compIdx = eqIdx - Indices::conti0EqIdx;
// make all kg equal
return FluidSystem::molarMass(compIdx);
}
void registerOutputModules_()
{
ParentType::registerOutputModules_();
// add the VTK output modules which are meaningful for the model
this->addOutputModule(std::make_unique<VtkCompositionModule<TypeTag>>(this->simulator_));
if constexpr (enableDiffusion) {
this->addOutputModule(std::make_unique<VtkDiffusionModule<TypeTag>>(this->simulator_));
}
if constexpr (enableEnergy) {
this->addOutputModule(std::make_unique<VtkEnergyModule<TypeTag>>(this->simulator_));
}
}
};
} // namespace Opm
#endif
Opm::FlashBoundaryRateVector
Implements a boundary vector for the fully implicit compositional multi-phase model which is based on...
Definition flashboundaryratevector.hh:49
Opm::FlashExtensiveQuantities
This template class contains the data which is required to calculate all fluxes of components over a ...
Definition flashextensivequantities.hh:54
Opm::FlashIndices
Defines the primary variable and equation indices for the compositional multi-phase model based on fl...
Definition flashindices.hh:47
Opm::FlashIntensiveQuantities
Contains the intensive quantities of the flash-based compositional multi-phase model.
Definition flashintensivequantities.hh:60
Opm::FlashLocalResidual
Calculates the local residual of the compositional multi-phase model based on flash calculations.
Definition flashlocalresidual.hh:47
Opm::FlashModel
A compositional multi-phase model based on flash-calculations.
Definition flashmodel.hh:194
Opm::FlashModel::registerParameters
static void registerParameters()
Register all run-time parameters for the immiscible model.
Definition flashmodel.hh:225
Opm::FlashModel::primaryVarWeight
Scalar primaryVarWeight(unsigned globalDofIdx, unsigned pvIdx) const
Returns the relative weight of a primary variable for calculating relative errors.
Definition flashmodel.hh:306
Opm::FlashModel::name
static std::string name()
Definition flashmodel.hh:257
Opm::FlashModel::eqWeight
Scalar eqWeight(unsigned globalDofIdx, unsigned eqIdx) const
Returns the relative weight of an equation.
Definition flashmodel.hh:329
Opm::FlashModel::primaryVarName
std::string primaryVarName(unsigned pvIdx) const
Given an primary variable index, return a human readable name.
Definition flashmodel.hh:263
Opm::FlashModel::eqName
std::string eqName(unsigned eqIdx) const
Given an equation index, return a human readable name.
Definition flashmodel.hh:284
Opm::FlashPrimaryVariables
Represents the primary variables used by the compositional flow model based on flash calculations.
Definition flashprimaryvariables.hh:52
Opm::FlashRateVector
Implements a vector representing rates of conserved quantities.
Definition flashratevector.hh:48
Opm::MultiPhaseBaseModel
A base class for fully-implicit multi-phase porous-media flow models which assume multiple fluid phas...
Definition multiphasebasemodel.hh:168
Opm::MultiPhaseBaseModel::registerParameters
static void registerParameters()
Register all run-time parameters for the immiscible model.
Definition multiphasebasemodel.hh:190
Opm::Simulator
Manages the initializing and running of time dependent problems.
Definition simulator.hh:84
Opm::VtkCompositionModule
VTK output module for the fluid composition.
Definition vtkcompositionmodule.hpp:57
Opm::VtkCompositionModule::registerParameters
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition vtkcompositionmodule.hpp:87
Opm::VtkDiffusionModule
VTK output module for quantities which make sense for models which incorperate molecular diffusion.
Definition vtkdiffusionmodule.hpp:58
Opm::VtkDiffusionModule::registerParameters
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition vtkdiffusionmodule.hpp:88
Opm::VtkEnergyModule::registerParameters
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition vtkenergymodule.hpp:87
energymodule.hh
Contains the classes required to consider energy as a conservation quantity in a multi-phase module.
flashindices.hh
Defines the primary variable and equation indices for the compositional multi-phase model based on fl...
flashintensivequantities.hh
Contains the intensive quantities of the flash-based compositional multi-phase model.
flashlocalresidual.hh
Calculates the local residual of the compositional multi-phase model based on flash calculations.
flashparameters.hh
Declares the parameters for the compositional multi-phase model based on flash calculations.
flashprimaryvariables.hh
Represents the primary variables used by the compositional flow model based on flash calculations.
flashboundaryratevector.hh
Implements a boundary vector for the fully implicit compositional multi-phase model which is based on...
flashextensivequantities.hh
This template class contains the data which is required to calculate all fluxes of components over a ...
flashproperties.hh
Declares the properties required by the compositional multi-phase model based on flash calculations.
flashratevector.hh
Implements a vector representing rates of conserved quantities.
multiphasebasemodel.hh
A base class for fully-implicit multi-phase porous-media flow models which assume multiple fluid phas...
Opm::Properties::TTag
The generic type tag for problems using the immiscible multi-phase model.
Definition blackoilmodel.hh:81
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::GetPropType
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition propertysystem.hh:233
Opm::getPropValue
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:240
Opm::Parameters::SetDefault
void SetDefault(decltype(Param::value) new_value)
Set a runtime parameter.
Definition parametersystem.hpp:212
Opm::Parameters::Register
void Register(const char *usageString)
Register a run-time parameter.
Definition parametersystem.hpp:292
Opm::Properties::BoundaryRateVector
Type of object for specifying boundary conditions.
Definition fvbaseproperties.hh:119
Opm::Properties::EnableDiffusion
Enable diffusive fluxes?
Definition multiphasebaseproperties.hh:91
Opm::Properties::EnableEnergy
Specify whether energy should be considered as a conservation quantity or not.
Definition multiphasebaseproperties.hh:87
Opm::Properties::ExtensiveQuantities
Data required to calculate a flux over a face.
Definition fvbaseproperties.hh:149
Opm::Properties::FlashSolver
The type of the flash constraint solver.
Definition flashproperties.hh:39
Opm::Properties::Indices
Enumerations used by the model.
Definition multiphasebaseproperties.hh:51
Opm::Properties::IntensiveQuantities
The secondary variables within a sub-control volume.
Definition fvbaseproperties.hh:133
Opm::Properties::LocalResidual
The type of the local residual function.
Definition fvbaseproperties.hh:94
Opm::Properties::Model
The type of the model.
Definition basicproperties.hh:88
Opm::Properties::PrimaryVariables
A vector of primary variables within a sub-control volume.
Definition fvbaseproperties.hh:130
Opm::Properties::RateVector
Vector containing volumetric or areal rates of quantities.
Definition fvbaseproperties.hh:116
Opm::Properties::TTag::FlashModel
The type tag for the isothermal single phase problems.
Definition flashmodel.hh:74
vtkcompositionmodule.hpp
VTK output module for the fluid composition.
vtkdiffusionmodule.hpp
VTK output module for quantities which make sense for models which incorperate molecular diffusion.
vtkenergymodule.hpp
VTK output module for quantities which make sense for models which assume thermal equilibrium.