All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
multiphasebaseproblem.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_PROBLEM_HH
29 #define EWOMS_MULTI_PHASE_BASE_PROBLEM_HH
30 
32 
35 
36 #include <opm/material/fluidmatrixinteractions/NullMaterial.hpp>
37 #include <opm/material/common/Means.hpp>
38 #include <opm/common/Unused.hpp>
39 #include <opm/common/ErrorMacros.hpp>
40 #include <opm/common/Exceptions.hpp>
41 
42 #include <dune/common/fvector.hh>
43 #include <dune/common/fmatrix.hh>
44 
45 namespace Ewoms {
46 namespace Properties {
47 NEW_PROP_TAG(HeatConductionLawParams);
48 NEW_PROP_TAG(EnableGravity);
49 NEW_PROP_TAG(FluxModule);
50 }
51 
58 template<class TypeTag>
60  : public FvBaseProblem<TypeTag>
61  , public GET_PROP_TYPE(TypeTag, FluxModule)::FluxBaseProblem
62 {
64  typedef Ewoms::FvBaseProblem<TypeTag> ParentType;
65 
66  typedef typename GET_PROP_TYPE(TypeTag, Problem) Implementation;
67  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
68  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
69  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
70  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
71  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
72  typedef typename GET_PROP_TYPE(TypeTag, HeatConductionLawParams) HeatConductionLawParams;
73  typedef typename GET_PROP_TYPE(TypeTag, MaterialLaw)::Params MaterialLawParams;
74 
75  enum { dimWorld = GridView::dimensionworld };
76  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
77  typedef Dune::FieldVector<Scalar, dimWorld> DimVector;
78  typedef Dune::FieldMatrix<Scalar, dimWorld, dimWorld> DimMatrix;
80 
81 public:
86  : ParentType(simulator)
87  { init_(); }
88 
92  static void registerParameters()
93  {
94  ParentType::registerParameters();
95 
96  EWOMS_REGISTER_PARAM(TypeTag, bool, EnableGravity,
97  "Use the gravity correction for the pressure gradients.");
98  }
99 
109  template <class Context>
110  void intersectionIntrinsicPermeability(DimMatrix& result,
111  const Context& context,
112  unsigned intersectionIdx,
113  unsigned timeIdx) const
114  {
115  const auto& scvf = context.stencil(timeIdx).interiorFace(intersectionIdx);
116 
117  const DimMatrix& K1 = asImp_().intrinsicPermeability(context, scvf.interiorIndex(), timeIdx);
118  const DimMatrix& K2 = asImp_().intrinsicPermeability(context, scvf.exteriorIndex(), timeIdx);
119 
120  // entry-wise harmonic mean. this is almost certainly wrong if
121  // you have off-main diagonal entries in your permeabilities!
122  for (unsigned i = 0; i < dimWorld; ++i)
123  for (unsigned j = 0; j < dimWorld; ++j)
124  result[i][j] = Opm::harmonicMean(K1[i][j], K2[i][j]);
125  }
126 
130  // \{
131 
140  template <class Context>
141  const DimMatrix& intrinsicPermeability(const Context& context OPM_UNUSED,
142  unsigned spaceIdx OPM_UNUSED,
143  unsigned timeIdx OPM_UNUSED) const
144  {
145  OPM_THROW(std::logic_error,
146  "Not implemented: Problem::intrinsicPermeability()");
147  }
148 
158  template <class Context>
159  Scalar porosity(const Context& context OPM_UNUSED,
160  unsigned spaceIdx OPM_UNUSED,
161  unsigned timeIdx OPM_UNUSED) const
162  {
163  OPM_THROW(std::logic_error,
164  "Not implemented: Problem::porosity()");
165  }
166 
176  template <class Context>
177  Scalar heatCapacitySolid(const Context& context OPM_UNUSED,
178  unsigned spaceIdx OPM_UNUSED,
179  unsigned timeIdx OPM_UNUSED) const
180  {
181  OPM_THROW(std::logic_error,
182  "Not implemented: Problem::heatCapacitySolid()");
183  }
184 
194  template <class Context>
195  const HeatConductionLawParams&
196  heatConductionParams(const Context& context OPM_UNUSED,
197  unsigned spaceIdx OPM_UNUSED,
198  unsigned timeIdx OPM_UNUSED) const
199  {
200  OPM_THROW(std::logic_error,
201  "Not implemented: Problem::heatConductionParams()");
202  }
203 
212  template <class Context>
213  Scalar tortuosity(const Context& context OPM_UNUSED,
214  unsigned spaceIdx OPM_UNUSED,
215  unsigned timeIdx OPM_UNUSED) const
216  {
217  OPM_THROW(std::logic_error,
218  "Not implemented: Problem::tortuosity()");
219  }
220 
229  template <class Context>
230  Scalar dispersivity(const Context& context OPM_UNUSED,
231  unsigned spaceIdx OPM_UNUSED,
232  unsigned timeIdx OPM_UNUSED) const
233  {
234  OPM_THROW(std::logic_error,
235  "Not implemented: Problem::dispersivity()");
236  }
237 
251  template <class Context>
252  const MaterialLawParams &
253  materialLawParams(const Context& context OPM_UNUSED,
254  unsigned spaceIdx OPM_UNUSED,
255  unsigned timeIdx OPM_UNUSED) const
256  {
257  static MaterialLawParams dummy;
258  return dummy;
259  }
260 
269  template <class Context>
270  Scalar temperature(const Context& context OPM_UNUSED,
271  unsigned spaceIdx OPM_UNUSED,
272  unsigned timeIdx OPM_UNUSED) const
273  { return asImp_().temperature(); }
274 
282  Scalar temperature() const
283  { OPM_THROW(std::logic_error,
284  "Not implemented:temperature() method not implemented by the actual problem"); }
285 
286 
295  template <class Context>
296  const DimVector& gravity(const Context& context OPM_UNUSED,
297  unsigned spaceIdx OPM_UNUSED,
298  unsigned timeIdx OPM_UNUSED) const
299  { return asImp_().gravity(); }
300 
310  const DimVector& gravity() const
311  { return gravity_; }
312 
319  {
320  typedef Opm::MathToolbox<Evaluation> Toolbox;
321 
322  unsigned numMarked = 0;
323  ElementContext elemCtx( this->simulator() );
324  auto gridView = this->simulator().gridManager().gridView();
325  auto& grid = this->simulator().gridManager().grid();
326  auto elemIt = gridView.template begin</*codim=*/0, Dune::Interior_Partition>();
327  auto elemEndIt = gridView.template end</*codim=*/0, Dune::Interior_Partition>();
328  for (; elemIt != elemEndIt; ++elemIt)
329  {
330  const auto& element = *elemIt ;
331  elemCtx.updateAll( element );
332 
333  // HACK: this should better be part of an AdaptionCriterion class
334  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
335  Scalar minSat = 1e100 ;
336  Scalar maxSat = -1e100;
337  size_t nDofs = elemCtx.numDof(/*timeIdx=*/0);
338  for (unsigned dofIdx = 0; dofIdx < nDofs; ++dofIdx)
339  {
340  const auto& intQuant = elemCtx.intensiveQuantities( dofIdx, /*timeIdx=*/0 );
341  minSat = std::min(minSat,
342  Toolbox::value(intQuant.fluidState().saturation(phaseIdx)));
343  maxSat = std::max(maxSat,
344  Toolbox::value(intQuant.fluidState().saturation(phaseIdx)));
345  }
346 
347  const Scalar indicator =
348  (maxSat - minSat)/(std::max<Scalar>(0.01, maxSat+minSat)/2);
349  if( indicator > 0.2 && element.level() < 2 ) {
350  grid.mark( 1, element );
351  ++ numMarked;
352  }
353  else if ( indicator < 0.025 ) {
354  grid.mark( -1, element );
355  ++ numMarked;
356  }
357  else
358  {
359  grid.mark( 0, element );
360  }
361  }
362  }
363 
364  // get global sum so that every proc is on the same page
365  numMarked = this->simulator().gridManager().grid().comm().sum( numMarked );
366 
367  return numMarked;
368  }
369 
370  // \}
371 
372 protected:
383  DimMatrix toDimMatrix_(Scalar val) const
384  {
385  DimMatrix ret(0.0);
386  for (unsigned i = 0; i < DimMatrix::rows; ++i)
387  ret[i][i] = val;
388  return ret;
389  }
390 
391  DimVector gravity_;
392 
393 private:
395  Implementation& asImp_()
396  { return *static_cast<Implementation *>(this); }
398  const Implementation& asImp_() const
399  { return *static_cast<const Implementation *>(this); }
400 
401  void init_()
402  {
403  gravity_ = 0.0;
404  if (EWOMS_GET_PARAM(TypeTag, bool, EnableGravity))
405  gravity_[dimWorld-1] = -9.81;
406  }
407 };
408 
409 } // namespace Ewoms
410 
411 #endif
const HeatConductionLawParams & heatConductionParams(const Context &context OPM_UNUSED, unsigned spaceIdx OPM_UNUSED, unsigned timeIdx OPM_UNUSED) const
Returns the parameter object for the heat conductivity law in a sub-control volume.
Definition: multiphasebaseproblem.hh:196
const DimVector & gravity(const Context &context OPM_UNUSED, unsigned spaceIdx OPM_UNUSED, unsigned timeIdx OPM_UNUSED) const
Returns the acceleration due to gravity .
Definition: multiphasebaseproblem.hh:296
static void registerParameters()
Register all run-time parameters for the problem and the model.
Definition: multiphasebaseproblem.hh:92
Scalar porosity(const Context &context OPM_UNUSED, unsigned spaceIdx OPM_UNUSED, unsigned timeIdx OPM_UNUSED) const
Returns the porosity [] of the porous medium for a given control volume.
Definition: multiphasebaseproblem.hh:159
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:469
Scalar tortuosity(const Context &context OPM_UNUSED, unsigned spaceIdx OPM_UNUSED, unsigned timeIdx OPM_UNUSED) const
Define the tortuosity.
Definition: multiphasebaseproblem.hh:213
Scalar dispersivity(const Context &context OPM_UNUSED, unsigned spaceIdx OPM_UNUSED, unsigned timeIdx OPM_UNUSED) const
Define the dispersivity.
Definition: multiphasebaseproblem.hh:230
Defines the common properties required by the porous medium multi-phase models.
const MaterialLawParams & materialLawParams(const Context &context OPM_UNUSED, unsigned spaceIdx OPM_UNUSED, unsigned timeIdx OPM_UNUSED) const
Returns the material law parameters within a control volume.
Definition: multiphasebaseproblem.hh:253
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:486
Base class for all problems which use a finite volume spatial discretization.
MultiPhaseBaseProblem(Simulator &simulator)
Definition: multiphasebaseproblem.hh:85
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:68
Scalar temperature() const
Returns the temperature for an isothermal problem.
Definition: multiphasebaseproblem.hh:282
DimMatrix toDimMatrix_(Scalar val) const
Converts a Scalar value to an isotropic Tensor.
Definition: multiphasebaseproblem.hh:383
GridManager & gridManager()
Return a reference to the grid manager of simulation.
Definition: simulator.hh:171
Declare the properties used by the infrastructure code of the finite volume discretizations.
const DimVector & gravity() const
Returns the acceleration due to gravity .
Definition: multiphasebaseproblem.hh:310
const DimMatrix & intrinsicPermeability(const Context &context OPM_UNUSED, unsigned spaceIdx OPM_UNUSED, unsigned timeIdx OPM_UNUSED) const
Returns the intrinsic permeability tensor at a given position.
Definition: multiphasebaseproblem.hh:141
const GridView & gridView() const
The GridView which used by the problem.
Definition: fvbaseproblem.hh:494
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:99
Scalar temperature(const Context &context OPM_UNUSED, unsigned spaceIdx OPM_UNUSED, unsigned timeIdx OPM_UNUSED) const
Returns the temperature within a control volume.
Definition: multiphasebaseproblem.hh:270
void intersectionIntrinsicPermeability(DimMatrix &result, const Context &context, unsigned intersectionIdx, unsigned timeIdx) const
Returns the intrinsic permeability of an intersection.
Definition: multiphasebaseproblem.hh:110
Simulator & simulator()
Returns Simulator object used by the simulation.
Definition: fvbaseproblem.hh:526
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:75
#define NEW_PROP_TAG(PTagName)
Define a property tag.
Definition: propertysystem.hh:247
The base class for the problems of ECFV discretizations which deal with a multi-phase flow through a ...
Definition: multiphasebaseproblem.hh:59
Scalar heatCapacitySolid(const Context &context OPM_UNUSED, unsigned spaceIdx OPM_UNUSED, unsigned timeIdx OPM_UNUSED) const
Returns the heat capacity [J/(K m^3)] of the solid phase with no pores in the sub-control volume...
Definition: multiphasebaseproblem.hh:177
Base class for all problems which use a finite volume spatial discretization.
Definition: fvbaseproblem.hh:59
unsigned markForGridAdaptation()
Mark grid cells for refinement or coarsening.
Definition: multiphasebaseproblem.hh:318