richardsprimaryvariables.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
28#ifndef EWOMS_RICHARDS_PRIMARY_VARIABLES_HH
29#define EWOMS_RICHARDS_PRIMARY_VARIABLES_HH
30
31#include "richardsproperties.hh"
32
34
35#include <opm/material/constraintsolvers/ImmiscibleFlash.hpp>
36#include <opm/material/fluidstates/ImmiscibleFluidState.hpp>
37#include <opm/material/common/Valgrind.hpp>
38
39#include <dune/common/fvector.hh>
40
41namespace Opm {
42
51template <class TypeTag>
53{
54 using ParentType = FvBasePrimaryVariables<TypeTag>;
62
63 // primary variable indices
64 enum { pressureWIdx = Indices::pressureWIdx };
65
66 enum { liquidPhaseIdx = getPropValue<TypeTag, Properties::LiquidPhaseIndex>() };
67 enum { gasPhaseIdx = getPropValue<TypeTag, Properties::GasPhaseIndex>() };
68
69 enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
70 enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
71
72 using ComponentVector = Dune::FieldVector<Scalar, numComponents>;
73 using PhaseVector = Dune::FieldVector<Scalar, numPhases>;
74 using Toolbox = typename Opm::MathToolbox<Evaluation>;
75 using ImmiscibleFlash = Opm::ImmiscibleFlash<Scalar, FluidSystem>;
76
77public:
78 RichardsPrimaryVariables() : ParentType()
79 { Opm::Valgrind::SetUndefined(*this); }
80
84 RichardsPrimaryVariables(Scalar value) : ParentType(value)
85 {}
86
93
103 void assignImmiscibleFromWetting(Scalar T, Scalar pw, Scalar Sw,
104 const MaterialLawParams& matParams)
105 {
106 Opm::ImmiscibleFluidState<Scalar, FluidSystem> fs;
107
108 fs.setTemperature(T);
109 fs.setSaturation(liquidPhaseIdx, Sw);
110 fs.setSaturation(gasPhaseIdx, 1 - Sw);
111
112 // set phase pressures
113 PhaseVector pC;
114 MaterialLaw::capillaryPressures(pC, matParams, fs);
115
116 fs.setPressure(liquidPhaseIdx, pw);
117 fs.setPressure(gasPhaseIdx, pw + (pC[gasPhaseIdx] - pC[liquidPhaseIdx]));
118
119 assignNaive(fs);
120 }
121
131 void assignImmiscibleFromNonWetting(Scalar T, Scalar pn, Scalar Sn,
132 const MaterialLawParams& matParams)
133 {
134 Opm::ImmiscibleFluidState<Scalar, FluidSystem> fs;
135
136 fs.setTemperature(T);
137 fs.setSaturation(liquidPhaseIdx, 1 - Sn);
138 fs.setSaturation(gasPhaseIdx, Sn);
139
140 // set phase pressures
141 PhaseVector pC;
142 MaterialLaw::capillaryPressures(pC, matParams, fs);
143
144 fs.setPressure(gasPhaseIdx, pn);
145 fs.setPressure(gasPhaseIdx, pn + (pC[liquidPhaseIdx] - pC[gasPhaseIdx]));
146
147 assignNaive(fs);
148 }
149
153 template <class FluidState>
154 void assignMassConservative(const FluidState& fluidState,
155 const MaterialLawParams& matParams,
156 bool = false)
157 {
158 ComponentVector globalMolarities(0.0);
159 for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
160 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
161 globalMolarities[compIdx] +=
162 fluidState.molarity(phaseIdx, compIdx) * fluidState.saturation(phaseIdx);
163 }
164 }
165
166 Opm::ImmiscibleFluidState<Scalar, FluidSystem> fsFlash;
167 fsFlash.assign(fluidState);
168 typename FluidSystem::ParameterCache paramCache;
169 ImmiscibleFlash::template solve<MaterialLaw>(fsFlash, paramCache,
170 matParams,
171 globalMolarities);
172
173 assignNaive(fsFlash);
174 }
175
179 template <class FluidState>
180 void assignNaive(const FluidState& fluidState)
181 {
182 // assign the phase temperatures. this is out-sourced to
183 // the energy module
184 EnergyModule::setPriVarTemperatures(*this, fluidState);
185
186 (*this)[pressureWIdx] = fluidState.pressure(liquidPhaseIdx);
187 }
188};
189
190} // namespace Opm
191
192#endif
Represents the primary variables used by the a model.
Definition: fvbaseprimaryvariables.hh:52
Represents the primary variables used in the Richards model.
Definition: richardsprimaryvariables.hh:53
RichardsPrimaryVariables & operator=(const RichardsPrimaryVariables &value)=default
void assignMassConservative(const FluidState &fluidState, const MaterialLawParams &matParams, bool=false)
Set the primary variables from an arbitrary fluid state in a mass conservative way.
Definition: richardsprimaryvariables.hh:154
RichardsPrimaryVariables(const RichardsPrimaryVariables &value)=default
void assignNaive(const FluidState &fluidState)
Directly retrieve the primary variables from an arbitrary fluid state.
Definition: richardsprimaryvariables.hh:180
RichardsPrimaryVariables()
Definition: richardsprimaryvariables.hh:78
void assignImmiscibleFromWetting(Scalar T, Scalar pw, Scalar Sw, const MaterialLawParams &matParams)
Set the primary variables with the wetting phase pressure, saturation and temperature.
Definition: richardsprimaryvariables.hh:103
void assignImmiscibleFromNonWetting(Scalar T, Scalar pn, Scalar Sn, const MaterialLawParams &matParams)
Set the primary variables with the non-wetting phase pressure, saturation and temperature.
Definition: richardsprimaryvariables.hh:131
RichardsPrimaryVariables(Scalar value)
Constructor with assignment from scalar.
Definition: richardsprimaryvariables.hh:84
Definition: blackoilboundaryratevector.hh:37
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:242
Contains the property declarations for the Richards model.