vtkdiffusionmodule.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 */
28 #ifndef EWOMS_VTK_DIFFUSION_MODULE_HH
29 #define EWOMS_VTK_DIFFUSION_MODULE_HH
30 
31 #include "vtkmultiwriter.hh"
32 #include "baseoutputmodule.hh"
33 
36 
37 #include <opm/material/densead/Evaluation.hpp>
38 #include <opm/material/densead/Math.hpp>
39 
40 namespace Ewoms {
41 namespace Properties {
42 // create new type tag for the VTK output of the quantities for molecular
43 // diffusion
44 NEW_TYPE_TAG(VtkDiffusion);
45 
46 // create the property tags needed for the diffusion module
47 NEW_PROP_TAG(VtkWriteTortuosities);
48 NEW_PROP_TAG(VtkWriteDiffusionCoefficients);
49 NEW_PROP_TAG(VtkWriteEffectiveDiffusionCoefficients);
50 NEW_PROP_TAG(VtkOutputFormat);
51 NEW_PROP_TAG(EnableVtkOutput);
52 
53 // set default values for what quantities to output
54 SET_BOOL_PROP(VtkDiffusion, VtkWriteTortuosities, false);
55 SET_BOOL_PROP(VtkDiffusion, VtkWriteDiffusionCoefficients, false);
56 SET_BOOL_PROP(VtkDiffusion, VtkWriteEffectiveDiffusionCoefficients, false);
57 } // namespace Properties
58 } // namespace Ewoms
59 
60 namespace Ewoms {
72 template <class TypeTag>
73 class VtkDiffusionModule : public BaseOutputModule<TypeTag>
74 {
76 
77  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
78  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
79  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
80  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
81 
82  typedef Opm::MathToolbox<Evaluation> Toolbox;
83 
84  typedef typename ParentType::PhaseComponentBuffer PhaseComponentBuffer;
85  typedef typename ParentType::PhaseBuffer PhaseBuffer;
86 
87  static const int vtkFormat = GET_PROP_VALUE(TypeTag, VtkOutputFormat);
89 
90  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
91  enum { numComponents = GET_PROP_VALUE(TypeTag, NumComponents) };
92 
93 public:
94  VtkDiffusionModule(const Simulator& simulator)
95  : ParentType(simulator)
96  { }
97 
101  static void registerParameters()
102  {
103  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteTortuosities,
104  "Include the tortuosity for each phase in the VTK "
105  "output files");
106  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteDiffusionCoefficients,
107  "Include the molecular diffusion coefficients in "
108  "the VTK output files");
109  EWOMS_REGISTER_PARAM(TypeTag, bool,
110  VtkWriteEffectiveDiffusionCoefficients,
111  "Include the effective molecular diffusion "
112  "coefficients the medium in the VTK output files");
113  }
114 
120  {
121  if (tortuosityOutput_())
122  this->resizePhaseBuffer_(tortuosity_);
123  if (diffusionCoefficientOutput_())
124  this->resizePhaseComponentBuffer_(diffusionCoefficient_);
125  if (effectiveDiffusionCoefficientOutput_())
126  this->resizePhaseComponentBuffer_(effectiveDiffusionCoefficient_);
127  }
128 
133  void processElement(const ElementContext& elemCtx)
134  {
135  if (!EWOMS_GET_PARAM(TypeTag, bool, EnableVtkOutput))
136  return;
137 
138  for (unsigned i = 0; i < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++i) {
139  unsigned I = elemCtx.globalSpaceIndex(i, /*timeIdx=*/0);
140  const auto& intQuants = elemCtx.intensiveQuantities(i, /*timeIdx=*/0);
141 
142  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
143  if (tortuosityOutput_())
144  tortuosity_[phaseIdx][I] = Toolbox::value(intQuants.tortuosity(phaseIdx));
145  for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
146  if (diffusionCoefficientOutput_())
147  diffusionCoefficient_[phaseIdx][compIdx][I] =
148  Toolbox::value(intQuants.diffusionCoefficient(phaseIdx, compIdx));
149  if (effectiveDiffusionCoefficientOutput_())
150  effectiveDiffusionCoefficient_[phaseIdx][compIdx][I] =
151  Toolbox::value(intQuants.effectiveDiffusionCoefficient(phaseIdx, compIdx));
152  }
153  }
154  }
155  }
156 
160  void commitBuffers(BaseOutputWriter& baseWriter)
161  {
162  VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
163  if (!vtkWriter) {
164  return;
165  }
166 
167  if (tortuosityOutput_())
168  this->commitPhaseBuffer_(baseWriter, "tortuosity", tortuosity_);
169  if (diffusionCoefficientOutput_())
170  this->commitPhaseComponentBuffer_(baseWriter, "diffusionCoefficient",
171  diffusionCoefficient_);
172  if (effectiveDiffusionCoefficientOutput_())
173  this->commitPhaseComponentBuffer_(baseWriter,
174  "effectiveDiffusionCoefficient",
175  effectiveDiffusionCoefficient_);
176  }
177 
178 private:
179  static bool tortuosityOutput_()
180  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteTortuosities); }
181 
182  static bool diffusionCoefficientOutput_()
183  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteDiffusionCoefficients); }
184 
185  static bool effectiveDiffusionCoefficientOutput_()
186  {
187  return EWOMS_GET_PARAM(TypeTag, bool,
188  VtkWriteEffectiveDiffusionCoefficients);
189  }
190 
191  PhaseBuffer tortuosity_;
192  PhaseComponentBuffer diffusionCoefficient_;
193  PhaseComponentBuffer effectiveDiffusionCoefficient_;
194 };
195 
196 } // namespace Ewoms
197 
198 #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
void commitPhaseBuffer_(BaseOutputWriter &baseWriter, const char *pattern, PhaseBuffer &buffer, BufferType bufferType=DofBuffer)
Add a phase-specific buffer to the result file.
Definition: baseoutputmodule.hh:408
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:63
void allocBuffers()
Allocate memory for the scalar fields we would like to write to the VTK file.
Definition: vtkdiffusionmodule.hh:119
#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 processElement(const ElementContext &elemCtx)
Modify the internal buffers according to the intensive quanties relevant for an element.
Definition: vtkdiffusionmodule.hh:133
#define NEW_TYPE_TAG(...)
Define a new type tag.
Definition: propertysystem.hh:169
#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.
The base class for writer modules.
Definition: baseoutputmodule.hh:80
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkdiffusionmodule.hh:101
void resizePhaseComponentBuffer_(PhaseComponentBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a phase and component specific buffer.
Definition: baseoutputmodule.hh:281
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:99
void resizePhaseBuffer_(PhaseBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a phase-specific quantity.
Definition: baseoutputmodule.hh:235
VTK output module for quantities which make sense for models which incorperate molecular diffusion...
Definition: vtkdiffusionmodule.hh:73
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
void commitBuffers(BaseOutputWriter &baseWriter)
Add all buffers to the VTK output writer.
Definition: vtkdiffusionmodule.hh:160
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