All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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  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 */
27 #ifndef EWOMS_VTK_BLACK_OIL_MODULE_HH
28 #define EWOMS_VTK_BLACK_OIL_MODULE_HH
29 
30 #include <opm/material/densead/Math.hpp>
31 
32 #include "vtkmultiwriter.hh"
33 #include "baseoutputmodule.hh"
34 
38 
39 #include <dune/common/fvector.hh>
40 
41 #include <cstdio>
42 
43 namespace Ewoms {
44 namespace Properties {
45 // create new type tag for the VTK multi-phase output
46 NEW_TYPE_TAG(VtkBlackOil);
47 
48 // create the property tags needed for the multi phase module
49 NEW_PROP_TAG(EnableVtkOutput);
50 NEW_PROP_TAG(VtkOutputFormat);
51 NEW_PROP_TAG(VtkWriteGasDissolutionFactor);
52 NEW_PROP_TAG(VtkWriteOilVaporizationFactor);
53 NEW_PROP_TAG(VtkWriteOilFormationVolumeFactor);
54 NEW_PROP_TAG(VtkWriteGasFormationVolumeFactor);
55 NEW_PROP_TAG(VtkWriteWaterFormationVolumeFactor);
56 NEW_PROP_TAG(VtkWriteOilSaturationPressure);
57 NEW_PROP_TAG(VtkWriteGasSaturationPressure);
58 NEW_PROP_TAG(VtkWriteSaturationRatios);
59 NEW_PROP_TAG(VtkWriteSaturatedOilGasDissolutionFactor);
60 NEW_PROP_TAG(VtkWriteSaturatedGasOilVaporizationFactor);
61 NEW_PROP_TAG(VtkWriteSaturatedOilFormationVolumeFactor);
62 NEW_PROP_TAG(VtkWriteSaturatedGasFormationVolumeFactor);
63 NEW_PROP_TAG(VtkWritePrimaryVarsMeaning);
64 
65 // set default values for what quantities to output
66 SET_BOOL_PROP(VtkBlackOil, VtkWriteGasDissolutionFactor, false);
67 SET_BOOL_PROP(VtkBlackOil, VtkWriteOilVaporizationFactor, false);
68 SET_BOOL_PROP(VtkBlackOil, VtkWriteOilFormationVolumeFactor, false);
69 SET_BOOL_PROP(VtkBlackOil, VtkWriteGasFormationVolumeFactor, false);
70 SET_BOOL_PROP(VtkBlackOil, VtkWriteWaterFormationVolumeFactor, false);
71 SET_BOOL_PROP(VtkBlackOil, VtkWriteOilSaturationPressure, false);
72 SET_BOOL_PROP(VtkBlackOil, VtkWriteGasSaturationPressure, false);
73 SET_BOOL_PROP(VtkBlackOil, VtkWriteSaturationRatios, false);
74 SET_BOOL_PROP(VtkBlackOil, VtkWriteSaturatedOilGasDissolutionFactor, false);
75 SET_BOOL_PROP(VtkBlackOil, VtkWriteSaturatedGasOilVaporizationFactor, false);
76 SET_BOOL_PROP(VtkBlackOil, VtkWriteSaturatedOilFormationVolumeFactor, false);
77 SET_BOOL_PROP(VtkBlackOil, VtkWriteSaturatedGasFormationVolumeFactor, false);
78 SET_BOOL_PROP(VtkBlackOil, VtkWritePrimaryVarsMeaning, false);
79 } // namespace Properties
80 } // namespace Ewoms
81 
82 namespace Ewoms {
88 template <class TypeTag>
89 class VtkBlackOilModule : public BaseOutputModule<TypeTag>
90 {
92 
93  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
94  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
95  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
96  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
97 
98  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
99  typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
100 
101  static const int vtkFormat = GET_PROP_VALUE(TypeTag, VtkOutputFormat);
103 
104  enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
105  enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
106  enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
107 
108  enum { gasCompIdx = FluidSystem::gasCompIdx };
109  enum { oilCompIdx = FluidSystem::oilCompIdx };
110  enum { waterCompIdx = FluidSystem::waterCompIdx };
111 
112  typedef typename ParentType::ScalarBuffer ScalarBuffer;
113 
114 public:
115  VtkBlackOilModule(const Simulator& simulator)
116  : ParentType(simulator)
117  { }
118 
123  static void registerParameters()
124  {
125  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteGasDissolutionFactor,
126  "Include the gas dissolution factor (R_s) of the observed oil "
127  "in the VTK output files");
128  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteOilVaporizationFactor,
129  "Include the oil vaporization factor (R_v) of the observed gas "
130  "in the VTK output files");
131  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteOilFormationVolumeFactor,
132  "Include the oil formation volume factor (B_o) of gas saturated "
133  "oil in the VTK output files");
134  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteGasFormationVolumeFactor,
135  "Include the gas formation volume factor (B_g) in the "
136  "VTK output files");
137  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteWaterFormationVolumeFactor,
138  "Include the water formation volume factor (B_w) in the "
139  "VTK output files");
140  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteOilSaturationPressure,
141  "Include the saturation pressure of oil (p_o,sat) in the "
142  "VTK output files");
143  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteGasSaturationPressure,
144  "Include the saturation pressure of gas (p_g,sat) in the "
145  "VTK output files");
146  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteSaturatedOilGasDissolutionFactor,
147  "Include the gas dissolution factor (R_s,sat) of gas saturated "
148  "oil in the VTK output files");
149  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteSaturatedGasOilVaporizationFactor,
150  "Include the oil vaporization factor (R_v,sat) of oil saturated "
151  "gas in the VTK output files");
152  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteSaturationRatios,
153  "Write the ratio of the actually and maximum dissolved component of "
154  "the mixtures");
155  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteSaturatedOilFormationVolumeFactor,
156  "Include the formation volume factor (B_o,sat) of saturated oil in the "
157  "VTK output files");
158  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteSaturatedGasFormationVolumeFactor,
159  "Include the formation volume factor (B_g,sat) of saturated gas in the "
160  "VTK output files");
161  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWritePrimaryVarsMeaning,
162  "Include how the primary variables should be interpreted to the "
163  "VTK output files");
164  }
165 
171  {
172  if (gasDissolutionFactorOutput_())
173  this->resizeScalarBuffer_(gasDissolutionFactor_);
174  if (oilVaporizationFactorOutput_())
175  this->resizeScalarBuffer_(oilVaporizationFactor_);
176  if (oilFormationVolumeFactorOutput_())
177  this->resizeScalarBuffer_(oilFormationVolumeFactor_);
178  if (gasFormationVolumeFactorOutput_())
179  this->resizeScalarBuffer_(gasFormationVolumeFactor_);
180  if (waterFormationVolumeFactorOutput_())
181  this->resizeScalarBuffer_(waterFormationVolumeFactor_);
182  if (oilSaturationPressureOutput_())
183  this->resizeScalarBuffer_(oilSaturationPressure_);
184  if (gasSaturationPressureOutput_())
185  this->resizeScalarBuffer_(gasSaturationPressure_);
186  if (saturatedOilGasDissolutionFactorOutput_())
187  this->resizeScalarBuffer_(saturatedOilGasDissolutionFactor_);
188  if (saturatedGasOilVaporizationFactorOutput_())
189  this->resizeScalarBuffer_(saturatedGasOilVaporizationFactor_);
190  if (saturationRatiosOutput_()) {
191  this->resizeScalarBuffer_(oilSaturationRatio_);
192  this->resizeScalarBuffer_(gasSaturationRatio_);
193  }
194  if (saturatedGasFormationVolumeFactorOutput_())
195  this->resizeScalarBuffer_(saturatedGasFormationVolumeFactor_);
196  if (primaryVarsMeaningOutput_())
197  this->resizeScalarBuffer_(primaryVarsMeaning_);
198  }
199 
204  void processElement(const ElementContext& elemCtx)
205  {
206  if (!EWOMS_GET_PARAM(TypeTag, bool, EnableVtkOutput))
207  return;
208 
209  typedef Opm::MathToolbox<Evaluation> Toolbox;
210 
211  for (unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) {
212  const auto& fs = elemCtx.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState();
213  typedef typename std::remove_const<typename std::remove_reference<decltype(fs)>::type>::type FluidState;
214  unsigned globalDofIdx = elemCtx.globalSpaceIndex(dofIdx, /*timeIdx=*/0);
215 
216  const auto& primaryVars = elemCtx.primaryVars(dofIdx, /*timeIdx=*/0);
217 
218  unsigned pvtRegionIdx = elemCtx.primaryVars(dofIdx, /*timeIdx=*/0).pvtRegionIndex();
219  Scalar SoMax = elemCtx.model().maxOilSaturation(globalDofIdx);
220  Scalar x_oG = Toolbox::value(fs.moleFraction(oilPhaseIdx, gasCompIdx));
221  Scalar x_gO = Toolbox::value(fs.moleFraction(gasPhaseIdx, oilCompIdx));
222  Scalar X_oG = Toolbox::value(fs.massFraction(oilPhaseIdx, gasCompIdx));
223  Scalar X_gO = Toolbox::value(fs.massFraction(gasPhaseIdx, oilCompIdx));
224  Scalar Rs = FluidSystem::convertXoGToRs(X_oG, pvtRegionIdx);
225  Scalar Rv = FluidSystem::convertXgOToRv(X_gO, pvtRegionIdx);
226 
227  Scalar RsSat =
228  FluidSystem::template saturatedDissolutionFactor<FluidState, Scalar>(fs,
229  oilPhaseIdx,
230  pvtRegionIdx,
231  SoMax);
232  Scalar X_oG_sat = FluidSystem::convertRsToXoG(RsSat, pvtRegionIdx);
233  Scalar x_oG_sat = FluidSystem::convertXoGToxoG(X_oG_sat, pvtRegionIdx);
234 
235  Scalar RvSat =
236  FluidSystem::template saturatedDissolutionFactor<FluidState, Scalar>(fs,
237  gasPhaseIdx,
238  pvtRegionIdx,
239  SoMax);
240  Scalar X_gO_sat = FluidSystem::convertRvToXgO(RvSat, pvtRegionIdx);
241  Scalar x_gO_sat = FluidSystem::convertXgOToxgO(X_gO_sat, pvtRegionIdx);
242 
243  if (gasDissolutionFactorOutput_())
244  gasDissolutionFactor_[globalDofIdx] = Rs;
245  if (oilVaporizationFactorOutput_())
246  oilVaporizationFactor_[globalDofIdx] = Rv;
247  if (oilFormationVolumeFactorOutput_())
248  oilFormationVolumeFactor_[globalDofIdx] =
249  1.0/FluidSystem::template inverseFormationVolumeFactor<FluidState, Scalar>(fs, oilPhaseIdx, pvtRegionIdx);
250  if (gasFormationVolumeFactorOutput_())
251  gasFormationVolumeFactor_[globalDofIdx] =
252  1.0/FluidSystem::template inverseFormationVolumeFactor<FluidState, Scalar>(fs, gasPhaseIdx, pvtRegionIdx);
253  if (waterFormationVolumeFactorOutput_())
254  waterFormationVolumeFactor_[globalDofIdx] =
255  1.0/FluidSystem::template inverseFormationVolumeFactor<FluidState, Scalar>(fs, waterPhaseIdx, pvtRegionIdx);
256  if (oilSaturationPressureOutput_())
257  oilSaturationPressure_[globalDofIdx] =
258  FluidSystem::template saturationPressure<FluidState, Scalar>(fs, oilPhaseIdx, pvtRegionIdx);
259  if (gasSaturationPressureOutput_())
260  gasSaturationPressure_[globalDofIdx] =
261  FluidSystem::template saturationPressure<FluidState, Scalar>(fs, gasPhaseIdx, pvtRegionIdx);
262  if (saturatedOilGasDissolutionFactorOutput_())
263  saturatedOilGasDissolutionFactor_[globalDofIdx] = RsSat;
264  if (saturatedGasOilVaporizationFactorOutput_())
265  saturatedGasOilVaporizationFactor_[globalDofIdx] = RvSat;
266  if (saturationRatiosOutput_()) {
267  if (x_oG_sat <= 0.0)
268  oilSaturationRatio_[globalDofIdx] = 1.0;
269  else
270  oilSaturationRatio_[globalDofIdx] = x_oG / x_oG_sat;
271 
272  if (x_gO_sat <= 0.0)
273  gasSaturationRatio_[globalDofIdx] = 1.0;
274  else
275  gasSaturationRatio_[globalDofIdx] = x_gO / x_gO_sat;
276  }
277  if (saturatedOilFormationVolumeFactorOutput_())
278  saturatedOilFormationVolumeFactor_[globalDofIdx] =
279  1.0/FluidSystem::template saturatedInverseFormationVolumeFactor<FluidState, Scalar>(fs, oilPhaseIdx, pvtRegionIdx);
280  if (saturatedGasFormationVolumeFactorOutput_())
281  saturatedGasFormationVolumeFactor_[globalDofIdx] =
282  1.0/FluidSystem::template saturatedInverseFormationVolumeFactor<FluidState, Scalar>(fs, gasPhaseIdx, pvtRegionIdx);
283 
284  if (primaryVarsMeaningOutput_())
285  primaryVarsMeaning_[globalDofIdx] =
286  primaryVars.primaryVarsMeaning();
287  }
288  }
289 
293  void commitBuffers(BaseOutputWriter& baseWriter)
294  {
295  VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
296  if (!vtkWriter)
297  return;
298 
299  if (gasDissolutionFactorOutput_())
300  this->commitScalarBuffer_(baseWriter, "R_s", gasDissolutionFactor_);
301  if (oilVaporizationFactorOutput_())
302  this->commitScalarBuffer_(baseWriter, "R_v", oilVaporizationFactor_);
303  if (oilFormationVolumeFactorOutput_())
304  this->commitScalarBuffer_(baseWriter, "B_o", oilFormationVolumeFactor_);
305  if (gasFormationVolumeFactorOutput_())
306  this->commitScalarBuffer_(baseWriter, "B_g", gasFormationVolumeFactor_);
307  if (waterFormationVolumeFactorOutput_())
308  this->commitScalarBuffer_(baseWriter, "B_w", waterFormationVolumeFactor_);
309  if (oilSaturationPressureOutput_())
310  this->commitScalarBuffer_(baseWriter, "p_o,sat", oilSaturationPressure_);
311  if (gasSaturationPressureOutput_())
312  this->commitScalarBuffer_(baseWriter, "p_g,sat", gasSaturationPressure_);
313  if (saturatedOilGasDissolutionFactorOutput_())
314  this->commitScalarBuffer_(baseWriter, "R_s,sat", saturatedOilGasDissolutionFactor_);
315  if (saturatedGasOilVaporizationFactorOutput_())
316  this->commitScalarBuffer_(baseWriter, "R_v,sat", saturatedGasOilVaporizationFactor_);
317  if (saturationRatiosOutput_()) {
318  this->commitScalarBuffer_(baseWriter, "saturation ratio_oil", oilSaturationRatio_);
319  this->commitScalarBuffer_(baseWriter, "saturation ratio_gas", gasSaturationRatio_);
320  }
321  if (saturatedOilFormationVolumeFactorOutput_())
322  this->commitScalarBuffer_(baseWriter, "B_o,sat", saturatedOilFormationVolumeFactor_);
323  if (saturatedGasFormationVolumeFactorOutput_())
324  this->commitScalarBuffer_(baseWriter, "B_g,sat", saturatedGasFormationVolumeFactor_);
325 
326  if (primaryVarsMeaningOutput_())
327  this->commitScalarBuffer_(baseWriter, "primary vars meaning", primaryVarsMeaning_);
328  }
329 
330 private:
331  static bool gasDissolutionFactorOutput_()
332  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteGasDissolutionFactor); }
333 
334  static bool oilVaporizationFactorOutput_()
335  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteOilVaporizationFactor); }
336 
337  static bool oilFormationVolumeFactorOutput_()
338  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteOilFormationVolumeFactor); }
339 
340  static bool gasFormationVolumeFactorOutput_()
341  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteGasFormationVolumeFactor); }
342 
343  static bool waterFormationVolumeFactorOutput_()
344  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteWaterFormationVolumeFactor); }
345 
346  static bool oilSaturationPressureOutput_()
347  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteOilSaturationPressure); }
348 
349  static bool gasSaturationPressureOutput_()
350  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteGasSaturationPressure); }
351 
352  static bool saturatedOilGasDissolutionFactorOutput_()
353  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteSaturatedOilGasDissolutionFactor); }
354 
355  static bool saturatedGasOilVaporizationFactorOutput_()
356  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteSaturatedGasOilVaporizationFactor); }
357 
358  static bool saturationRatiosOutput_()
359  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteSaturationRatios); }
360 
361  static bool saturatedOilFormationVolumeFactorOutput_()
362  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteSaturatedOilFormationVolumeFactor); }
363 
364  static bool saturatedGasFormationVolumeFactorOutput_()
365  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteSaturatedGasFormationVolumeFactor); }
366 
367  static bool primaryVarsMeaningOutput_()
368  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWritePrimaryVarsMeaning); }
369 
370  ScalarBuffer gasDissolutionFactor_;
371  ScalarBuffer oilVaporizationFactor_;
372  ScalarBuffer oilFormationVolumeFactor_;
373  ScalarBuffer gasFormationVolumeFactor_;
374  ScalarBuffer waterFormationVolumeFactor_;
375  ScalarBuffer oilSaturationPressure_;
376  ScalarBuffer gasSaturationPressure_;
377 
378  ScalarBuffer saturatedOilGasDissolutionFactor_;
379  ScalarBuffer saturatedGasOilVaporizationFactor_;
380  ScalarBuffer oilSaturationRatio_;
381  ScalarBuffer gasSaturationRatio_;
382  ScalarBuffer saturatedOilFormationVolumeFactor_;
383  ScalarBuffer saturatedGasFormationVolumeFactor_;
384 
385  ScalarBuffer primaryVarsMeaning_;
386 };
387 } // namespace Ewoms
388 
389 #endif
The base class for all output writers.
Definition: baseoutputwriter.hh:43
#define SET_BOOL_PROP(EffTypeTagName, PropTagName,...)
Set a property to a simple constant boolean value.
Definition: propertysystem.hh:361
static void registerParameters()
Register all run-time parameters for the multi-phase VTK output module.
Definition: vtkblackoilmodule.hh:123
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:63
void commitBuffers(BaseOutputWriter &baseWriter)
Add all buffers to the VTK output writer.
Definition: vtkblackoilmodule.hh:293
void processElement(const ElementContext &elemCtx)
Modify the internal buffers according to the intensive quantities relevant for an element...
Definition: vtkblackoilmodule.hh:204
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:305
VTK output module for the black oil model&#39;s parameters.
Definition: vtkblackoilmodule.hh:89
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:469
The base class for writer modules.
#define NEW_TYPE_TAG(...)
Define a new type tag.
Definition: propertysystem.hh:169
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:68
Declares the properties required by the black oil model.
This file provides the infrastructure to retrieve run-time parameters.
The base class for writer modules.
Definition: baseoutputmodule.hh:80
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:99
Provides the magic behind the eWoms property system.
void resizeScalarBuffer_(ScalarBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a scalar quantity.
Definition: baseoutputmodule.hh:170
Simplifies writing multi-file VTK datasets.
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
void allocBuffers()
Allocate memory for the scalar fields we would like to write to the VTK file.
Definition: vtkblackoilmodule.hh:170