25#ifndef DUMUX_2P1C_VOLUME_VARIABLES_HH
26#define DUMUX_2P1C_VOLUME_VARIABLES_HH
30#include <dune/common/exceptions.hh>
46template <
class Traits>
53 using Scalar =
typename Traits::PrimaryVariables::value_type;
54 using PermeabilityType =
typename Traits::PermeabilityType;
55 using FS =
typename Traits::FluidSystem;
56 using Idx =
typename Traits::ModelTraits::Indices;
62 numFluidPhases = Traits::ModelTraits::numFluidPhases(),
63 switchIdx = Idx::switchIdx,
64 pressureIdx = Idx::pressureIdx
70 comp0Idx = FS::comp0Idx,
71 liquidPhaseIdx = FS::liquidPhaseIdx,
72 gasPhaseIdx = FS::gasPhaseIdx
78 twoPhases = Idx::twoPhases,
79 liquidPhaseOnly = Idx::liquidPhaseOnly,
80 gasPhaseOnly = Idx::gasPhaseOnly,
84 static constexpr auto formulation = Traits::ModelTraits::priVarFormulation();
92 using Indices =
typename Traits::ModelTraits::Indices;
104 static_assert(Traits::ModelTraits::numFluidPhases() == 2,
"NumPhases set in the model is not two!");
105 static_assert(Traits::ModelTraits::numFluidComponents() == 1,
"NumComponents set in the model is not one!");
117 template<
class ElemSol,
class Problem,
class Element,
class Scv>
119 const Problem &problem,
120 const Element &element,
130 using MaterialLaw =
typename Problem::SpatialParams::MaterialLaw;
131 const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
132 const int wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
137 typename FluidSystem::ParameterCache paramCache;
139 for (
int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
143 if (phaseIdx == wPhaseIdx)
144 kr = MaterialLaw::krw(materialParams,
saturation(wPhaseIdx));
147 kr = MaterialLaw::krn(materialParams,
saturation(wPhaseIdx));
148 relativePermeability_[phaseIdx] = kr;
155 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv,
solidState_);
156 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
170 template<
class ElemSol,
class Problem,
class Element,
class Scv>
172 const Problem& problem,
173 const Element& element,
180 const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
181 const int wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
184 const auto&
priVars = elemSol[scv.localDofIndex()];
185 const auto phasePresence =
priVars.state();
188 if (phasePresence == twoPhases)
201 else if (phasePresence == liquidPhaseOnly)
203 fluidState.setSaturation(liquidPhaseIdx, 1.0);
206 else if (phasePresence == gasPhaseOnly)
208 fluidState.setSaturation(liquidPhaseIdx, 0.0);
212 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " << phasePresence <<
" is invalid.");
215 using MaterialLaw =
typename Problem::SpatialParams::MaterialLaw;
216 pc_ = MaterialLaw::pc(materialParams,
fluidState.saturation(wPhaseIdx));
220 fluidState.setPressure(gasPhaseIdx, (wPhaseIdx == liquidPhaseIdx) ?
priVars[pressureIdx] + pc_
226 fluidState.setPressure(liquidPhaseIdx, (wPhaseIdx == liquidPhaseIdx) ?
priVars[pressureIdx] - pc_
234 for (
int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
236 Scalar rho = FluidSystem::density(
fluidState, phaseIdx);
237 Scalar rhoMolar = FluidSystem::molarDensity(
fluidState, phaseIdx);
240 fluidState.setMolarDensity(phaseIdx, rhoMolar);
244 for (
int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
254 for (
int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
256 const Scalar h = FluidSystem::enthalpy(
fluidState, phaseIdx);
263 template<
class ElemSol,
class Problem,
class Element,
class Scv>
265 const Problem& problem,
266 const Element& element,
271 const auto&
priVars = elemSol[scv.localDofIndex()];
272 const auto phasePresence =
priVars.state();
273 const int wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
276 Scalar fluidTemperature;
277 if (phasePresence == liquidPhaseOnly || phasePresence == gasPhaseOnly)
278 fluidTemperature =
priVars[switchIdx];
279 else if (phasePresence == twoPhases)
280 fluidTemperature = FluidSystem::vaporTemperature(
fluidState, wPhaseIdx);
282 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " << phasePresence <<
" is invalid.");
287 for (
int phaseIdx=0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
288 fluidState.setTemperature(phaseIdx, fluidTemperature);
291 if (Traits::ModelTraits::numEnergyEq() == 1)
295 const Scalar solidTemperature = elemSol[scv.localDofIndex()][Traits::ModelTraits::numEq()-1];
374 return relativePermeability_[phaseIdx]/
fluidState_.viscosity(phaseIdx);
394 {
return permeability_; }
400 {
return FluidSystem::vaporTemperature(
fluidState_, liquidPhaseIdx);}
408 PermeabilityType permeability_;
411 std::array<Scalar, numFluidPhases> relativePermeability_;
Some templates to wrap the valgrind macros.
Update the solid volume fractions (inert and reacitve) and set them in the solidstate.
Defines an enumeration for the formulations accepted by the two-phase model.
TwoPFormulation
Enumerates the formulations which the two-phase model accepts.
Definition formulation.hh:35
@ p1s0
first phase saturation and second phase pressure as primary variables
Definition formulation.hh:37
@ p0s1
first phase pressure and second phase saturation as primary variables
Definition formulation.hh:36
EnergyVolumeVariablesImplementation< IsothermalTraits, Impl, IsothermalTraits::ModelTraits::enableEnergyBalance()> EnergyVolumeVariables
Base class for the model specific class which provides access to all volume averaged quantities.
Definition porousmediumflow/nonisothermal/volumevariables.hh:85
void updateSolidVolumeFractions(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, SolidState &solidState, const int solidVolFracOffset)
update the solid volume fractions (inert and reacitve) and set them in the solidstate
Definition updatesolidvolumefractions.hh:36
bool CheckDefined(const T &value)
Make valgrind complain if the object occupied by an object is undefined.
Definition valgrind.hh:72
make the local view function available whenever we use the grid geometry
Definition adapt.hh:29
The primary variable switch for the two-phase one-component model.
Definition 2p1c/primaryvariableswitch.hh:41
The volume variables (i.e. secondary variables) for the two-phase one-component model.
Definition porousmediumflow/2p1c/volumevariables.hh:50
Scalar saturation(const int phaseIdx) const
Returns the effective saturation of a given phase within the control volume.
Definition porousmediumflow/2p1c/volumevariables.hh:326
typename Traits::FluidSystem FluidSystem
The type of the fluid system.
Definition porousmediumflow/2p1c/volumevariables.hh:90
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition porousmediumflow/2p1c/volumevariables.hh:393
TwoPOneCPrimaryVariableSwitch PrimaryVariableSwitch
Export the primary variable switch.
Definition porousmediumflow/2p1c/volumevariables.hh:98
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition porousmediumflow/2p1c/volumevariables.hh:335
Scalar temperature(const int phaseIdx=0) const
Returns temperature inside the sub-control volume.
Definition porousmediumflow/2p1c/volumevariables.hh:363
typename Traits::FluidState FluidState
The type of the object returned by the fluidState() method.
Definition porousmediumflow/2p1c/volumevariables.hh:88
const FluidState & fluidState() const
Returns the fluid state for the control-volume.
Definition porousmediumflow/2p1c/volumevariables.hh:303
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition porousmediumflow/2p1c/volumevariables.hh:317
Scalar vaporTemperature() const
Returns the vapor temperature of the fluid within the control volume.
Definition porousmediumflow/2p1c/volumevariables.hh:399
void completeFluidState(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, FluidState &fluidState, SolidState &solidState)
Sets complete fluid state.
Definition porousmediumflow/2p1c/volumevariables.hh:171
Scalar molarDensity(const int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition porousmediumflow/2p1c/volumevariables.hh:344
FluidState fluidState_
Definition porousmediumflow/2p1c/volumevariables.hh:403
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition porousmediumflow/2p1c/volumevariables.hh:96
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition porousmediumflow/2p1c/volumevariables.hh:381
void updateTemperature(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, FluidState &fluidState, SolidState &solidState)
Definition porousmediumflow/2p1c/volumevariables.hh:264
typename Traits::ModelTraits::Indices Indices
The type of the indices.
Definition porousmediumflow/2p1c/volumevariables.hh:92
void update(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv)
Updates all quantities for a given control volume.
Definition porousmediumflow/2p1c/volumevariables.hh:118
Scalar porosity() const
Returns the average porosity within the control volume.
Definition porousmediumflow/2p1c/volumevariables.hh:387
typename Traits::SolidState SolidState
Export type of solid state.
Definition porousmediumflow/2p1c/volumevariables.hh:94
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition porousmediumflow/2p1c/volumevariables.hh:372
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition porousmediumflow/2p1c/volumevariables.hh:309
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition porousmediumflow/2p1c/volumevariables.hh:101
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition porousmediumflow/2p1c/volumevariables.hh:353
SolidState solidState_
Definition porousmediumflow/2p1c/volumevariables.hh:404
The isothermal base class.
Definition porousmediumflow/volumevariables.hh:40
static constexpr int numFluidComponents()
Return number of components considered by the model.
Definition porousmediumflow/volumevariables.hh:52
const PrimaryVariables & priVars() const
Returns the vector of primary variables.
Definition porousmediumflow/volumevariables.hh:76
void update(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv)
Updates all quantities for a given control volume.
Definition porousmediumflow/volumevariables.hh:64
Base class for the model specific class which provides access to all volume averaged quantities.
Base class for the model specific class which provides access to all volume averaged quantities.
The primary variable switch for the two-phase one-component model.