vtkblackoilmodule.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 */
25 #ifndef EWOMS_VTK_BLACK_OIL_MODULE_HH
26 #define EWOMS_VTK_BLACK_OIL_MODULE_HH
27 
28 #include <opm/material/localad/Math.hpp>
29 
30 #include "vtkmultiwriter.hh"
31 #include "baseoutputmodule.hh"
32 
36 
37 #include <dune/common/fvector.hh>
38 
39 #include <cstdio>
40 
41 namespace Ewoms {
42 namespace Properties {
43 // create new type tag for the VTK multi-phase output
44 NEW_TYPE_TAG(VtkBlackOil);
45 
46 // create the property tags needed for the multi phase module
47 NEW_PROP_TAG(VtkWriteGasDissolutionFactor);
48 NEW_PROP_TAG(VtkWriteSaturatedOilGasDissolutionFactor);
49 NEW_PROP_TAG(VtkWriteGasFormationVolumeFactor);
50 NEW_PROP_TAG(VtkWriteOilFormationVolumeFactor);
51 NEW_PROP_TAG(VtkWriteOilSaturationPressure);
52 NEW_PROP_TAG(VtkOutputFormat);
53 
54 // set default values for what quantities to output
55 SET_BOOL_PROP(VtkBlackOil, VtkWriteGasDissolutionFactor, false);
56 SET_BOOL_PROP(VtkBlackOil, VtkWriteSaturatedOilGasDissolutionFactor, false);
57 SET_BOOL_PROP(VtkBlackOil, VtkWriteGasFormationVolumeFactor, false);
58 SET_BOOL_PROP(VtkBlackOil, VtkWriteOilFormationVolumeFactor, false);
59 SET_BOOL_PROP(VtkBlackOil, VtkWriteOilSaturationPressure, false);
60 } // namespace Properties
61 } // namespace Ewoms
62 
63 namespace Ewoms {
69 template <class TypeTag>
70 class VtkBlackOilModule : public BaseOutputModule<TypeTag>
71 {
73 
74  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
75  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
76  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
77  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
78 
79  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
80  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
81 
82  static const int vtkFormat = GET_PROP_VALUE(TypeTag, VtkOutputFormat);
84 
85  enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
86  enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
87  enum { gasCompIdx = FluidSystem::gasCompIdx };
88  enum { oilCompIdx = FluidSystem::oilCompIdx };
89 
90  typedef typename ParentType::ScalarBuffer ScalarBuffer;
91 
92 public:
93  VtkBlackOilModule(const Simulator &simulator)
94  : ParentType(simulator)
95  { }
96 
101  static void registerParameters()
102  {
103  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteGasDissolutionFactor,
104  "Include the gas dissolution factor (R_s) of the observed oil "
105  "in the VTK output files");
106  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteSaturatedOilGasDissolutionFactor,
107  "Include the gas dissolution factor (R_s,sat) of gas saturated "
108  "oil in the VTK output files");
109  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteGasFormationVolumeFactor,
110  "Include the gas formation volume factor (B_g) in the "
111  "VTK output files");
112  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteOilFormationVolumeFactor,
113  "Include the oil formation volume factor (B_o) of gas saturated "
114  "oil in the VTK output files");
115  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteOilSaturationPressure,
116  "Include the saturation pressure of oil in the "
117  "VTK output files");
118  }
119 
125  {
126  if (gasDissolutionFactorOutput_())
127  this->resizeScalarBuffer_(gasDissolutionFactor_);
128  if (saturatedOilGasDissolutionFactorOutput_())
129  this->resizeScalarBuffer_(saturatedOilGasDissolutionFactor_);
130  if (gasFormationVolumeFactorOutput_())
131  this->resizeScalarBuffer_(gasFormationVolumeFactor_);
132  if (saturatedOilFormationVolumeFactorOutput_())
133  this->resizeScalarBuffer_(saturatedOilFormationVolumeFactor_);
134  if (oilSaturationPressureOutput_())
135  this->resizeScalarBuffer_(oilSaturationPressure_);
136  }
137 
142  void processElement(const ElementContext &elemCtx)
143  {
144  typedef Opm::MathToolbox<Evaluation> Toolbox;
145 
146  for (int dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) {
147  const auto &fs = elemCtx.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState();
148  int globalDofIdx = elemCtx.globalSpaceIndex(dofIdx, /*timeIdx=*/0);
149  Scalar po = Toolbox::value(fs.pressure(oilPhaseIdx));
150  Scalar To = Toolbox::value(fs.temperature(oilPhaseIdx));
151  Scalar X_oG = Toolbox::value(fs.massFraction(oilPhaseIdx, gasCompIdx));
152  Scalar X_gO = Toolbox::value(fs.massFraction(gasPhaseIdx, oilCompIdx));
153  int regionIdx = elemCtx.primaryVars(dofIdx, /*timeIdx=*/0).pvtRegionIndex();
154  Scalar rhooRef = FluidSystem::referenceDensity(oilPhaseIdx, regionIdx);
155  Scalar rhogRef = FluidSystem::referenceDensity(gasPhaseIdx, regionIdx);
156 
157  if (gasDissolutionFactorOutput_())
158  gasDissolutionFactor_[globalDofIdx] = X_oG / rhogRef * rhooRef / (1 - X_oG);
159  if (saturatedOilGasDissolutionFactorOutput_())
160  saturatedOilGasDissolutionFactor_[globalDofIdx] =
161  FluidSystem::template gasDissolutionFactor<Scalar>(To, po, regionIdx);
162  if (gasFormationVolumeFactorOutput_())
163  gasFormationVolumeFactor_[globalDofIdx] =
164  FluidSystem::gasFormationVolumeFactor(To, po, X_gO, regionIdx);
165  if (saturatedOilFormationVolumeFactorOutput_())
166  saturatedOilFormationVolumeFactor_[globalDofIdx] =
167  FluidSystem::saturatedOilFormationVolumeFactor(To, po, regionIdx);
168  if (oilSaturationPressureOutput_())
169  oilSaturationPressure_[globalDofIdx] =
170  FluidSystem::oilSaturationPressure(To, X_oG, regionIdx);
171  }
172  }
173 
177  void commitBuffers(BaseOutputWriter &baseWriter)
178  {
179  VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
180  if (!vtkWriter)
181  return;
182 
183  if (gasDissolutionFactorOutput_())
184  this->commitScalarBuffer_(baseWriter, "R_s", gasDissolutionFactor_);
185  if (saturatedOilGasDissolutionFactorOutput_())
186  this->commitScalarBuffer_(baseWriter, "R_s,sat", saturatedOilGasDissolutionFactor_);
187  if (gasFormationVolumeFactorOutput_())
188  this->commitScalarBuffer_(baseWriter, "B_g", gasFormationVolumeFactor_);
189  if (saturatedOilFormationVolumeFactorOutput_())
190  this->commitScalarBuffer_(baseWriter, "B_o", saturatedOilFormationVolumeFactor_);
191  if (oilSaturationPressureOutput_())
192  this->commitScalarBuffer_(baseWriter, "pressure_sat,o", oilSaturationPressure_);
193  }
194 
195 private:
196  static bool gasDissolutionFactorOutput_()
197  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteGasDissolutionFactor); }
198 
199  static bool saturatedOilGasDissolutionFactorOutput_()
200  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteSaturatedOilGasDissolutionFactor); }
201 
202  static bool gasFormationVolumeFactorOutput_()
203  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteGasFormationVolumeFactor); }
204 
205  static bool saturatedOilFormationVolumeFactorOutput_()
206  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteOilFormationVolumeFactor); }
207 
208  static bool oilSaturationPressureOutput_()
209  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteOilSaturationPressure); }
210 
211  ScalarBuffer gasDissolutionFactor_;
212  ScalarBuffer saturatedOilGasDissolutionFactor_;
213  ScalarBuffer gasFormationVolumeFactor_;
214  ScalarBuffer saturatedOilFormationVolumeFactor_;
215  ScalarBuffer oilSaturationPressure_;
216 };
217 } // namespace Ewoms
218 
219 #endif
void processElement(const ElementContext &elemCtx)
Modify the internal buffers according to the intensive quantities relevant for an element...
Definition: vtkblackoilmodule.hh:142
void resizeScalarBuffer_(ScalarBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a scalar quantity.
Definition: baseoutputmodule.hh:148
static void registerParameters()
Register all run-time parameters for the multi-phase VTK output module.
Definition: vtkblackoilmodule.hh:101
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:468
VtkBlackOilModule(const Simulator &simulator)
Definition: vtkblackoilmodule.hh:93
NEW_PROP_TAG(Grid)
The type of the DUNE grid.
This file provides the infrastructure to retrieve run-time parameters.
Declares the properties required by the black oil model.
The base class for all output writers.
Definition: baseoutputwriter.hh:41
Simplifies writing multi-file VTK datasets.
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:73
Definition: baseauxiliarymodule.hh:35
void commitBuffers(BaseOutputWriter &baseWriter)
Add all buffers to the VTK output writer.
Definition: vtkblackoilmodule.hh:177
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:64
void allocBuffers()
Allocate memory for the scalar fields we would like to write to the VTK file.
Definition: vtkblackoilmodule.hh:124
void commitScalarBuffer_(BaseOutputWriter &baseWriter, const char *name, ScalarBuffer &buffer, BufferType bufferType=DofBuffer)
Add a buffer containing scalar quantities to the result file.
Definition: baseoutputmodule.hh:283
NEW_TYPE_TAG(AuxModule)
Provides the magic behind the eWoms property system.
The base class for writer modules.
SET_BOOL_PROP(FvBaseDiscretization, EnableVtkOutput, true)
Enable the VTK output by default.
VTK output module for the black oil model's parameters.
Definition: vtkblackoilmodule.hh:70
The base class for writer modules.
Definition: baseoutputmodule.hh:71
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:61
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:95
BaseOutputWriter::ScalarBuffer ScalarBuffer
Definition: baseoutputmodule.hh:90