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
43namespace Opm::Properties {
44
45namespace TTag {
46
47// create new type tag for the VTK multi-phase output
48struct VtkBlackOil {};
49
50} // namespace TTag
51
52// create the property tags needed for the multi phase module
53template<class TypeTag, class MyTypeTag>
55template<class TypeTag, class MyTypeTag>
57template<class TypeTag, class MyTypeTag>
59template<class TypeTag, class MyTypeTag>
61template<class TypeTag, class MyTypeTag>
63template<class TypeTag, class MyTypeTag>
65template<class TypeTag, class MyTypeTag>
67template<class TypeTag, class MyTypeTag>
69template<class TypeTag, class MyTypeTag>
71template<class TypeTag, class MyTypeTag>
73template<class TypeTag, class MyTypeTag>
75
76// set default values for what quantities to output
77template<class TypeTag>
78struct VtkWriteGasDissolutionFactor<TypeTag, TTag::VtkBlackOil> { static constexpr bool value = false; };
79template<class TypeTag>
80struct VtkWriteOilVaporizationFactor<TypeTag, TTag::VtkBlackOil> { static constexpr bool value = false; };
81template<class TypeTag>
82struct VtkWriteOilFormationVolumeFactor<TypeTag, TTag::VtkBlackOil> { static constexpr bool value = false; };
83template<class TypeTag>
84struct VtkWriteGasFormationVolumeFactor<TypeTag, TTag::VtkBlackOil> { static constexpr bool value = false; };
85template<class TypeTag>
86struct VtkWriteWaterFormationVolumeFactor<TypeTag, TTag::VtkBlackOil> { static constexpr bool value = false; };
87template<class TypeTag>
88struct VtkWriteOilSaturationPressure<TypeTag, TTag::VtkBlackOil> { static constexpr bool value = false; };
89template<class TypeTag>
90struct VtkWriteGasSaturationPressure<TypeTag, TTag::VtkBlackOil> { static constexpr bool value = false; };
91template<class TypeTag>
92struct VtkWriteSaturationRatios<TypeTag, TTag::VtkBlackOil> { static constexpr bool value = false; };
93template<class TypeTag>
94struct VtkWriteSaturatedOilGasDissolutionFactor<TypeTag, TTag::VtkBlackOil> { static constexpr bool value = false; };
95template<class TypeTag>
96struct VtkWriteSaturatedGasOilVaporizationFactor<TypeTag, TTag::VtkBlackOil> { static constexpr bool value = false; };
97template<class TypeTag>
98struct VtkWritePrimaryVarsMeaning<TypeTag, TTag::VtkBlackOil> { static constexpr bool value = false; };
99} // namespace Opm::Properties
100
101namespace Opm {
107template <class TypeTag>
108class VtkBlackOilModule : public BaseOutputModule<TypeTag>
109{
111
116
119
120 static const int vtkFormat = getPropValue<TypeTag, Properties::VtkOutputFormat>();
122
123 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
124 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
125 enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
126
127 enum { gasCompIdx = FluidSystem::gasCompIdx };
128 enum { oilCompIdx = FluidSystem::oilCompIdx };
129 enum { waterCompIdx = FluidSystem::waterCompIdx };
130
131 using ScalarBuffer = typename ParentType::ScalarBuffer;
132
133public:
134 VtkBlackOilModule(const Simulator& simulator)
135 : ParentType(simulator)
136 { }
137
142 static void registerParameters()
143 {
144 Parameters::registerParam<TypeTag, Properties::VtkWriteGasDissolutionFactor>
145 ("Include the gas dissolution factor (R_s) of the observed oil "
146 "in the VTK output files");
147 Parameters::registerParam<TypeTag, Properties::VtkWriteOilVaporizationFactor>
148 ("Include the oil vaporization factor (R_v) of the observed gas "
149 "in the VTK output files");
150 Parameters::registerParam<TypeTag, Properties::VtkWriteOilFormationVolumeFactor>
151 ("Include the oil formation volume factor (B_o) in the VTK output files");
152 Parameters::registerParam<TypeTag, Properties::VtkWriteGasFormationVolumeFactor>
153 ("Include the gas formation volume factor (B_g) in the "
154 "VTK output files");
155 Parameters::registerParam<TypeTag, Properties::VtkWriteWaterFormationVolumeFactor>
156 ("Include the water formation volume factor (B_w) in the "
157 "VTK output files");
158 Parameters::registerParam<TypeTag, Properties::VtkWriteOilSaturationPressure>
159 ("Include the saturation pressure of oil (p_o,sat) in the "
160 "VTK output files");
161 Parameters::registerParam<TypeTag, Properties::VtkWriteGasSaturationPressure>
162 ("Include the saturation pressure of gas (p_g,sat) in the "
163 "VTK output files");
164 Parameters::registerParam<TypeTag, Properties::VtkWriteSaturatedOilGasDissolutionFactor>
165 ("Include the gas dissolution factor (R_s,sat) of gas saturated "
166 "oil in the VTK output files");
167 Parameters::registerParam<TypeTag, Properties::VtkWriteSaturatedGasOilVaporizationFactor>
168 ("Include the oil vaporization factor (R_v,sat) of oil saturated "
169 "gas in the VTK output files");
170 Parameters::registerParam<TypeTag, Properties::VtkWriteSaturationRatios>
171 ("Write the ratio of the actually and maximum dissolved component of "
172 "the mixtures");
173 Parameters::registerParam<TypeTag, Properties::VtkWritePrimaryVarsMeaning>
174 ("Include how the primary variables should be interpreted to the "
175 "VTK output files");
176 }
177
183 {
184 if (gasDissolutionFactorOutput_())
185 this->resizeScalarBuffer_(gasDissolutionFactor_);
186 if (oilVaporizationFactorOutput_())
187 this->resizeScalarBuffer_(oilVaporizationFactor_);
188 if (oilFormationVolumeFactorOutput_())
189 this->resizeScalarBuffer_(oilFormationVolumeFactor_);
190 if (gasFormationVolumeFactorOutput_())
191 this->resizeScalarBuffer_(gasFormationVolumeFactor_);
192 if (waterFormationVolumeFactorOutput_())
193 this->resizeScalarBuffer_(waterFormationVolumeFactor_);
194 if (oilSaturationPressureOutput_())
195 this->resizeScalarBuffer_(oilSaturationPressure_);
196 if (gasSaturationPressureOutput_())
197 this->resizeScalarBuffer_(gasSaturationPressure_);
198 if (saturatedOilGasDissolutionFactorOutput_())
199 this->resizeScalarBuffer_(saturatedOilGasDissolutionFactor_);
200 if (saturatedGasOilVaporizationFactorOutput_())
201 this->resizeScalarBuffer_(saturatedGasOilVaporizationFactor_);
202 if (saturationRatiosOutput_()) {
203 this->resizeScalarBuffer_(oilSaturationRatio_);
204 this->resizeScalarBuffer_(gasSaturationRatio_);
205 }
206 if (primaryVarsMeaningOutput_()) {
207 this->resizeScalarBuffer_(primaryVarsMeaningPressure_);
208 this->resizeScalarBuffer_(primaryVarsMeaningWater_);
209 this->resizeScalarBuffer_(primaryVarsMeaningGas_);
210 }
211 }
212
217 void processElement(const ElementContext& elemCtx)
218 {
219 if (!Parameters::get<TypeTag, Properties::EnableVtkOutput>())
220 return;
221
222 for (unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) {
223 const auto& fs = elemCtx.intensiveQuantities(dofIdx, /*timeIdx=*/0).fluidState();
224 using FluidState = typename std::remove_const<typename std::remove_reference<decltype(fs)>::type>::type;
225 unsigned globalDofIdx = elemCtx.globalSpaceIndex(dofIdx, /*timeIdx=*/0);
226
227 const auto& primaryVars = elemCtx.primaryVars(dofIdx, /*timeIdx=*/0);
228
229 unsigned pvtRegionIdx = elemCtx.primaryVars(dofIdx, /*timeIdx=*/0).pvtRegionIndex();
230 Scalar SoMax = 0.0;
231 if (FluidSystem::phaseIsActive(oilPhaseIdx))
232 SoMax = std::max(getValue(fs.saturation(oilPhaseIdx)),
233 elemCtx.problem().maxOilSaturation(globalDofIdx));
234
235 if (FluidSystem::phaseIsActive(gasPhaseIdx) && FluidSystem::phaseIsActive(oilPhaseIdx)) {
236 Scalar x_oG = getValue(fs.moleFraction(oilPhaseIdx, gasCompIdx));
237 Scalar x_gO = getValue(fs.moleFraction(gasPhaseIdx, oilCompIdx));
238 Scalar X_oG = getValue(fs.massFraction(oilPhaseIdx, gasCompIdx));
239 Scalar X_gO = getValue(fs.massFraction(gasPhaseIdx, oilCompIdx));
240 Scalar Rs = FluidSystem::convertXoGToRs(X_oG, pvtRegionIdx);
241 Scalar Rv = FluidSystem::convertXgOToRv(X_gO, pvtRegionIdx);
242
243 Scalar RsSat =
244 FluidSystem::template saturatedDissolutionFactor<FluidState, Scalar>(fs,
245 oilPhaseIdx,
246 pvtRegionIdx,
247 SoMax);
248 Scalar X_oG_sat = FluidSystem::convertRsToXoG(RsSat, pvtRegionIdx);
249 Scalar x_oG_sat = FluidSystem::convertXoGToxoG(X_oG_sat, pvtRegionIdx);
250
251 Scalar RvSat =
252 FluidSystem::template saturatedDissolutionFactor<FluidState, Scalar>(fs,
253 gasPhaseIdx,
254 pvtRegionIdx,
255 SoMax);
256 Scalar X_gO_sat = FluidSystem::convertRvToXgO(RvSat, pvtRegionIdx);
257 Scalar x_gO_sat = FluidSystem::convertXgOToxgO(X_gO_sat, pvtRegionIdx);
258 if (gasDissolutionFactorOutput_())
259 gasDissolutionFactor_[globalDofIdx] = Rs;
260 if (oilVaporizationFactorOutput_())
261 oilVaporizationFactor_[globalDofIdx] = Rv;
262 if (oilSaturationPressureOutput_())
263 oilSaturationPressure_[globalDofIdx] =
264 FluidSystem::template saturationPressure<FluidState, Scalar>(fs, oilPhaseIdx, pvtRegionIdx);
265 if (gasSaturationPressureOutput_())
266 gasSaturationPressure_[globalDofIdx] =
267 FluidSystem::template saturationPressure<FluidState, Scalar>(fs, gasPhaseIdx, pvtRegionIdx);
268 if (saturatedOilGasDissolutionFactorOutput_())
269 saturatedOilGasDissolutionFactor_[globalDofIdx] = RsSat;
270 if (saturatedGasOilVaporizationFactorOutput_())
271 saturatedGasOilVaporizationFactor_[globalDofIdx] = RvSat;
272 if (saturationRatiosOutput_()) {
273 if (x_oG_sat <= 0.0)
274 oilSaturationRatio_[globalDofIdx] = 1.0;
275 else
276 oilSaturationRatio_[globalDofIdx] = x_oG / x_oG_sat;
277
278 if (x_gO_sat <= 0.0)
279 gasSaturationRatio_[globalDofIdx] = 1.0;
280 else
281 gasSaturationRatio_[globalDofIdx] = x_gO / x_gO_sat;
282 }
283 }
284 if (oilFormationVolumeFactorOutput_())
285 oilFormationVolumeFactor_[globalDofIdx] =
286 1.0/FluidSystem::template inverseFormationVolumeFactor<FluidState, Scalar>(fs, oilPhaseIdx, pvtRegionIdx);
287 if (gasFormationVolumeFactorOutput_())
288 gasFormationVolumeFactor_[globalDofIdx] =
289 1.0/FluidSystem::template inverseFormationVolumeFactor<FluidState, Scalar>(fs, gasPhaseIdx, pvtRegionIdx);
290 if (waterFormationVolumeFactorOutput_())
291 waterFormationVolumeFactor_[globalDofIdx] =
292 1.0/FluidSystem::template inverseFormationVolumeFactor<FluidState, Scalar>(fs, waterPhaseIdx, pvtRegionIdx);
293
294 if (primaryVarsMeaningOutput_()) {
295 primaryVarsMeaningWater_[globalDofIdx] =
296 static_cast<int>(primaryVars.primaryVarsMeaningWater());
297 primaryVarsMeaningGas_[globalDofIdx] =
298 static_cast<int>(primaryVars.primaryVarsMeaningGas());
299 primaryVarsMeaningPressure_[globalDofIdx] =
300 static_cast<int>(primaryVars.primaryVarsMeaningPressure());
301 }
302 }
303 }
304
309 {
310 VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
311 if (!vtkWriter)
312 return;
313
314 if (gasDissolutionFactorOutput_())
315 this->commitScalarBuffer_(baseWriter, "R_s", gasDissolutionFactor_);
316 if (oilVaporizationFactorOutput_())
317 this->commitScalarBuffer_(baseWriter, "R_v", oilVaporizationFactor_);
318 if (oilFormationVolumeFactorOutput_())
319 this->commitScalarBuffer_(baseWriter, "B_o", oilFormationVolumeFactor_);
320 if (gasFormationVolumeFactorOutput_())
321 this->commitScalarBuffer_(baseWriter, "B_g", gasFormationVolumeFactor_);
322 if (waterFormationVolumeFactorOutput_())
323 this->commitScalarBuffer_(baseWriter, "B_w", waterFormationVolumeFactor_);
324 if (oilSaturationPressureOutput_())
325 this->commitScalarBuffer_(baseWriter, "p_o,sat", oilSaturationPressure_);
326 if (gasSaturationPressureOutput_())
327 this->commitScalarBuffer_(baseWriter, "p_g,sat", gasSaturationPressure_);
328 if (saturatedOilGasDissolutionFactorOutput_())
329 this->commitScalarBuffer_(baseWriter, "R_s,sat", saturatedOilGasDissolutionFactor_);
330 if (saturatedGasOilVaporizationFactorOutput_())
331 this->commitScalarBuffer_(baseWriter, "R_v,sat", saturatedGasOilVaporizationFactor_);
332 if (saturationRatiosOutput_()) {
333 this->commitScalarBuffer_(baseWriter, "saturation ratio_oil", oilSaturationRatio_);
334 this->commitScalarBuffer_(baseWriter, "saturation ratio_gas", gasSaturationRatio_);
335 }
336
337 if (primaryVarsMeaningOutput_()) {
338 this->commitScalarBuffer_(baseWriter, "primary vars meaning water", primaryVarsMeaningWater_);
339 this->commitScalarBuffer_(baseWriter, "primary vars meaning gas", primaryVarsMeaningGas_);
340 this->commitScalarBuffer_(baseWriter, "primary vars meaning pressure", primaryVarsMeaningPressure_);
341 }
342 }
343
344private:
345 static bool gasDissolutionFactorOutput_()
346 {
347 static bool val = Parameters::get<TypeTag, Properties::VtkWriteGasDissolutionFactor>();
348 return val;
349 }
350
351 static bool oilVaporizationFactorOutput_()
352 {
353 static bool val = Parameters::get<TypeTag, Properties::VtkWriteOilVaporizationFactor>();
354 return val;
355 }
356
357 static bool oilFormationVolumeFactorOutput_()
358 {
359 static bool val = Parameters::get<TypeTag, Properties::VtkWriteOilFormationVolumeFactor>();
360 return val;
361 }
362
363 static bool gasFormationVolumeFactorOutput_()
364 {
365 static bool val = Parameters::get<TypeTag, Properties::VtkWriteGasFormationVolumeFactor>();
366 return val;
367 }
368
369 static bool waterFormationVolumeFactorOutput_()
370 {
371 static bool val = Parameters::get<TypeTag, Properties::VtkWriteWaterFormationVolumeFactor>();
372 return val;
373 }
374
375 static bool oilSaturationPressureOutput_()
376 {
377 static bool val = Parameters::get<TypeTag, Properties::VtkWriteOilSaturationPressure>();
378 return val;
379 }
380
381 static bool gasSaturationPressureOutput_()
382 {
383 static bool val = Parameters::get<TypeTag, Properties::VtkWriteGasSaturationPressure>();
384 return val;
385 }
386
387 static bool saturatedOilGasDissolutionFactorOutput_()
388 {
389 static bool val = Parameters::get<TypeTag, Properties::VtkWriteSaturatedOilGasDissolutionFactor>();
390 return val;
391 }
392
393 static bool saturatedGasOilVaporizationFactorOutput_()
394 {
395 static bool val = Parameters::get<TypeTag, Properties::VtkWriteSaturatedGasOilVaporizationFactor>();
396 return val;
397 }
398
399 static bool saturationRatiosOutput_()
400 {
401 static bool val = Parameters::get<TypeTag, Properties::VtkWriteSaturationRatios>();
402 return val;
403 }
404
405 static bool primaryVarsMeaningOutput_()
406 {
407 static bool val = Parameters::get<TypeTag, Properties::VtkWritePrimaryVarsMeaning>();
408 return val;
409 }
410
411 ScalarBuffer gasDissolutionFactor_;
412 ScalarBuffer oilVaporizationFactor_;
413 ScalarBuffer oilFormationVolumeFactor_;
414 ScalarBuffer gasFormationVolumeFactor_;
415 ScalarBuffer waterFormationVolumeFactor_;
416 ScalarBuffer oilSaturationPressure_;
417 ScalarBuffer gasSaturationPressure_;
418
419 ScalarBuffer saturatedOilGasDissolutionFactor_;
420 ScalarBuffer saturatedGasOilVaporizationFactor_;
421 ScalarBuffer oilSaturationRatio_;
422 ScalarBuffer gasSaturationRatio_;
423
424 ScalarBuffer primaryVarsMeaningPressure_;
425 ScalarBuffer primaryVarsMeaningWater_;
426 ScalarBuffer primaryVarsMeaningGas_;
427
428
429};
430} // namespace Opm
431
432#endif
Declares the properties required by the black oil model.
The base class for writer modules.
Definition: baseoutputmodule.hh:73
BaseOutputWriter::ScalarBuffer ScalarBuffer
Definition: baseoutputmodule.hh:91
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:316
void resizeScalarBuffer_(ScalarBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a scalar quantity.
Definition: baseoutputmodule.hh:162
The base class for all output writers.
Definition: baseoutputwriter.hh:44
VTK output module for the black oil model's parameters.
Definition: vtkblackoilmodule.hh:109
void processElement(const ElementContext &elemCtx)
Modify the internal buffers according to the intensive quantities relevant for an element.
Definition: vtkblackoilmodule.hh:217
static void registerParameters()
Register all run-time parameters for the multi-phase VTK output module.
Definition: vtkblackoilmodule.hh:142
void commitBuffers(BaseOutputWriter &baseWriter)
Add all buffers to the VTK output writer.
Definition: vtkblackoilmodule.hh:308
VtkBlackOilModule(const Simulator &simulator)
Definition: vtkblackoilmodule.hh:134
void allocBuffers()
Allocate memory for the scalar fields we would like to write to the VTK file.
Definition: vtkblackoilmodule.hh:182
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:66
Definition: blackoilmodel.hh:72
Definition: blackoilboundaryratevector.hh:37
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:242
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.
Definition: vtkblackoilmodule.hh:48
a tag to mark properties as undefined
Definition: propertysystem.hh:40
Definition: vtkblackoilmodule.hh:54
Definition: vtkblackoilmodule.hh:60
Definition: vtkblackoilmodule.hh:66
Definition: vtkblackoilmodule.hh:58
Definition: vtkblackoilmodule.hh:64
Definition: vtkblackoilmodule.hh:56
Definition: vtkblackoilmodule.hh:74
Definition: vtkblackoilmodule.hh:68
Definition: vtkblackoilmodule.hh:62