vtkcompositionmodule.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_COMPOSITION_MODULE_HH
28 #define EWOMS_VTK_COMPOSITION_MODULE_HH
29 
30 #include "vtkmultiwriter.hh"
31 #include "baseoutputmodule.hh"
32 
35 
36 #include <opm/material/common/MathToolbox.hpp>
37 
38 namespace Ewoms {
39 namespace Properties {
40 // create new type tag for the VTK composition output
41 NEW_TYPE_TAG(VtkComposition);
42 
43 // create the property tags needed for the composition module
44 NEW_PROP_TAG(VtkWriteMassFractions);
45 NEW_PROP_TAG(VtkWriteMoleFractions);
46 NEW_PROP_TAG(VtkWriteTotalMassFractions);
47 NEW_PROP_TAG(VtkWriteTotalMoleFractions);
48 NEW_PROP_TAG(VtkWriteMolarities);
49 NEW_PROP_TAG(VtkWriteFugacities);
50 NEW_PROP_TAG(VtkWriteFugacityCoeffs);
51 NEW_PROP_TAG(VtkOutputFormat);
52 NEW_PROP_TAG(EnableVtkOutput);
53 
54 // set default values for what quantities to output
55 SET_BOOL_PROP(VtkComposition, VtkWriteMassFractions, false);
56 SET_BOOL_PROP(VtkComposition, VtkWriteMoleFractions, true);
57 SET_BOOL_PROP(VtkComposition, VtkWriteTotalMassFractions, false);
58 SET_BOOL_PROP(VtkComposition, VtkWriteTotalMoleFractions, false);
59 SET_BOOL_PROP(VtkComposition, VtkWriteMolarities, false);
60 SET_BOOL_PROP(VtkComposition, VtkWriteFugacities, false);
61 SET_BOOL_PROP(VtkComposition, VtkWriteFugacityCoeffs, false);
62 } // namespace Properties
63 
76 template <class TypeTag>
77 class VtkCompositionModule : public BaseOutputModule<TypeTag>
78 {
80 
81  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
82  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
83  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
84  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
85 
86  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
87 
88  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
89  enum { numComponents = GET_PROP_VALUE(TypeTag, NumComponents) };
90 
91  static const int vtkFormat = GET_PROP_VALUE(TypeTag, VtkOutputFormat);
93 
94  typedef typename ParentType::ComponentBuffer ComponentBuffer;
95  typedef typename ParentType::PhaseComponentBuffer PhaseComponentBuffer;
96 
97 public:
98  VtkCompositionModule(const Simulator& simulator)
99  : ParentType(simulator)
100  { }
101 
105  static void registerParameters()
106  {
107  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteMassFractions,
108  "Include mass fractions in the VTK output files");
109  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteMoleFractions,
110  "Include mole fractions in the VTK output files");
111  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteTotalMassFractions,
112  "Include total mass fractions in the VTK output files");
113  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteTotalMoleFractions,
114  "Include total mole fractions in the VTK output files");
115  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteMolarities,
116  "Include component molarities in the VTK output files");
117  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteFugacities,
118  "Include component fugacities in the VTK output files");
119  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteFugacityCoeffs,
120  "Include component fugacity coefficients in the VTK output files");
121  }
122 
128  {
129  if (moleFracOutput_())
130  this->resizePhaseComponentBuffer_(moleFrac_);
131  if (massFracOutput_())
132  this->resizePhaseComponentBuffer_(massFrac_);
133  if (totalMassFracOutput_())
134  this->resizeComponentBuffer_(totalMassFrac_);
135  if (totalMoleFracOutput_())
136  this->resizeComponentBuffer_(totalMoleFrac_);
137  if (molarityOutput_())
138  this->resizePhaseComponentBuffer_(molarity_);
139 
140  if (fugacityOutput_())
141  this->resizeComponentBuffer_(fugacity_);
142  if (fugacityCoeffOutput_())
143  this->resizePhaseComponentBuffer_(fugacityCoeff_);
144  }
145 
150  void processElement(const ElementContext& elemCtx)
151  {
152  typedef Opm::MathToolbox<Evaluation> Toolbox;
153 
154  if (!EWOMS_GET_PARAM(TypeTag, bool, EnableVtkOutput))
155  return;
156 
157  for (unsigned i = 0; i < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++i) {
158  unsigned I = elemCtx.globalSpaceIndex(i, /*timeIdx=*/0);
159  const auto& intQuants = elemCtx.intensiveQuantities(i, /*timeIdx=*/0);
160  const auto& fs = intQuants.fluidState();
161 
162  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
163  for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
164  if (moleFracOutput_())
165  moleFrac_[phaseIdx][compIdx][I] = Toolbox::value(fs.moleFraction(phaseIdx, compIdx));
166  if (massFracOutput_())
167  massFrac_[phaseIdx][compIdx][I] = Toolbox::value(fs.massFraction(phaseIdx, compIdx));
168  if (molarityOutput_())
169  molarity_[phaseIdx][compIdx][I] = Toolbox::value(fs.molarity(phaseIdx, compIdx));
170 
171  if (fugacityCoeffOutput_())
172  fugacityCoeff_[phaseIdx][compIdx][I] =
173  Toolbox::value(fs.fugacityCoefficient(phaseIdx, compIdx));
174  }
175  }
176 
177  for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
178  if (totalMassFracOutput_()) {
179  Scalar compMass = 0;
180  Scalar totalMass = 0;
181  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
182  totalMass += Toolbox::value(fs.density(phaseIdx)) * Toolbox::value(fs.saturation(phaseIdx));
183  compMass +=
184  Toolbox::value(fs.density(phaseIdx))
185  *Toolbox::value(fs.saturation(phaseIdx))
186  *Toolbox::value(fs.massFraction(phaseIdx, compIdx));
187  }
188  totalMassFrac_[compIdx][I] = compMass / totalMass;
189  }
190  if (totalMoleFracOutput_()) {
191  Scalar compMoles = 0;
192  Scalar totalMoles = 0;
193  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
194  totalMoles +=
195  Toolbox::value(fs.molarDensity(phaseIdx))
196  *Toolbox::value(fs.saturation(phaseIdx));
197  compMoles +=
198  Toolbox::value(fs.molarDensity(phaseIdx))
199  *Toolbox::value(fs.saturation(phaseIdx))
200  *Toolbox::value(fs.moleFraction(phaseIdx, compIdx));
201  }
202  totalMoleFrac_[compIdx][I] = compMoles / totalMoles;
203  }
204  if (fugacityOutput_())
205  fugacity_[compIdx][I] = Toolbox::value(intQuants.fluidState().fugacity(/*phaseIdx=*/0, compIdx));
206  }
207  }
208  }
209 
213  void commitBuffers(BaseOutputWriter& baseWriter)
214  {
215  VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
216  if (!vtkWriter) {
217  return;
218  }
219 
220  if (moleFracOutput_())
221  this->commitPhaseComponentBuffer_(baseWriter, "moleFrac_%s^%s", moleFrac_);
222  if (massFracOutput_())
223  this->commitPhaseComponentBuffer_(baseWriter, "massFrac_%s^%s", massFrac_);
224  if (molarityOutput_())
225  this->commitPhaseComponentBuffer_(baseWriter, "molarity_%s^%s", molarity_);
226  if (totalMassFracOutput_())
227  this->commitComponentBuffer_(baseWriter, "totalMassFrac^%s", totalMassFrac_);
228  if (totalMoleFracOutput_())
229  this->commitComponentBuffer_(baseWriter, "totalMoleFrac^%s", totalMoleFrac_);
230 
231  if (fugacityOutput_())
232  this->commitComponentBuffer_(baseWriter, "fugacity^%s", fugacity_);
233  if (fugacityCoeffOutput_())
234  this->commitPhaseComponentBuffer_(baseWriter, "fugacityCoeff_%s^%s", fugacityCoeff_);
235  }
236 
237 private:
238  static bool massFracOutput_()
239  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteMassFractions); }
240 
241  static bool moleFracOutput_()
242  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteMoleFractions); }
243 
244  static bool totalMassFracOutput_()
245  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteTotalMassFractions); }
246 
247  static bool totalMoleFracOutput_()
248  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteTotalMoleFractions); }
249 
250  static bool molarityOutput_()
251  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteMolarities); }
252 
253  static bool fugacityOutput_()
254  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteFugacities); }
255 
256  static bool fugacityCoeffOutput_()
257  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteFugacityCoeffs); }
258 
259  PhaseComponentBuffer moleFrac_;
260  PhaseComponentBuffer massFrac_;
261  PhaseComponentBuffer molarity_;
262  ComponentBuffer totalMassFrac_;
263  ComponentBuffer totalMoleFrac_;
264 
265  ComponentBuffer fugacity_;
266  PhaseComponentBuffer fugacityCoeff_;
267 };
268 
269 } // namespace Ewoms
270 
271 #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
Definition: baseauxiliarymodule.hh:37
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkcompositionmodule.hh:105
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:63
#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.
void allocBuffers()
Allocate memory for the scalar fields we would like to write to the VTK file.
Definition: vtkcompositionmodule.hh:127
#define NEW_TYPE_TAG(...)
Define a new type tag.
Definition: propertysystem.hh:169
void commitBuffers(BaseOutputWriter &baseWriter)
Add all buffers to the VTK output writer.
Definition: vtkcompositionmodule.hh:213
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:68
This file provides the infrastructure to retrieve run-time parameters.
void resizeComponentBuffer_(ComponentBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a component specific quantity.
Definition: baseoutputmodule.hh:258
The base class for writer modules.
Definition: baseoutputmodule.hh:80
void resizePhaseComponentBuffer_(PhaseComponentBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a phase and component specific buffer.
Definition: baseoutputmodule.hh:281
void commitComponentBuffer_(BaseOutputWriter &baseWriter, const char *pattern, ComponentBuffer &buffer, BufferType bufferType=DofBuffer)
Add a component-specific buffer to the result file.
Definition: baseoutputmodule.hh:431
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:99
Provides the magic behind the eWoms property system.
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
VTK output module for the fluid composition.
Definition: vtkcompositionmodule.hh:77
void processElement(const ElementContext &elemCtx)
Modify the internal buffers according to the intensive quantities relevant for an element...
Definition: vtkcompositionmodule.hh:150
void commitPhaseComponentBuffer_(BaseOutputWriter &baseWriter, const char *pattern, PhaseComponentBuffer &buffer, BufferType bufferType=DofBuffer)
Add a phase and component specific quantities to the output.
Definition: baseoutputmodule.hh:454