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
48namespace Opm {
49
55template <class TypeTag>
56class 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;
81
82public:
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 }
111 this->resizeScalarBuffer_(oilFormationVolumeFactor_, BufferType::Dof);
112 }
114 this->resizeScalarBuffer_(gasFormationVolumeFactor_, BufferType::Dof);
115 }
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 }
126 this->resizeScalarBuffer_(saturatedOilGasDissolutionFactor_, BufferType::Dof);
127 }
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 }
204 saturatedOilGasDissolutionFactor_[globalDofIdx] = RsSat;
205 }
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 }
226 oilFormationVolumeFactor_[globalDofIdx] =
227 1.0 / FluidSystem::template inverseFormationVolumeFactor<FluidState, Scalar>(fs, oilPhaseIdx, pvtRegionIdx);
228 }
230 gasFormationVolumeFactor_[globalDofIdx] =
231 1.0 / FluidSystem::template inverseFormationVolumeFactor<FluidState, Scalar>(fs, gasPhaseIdx, pvtRegionIdx);
232 }
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 }
267 this->commitScalarBuffer_(baseWriter, "B_o",
268 oilFormationVolumeFactor_, BufferType::Dof);
269 }
271 this->commitScalarBuffer_(baseWriter, "B_g",
272 gasFormationVolumeFactor_, BufferType::Dof);
273 }
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 }
287 this->commitScalarBuffer_(baseWriter, "R_s,sat",
288 saturatedOilGasDissolutionFactor_, BufferType::Dof);
289 }
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
311private:
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
Declares the properties required by the black oil model.
The base class for writer modules.
Definition: baseoutputmodule.hh:68
BaseOutputWriter::ScalarBuffer ScalarBuffer
Definition: baseoutputmodule.hh:86
void resizeScalarBuffer_(ScalarBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a scalar quantity.
Definition: baseoutputmodule.hh:157
BufferType
Definition: baseoutputmodule.hh:143
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
The base class for all output writers.
Definition: baseoutputwriter.hh:46
VTK output module for the black oil model's parameters.
Definition: vtkblackoilmodule.hpp:57
void processElement(const ElementContext &elemCtx) override
Modify the internal buffers according to the intensive quantities relevant for an element.
Definition: vtkblackoilmodule.hpp:146
static void registerParameters()
Register all run-time parameters for the multi-phase VTK output module.
Definition: vtkblackoilmodule.hpp:93
void commitBuffers(BaseOutputWriter &baseWriter) override
Add all buffers to the VTK output writer.
Definition: vtkblackoilmodule.hpp:252
void allocBuffers() override
Allocate memory for the scalar fields we would like to write to the VTK file.
Definition: vtkblackoilmodule.hpp:102
VtkBlackOilModule(const Simulator &simulator)
Definition: vtkblackoilmodule.hpp:83
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:65
Declare the properties used by the infrastructure code of the finite volume discretizations.
Definition: blackoilboundaryratevector.hh:39
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
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.
Struct holding the parameters for VtkBlackoilOutputModule.
Definition: vtkblackoilparams.hpp:53
bool gasSaturationPressureOutput_
Definition: vtkblackoilparams.hpp:66
bool oilFormationVolumeFactorOutput_
Definition: vtkblackoilparams.hpp:62
static void registerParameters()
Registers the parameters in parameter system.
bool gasFormationVolumeFactorOutput_
Definition: vtkblackoilparams.hpp:63
bool oilVaporizationFactorOutput_
Definition: vtkblackoilparams.hpp:61
bool saturatedGasOilVaporizationFactorOutput_
Definition: vtkblackoilparams.hpp:68
bool primaryVarsMeaningOutput_
Definition: vtkblackoilparams.hpp:70
bool gasDissolutionFactorOutput_
Definition: vtkblackoilparams.hpp:60
bool waterFormationVolumeFactorOutput_
Definition: vtkblackoilparams.hpp:64
bool saturatedOilGasDissolutionFactorOutput_
Definition: vtkblackoilparams.hpp:67
bool saturationRatiosOutput_
Definition: vtkblackoilparams.hpp:69
bool oilSaturationPressureOutput_
Definition: vtkblackoilparams.hpp:65
void read()
Reads the parameter values from the parameter system.