All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
multiphasebasemodel.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_MULTI_PHASE_BASE_MODEL_HH
29 #define EWOMS_MULTI_PHASE_BASE_MODEL_HH
30 
31 #include <opm/material/densead/Math.hpp>
32 
34 #include "multiphasebaseproblem.hh"
36 
39 
40 #include <opm/material/fluidmatrixinteractions/NullMaterial.hpp>
41 #include <opm/material/fluidmatrixinteractions/MaterialTraits.hpp>
42 #include <opm/material/heatconduction/DummyHeatConductionLaw.hpp>
43 #include <opm/common/Unused.hpp>
44 
45 namespace Ewoms {
46 template <class TypeTag>
48 }
49 
50 namespace Ewoms {
51 namespace Properties {
53 NEW_TYPE_TAG(MultiPhaseBaseModel, INHERITS_FROM(VtkMultiPhase, VtkTemperature));
54 
56 SET_SPLICES(MultiPhaseBaseModel, SpatialDiscretizationSplice);
57 
61 SET_TAG_PROP(MultiPhaseBaseModel, SpatialDiscretizationSplice, VcfvDiscretization);
62 
64 SET_INT_PROP(MultiPhaseBaseModel, NumEq, GET_PROP_TYPE(TypeTag, Indices)::numEq);
66 SET_INT_PROP(MultiPhaseBaseModel, NumPhases, GET_PROP_TYPE(TypeTag, FluidSystem)::numPhases);
68 SET_INT_PROP(MultiPhaseBaseModel, NumComponents, GET_PROP_TYPE(TypeTag, FluidSystem)::numComponents);
69 
72 
75 
79 SET_PROP(MultiPhaseBaseModel, MaterialLaw)
80 {
81 private:
82  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
83  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
84  typedef Opm::NullMaterialTraits<Scalar, FluidSystem::numPhases> Traits;
85 
86 public:
87  typedef Opm::NullMaterial<Traits> type;
88 };
89 
95  MaterialLawParams,
96  typename GET_PROP_TYPE(TypeTag, MaterialLaw)::Params);
97 
99 SET_TYPE_PROP(MultiPhaseBaseModel,
100  HeatConductionLaw,
101  Opm::DummyHeatConductionLaw<typename GET_PROP_TYPE(TypeTag, Scalar)>);
102 
105 SET_TYPE_PROP(MultiPhaseBaseModel,
106  HeatConductionLawParams,
107  typename GET_PROP_TYPE(TypeTag, HeatConductionLaw)::Params);
108 
110 SET_BOOL_PROP(MultiPhaseBaseModel, EnableGravity, false);
111 
112 } // namespace Properties
113 
119 template <class TypeTag>
120 class MultiPhaseBaseModel : public GET_PROP_TYPE(TypeTag, Discretization)
121 {
122  typedef typename GET_PROP_TYPE(TypeTag, Discretization) ParentType;
123  typedef typename GET_PROP_TYPE(TypeTag, Model) Implementation;
124  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
125  typedef typename GET_PROP_TYPE(TypeTag, ThreadManager) ThreadManager;
126  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
127  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
128  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
129  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
130  typedef typename GET_PROP_TYPE(TypeTag, EqVector) EqVector;
131  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
132 
133  typedef typename GridView::template Codim<0>::Iterator ElementIterator;
134  typedef typename GridView::template Codim<0>::Entity Element;
135 
136  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
137  enum { numComponents = FluidSystem::numComponents };
138 
139 public:
140  MultiPhaseBaseModel(Simulator& simulator)
141  : ParentType(simulator)
142  { }
143 
147  static void registerParameters()
148  {
149  ParentType::registerParameters();
150 
151  // register runtime parameters of the VTK output modules
154  }
155 
159  void finishInit()
160  {
161  ParentType::finishInit();
162 
163  // Reduce the Newton tolerance by the volume of smallest degree of freedom. (For
164  // large grids the tolerance needs to be reduced because the total mass lost
165  // would be too large.)
166  Scalar minDofVolume = 1e100;
167  for (unsigned globalDofIdx = 0; globalDofIdx < this->numGridDof(); ++ globalDofIdx)
168  if (this->isLocalDof(globalDofIdx))
169  minDofVolume = std::min(minDofVolume, this->dofTotalVolume(globalDofIdx));
170  minDofVolume = this->gridView().comm().min(minDofVolume);
171 
172  Scalar newtonTolerance = EWOMS_GET_PARAM(TypeTag, Scalar, NewtonRawTolerance);
173  newtonTolerance /= std::sqrt(minDofVolume);
174  this->newtonMethod().setTolerance(newtonTolerance);
175  }
176 
182  bool phaseIsConsidered(unsigned phaseIdx OPM_UNUSED) const
183  { return true; }
184 
192  void globalPhaseStorage(EqVector& storage, unsigned phaseIdx)
193  {
194  assert(0 <= phaseIdx && phaseIdx < numPhases);
195 
196  storage = 0;
197 
198  ThreadedEntityIterator<GridView, /*codim=*/0> threadedElemIt(this->gridView());
199  OmpMutex addMutex;
200 #ifdef _OPENMP
201 #pragma omp parallel
202 #endif
203  {
204  // Attention: the variables below are thread specific and thus cannot be
205  // moved in front of the #pragma!
206  unsigned threadId = ThreadManager::threadId();
207  ElementContext elemCtx(this->simulator_);
208  ElementIterator elemIt = threadedElemIt.beginParallel();
209  EqVector tmp;
210 
211  for (; !threadedElemIt.isFinished(elemIt); elemIt = threadedElemIt.increment()) {
212  const Element& elem = *elemIt;
213  if (elem.partitionType() != Dune::InteriorEntity)
214  continue; // ignore ghost and overlap elements
215 
216  elemCtx.updateStencil(elem);
217  elemCtx.updateIntensiveQuantities(/*timeIdx=*/0);
218 
219  const auto& stencil = elemCtx.stencil(/*timeIdx=*/0);
220 
221  for (unsigned dofIdx = 0; dofIdx < elemCtx.numDof(/*timeIdx=*/0); ++dofIdx) {
222  const auto& scv = stencil.subControlVolume(dofIdx);
223  const auto& intQuants = elemCtx.intensiveQuantities(dofIdx, /*timeIdx=*/0);
224 
225  tmp = 0;
226  this->localResidual(threadId).addPhaseStorage(tmp,
227  elemCtx,
228  dofIdx,
229  /*timeIdx=*/0,
230  phaseIdx);
231  tmp *= scv.volume()*intQuants.extrusionFactor();
232 
233  OmpMutex addLock(addMutex);
234  storage += tmp;
235  addLock.unlock();
236  }
237  }
238  }
239 
240  storage = this->gridView_.comm().sum(storage);
241  }
242 
243  void registerOutputModules_()
244  {
245  ParentType::registerOutputModules_();
246 
247  // add the VTK output modules which make sense for all multi-phase models
248  this->addOutputModule(new Ewoms::VtkMultiPhaseModule<TypeTag>(this->simulator_));
249  this->addOutputModule(new Ewoms::VtkTemperatureModule<TypeTag>(this->simulator_));
250  }
251 
252 private:
253  const Implementation& asImp_() const
254  { return *static_cast<const Implementation *>(this); }
255 };
256 } // namespace Ewoms
257 
258 #endif
This file contains the necessary classes to calculate the velocity out of a pressure potential gradie...
#define SET_BOOL_PROP(EffTypeTagName, PropTagName,...)
Set a property to a simple constant boolean value.
Definition: propertysystem.hh:361
Specifies a flux module which uses the Darcy relation.
Definition: darcyfluxmodule.hh:65
Simplifies multi-threaded capabilities.
Definition: threadmanager.hh:52
The base class for the vertex centered finite volume discretization scheme.
Definition: vcfvdiscretization.hh:49
VTK output module for quantities which make sense for all models which deal with multiple fluid phase...
Definition: vtkmultiphasemodule.hh:99
Definition: locks.hh:54
Provides an STL-iterator like interface to iterate over the enties of a GridView in OpenMP threaded a...
Definition: threadedentityiterator.hh:41
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:469
Defines the common properties required by the porous medium multi-phase models.
#define NEW_TYPE_TAG(...)
Define a new type tag.
Definition: propertysystem.hh:169
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:486
#define SET_TAG_PROP(EffTypeTagName, PropTagName, ValueTypeTagName)
Define a property containing a type tag.
Definition: propertysystem.hh:436
#define INHERITS_FROM(...)
Syntactic sugar for NEW_TYPE_TAG.
Definition: propertysystem.hh:230
#define SET_INT_PROP(EffTypeTagName, PropTagName,...)
Set a property to a simple constant integer value.
Definition: propertysystem.hh:345
static unsigned threadId()
Return the index of the current OpenMP thread.
Definition: threadmanager.hh:119
The base class for the vertex centered finite volume discretization scheme.
void finishInit()
Apply the initial conditions to the model.
Definition: multiphasebasemodel.hh:159
#define SET_SPLICES(TypeTagName,...)
Define splices for a given type tag.
Definition: propertysystem.hh:213
VTK output module for the temperature in which assume thermal equilibrium.
Definition: vtktemperaturemodule.hh:59
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtktemperaturemodule.hh:82
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:99
bool phaseIsConsidered(unsigned phaseIdx OPM_UNUSED) const
Returns true iff a fluid phase is used by the model.
Definition: multiphasebasemodel.hh:182
#define SET_PROP(EffTypeTagName, PropTagName)
Set a property for a specific type tag.
Definition: propertysystem.hh:297
void globalPhaseStorage(EqVector &storage, unsigned phaseIdx)
Compute the total storage inside one phase of all conservation quantities.
Definition: multiphasebasemodel.hh:192
This class calculates the pressure potential gradients and the filter velocities for multi-phase flow...
static void registerParameters()
Register all run-time parameters for the multi-phase VTK output module.
Definition: vtkmultiphasemodule.hh:137
static void registerParameters()
Register all run-time parameters for the immiscible model.
Definition: multiphasebasemodel.hh:147
A base class for fully-implicit multi-phase porous-media flow models which assume multiple fluid phas...
Definition: multiphasebasemodel.hh:47
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:75
The base class for the problems of ECFV discretizations which deal with a multi-phase flow through a ...
Definition: multiphasebaseproblem.hh:59
#define SET_TYPE_PROP(EffTypeTagName, PropTagName,...)
Set a property which defines a type.
Definition: propertysystem.hh:377
The base class for the problems of ECFV discretizations which deal with a multi-phase flow through a ...