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 <dune/common/fvector.hh>
32
33#include <opm/material/common/Valgrind.hpp>
34#include <opm/material/constraintsolvers/ImmiscibleFlash.hpp>
35#include <opm/material/fluidstates/ImmiscibleFluidState.hpp>
36
38
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 = MathToolbox<Evaluation>;
75 using ImmiscibleFlash = ::Opm::ImmiscibleFlash<Scalar, FluidSystem>;
76
77public:
79 : ParentType()
80 { Opm::Valgrind::SetUndefined(*this); }
81
88
89 using ParentType::operator=;
90
100 void assignImmiscibleFromWetting(Scalar T, Scalar pw, Scalar Sw,
101 const MaterialLawParams& matParams)
102 {
103 ImmiscibleFluidState<Scalar, FluidSystem> fs;
104
105 fs.setTemperature(T);
106 fs.setSaturation(liquidPhaseIdx, Sw);
107 fs.setSaturation(gasPhaseIdx, 1 - Sw);
108
109 // set phase pressures
110 PhaseVector pC;
111 MaterialLaw::capillaryPressures(pC, matParams, fs);
112
113 fs.setPressure(liquidPhaseIdx, pw);
114 fs.setPressure(gasPhaseIdx, pw + (pC[gasPhaseIdx] - pC[liquidPhaseIdx]));
115
116 assignNaive(fs);
117 }
118
128 void assignImmiscibleFromNonWetting(Scalar T, Scalar pn, Scalar Sn,
129 const MaterialLawParams& matParams)
130 {
131 Opm::ImmiscibleFluidState<Scalar, FluidSystem> fs;
132
133 fs.setTemperature(T);
134 fs.setSaturation(liquidPhaseIdx, 1 - Sn);
135 fs.setSaturation(gasPhaseIdx, Sn);
136
137 // set phase pressures
138 PhaseVector pC;
139 MaterialLaw::capillaryPressures(pC, matParams, fs);
140
141 fs.setPressure(gasPhaseIdx, pn);
142 fs.setPressure(gasPhaseIdx, pn + (pC[liquidPhaseIdx] - pC[gasPhaseIdx]));
143
144 assignNaive(fs);
145 }
146
150 template <class FluidState>
151 void assignMassConservative(const FluidState& fluidState,
152 const MaterialLawParams& matParams,
153 bool = false)
154 {
155 ComponentVector globalMolarities(0.0);
156 for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
157 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
158 globalMolarities[compIdx] +=
159 fluidState.molarity(phaseIdx, compIdx) * fluidState.saturation(phaseIdx);
160 }
161 }
162
163 ImmiscibleFluidState<Scalar, FluidSystem> fsFlash;
164 fsFlash.assign(fluidState);
165 typename FluidSystem::ParameterCache paramCache;
166 ImmiscibleFlash::template solve<MaterialLaw>(fsFlash, paramCache,
167 matParams,
168 globalMolarities);
169
170 assignNaive(fsFlash);
171 }
172
176 template <class FluidState>
177 void assignNaive(const FluidState& fluidState)
178 {
179 // assign the phase temperatures. this is out-sourced to
180 // the energy module
181 EnergyModule::setPriVarTemperatures(*this, fluidState);
182
183 (*this)[pressureWIdx] = fluidState.pressure(liquidPhaseIdx);
184 }
185};
186
187} // namespace Opm
188
189#endif
Represents the primary variables used by the a model.
Definition: fvbaseprimaryvariables.hh:53
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)
< Import base class assignment operators.
Definition: richardsprimaryvariables.hh:151
RichardsPrimaryVariables(const RichardsPrimaryVariables &value)=default
void assignNaive(const FluidState &fluidState)
Directly retrieve the primary variables from an arbitrary fluid state.
Definition: richardsprimaryvariables.hh:177
RichardsPrimaryVariables()
Definition: richardsprimaryvariables.hh:78
void assignImmiscibleFromWetting(Scalar T, Scalar pw, Scalar Sw, const MaterialLawParams &matParams)
< Import base class assignment operators.
Definition: richardsprimaryvariables.hh:100
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:128
Definition: blackoilboundaryratevector.hh:39
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
Contains the property declarations for the Richards model.