opm-simulators
vtkblackoilmodule.hpp
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 OPM_VTK_BLACK_OIL_MODULE_HPP
28 #define OPM_VTK_BLACK_OIL_MODULE_HPP
29 
30 #include <dune/common/fvector.hh>
31 
32 #include <opm/material/densead/Math.hpp>
33 
35 
37 
41 
44 
45 #include <algorithm>
46 #include <type_traits>
47 
48 namespace Opm {
49 
55 template <class TypeTag>
56 class VtkBlackOilModule : public BaseOutputModule<TypeTag>
57 {
59 
64 
67 
68  static constexpr auto vtkFormat = getPropValue<TypeTag, Properties::VtkOutputFormat>();
70 
71  enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
72  enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
73  enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
74 
75  enum { gasCompIdx = FluidSystem::gasCompIdx };
76  enum { oilCompIdx = FluidSystem::oilCompIdx };
77  enum { waterCompIdx = FluidSystem::waterCompIdx };
78 
79  using BufferType = typename ParentType::BufferType;
80  using ScalarBuffer = typename ParentType::ScalarBuffer;
81 
82 public:
83  explicit VtkBlackOilModule(const Simulator& simulator)
84  : ParentType(simulator)
85  {
86  params_.read();
87  }
88 
93  static void registerParameters()
94  {
96  }
97 
102  void allocBuffers() override
103  {
104  if (params_.gasDissolutionFactorOutput_) {
105  this->resizeScalarBuffer_(gasDissolutionFactor_, BufferType::Dof);
106  }
107  if (params_.oilVaporizationFactorOutput_) {
108  this->resizeScalarBuffer_(oilVaporizationFactor_, BufferType::Dof);
109  }
110  if (params_.oilFormationVolumeFactorOutput_) {
111  this->resizeScalarBuffer_(oilFormationVolumeFactor_, BufferType::Dof);
112  }
113  if (params_.gasFormationVolumeFactorOutput_) {
114  this->resizeScalarBuffer_(gasFormationVolumeFactor_, BufferType::Dof);
115  }
116  if (params_.waterFormationVolumeFactorOutput_) {
117  this->resizeScalarBuffer_(waterFormationVolumeFactor_, BufferType::Dof);
118  }
119  if (params_.oilSaturationPressureOutput_) {
120  this->resizeScalarBuffer_(oilSaturationPressure_, BufferType::Dof);
121  }
122  if (params_.gasSaturationPressureOutput_) {
123  this->resizeScalarBuffer_(gasSaturationPressure_, BufferType::Dof);
124  }
125  if (params_.saturatedOilGasDissolutionFactorOutput_) {
126  this->resizeScalarBuffer_(saturatedOilGasDissolutionFactor_, BufferType::Dof);
127  }
128  if (params_.saturatedGasOilVaporizationFactorOutput_) {
129  this->resizeScalarBuffer_(saturatedGasOilVaporizationFactor_, BufferType::Dof);
130  }
131  if (params_.saturationRatiosOutput_) {
132  this->resizeScalarBuffer_(oilSaturationRatio_, BufferType::Dof);
133  this->resizeScalarBuffer_(gasSaturationRatio_, BufferType::Dof);
134  }
135  if (params_.primaryVarsMeaningOutput_) {
136  this->resizeScalarBuffer_(primaryVarsMeaningPressure_, BufferType::Dof);
137  this->resizeScalarBuffer_(primaryVarsMeaningWater_, BufferType::Dof);
138  this->resizeScalarBuffer_(primaryVarsMeaningGas_, BufferType::Dof);
139  }
140  }
141 
146  void processElement(const ElementContext& elemCtx) override
147  {
148  if (!Parameters::Get<Parameters::EnableVtkOutput>()) {
149  return;
150  }
151 
152  for (unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) {
153  const auto& fs = elemCtx.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState();
154  using FluidState = std::remove_const_t<std::remove_reference_t<decltype(fs)>>;
155  const unsigned globalDofIdx = elemCtx.globalSpaceIndex(dofIdx, /*timeIdx=*/0);
156 
157  const auto& primaryVars = elemCtx.primaryVars(dofIdx, /*timeIdx=*/0);
158 
159  const unsigned pvtRegionIdx = elemCtx.primaryVars(dofIdx, /*timeIdx=*/0).pvtRegionIndex();
160  const Scalar SoMax =
161  FluidSystem::phaseIsActive(oilPhaseIdx)
162  ? std::max(getValue(fs.saturation(oilPhaseIdx)),
163  elemCtx.problem().maxOilSaturation(globalDofIdx))
164  : 0.0;
165 
166  if (FluidSystem::phaseIsActive(gasPhaseIdx) && FluidSystem::phaseIsActive(oilPhaseIdx)) {
167  const Scalar x_oG = getValue(fs.moleFraction(oilPhaseIdx, gasCompIdx));
168  const Scalar x_gO = getValue(fs.moleFraction(gasPhaseIdx, oilCompIdx));
169  const Scalar X_oG = getValue(fs.massFraction(oilPhaseIdx, gasCompIdx));
170  const Scalar X_gO = getValue(fs.massFraction(gasPhaseIdx, oilCompIdx));
171  const Scalar Rs = FluidSystem::convertXoGToRs(X_oG, pvtRegionIdx);
172  const Scalar Rv = FluidSystem::convertXgOToRv(X_gO, pvtRegionIdx);
173 
174  const Scalar RsSat =
175  FluidSystem::template saturatedDissolutionFactor<FluidState, Scalar>(fs,
176  oilPhaseIdx,
177  pvtRegionIdx,
178  SoMax);
179  const Scalar X_oG_sat = FluidSystem::convertRsToXoG(RsSat, pvtRegionIdx);
180  const Scalar x_oG_sat = FluidSystem::convertXoGToxoG(X_oG_sat, pvtRegionIdx);
181 
182  const Scalar RvSat =
183  FluidSystem::template saturatedDissolutionFactor<FluidState, Scalar>(fs,
184  gasPhaseIdx,
185  pvtRegionIdx,
186  SoMax);
187  const Scalar X_gO_sat = FluidSystem::convertRvToXgO(RvSat, pvtRegionIdx);
188  const Scalar x_gO_sat = FluidSystem::convertXgOToxgO(X_gO_sat, pvtRegionIdx);
189  if (params_.gasDissolutionFactorOutput_) {
190  gasDissolutionFactor_[globalDofIdx] = Rs;
191  }
192  if (params_.oilVaporizationFactorOutput_) {
193  oilVaporizationFactor_[globalDofIdx] = Rv;
194  }
195  if (params_.oilSaturationPressureOutput_) {
196  oilSaturationPressure_[globalDofIdx] =
197  FluidSystem::template saturationPressure<FluidState, Scalar>(fs, oilPhaseIdx, pvtRegionIdx);
198  }
199  if (params_.gasSaturationPressureOutput_) {
200  gasSaturationPressure_[globalDofIdx] =
201  FluidSystem::template saturationPressure<FluidState, Scalar>(fs, gasPhaseIdx, pvtRegionIdx);
202  }
203  if (params_.saturatedOilGasDissolutionFactorOutput_) {
204  saturatedOilGasDissolutionFactor_[globalDofIdx] = RsSat;
205  }
206  if (params_.saturatedGasOilVaporizationFactorOutput_) {
207  saturatedGasOilVaporizationFactor_[globalDofIdx] = RvSat;
208  }
209  if (params_.saturationRatiosOutput_) {
210  if (x_oG_sat <= 0.0) {
211  oilSaturationRatio_[globalDofIdx] = 1.0;
212  }
213  else {
214  oilSaturationRatio_[globalDofIdx] = x_oG / x_oG_sat;
215  }
216 
217  if (x_gO_sat <= 0.0) {
218  gasSaturationRatio_[globalDofIdx] = 1.0;
219  }
220  else {
221  gasSaturationRatio_[globalDofIdx] = x_gO / x_gO_sat;
222  }
223  }
224  }
225  if (params_.oilFormationVolumeFactorOutput_) {
226  oilFormationVolumeFactor_[globalDofIdx] =
227  1.0 / FluidSystem::template inverseFormationVolumeFactor<FluidState, Scalar>(fs, oilPhaseIdx, pvtRegionIdx);
228  }
229  if (params_.gasFormationVolumeFactorOutput_) {
230  gasFormationVolumeFactor_[globalDofIdx] =
231  1.0 / FluidSystem::template inverseFormationVolumeFactor<FluidState, Scalar>(fs, gasPhaseIdx, pvtRegionIdx);
232  }
233  if (params_.waterFormationVolumeFactorOutput_) {
234  waterFormationVolumeFactor_[globalDofIdx] =
235  1.0 / FluidSystem::template inverseFormationVolumeFactor<FluidState, Scalar>(fs, waterPhaseIdx, pvtRegionIdx);
236  }
237 
238  if (params_.primaryVarsMeaningOutput_) {
239  primaryVarsMeaningWater_[globalDofIdx] =
240  static_cast<int>(primaryVars.primaryVarsMeaningWater());
241  primaryVarsMeaningGas_[globalDofIdx] =
242  static_cast<int>(primaryVars.primaryVarsMeaningGas());
243  primaryVarsMeaningPressure_[globalDofIdx] =
244  static_cast<int>(primaryVars.primaryVarsMeaningPressure());
245  }
246  }
247  }
248 
252  void commitBuffers(BaseOutputWriter& baseWriter) override
253  {
254  if (!dynamic_cast<VtkMultiWriter*>(&baseWriter)) {
255  return;
256  }
257 
258  if (params_.gasDissolutionFactorOutput_) {
259  this->commitScalarBuffer_(baseWriter, "R_s",
260  gasDissolutionFactor_, BufferType::Dof);
261  }
262  if (params_.oilVaporizationFactorOutput_) {
263  this->commitScalarBuffer_(baseWriter, "R_v",
264  oilVaporizationFactor_, BufferType::Dof);
265  }
266  if (params_.oilFormationVolumeFactorOutput_) {
267  this->commitScalarBuffer_(baseWriter, "B_o",
268  oilFormationVolumeFactor_, BufferType::Dof);
269  }
270  if (params_.gasFormationVolumeFactorOutput_) {
271  this->commitScalarBuffer_(baseWriter, "B_g",
272  gasFormationVolumeFactor_, BufferType::Dof);
273  }
274  if (params_.waterFormationVolumeFactorOutput_) {
275  this->commitScalarBuffer_(baseWriter, "B_w",
276  waterFormationVolumeFactor_, BufferType::Dof);
277  }
278  if (params_.oilSaturationPressureOutput_) {
279  this->commitScalarBuffer_(baseWriter, "p_o,sat",
280  oilSaturationPressure_, BufferType::Dof);
281  }
282  if (params_.gasSaturationPressureOutput_) {
283  this->commitScalarBuffer_(baseWriter, "p_g,sat",
284  gasSaturationPressure_, BufferType::Dof);
285  }
286  if (params_.saturatedOilGasDissolutionFactorOutput_) {
287  this->commitScalarBuffer_(baseWriter, "R_s,sat",
288  saturatedOilGasDissolutionFactor_, BufferType::Dof);
289  }
290  if (params_.saturatedGasOilVaporizationFactorOutput_) {
291  this->commitScalarBuffer_(baseWriter, "R_v,sat",
292  saturatedGasOilVaporizationFactor_, BufferType::Dof);
293  }
294  if (params_.saturationRatiosOutput_) {
295  this->commitScalarBuffer_(baseWriter, "saturation ratio_oil",
296  oilSaturationRatio_, BufferType::Dof);
297  this->commitScalarBuffer_(baseWriter, "saturation ratio_gas",
298  gasSaturationRatio_, BufferType::Dof);
299  }
300 
301  if (params_.primaryVarsMeaningOutput_) {
302  this->commitScalarBuffer_(baseWriter, "primary vars meaning water",
303  primaryVarsMeaningWater_, BufferType::Dof);
304  this->commitScalarBuffer_(baseWriter, "primary vars meaning gas",
305  primaryVarsMeaningGas_, BufferType::Dof);
306  this->commitScalarBuffer_(baseWriter, "primary vars meaning pressure",
307  primaryVarsMeaningPressure_, BufferType::Dof);
308  }
309  }
310 
311 private:
312  VtkBlackoilParams params_{};
313  ScalarBuffer gasDissolutionFactor_{};
314  ScalarBuffer oilVaporizationFactor_{};
315  ScalarBuffer oilFormationVolumeFactor_{};
316  ScalarBuffer gasFormationVolumeFactor_{};
317  ScalarBuffer waterFormationVolumeFactor_{};
318  ScalarBuffer oilSaturationPressure_{};
319  ScalarBuffer gasSaturationPressure_{};
320 
321  ScalarBuffer saturatedOilGasDissolutionFactor_{};
322  ScalarBuffer saturatedGasOilVaporizationFactor_{};
323  ScalarBuffer oilSaturationRatio_{};
324  ScalarBuffer gasSaturationRatio_{};
325 
326  ScalarBuffer primaryVarsMeaningPressure_{};
327  ScalarBuffer primaryVarsMeaningWater_{};
328  ScalarBuffer primaryVarsMeaningGas_{};
329 };
330 
331 } // namespace Opm
332 
333 #endif // OPM_VTK_BLACK_OIL_MODULE_HPP
void commitBuffers(BaseOutputWriter &baseWriter) override
Add all buffers to the VTK output writer.
Definition: vtkblackoilmodule.hpp:252
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(...))
Definition: propertysystem.hh:233
VTK output module for the black oil model&#39;s parameters.
void commitScalarBuffer_(BaseOutputWriter &baseWriter, const char *name, ScalarBuffer &buffer, BufferType bufferType)
Add a buffer containing scalar quantities to the result file.
Definition: baseoutputmodule.hh:238
VTK output module for the black oil model&#39;s parameters.
Definition: vtkblackoilmodule.hpp:56
This file provides the infrastructure to retrieve run-time parameters.
The base class for writer modules.
Definition: baseoutputmodule.hh:67
The base class for writer modules.
BufferType
Definition: baseoutputmodule.hh:143
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:64
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
The base class for all output writers.
Definition: baseoutputwriter.hh:45
void processElement(const ElementContext &elemCtx) override
Modify the internal buffers according to the intensive quantities relevant for an element...
Definition: vtkblackoilmodule.hpp:146
Declares the properties required by the black oil model.
void read()
Reads the parameter values from the parameter system.
Definition: vtkblackoilparams.cpp:67
Declare the properties used by the infrastructure code of the finite volume discretizations.
void resizeScalarBuffer_(ScalarBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a scalar quantity.
Definition: baseoutputmodule.hh:157
The Opm property system, traits with inheritance.
Simplifies writing multi-file VTK datasets.
static void registerParameters()
Register all run-time parameters for the multi-phase VTK output module.
Definition: vtkblackoilmodule.hpp:93
Struct holding the parameters for VtkBlackoilOutputModule.
Definition: vtkblackoilparams.hpp:52
static void registerParameters()
Registers the parameters in parameter system.
Definition: vtkblackoilparams.cpp:31
void allocBuffers() override
Allocate memory for the scalar fields we would like to write to the VTK file.
Definition: vtkblackoilmodule.hpp:102