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  Copyright (C) 2011-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
25 #ifndef EWOMS_VTK_COMPOSITION_MODULE_HH
26 #define EWOMS_VTK_COMPOSITION_MODULE_HH
27 
28 #include "vtkmultiwriter.hh"
29 #include "baseoutputmodule.hh"
30 
33 
34 #include <opm/material/common/MathToolbox.hpp>
35 
36 namespace Ewoms {
37 namespace Properties {
38 // create new type tag for the VTK composition output
39 NEW_TYPE_TAG(VtkComposition);
40 
41 // create the property tags needed for the composition module
42 NEW_PROP_TAG(VtkWriteMassFractions);
43 NEW_PROP_TAG(VtkWriteMoleFractions);
44 NEW_PROP_TAG(VtkWriteTotalMassFractions);
45 NEW_PROP_TAG(VtkWriteTotalMoleFractions);
46 NEW_PROP_TAG(VtkWriteMolarities);
47 NEW_PROP_TAG(VtkWriteFugacities);
48 NEW_PROP_TAG(VtkWriteFugacityCoeffs);
49 NEW_PROP_TAG(VtkOutputFormat);
50 
51 // set default values for what quantities to output
52 SET_BOOL_PROP(VtkComposition, VtkWriteMassFractions, false);
53 SET_BOOL_PROP(VtkComposition, VtkWriteMoleFractions, true);
54 SET_BOOL_PROP(VtkComposition, VtkWriteTotalMassFractions, false);
55 SET_BOOL_PROP(VtkComposition, VtkWriteTotalMoleFractions, false);
56 SET_BOOL_PROP(VtkComposition, VtkWriteMolarities, false);
57 SET_BOOL_PROP(VtkComposition, VtkWriteFugacities, false);
58 SET_BOOL_PROP(VtkComposition, VtkWriteFugacityCoeffs, false);
59 } // namespace Properties
60 
73 template <class TypeTag>
74 class VtkCompositionModule : public BaseOutputModule<TypeTag>
75 {
77 
78  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
79  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
80  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
81  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
82 
83  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
84 
85  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
86  enum { numComponents = GET_PROP_VALUE(TypeTag, NumComponents) };
87 
88  static const int vtkFormat = GET_PROP_VALUE(TypeTag, VtkOutputFormat);
90 
93 
94 public:
95  VtkCompositionModule(const Simulator &simulator)
96  : ParentType(simulator)
97  { }
98 
102  static void registerParameters()
103  {
104  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteMassFractions,
105  "Include mass fractions in the VTK output files");
106  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteMoleFractions,
107  "Include mole fractions in the VTK output files");
108  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteTotalMassFractions,
109  "Include total mass fractions in the VTK output files");
110  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteTotalMoleFractions,
111  "Include total mole fractions in the VTK output files");
112  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteMolarities,
113  "Include component molarities in the VTK output files");
114  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteFugacities,
115  "Include component fugacities in the VTK output files");
116  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteFugacityCoeffs,
117  "Include component fugacity coefficients in the VTK output files");
118  }
119 
125  {
126  if (moleFracOutput_())
127  this->resizePhaseComponentBuffer_(moleFrac_);
128  if (massFracOutput_())
129  this->resizePhaseComponentBuffer_(massFrac_);
130  if (totalMassFracOutput_())
131  this->resizeComponentBuffer_(totalMassFrac_);
132  if (totalMoleFracOutput_())
133  this->resizeComponentBuffer_(totalMoleFrac_);
134  if (molarityOutput_())
135  this->resizePhaseComponentBuffer_(molarity_);
136 
137  if (fugacityOutput_())
138  this->resizeComponentBuffer_(fugacity_);
139  if (fugacityCoeffOutput_())
140  this->resizePhaseComponentBuffer_(fugacityCoeff_);
141  }
142 
147  void processElement(const ElementContext &elemCtx)
148  {
149  typedef Opm::MathToolbox<Evaluation> Toolbox;
150 
151  for (int i = 0; i < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++i) {
152  int I = elemCtx.globalSpaceIndex(i, /*timeIdx=*/0);
153  const auto &intQuants = elemCtx.intensiveQuantities(i, /*timeIdx=*/0);
154  const auto &fs = intQuants.fluidState();
155 
156  for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
157  for (int compIdx = 0; compIdx < numComponents; ++compIdx) {
158  if (moleFracOutput_())
159  moleFrac_[phaseIdx][compIdx][I] = Toolbox::value(fs.moleFraction(phaseIdx, compIdx));
160  if (massFracOutput_())
161  massFrac_[phaseIdx][compIdx][I] = Toolbox::value(fs.massFraction(phaseIdx, compIdx));
162  if (molarityOutput_())
163  molarity_[phaseIdx][compIdx][I] = Toolbox::value(fs.molarity(phaseIdx, compIdx));
164 
165  if (fugacityCoeffOutput_())
166  fugacityCoeff_[phaseIdx][compIdx][I] =
167  Toolbox::value(fs.fugacityCoefficient(phaseIdx, compIdx));
168  }
169  }
170 
171  for (int compIdx = 0; compIdx < numComponents; ++compIdx) {
172  if (totalMassFracOutput_()) {
173  Scalar compMass = 0;
174  Scalar totalMass = 0;
175  for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
176  totalMass += Toolbox::value(fs.density(phaseIdx)) * Toolbox::value(fs.saturation(phaseIdx));
177  compMass +=
178  Toolbox::value(fs.density(phaseIdx))
179  *Toolbox::value(fs.saturation(phaseIdx))
180  *Toolbox::value(fs.massFraction(phaseIdx, compIdx));
181  }
182  totalMassFrac_[compIdx][I] = compMass / totalMass;
183  }
184  if (totalMoleFracOutput_()) {
185  Scalar compMoles = 0;
186  Scalar totalMoles = 0;
187  for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
188  totalMoles +=
189  Toolbox::value(fs.molarDensity(phaseIdx))
190  *Toolbox::value(fs.saturation(phaseIdx));
191  compMoles +=
192  Toolbox::value(fs.molarDensity(phaseIdx))
193  *Toolbox::value(fs.saturation(phaseIdx))
194  *Toolbox::value(fs.moleFraction(phaseIdx, compIdx));
195  }
196  totalMoleFrac_[compIdx][I] = compMoles / totalMoles;
197  }
198  if (fugacityOutput_())
199  fugacity_[compIdx][I] = Toolbox::value(intQuants.fluidState().fugacity(/*phaseIdx=*/0, compIdx));
200  }
201  }
202  }
203 
207  void commitBuffers(BaseOutputWriter &baseWriter)
208  {
209  VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
210  if (!vtkWriter) {
211  return;
212  }
213 
214  if (moleFracOutput_())
215  this->commitPhaseComponentBuffer_(baseWriter, "moleFrac_%s^%s", moleFrac_);
216  if (massFracOutput_())
217  this->commitPhaseComponentBuffer_(baseWriter, "massFrac_%s^%s", massFrac_);
218  if (molarityOutput_())
219  this->commitPhaseComponentBuffer_(baseWriter, "molarity_%s^%s", molarity_);
220  if (totalMassFracOutput_())
221  this->commitComponentBuffer_(baseWriter, "totalMassFrac^%s", totalMassFrac_);
222  if (totalMoleFracOutput_())
223  this->commitComponentBuffer_(baseWriter, "totalMoleFrac^%s", totalMoleFrac_);
224 
225  if (fugacityOutput_())
226  this->commitComponentBuffer_(baseWriter, "fugacity^%s", fugacity_);
227  if (fugacityCoeffOutput_())
228  this->commitPhaseComponentBuffer_(baseWriter, "fugacityCoeff_%s^%s", fugacityCoeff_);
229  }
230 
231 private:
232  static bool massFracOutput_()
233  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteMassFractions); }
234 
235  static bool moleFracOutput_()
236  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteMoleFractions); }
237 
238  static bool totalMassFracOutput_()
239  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteTotalMassFractions); }
240 
241  static bool totalMoleFracOutput_()
242  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteTotalMoleFractions); }
243 
244  static bool molarityOutput_()
245  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteMolarities); }
246 
247  static bool fugacityOutput_()
248  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteFugacities); }
249 
250  static bool fugacityCoeffOutput_()
251  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteFugacityCoeffs); }
252 
253  PhaseComponentBuffer moleFrac_;
254  PhaseComponentBuffer massFrac_;
255  PhaseComponentBuffer molarity_;
256  ComponentBuffer totalMassFrac_;
257  ComponentBuffer totalMoleFrac_;
258 
259  ComponentBuffer fugacity_;
260  PhaseComponentBuffer fugacityCoeff_;
261 };
262 
263 } // namespace Ewoms
264 
265 #endif
std::array< ScalarBuffer, numComponents > ComponentBuffer
Definition: baseoutputmodule.hh:96
void resizePhaseComponentBuffer_(PhaseComponentBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a phase and component specific buffer.
Definition: baseoutputmodule.hh:259
void processElement(const ElementContext &elemCtx)
Modify the internal buffers according to the intensive quantities relevant for an element...
Definition: vtkcompositionmodule.hh:147
void resizeComponentBuffer_(ComponentBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a component specific quantity.
Definition: baseoutputmodule.hh:236
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:468
std::array< std::array< ScalarBuffer, numComponents >, numPhases > PhaseComponentBuffer
Definition: baseoutputmodule.hh:97
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:432
NEW_PROP_TAG(Grid)
The type of the DUNE grid.
This file provides the infrastructure to retrieve run-time parameters.
void commitComponentBuffer_(BaseOutputWriter &baseWriter, const char *pattern, ComponentBuffer &buffer, BufferType bufferType=DofBuffer)
Add a component-specific buffer to the result file.
Definition: baseoutputmodule.hh:409
The base class for all output writers.
Definition: baseoutputwriter.hh:41
Simplifies writing multi-file VTK datasets.
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:73
Definition: baseauxiliarymodule.hh:35
void commitBuffers(BaseOutputWriter &baseWriter)
Add all buffers to the VTK output writer.
Definition: vtkcompositionmodule.hh:207
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:64
void allocBuffers()
Allocate memory for the scalar fields we would like to write to the VTK file.
Definition: vtkcompositionmodule.hh:124
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkcompositionmodule.hh:102
VtkCompositionModule(const Simulator &simulator)
Definition: vtkcompositionmodule.hh:95
NEW_TYPE_TAG(AuxModule)
Provides the magic behind the eWoms property system.
The base class for writer modules.
SET_BOOL_PROP(FvBaseDiscretization, EnableVtkOutput, true)
Enable the VTK output by default.
The base class for writer modules.
Definition: baseoutputmodule.hh:71
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:61
VTK output module for the fluid composition.
Definition: vtkcompositionmodule.hh:74
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:95