vtkenergymodule.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_ENERGY_MODULE_HH
26 #define EWOMS_VTK_ENERGY_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 energy output
39 NEW_TYPE_TAG(VtkEnergy);
40 
41 // create the property tags needed for the energy module
42 NEW_PROP_TAG(VtkWriteSolidHeatCapacity);
43 NEW_PROP_TAG(VtkWriteHeatConductivity);
44 NEW_PROP_TAG(VtkWriteInternalEnergies);
45 NEW_PROP_TAG(VtkWriteEnthalpies);
46 NEW_PROP_TAG(VtkOutputFormat);
47 
48 // set default values for what quantities to output
49 SET_BOOL_PROP(VtkEnergy, VtkWriteSolidHeatCapacity, false);
50 SET_BOOL_PROP(VtkEnergy, VtkWriteHeatConductivity, false);
51 SET_BOOL_PROP(VtkEnergy, VtkWriteInternalEnergies, false);
52 SET_BOOL_PROP(VtkEnergy, VtkWriteEnthalpies, false);
53 } // namespace Properties
54 } // namespace Ewoms
55 
56 namespace Ewoms {
69 template <class TypeTag>
70 class VtkEnergyModule : public BaseOutputModule<TypeTag>
71 {
73 
74  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
75  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
76  typedef typename GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
77  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
78  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
79 
80  typedef typename ParentType::ScalarBuffer ScalarBuffer;
81  typedef typename ParentType::PhaseBuffer PhaseBuffer;
82 
83  static const int vtkFormat = GET_PROP_VALUE(TypeTag, VtkOutputFormat);
84  enum { numPhases = GET_PROP_VALUE(TypeTag, NumPhases) };
85 
86  typedef typename Opm::MathToolbox<Evaluation> Toolbox;
88 
89 public:
90  VtkEnergyModule(const Simulator &simulator)
91  : ParentType(simulator)
92  {
93  }
94 
98  static void registerParameters()
99  {
100  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteSolidHeatCapacity,
101  "Include the specific heat capacities of rock "
102  "matrix in the VTK output files");
103  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteHeatConductivity,
104  "Include the lumped heat conductivity of the "
105  "medium in the VTK output files");
106  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteEnthalpies,
107  "Include the specific enthalpy of the phases in "
108  "the VTK output files");
109  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteInternalEnergies,
110  "Include the specific internal energy of the "
111  "phases in the VTK output files");
112  }
113 
119  {
120  if (enthalpyOutput_())
121  this->resizePhaseBuffer_(enthalpy_);
122  if (internalEnergyOutput_())
123  this->resizePhaseBuffer_(internalEnergy_);
124 
125  if (solidHeatCapacityOutput_())
126  this->resizeScalarBuffer_(solidHeatCapacity_);
127  if (heatConductivityOutput_())
128  this->resizeScalarBuffer_(heatConductivity_);
129  }
130 
135  void processElement(const ElementContext &elemCtx)
136  {
137  for (int i = 0; i < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++i) {
138  int I = elemCtx.globalSpaceIndex(i, /*timeIdx=*/0);
139  const auto &intQuants = elemCtx.intensiveQuantities(i, /*timeIdx=*/0);
140  const auto &fs = intQuants.fluidState();
141 
142  if (solidHeatCapacityOutput_())
143  solidHeatCapacity_[I] = Toolbox::value(intQuants.heatCapacitySolid());
144  if (heatConductivityOutput_())
145  heatConductivity_[I] = Toolbox::value(intQuants.heatConductivity());
146 
147  for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
148  if (enthalpyOutput_())
149  enthalpy_[phaseIdx][I] = Toolbox::value(fs.enthalpy(phaseIdx));
150  if (internalEnergyOutput_())
151  internalEnergy_[phaseIdx][I] = Toolbox::value(fs.internalEnergy(phaseIdx));
152  }
153  }
154  }
155 
159  void commitBuffers(BaseOutputWriter &baseWriter)
160  {
161  VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
162  if (!vtkWriter) {
163  return;
164  }
165 
166  if (solidHeatCapacityOutput_())
167  this->commitScalarBuffer_(baseWriter, "heatCapacitySolid", solidHeatCapacity_);
168  if (heatConductivityOutput_())
169  this->commitScalarBuffer_(baseWriter, "heatConductivity", heatConductivity_);
170 
171  if (enthalpyOutput_())
172  this->commitPhaseBuffer_(baseWriter, "enthalpy_%s", enthalpy_);
173  if (internalEnergyOutput_())
174  this->commitPhaseBuffer_(baseWriter, "internalEnergy_%s", internalEnergy_);
175  }
176 
177 private:
178  static bool solidHeatCapacityOutput_()
179  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteSolidHeatCapacity); }
180 
181  static bool heatConductivityOutput_()
182  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteHeatConductivity); }
183 
184  static bool enthalpyOutput_()
185  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteEnthalpies); }
186 
187  static bool internalEnergyOutput_()
188  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteInternalEnergies); }
189 
190  PhaseBuffer enthalpy_;
191  PhaseBuffer internalEnergy_;
192 
193  ScalarBuffer heatConductivity_;
194  ScalarBuffer solidHeatCapacity_;
195 };
196 
197 } // namespace Ewoms
198 
199 #endif
void resizeScalarBuffer_(ScalarBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a scalar quantity.
Definition: baseoutputmodule.hh:148
void resizePhaseBuffer_(PhaseBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a phase-specific quantity.
Definition: baseoutputmodule.hh:213
VTK output module for quantities which make sense for models which assume thermal equilibrium...
Definition: vtkenergymodule.hh:70
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:468
void processElement(const ElementContext &elemCtx)
Modify the internal buffers according to the intensive quanties relevant for an element.
Definition: vtkenergymodule.hh:135
NEW_PROP_TAG(Grid)
The type of the DUNE grid.
This file provides the infrastructure to retrieve run-time parameters.
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
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:64
void commitBuffers(BaseOutputWriter &baseWriter)
Add all buffers to the VTK output writer.
Definition: vtkenergymodule.hh:159
void allocBuffers()
Allocate memory for the scalar fields we would like to write to the VTK file.
Definition: vtkenergymodule.hh:118
std::array< ScalarBuffer, numPhases > PhaseBuffer
Definition: baseoutputmodule.hh:95
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:283
NEW_TYPE_TAG(AuxModule)
Provides the magic behind the eWoms property system.
The base class for writer modules.
void commitPhaseBuffer_(BaseOutputWriter &baseWriter, const char *pattern, PhaseBuffer &buffer, BufferType bufferType=DofBuffer)
Add a phase-specific buffer to the result file.
Definition: baseoutputmodule.hh:386
SET_BOOL_PROP(FvBaseDiscretization, EnableVtkOutput, true)
Enable the VTK output by default.
VtkEnergyModule(const Simulator &simulator)
Definition: vtkenergymodule.hh:90
The base class for writer modules.
Definition: baseoutputmodule.hh:71
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkenergymodule.hh:98
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:61
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:95
BaseOutputWriter::ScalarBuffer ScalarBuffer
Definition: baseoutputmodule.hh:90