immiscibleboundaryratevector.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  Copyright (C) 2009-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
26 #ifndef EWOMS_IMMISCIBLE_BOUNDARY_RATE_VECTOR_HH
27 #define EWOMS_IMMISCIBLE_BOUNDARY_RATE_VECTOR_HH
28 
29 #include <opm/material/common/Valgrind.hpp>
30 #include <opm/material/constraintsolvers/NcpFlash.hpp>
31 
33 
34 namespace Ewoms {
35 
42 template <class TypeTag>
43 class ImmiscibleBoundaryRateVector : public GET_PROP_TYPE(TypeTag, RateVector)
44 {
45  typedef typename GET_PROP_TYPE(TypeTag, RateVector) ParentType;
46  typedef typename GET_PROP_TYPE(TypeTag, ExtensiveQuantities) ExtensiveQuantities;
47  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
48  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
49  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
50  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
51 
52  enum { numEq = GET_PROP_VALUE(TypeTag, NumEq) };
53  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
54  enum { conti0EqIdx = Indices::conti0EqIdx };
55  enum { enableEnergy = GET_PROP_VALUE(TypeTag, EnableEnergy) };
56 
57  typedef Opm::MathToolbox<Evaluation> Toolbox;
59 
60 public:
62  : ParentType()
63  {}
64 
71  ImmiscibleBoundaryRateVector(const Evaluation& value)
72  : ParentType(value)
73  {}
74 
81  : ParentType(value)
82  {}
83 
95  template <class Context, class FluidState>
96  void setFreeFlow(const Context &context, int bfIdx, int timeIdx, const FluidState &fluidState)
97  {
98  typename FluidSystem::ParameterCache paramCache;
99  paramCache.updateAll(fluidState);
100 
101  ExtensiveQuantities extQuants;
102  extQuants.updateBoundary(context, bfIdx, timeIdx, fluidState, paramCache);
103  const auto &insideIntQuants = context.intensiveQuantities(bfIdx, timeIdx);
104 
106  // advective fluxes of all components in all phases
108  (*this) = Toolbox::createConstant(0.0);
109  for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
110  Evaluation density;
111  if (fluidState.pressure(phaseIdx) > insideIntQuants.fluidState().pressure(phaseIdx))
112  density = FluidSystem::density(fluidState, paramCache, phaseIdx);
113  else
114  density = insideIntQuants.fluidState().density(phaseIdx);
115 
116  Valgrind::CheckDefined(density);
117  Valgrind::CheckDefined(extQuants.volumeFlux(phaseIdx));
118 
119  // add advective flux of current component in current
120  // phase
121  (*this)[conti0EqIdx + phaseIdx] += extQuants.volumeFlux(phaseIdx)*density;
122 
123  if (enableEnergy) {
124  Evaluation specificEnthalpy;
125  Scalar pBoundary = fluidState.pressure(phaseIdx);
126  const Evaluation& pElement = insideIntQuants.fluidState().pressure(phaseIdx);
127  if (pBoundary > pElement)
128  specificEnthalpy = FluidSystem::enthalpy(fluidState, paramCache, phaseIdx);
129  else
130  specificEnthalpy = insideIntQuants.fluidState().enthalpy(phaseIdx);
131 
132  // currently we neglect heat conduction!
133  Evaluation enthalpyRate = density*extQuants.volumeFlux(phaseIdx)*specificEnthalpy;
134  EnergyModule::addToEnthalpyRate(*this, enthalpyRate);
135  }
136  }
137 
138  EnergyModule::addToEnthalpyRate(*this, EnergyModule::heatConductionRate(extQuants));
139 
140 #ifndef NDEBUG
141  for (int i = 0; i < numEq; ++i)
142  Valgrind::CheckDefined((*this)[i]);
143  Valgrind::CheckDefined(*this);
144 #endif
145  }
146 
156  template <class Context, class FluidState>
157  void setInFlow(const Context &context, int bfIdx, int timeIdx,
158  const FluidState &fluidState)
159  {
160  this->setFreeFlow(context, bfIdx, timeIdx, fluidState);
161 
162  // we only allow fluxes in the direction opposite to the outer unit normal
163  for (int eqIdx = 0; eqIdx < numEq; ++eqIdx) {
164  Evaluation& val = this->operator[](eqIdx);
165  val = Toolbox::min(0.0, val);
166  }
167  }
168 
178  template <class Context, class FluidState>
179  void setOutFlow(const Context &context, int bfIdx, int timeIdx,
180  const FluidState &fluidState)
181  {
182  this->setFreeFlow(context, bfIdx, timeIdx, fluidState);
183 
184  // we only allow fluxes in the same direction as the outer unit normal
185  for (int eqIdx = 0; eqIdx < numEq; ++eqIdx) {
186  Evaluation &val = this->operator[](eqIdx);
187  val = Toolbox::max(0.0, val);
188  }
189  }
190 
194  void setNoFlow()
195  { (*this) = Toolbox::createConstant(0.0); }
196 };
197 
198 } // namespace Ewoms
199 
200 #endif
void setNoFlow()
Specify a no-flow boundary for all conserved quantities.
Definition: immiscibleboundaryratevector.hh:194
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:468
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:485
ImmiscibleBoundaryRateVector(const Evaluation &value)
Constructor that assigns all entries to a scalar value.
Definition: immiscibleboundaryratevector.hh:71
Provides the auxiliary methods required for consideration of the energy equation. ...
Definition: energymodule.hh:54
void setFreeFlow(const Context &context, int bfIdx, int timeIdx, const FluidState &fluidState)
Specify a free-flow boundary.
Definition: immiscibleboundaryratevector.hh:96
ImmiscibleBoundaryRateVector(const ImmiscibleBoundaryRateVector &value)
Copy constructor.
Definition: immiscibleboundaryratevector.hh:80
Definition: baseauxiliarymodule.hh:35
ImmiscibleBoundaryRateVector()
Definition: immiscibleboundaryratevector.hh:61
Implements a boundary vector for the fully implicit multi-phase model which assumes immiscibility...
Definition: immiscibleboundaryratevector.hh:43
void setOutFlow(const Context &context, int bfIdx, int timeIdx, const FluidState &fluidState)
Specify an outflow boundary.
Definition: immiscibleboundaryratevector.hh:179
void setInFlow(const Context &context, int bfIdx, int timeIdx, const FluidState &fluidState)
Specify an inflow boundary.
Definition: immiscibleboundaryratevector.hh:157
Contains the quantities which are are constant within a finite volume for the immiscible multi-phase ...