stokesintensivequantities.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) 2010-2013 by Andreas Lauser
5  Copyright (C) 2012 by Klaus Mosthaf
6 
7  This file is part of the Open Porous Media project (OPM).
8 
9  OPM is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 2 of the License, or
12  (at your option) any later version.
13 
14  OPM is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OPM. If not, see <http://www.gnu.org/licenses/>.
21 */
27 #ifndef EWOMS_STOKES_INTENSIVE_QUANTITIES_HH
28 #define EWOMS_STOKES_INTENSIVE_QUANTITIES_HH
29 
30 #include "stokesproperties.hh"
31 
33 #include <opm/material/fluidstates/ImmiscibleFluidState.hpp>
34 #include <dune/geometry/quadraturerules.hh>
35 
36 #include <dune/common/fvector.hh>
37 
38 #include <vector>
39 
40 namespace Ewoms {
41 
48 template <class TypeTag>
50  : public GET_PROP_TYPE(TypeTag, DiscIntensiveQuantities)
51  , public EnergyIntensiveQuantities<TypeTag, GET_PROP_VALUE(TypeTag, EnableEnergy) >
52 {
53  typedef typename GET_PROP_TYPE(TypeTag, DiscIntensiveQuantities) ParentType;
54  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
55  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
56  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
57  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
58  typedef typename GET_PROP_TYPE(TypeTag, FluidState) FluidState;
59  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
60 
61  enum { numComponents = FluidSystem::numComponents };
62  enum { dim = GridView::dimension };
63  enum { dimWorld = GridView::dimensionworld };
64  enum { pressureIdx = Indices::pressureIdx };
65  enum { moleFrac1Idx = Indices::moleFrac1Idx };
66  enum { phaseIdx = GET_PROP_VALUE(TypeTag, StokesPhaseIndex) };
67  enum { enableEnergy = GET_PROP_VALUE(TypeTag, EnableEnergy) };
68 
69  typedef typename GridView::ctype CoordScalar;
70  typedef Dune::FieldVector<Scalar, dimWorld> DimVector;
71  typedef Dune::FieldVector<CoordScalar, dim> LocalPosition;
73 
74 public:
78  void update(const ElementContext &elemCtx, int dofIdx, int timeIdx)
79  {
80  ParentType::update(elemCtx, dofIdx, timeIdx);
81 
82  EnergyIntensiveQuantities::updateTemperatures_(fluidState_, elemCtx, dofIdx, timeIdx);
83 
84  const auto &priVars = elemCtx.primaryVars(dofIdx, timeIdx);
85  fluidState_.setPressure(phaseIdx, priVars[pressureIdx]);
86  Valgrind::CheckDefined(fluidState_.pressure(phaseIdx));
87 
88  // set the saturation of the phase to 1. for the stokes model,
89  // saturation is not a meaningful quanity, but it allows us to
90  // reuse infrastructure written for the porous media models
91  // more easily (e.g. the energy module)
92  fluidState_.setSaturation(phaseIdx, 1.0);
93 
94  // set the phase composition
95  Scalar sumx = 0;
96  for (int compIdx = 1; compIdx < numComponents; ++compIdx) {
97  fluidState_.setMoleFraction(phaseIdx, compIdx,
98  priVars[moleFrac1Idx + compIdx - 1]);
99  sumx += priVars[moleFrac1Idx + compIdx - 1];
100  }
101  fluidState_.setMoleFraction(phaseIdx, 0, 1 - sumx);
102 
103  // create NullParameterCache and do dummy update
104  typename FluidSystem::ParameterCache paramCache;
105  paramCache.updateAll(fluidState_);
106 
107  fluidState_.setDensity(phaseIdx, FluidSystem::density(fluidState_, paramCache, phaseIdx));
108  fluidState_.setViscosity(phaseIdx, FluidSystem::viscosity(fluidState_, paramCache, phaseIdx));
109 
110  // energy related quantities
111  EnergyIntensiveQuantities::update_(fluidState_, paramCache, elemCtx, dofIdx, timeIdx);
112 
113  // the effective velocity of the control volume
114  for (int dimIdx = 0; dimIdx < dimWorld; ++dimIdx)
115  velocityCenter_[dimIdx] = priVars[Indices::velocity0Idx + dimIdx];
116 
117  // the gravitational acceleration applying to the material
118  // inside the volume
119  gravity_ = elemCtx.problem().gravity();
120  }
121 
125  void updateScvGradients(const ElementContext &elemCtx, int dofIdx, int timeIdx)
126  {
127  // calculate the pressure gradient at the SCV using finite
128  // element gradients
129  pressureGrad_ = 0.0;
130  for (int i = 0; i < elemCtx.numDof(/*timeIdx=*/0); ++i) {
131  const auto &feGrad = elemCtx.stencil(timeIdx).subControlVolume(dofIdx).gradCenter[i];
132  Valgrind::CheckDefined(feGrad);
133  DimVector tmp(feGrad);
134  tmp *= elemCtx.intensiveQuantities(i, timeIdx).fluidState().pressure(phaseIdx);
135  Valgrind::CheckDefined(tmp);
136 
137  pressureGrad_ += tmp;
138  }
139 
140  // integrate the velocity over the sub-control volume
141  // const auto &elemGeom = elemCtx.element().geometry();
142  const auto &stencil = elemCtx.stencil(timeIdx);
143  const auto &scvLocalGeom = stencil.subControlVolume(dofIdx).localGeometry();
144 
145  Dune::GeometryType geomType = scvLocalGeom.type();
146  static const int quadratureOrder = 2;
147  const auto &rule = Dune::QuadratureRules<Scalar, dimWorld>::rule(geomType, quadratureOrder);
148 
149  // integrate the veloc over the sub-control volume
150  velocity_ = 0.0;
151  for (auto it = rule.begin(); it != rule.end(); ++it) {
152  const auto &posScvLocal = it->position();
153  const auto &posElemLocal = scvLocalGeom.global(posScvLocal);
154 
155  DimVector velocityAtPos = velocityAtPos_(elemCtx, timeIdx, posElemLocal);
156  Scalar weight = it->weight();
157  Scalar detjac = 1.0;
158  // scvLocalGeom.integrationElement(posScvLocal) *
159  // elemGeom.integrationElement(posElemLocal);
160  velocity_.axpy(weight * detjac, velocityAtPos);
161  }
162 
163  // since we want the average velocity, we have to divide the
164  // integrated value by the volume of the SCV
165  //velocity_ /= stencil.subControlVolume(dofIdx).volume;
166  }
167 
172  const FluidState &fluidState() const
173  { return fluidState_; }
174 
183  Scalar porosity() const
184  { return 1.0; }
185 
189  const DimVector &velocity() const
190  { return velocity_; }
191 
195  const DimVector &velocityCenter() const
196  { return velocityCenter_; }
197 
201  const DimVector &pressureGradient() const
202  { return pressureGrad_; }
203 
208  const DimVector &gravity() const
209  { return gravity_; }
210 
211 private:
212  DimVector velocityAtPos_(const ElementContext &elemCtx,
213  int timeIdx,
214  const LocalPosition &localPos) const
215  {
216  auto &feCache =
217  elemCtx.gradientCalculator().localFiniteElementCache();
218  const auto &localFiniteElement =
219  feCache.get(elemCtx.element().type());
220 
221  typedef Dune::FieldVector<Scalar, 1> ShapeValue;
222  std::vector<ShapeValue> shapeValue;
223 
224  localFiniteElement.localBasis().evaluateFunction(localPos, shapeValue);
225 
226  DimVector result(0.0);
227  for (int dofIdx = 0; dofIdx < elemCtx.numDof(/*timeIdx=*/0); dofIdx++) {
228  result.axpy(shapeValue[dofIdx][0], elemCtx.intensiveQuantities(dofIdx, timeIdx).velocityCenter());
229  }
230 
231  return result;
232  }
233 
234  DimVector velocity_;
235  DimVector velocityCenter_;
236  DimVector gravity_;
237  DimVector pressureGrad_;
238  FluidState fluidState_;
239 };
240 
241 } // namespace Ewoms
242 
243 #endif
const DimVector & gravity() const
Returns the gravitational acceleration vector in the sub-control volume.
Definition: stokesintensivequantities.hh:208
Provides the volumetric quantities required for the energy equation.
Definition: energymodule.hh:530
Contains the intensive quantities of the Stokes model.
Definition: stokesintensivequantities.hh:49
Declares the properties required by the Stokes model.
Scalar porosity() const
Returns the porosity of the medium.
Definition: stokesintensivequantities.hh:183
const FluidState & fluidState() const
Returns the thermodynamic state of the fluid for the control-volume.
Definition: stokesintensivequantities.hh:172
#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
void update(const ElementContext &elemCtx, int dofIdx, int timeIdx)
Definition: stokesintensivequantities.hh:78
Definition: baseauxiliarymodule.hh:35
const DimVector & velocity() const
Returns the average velocity in the sub-control volume.
Definition: stokesintensivequantities.hh:189
const DimVector & pressureGradient() const
Returns the pressure gradient in the sub-control volume.
Definition: stokesintensivequantities.hh:201
void updateScvGradients(const ElementContext &elemCtx, int dofIdx, int timeIdx)
Definition: stokesintensivequantities.hh:125
const DimVector & velocityCenter() const
Returns the velocity at the center in the sub-control volume.
Definition: stokesintensivequantities.hh:195
Contains the classes required to consider energy as a conservation quantity in a multi-phase module...