stokesmodel.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) 2011-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_MODEL_HH
27 #define EWOMS_STOKES_MODEL_HH
28 
29 #include "stokesproperties.hh"
30 #include "stokeslocalresidual.hh"
31 #include "stokesproblem.hh"
32 #include "stokesindices.hh"
33 #include "stokeslocalresidual.hh"
34 #include "stokesmodel.hh"
38 
39 
40 #include <opm/material/fluidsystems/GasPhase.hpp>
41 #include <opm/material/fluidsystems/LiquidPhase.hpp>
42 #include <opm/material/components/NullComponent.hpp>
43 #include <opm/material/heatconduction/FluidConduction.hpp>
44 #include <opm/material/fluidsystems/SinglePhaseFluidSystem.hpp>
45 #include <opm/material/fluidstates/CompositionalFluidState.hpp>
46 
48 
49 #include <dune/common/fvector.hh>
50 #include <dune/istl/bvector.hh>
51 
52 #include <sstream>
53 #include <string>
54 
55 namespace Ewoms {
56 template <class TypeTag>
58 
59 namespace Properties {
62 
69 NEW_TYPE_TAG(NavierStokesModel, INHERITS_FROM(StokesModel));
70 
73 {
74  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
75  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
76 
77 public:
78  static const int value = GridView::dimensionworld
79  + FluidSystem::numComponents;
80 };
81 
83 SET_INT_PROP(StokesModel, NumPhases, 1);
84 
86 SET_INT_PROP(StokesModel, NumComponents, 1);
87 
90  LocalResidual,
92 
95  BaseProblem,
97 
99 SET_SCALAR_PROP(StokesModel, NewtonRawTolerance, 1e-7);
100 
101 #if HAVE_SUPERLU
102 SET_TAG_PROP(StokesModel, LinearSolverSplice, SuperLULinearSolver);
103 #else
104 #warning "No SuperLU installed. SuperLU is the recommended linear " \
105  "solver for the Stokes models."
106 #endif
107 
110 
113 
116 
119 
121 SET_PROP(StokesModel, FluidSystem)
122 {
123 private:
124  typedef typename GET_PROP_TYPE(TypeTag, Fluid) Fluid;
125  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
126 
127 public:
128  typedef Opm::FluidSystems::SinglePhase<Scalar, Fluid> type;
129 };
130 
133 {
134 private:
135  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
136 
137 public:
138  typedef Opm::LiquidPhase<Scalar, Opm::NullComponent<Scalar> > type;
139 };
140 
142 
144 SET_PROP(StokesModel, FluidState)
145 {
146  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
147  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
148 
149 public:
150  typedef Opm::CompositionalFluidState<Scalar, FluidSystem> type;
151 };
152 
155  HeatConductionLaw,
156  Opm::FluidHeatConduction<typename GET_PROP_TYPE(TypeTag, FluidSystem),
157  typename GET_PROP_TYPE(TypeTag, Scalar),
158  GET_PROP_VALUE(TypeTag, StokesPhaseIndex)>);
159 
163  HeatConductionLawParams,
164  typename GET_PROP_TYPE(TypeTag, HeatConductionLaw)::Params);
165 
167 SET_INT_PROP(StokesModel, StokesPhaseIndex, 0);
168 
170 SET_BOOL_PROP(StokesModel, EnableEnergy, false);
171 
173 SET_BOOL_PROP(StokesModel, EnableNavierTerm, false);
174 
177 SET_BOOL_PROP(StokesModel, RequireScvCenterGradients, true);
178 
180 SET_BOOL_PROP(NavierStokesModel, EnableNavierTerm, true);
181 } // namespace Properties
182 
227 template <class TypeTag>
228 class StokesModel : public GET_PROP_TYPE(TypeTag, Discretization)
229 {
230  typedef typename GET_PROP_TYPE(TypeTag, Discretization) ParentType;
231  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
232  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
233  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
234  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
235  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
236  typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
237 
238  enum { dimWorld = GridView::dimensionworld };
239  enum { phaseIdx = GET_PROP_VALUE(TypeTag, StokesPhaseIndex) };
240  enum { numComponents = FluidSystem::numComponents };
241 
242  static const int vtkFormat = GET_PROP_VALUE(TypeTag, VtkOutputFormat);
243  typedef Ewoms::VtkMultiWriter<GridView, vtkFormat> VtkMultiWriter;
244 
245  typedef typename GridView::template Codim<0>::Iterator ElementIterator;
246  typedef typename GridView::template Codim<0>::Entity Element;
247 
248 public:
249  StokesModel(Simulator &simulator)
250  : ParentType(simulator)
251  {}
252 
258  bool phaseIsConsidered(int phaseIdxQueried) const
259  { return phaseIdxQueried == phaseIdx; }
260 
264  std::string primaryVarName(int pvIdx) const
265  {
266  std::ostringstream oss;
267  if (pvIdx == Indices::pressureIdx)
268  oss << "pressure";
269  else if (Indices::moleFrac1Idx <= pvIdx && pvIdx < Indices::moleFrac1Idx + numComponents - 1)
270  oss << "moleFraction^"
271  << FluidSystem::componentName(pvIdx - Indices::moleFrac1Idx + 1);
272  else if (Indices::velocity0Idx <= pvIdx && pvIdx < Indices::velocity0Idx + dimWorld)
273  oss << "velocity_" << pvIdx - Indices::velocity0Idx;
274  else
275  assert(false);
276 
277  return oss.str();
278  }
279 
283  std::string eqName(int eqIdx) const
284  {
285  std::ostringstream oss;
286  if (Indices::conti0EqIdx <= eqIdx && eqIdx < Indices::conti0EqIdx + numComponents)
287  oss << "continuity^"
288  << FluidSystem::componentName(eqIdx - Indices::conti0EqIdx);
289  else if (Indices::momentum0EqIdx <= eqIdx &&
290  eqIdx < Indices::momentum0EqIdx + dimWorld)
291  oss << "momentum_" << eqIdx - Indices::momentum0EqIdx;
292  else
293  assert(false);
294 
295  return oss.str();
296  }
297 
301  Scalar primaryVarWeight(int globalDofIdx, int pvIdx) const
302  {
303  // for stokes flow the pressure gradients are often quite
304  // small, so we need higher precision for pressure. TODO: find
305  // a good weight for the pressure.
306  if (Indices::pressureIdx == pvIdx) {
307  return 1e-5;
308  }
309 
310  return 1;
311  }
312 
316  void prepareOutputFields() const
317  { }
318 
323  {
324  VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&writer);
325  if (!vtkWriter)
326  return; // TODO (?): print warning
327 
328  typedef BaseOutputWriter::ScalarBuffer ScalarBuffer;
329  typedef BaseOutputWriter::VectorBuffer VectorBuffer;
330 
331  // create the required scalar fields
332  unsigned numVertices = this->gridView_.size(/*codim=*/dimWorld);
333  ScalarBuffer &pressure = *vtkWriter->allocateManagedScalarBuffer(numVertices);
334  ScalarBuffer &density = *vtkWriter->allocateManagedScalarBuffer(numVertices);
335  ScalarBuffer &temperature = *vtkWriter->allocateManagedScalarBuffer(numVertices);
336  ScalarBuffer &viscosity = *vtkWriter->allocateManagedScalarBuffer(numVertices);
337  VectorBuffer &velocity = *vtkWriter->allocateManagedVectorBuffer(/*numOuter=*/numVertices,
338  /*numInner=*/dimWorld);
339  ScalarBuffer *moleFraction[numComponents];
340  for (int compIdx = 0; compIdx < numComponents; ++compIdx)
341  moleFraction[compIdx] = vtkWriter->allocateManagedScalarBuffer(numVertices);
342 
343  // iterate over grid
344  ElementContext elemCtx(this->simulator_);
345 
346  ElementIterator elemIt = this->gridView().template begin<0>();
347  ElementIterator elemEndIt = this->gridView().template end<0>();
348  for (; elemIt != elemEndIt; ++elemIt) {
349  const Element& elem = *elemIt;
350  if (elem.partitionType() != Dune::InteriorEntity)
351  continue;
352 
353  elemCtx.updateAll(elem);
354 
355  int numScv = elemCtx.numPrimaryDof(/*timeIdx=*/0);
356  for (int dofIdx = 0; dofIdx < numScv; ++dofIdx)
357  {
358  int globalIdx = elemCtx.globalSpaceIndex(/*spaceIdx=*/dofIdx, /*timeIdx=*/0);
359  const auto &intQuants = elemCtx.intensiveQuantities(/*spaceIdx=*/dofIdx, /*timeIdx=*/0);
360  const auto &fluidState = intQuants.fluidState();
361 
362  pressure[globalIdx] = fluidState.pressure(phaseIdx);
363  density[globalIdx] = fluidState.density(phaseIdx);
364  temperature[globalIdx] = fluidState.temperature(phaseIdx);
365  viscosity[globalIdx] = fluidState.viscosity(phaseIdx);
366 
367  // this seems to be a bug in Dune's dense vector
368  // classes: It is possible to assign a DynamicVector
369  // from a scalar and also to add a FieldVector to it,
370  // but it is impossible to directly copy a FieldVector
371  // into a DynamicVector...
372  velocity[globalIdx] = 0;
373  velocity[globalIdx] += intQuants.velocityCenter();
374 
375  for (int compIdx = 0; compIdx < numComponents; ++compIdx)
376  (*moleFraction[compIdx])[globalIdx] = fluidState.moleFraction(phaseIdx, compIdx);
377  }
378  }
379 
380  std::ostringstream tmp;
381 
382  tmp.str("");
383  tmp << "pressure_" << FluidSystem::phaseName(phaseIdx);
384  vtkWriter->attachScalarVertexData(pressure, tmp.str());
385 
386  tmp.str("");
387  tmp << "density_" << FluidSystem::phaseName(phaseIdx);
388  vtkWriter->attachScalarVertexData(density, tmp.str());
389 
390  for (int compIdx = 0; compIdx < numComponents; ++compIdx) {
391  tmp.str("");
392  tmp << "moleFraction_" << FluidSystem::phaseName(phaseIdx) << "^"
393  << FluidSystem::componentName(compIdx);
394  vtkWriter->attachScalarVertexData(*moleFraction[compIdx], tmp.str());
395  }
396 
397  tmp.str("");
398  tmp << "temperature_" << FluidSystem::phaseName(phaseIdx);
399  vtkWriter->attachScalarVertexData(temperature, tmp.str());
400 
401  tmp.str("");
402  tmp << "viscosity_" << FluidSystem::phaseName(phaseIdx);
403  vtkWriter->attachScalarVertexData(viscosity, tmp.str());
404 
405  tmp.str("");
406  tmp << "velocity_" << FluidSystem::phaseName(phaseIdx);
407  vtkWriter->attachVectorVertexData(velocity, tmp.str());
408  }
409 };
410 } // namespace Ewoms
411 
412 #endif
Contains the intensive quantities of the Stokes model.
Definition: stokesintensivequantities.hh:49
Declares the properties required by the Stokes model.
VectorBuffer * allocateManagedVectorBuffer(int numOuter, int numInner)
Allocate a managed buffer for a vector field.
Definition: vtkmultiwriter.hh:160
void attachVectorVertexData(VectorBuffer &buf, std::string name)
Add a finished vertex centered vector field to the output.
Definition: vtkmultiwriter.hh:245
bool phaseIsConsidered(int phaseIdxQueried) const
Returns true iff a fluid phase is used by the model.
Definition: stokesmodel.hh:258
std::vector< Vector > VectorBuffer
Definition: baseoutputwriter.hh:48
SET_SCALAR_PROP(NumericModel, EndTime,-1e100)
The default value for the simulation's end time.
SET_TAG_PROP(FvBaseDiscretization, LinearSolverSplice, ParallelIterativeLinearSolver)
use a parallel iterative linear solver by default
std::vector< Scalar > ScalarBuffer
Definition: baseoutputwriter.hh:47
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:468
void prepareOutputFields() const
Prepare the quantities relevant for the current solution to be appended to the output writers...
Definition: stokesmodel.hh:316
The local residual function for problems using the Stokes model.
Definition: stokeslocalresidual.hh:47
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:485
void attachScalarVertexData(ScalarBuffer &buf, std::string name)
Add a finished vertex centered vector field to the output.
Definition: vtkmultiwriter.hh:186
Base class for all problems which use the Stokes model.
SET_PROP(NumericModel, ParameterTree)
Set the ParameterTree property.
Definition: basicproperties.hh:117
Implements a boundary vector for the fully implicit (Navier-)Stokes model.
SET_INT_PROP(NumericModel, GridGlobalRefinements, 0)
The base class for all output writers.
Definition: baseoutputwriter.hh:41
SET_TYPE_PROP(NumericModel, Scalar, double)
Set the default type of scalar values to double.
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:73
Definition: baseauxiliarymodule.hh:35
ScalarBuffer * allocateManagedScalarBuffer(int numEntities)
Allocate a managed buffer for a scalar field.
Definition: vtkmultiwriter.hh:147
Contains the data which is required to calculate the mass and momentum fluxes over the face of a sub-...
Definition: stokesextensivequantities.hh:52
The base class for the vertex centered finite volume discretization scheme.
Definition: vcfvdiscretization.hh:42
Contains the intensive quantities of the Stokes model.
Contains the data which is required to calculate the mass and momentum fluxes over the face of a sub-...
std::string primaryVarName(int pvIdx) const
Given an primary variable index, return a human readable name.
Definition: stokesmodel.hh:264
The local residual function for problems using the Stokes model.
Base class for all problems which use the Stokes model.
Definition: stokesproblem.hh:46
Implements a boundary vector for the fully implicit (Navier-)Stokes model.
Definition: stokesboundaryratevector.hh:46
The primary variable and equation indices of the (Navier-)Stokes model.
Definition: stokesindices.hh:42
Scalar primaryVarWeight(int globalDofIdx, int pvIdx) const
Returns the relative weight of a primary variable for calculating relative errors.
Definition: stokesmodel.hh:301
NEW_TYPE_TAG(AuxModule)
A model for the Navier-Stokes equations.
void appendOutputFields(BaseOutputWriter &writer) const
Append the quantities relevant for the current solution to an output writer.
Definition: stokesmodel.hh:322
std::string eqName(int eqIdx) const
Given an equation index, return a human readable name.
Definition: stokesmodel.hh:283
SET_BOOL_PROP(FvBaseDiscretization, EnableVtkOutput, true)
Enable the VTK output by default.
The primary variable and equation indices of the (Navier-)Stokes model.
#define INHERITS_FROM(...)
Syntactic sugar for NEW_TYPE_TAG.
Definition: propertysystem.hh:229
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:61
StokesModel(Simulator &simulator)
Definition: stokesmodel.hh:249
A model for the Navier-Stokes equations.
Definition: stokesmodel.hh:57