stokesboundaryratevector.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) 2012-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_STOKES_BOUNDARY_RATE_VECTOR_HH
27 #define EWOMS_STOKES_BOUNDARY_RATE_VECTOR_HH
28 
29 #include <opm/material/localad/Math.hpp>
30 #include <opm/material/common/Valgrind.hpp>
31 #include <opm/material/constraintsolvers/NcpFlash.hpp>
32 
33 #include <dune/common/fvector.hh>
34 
36 
37 namespace Ewoms {
38 
45 template <class TypeTag>
46 class StokesBoundaryRateVector : public GET_PROP_TYPE(TypeTag, RateVector)
47 {
48  typedef typename GET_PROP_TYPE(TypeTag, RateVector) ParentType;
49  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
50  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
51  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
52  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
53 
54  enum { numComponents = FluidSystem::numComponents };
55  enum { phaseIdx = GET_PROP_VALUE(TypeTag, StokesPhaseIndex) };
56  enum { dimWorld = GridView::dimensionworld };
57 
58  enum { conti0EqIdx = Indices::conti0EqIdx };
59  enum { momentum0EqIdx = Indices::momentum0EqIdx };
60  enum { enableEnergy = GET_PROP_VALUE(TypeTag, EnableEnergy) };
61 
63  typedef Dune::FieldVector<Scalar, dimWorld> DimVector;
64 
65 public:
66  StokesBoundaryRateVector() : ParentType()
67  {}
68 
73  StokesBoundaryRateVector(Scalar value) : ParentType(value)
74  {}
75 
81  : ParentType(value)
82  {}
83 
93  template <class Context, class FluidState>
94  void setFreeFlow(const Context &context, int bfIdx, int timeIdx,
95  const DimVector &velocity, const FluidState &fluidState)
96  {
97  const auto &stencil = context.stencil(timeIdx);
98  const auto &scvf = stencil.boundaryFace(bfIdx);
99 
100  int insideScvIdx = context.interiorScvIndex(bfIdx, timeIdx);
101  //const auto &insideScv = stencil.subControlVolume(insideScvIdx);
102  const auto &insideIntQuants = context.intensiveQuantities(bfIdx, timeIdx);
103 
104  // the outer unit normal
105  const auto &normal = scvf.normal();
106 
107  // distance between the center of the SCV and center of the boundary face
108  DimVector distVec = stencil.subControlVolume(insideScvIdx).geometry().center();
109  const auto &scvPos = context.element().geometry().corner(insideScvIdx);
110  distVec.axpy(-1, scvPos);
111 
112  Scalar dist = 0.0;
113  for (int dimIdx = 0; dimIdx < dimWorld; ++dimIdx)
114  dist += distVec[dimIdx] * normal[dimIdx];
115  dist = std::abs(dist);
116 
117  DimVector gradv[dimWorld];
118  for (int axisIdx = 0; axisIdx < dimWorld; ++axisIdx) {
119  // Approximation of the pressure gradient at the boundary
120  // segment's integration point.
121  gradv[axisIdx] = normal;
122  gradv[axisIdx] *= (velocity[axisIdx]
123  - insideIntQuants.velocity()[axisIdx]) / dist;
124  Valgrind::CheckDefined(gradv[axisIdx]);
125  }
126 
127  // specify the mass fluxes over the boundary
128  Scalar volumeFlux = 0;
129  for (int dimIdx = 0; dimIdx < dimWorld; ++dimIdx)
130  volumeFlux += velocity[dimIdx]*normal[dimIdx];
131 
132  typename FluidSystem::ParameterCache paramCache;
133  paramCache.updatePhase(fluidState, phaseIdx);
134  Scalar density = FluidSystem::density(fluidState, paramCache, phaseIdx);
135  Scalar molarDensity = density / fluidState.averageMolarMass(phaseIdx);
136  for (int compIdx = 0; compIdx < numComponents; ++compIdx) {
137  (*this)[conti0EqIdx + compIdx] =
138  volumeFlux
139  * molarDensity
140  * fluidState.moleFraction(phaseIdx, compIdx);
141  }
142 
143  // calculate the momentum flux over the boundary
144  for (int axisIdx = 0; axisIdx < dimWorld; ++axisIdx) {
145  // calculate a row of grad v + (grad v)^T
146  DimVector tmp(0.0);
147  for (int j = 0; j < dimWorld; ++j) {
148  tmp[j] = gradv[axisIdx][j] + gradv[j][axisIdx];
149  }
150 
151  // the momentum flux due to viscous forces
152  Scalar tmp2 = 0.0;
153  for (int dimIdx = 0; dimIdx < dimWorld; ++dimIdx)
154  tmp2 += tmp[dimIdx]*normal[dimIdx];
155 
156  (*this)[momentum0EqIdx + axisIdx] = -insideIntQuants.fluidState().viscosity(phaseIdx) * tmp2;
157  }
158 
159  EnergyModule::setEnthalpyRate(*this, fluidState, phaseIdx, volumeFlux);
160  }
161 
174  template <class Context, class FluidState>
175  void setInFlow(const Context &context, int bfIdx, int timeIdx,
176  const DimVector &velocity, const FluidState &fluidState)
177  {
178  const auto &intQuants = context.intensiveQuantities(bfIdx, timeIdx);
179 
180  setFreeFlow(context, bfIdx, timeIdx, velocity, fluidState);
181 
182  // don't let mass flow out
183  for (int compIdx = 0; compIdx < numComponents; ++compIdx)
184  (*this)[conti0EqIdx + compIdx] = std::min(0.0, (*this)[conti0EqIdx + compIdx]);
185 
186  // don't let momentum flow out
187  for (int axisIdx = 0; axisIdx < dimWorld; ++axisIdx)
188  (*this)[momentum0EqIdx + axisIdx] = std::min(0.0, (*this)[momentum0EqIdx + axisIdx]);
189  }
190 
196  template <class Context>
197  void setOutFlow(const Context &context, int spaceIdx, int timeIdx)
198  {
199  const auto &intQuants = context.intensiveQuantities(spaceIdx, timeIdx);
200 
201  DimVector velocity = intQuants.velocity();
202  const auto &fluidState = intQuants.fluidState();
203 
204  setFreeFlow(context, spaceIdx, timeIdx, velocity, fluidState);
205 
206  // don't let mass flow in
207  for (int compIdx = 0; compIdx < numComponents; ++compIdx)
208  (*this)[conti0EqIdx + compIdx] = std::max(0.0, (*this)[conti0EqIdx + compIdx]);
209 
210  // don't let momentum flow in
211  for (int axisIdx = 0; axisIdx < dimWorld; ++axisIdx)
212  (*this)[momentum0EqIdx + axisIdx] = std::max(0.0, (*this)[momentum0EqIdx + axisIdx]);
213  }
214 
220  template <class Context>
221  void setNoFlow(const Context &context, int spaceIdx, int timeIdx)
222  {
223  static DimVector v0(0.0);
224 
225  const auto &intQuants = context.intensiveQuantities(spaceIdx, timeIdx);
226  const auto &fluidState = intQuants.fluidState(); // don't care
227 
228  // no flow of mass and no slip for the momentum
229  setFreeFlow(context, spaceIdx, timeIdx,
230  /*velocity = */ v0, fluidState);
231  }
232 };
233 
234 } // namespace Ewoms
235 
236 #endif
#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 setInFlow(const Context &context, int bfIdx, int timeIdx, const DimVector &velocity, const FluidState &fluidState)
Set a in-flow boundary in the (Navier-)Stoke model.
Definition: stokesboundaryratevector.hh:175
void setNoFlow(const Context &context, int spaceIdx, int timeIdx)
Set a no-flow boundary in the (Navier-)Stoke model.
Definition: stokesboundaryratevector.hh:221
void setFreeFlow(const Context &context, int bfIdx, int timeIdx, const DimVector &velocity, const FluidState &fluidState)
Definition: stokesboundaryratevector.hh:94
Provides the auxiliary methods required for consideration of the energy equation. ...
Definition: energymodule.hh:54
void setOutFlow(const Context &context, int spaceIdx, int timeIdx)
Set a out-flow boundary in the (Navier-)Stoke model.
Definition: stokesboundaryratevector.hh:197
Definition: baseauxiliarymodule.hh:35
StokesBoundaryRateVector(const StokesBoundaryRateVector &value)
Definition: stokesboundaryratevector.hh:80
Contains the intensive quantities of the Stokes model.
StokesBoundaryRateVector(Scalar value)
Definition: stokesboundaryratevector.hh:73
StokesBoundaryRateVector()
Definition: stokesboundaryratevector.hh:66
Implements a boundary vector for the fully implicit (Navier-)Stokes model.
Definition: stokesboundaryratevector.hh:46