All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vtkprimaryvarsmodule.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_PRIMARY_VARS_MODULE_HH
28 #define EWOMS_VTK_PRIMARY_VARS_MODULE_HH
29 
32 
35 
36 namespace Ewoms {
37 namespace Properties {
38 // create new type tag for the VTK primary variables output
39 NEW_PROP_TAG(EnableVtkOutput);
40 NEW_TYPE_TAG(VtkPrimaryVars);
41 
42 // create the property tags needed for the primary variables module
43 NEW_PROP_TAG(VtkWritePrimaryVars);
44 NEW_PROP_TAG(VtkWriteProcessRank);
45 NEW_PROP_TAG(VtkWriteDofIndex);
46 NEW_PROP_TAG(VtkOutputFormat);
47 NEW_PROP_TAG(EnableVtkOutput);
48 
49 SET_BOOL_PROP(VtkPrimaryVars, VtkWritePrimaryVars, false);
50 SET_BOOL_PROP(VtkPrimaryVars, VtkWriteProcessRank, false);
51 SET_BOOL_PROP(VtkPrimaryVars, VtkWriteDofIndex, false);
52 } // namespace Properties
53 
59 template<class TypeTag>
60 class VtkPrimaryVarsModule : public BaseOutputModule<TypeTag>
61 {
63 
64  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
65  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
66  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
67 
68  static const int vtkFormat = GET_PROP_VALUE(TypeTag, VtkOutputFormat);
70 
71  typedef typename ParentType::ScalarBuffer ScalarBuffer;
72  typedef typename ParentType::EqBuffer EqBuffer;
73 
74  enum { numEq = GET_PROP_VALUE(TypeTag, NumEq) };
75 
76 public:
77  VtkPrimaryVarsModule(const Simulator& simulator)
78  : ParentType(simulator)
79  { }
80 
84  static void registerParameters()
85  {
86  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWritePrimaryVars,
87  "Include the primary variables into the VTK output files");
88  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteProcessRank,
89  "Include the MPI process rank into the VTK output files");
90  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteDofIndex,
91  "Include the index of the degrees of freedom into the VTK output files");
92  }
93 
98  void allocBuffers()
99  {
100  if (primaryVarsOutput_())
101  this->resizeEqBuffer_(primaryVars_);
102  if (processRankOutput_())
103  this->resizeScalarBuffer_(processRank_,
104  /*bufferType=*/ParentType::ElementBuffer);
105  if (dofIndexOutput_())
106  this->resizeScalarBuffer_(dofIndex_);
107  }
108 
113  void processElement(const ElementContext& elemCtx)
114  {
115  if (!EWOMS_GET_PARAM(TypeTag, bool, EnableVtkOutput))
116  return;
117 
118  const auto& elementMapper = elemCtx.model().elementMapper();
119  unsigned elemIdx = static_cast<unsigned>(elementMapper.index(elemCtx.element()));
120  if (processRankOutput_() && !processRank_.empty())
121  processRank_[elemIdx] = static_cast<unsigned>(this->simulator_.gridView().comm().rank());
122 
123  for (unsigned i = 0; i < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++i) {
124  unsigned I = elemCtx.globalSpaceIndex(i, /*timeIdx=*/0);
125  const auto& priVars = elemCtx.primaryVars(i, /*timeIdx=*/0);
126 
127  if (dofIndexOutput_())
128  dofIndex_[I] = I;
129 
130  for (unsigned eqIdx = 0; eqIdx < numEq; ++eqIdx) {
131  if (primaryVarsOutput_() && !primaryVars_[eqIdx].empty())
132  primaryVars_[eqIdx][I] = priVars[eqIdx];
133  }
134  }
135  }
136 
140  void commitBuffers(BaseOutputWriter& baseWriter)
141  {
142  VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
143  if (!vtkWriter) {
144  return;
145  }
146 
147  if (primaryVarsOutput_())
148  this->commitPriVarsBuffer_(baseWriter, "PV_%s", primaryVars_);
149  if (processRankOutput_())
150  this->commitScalarBuffer_(baseWriter,
151  "process rank",
152  processRank_,
153  /*bufferType=*/ParentType::ElementBuffer);
154  if (dofIndexOutput_())
155  this->commitScalarBuffer_(baseWriter, "DOF index", dofIndex_);
156  }
157 
158 private:
159  static bool primaryVarsOutput_()
160  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWritePrimaryVars); }
161  static bool processRankOutput_()
162  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteProcessRank); }
163  static bool dofIndexOutput_()
164  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteDofIndex); }
165 
166  EqBuffer primaryVars_;
167  ScalarBuffer processRank_;
168  ScalarBuffer dofIndex_;
169 };
170 
171 } // namespace Ewoms
172 
173 #endif
void commitBuffers(BaseOutputWriter &baseWriter)
Add all buffers to the VTK output writer.
Definition: vtkprimaryvarsmodule.hh:140
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
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:63
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:305
#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.
#define NEW_TYPE_TAG(...)
Define a new type tag.
Definition: propertysystem.hh:169
void commitPriVarsBuffer_(BaseOutputWriter &baseWriter, const char *pattern, EqBuffer &buffer, BufferType bufferType=DofBuffer)
Add a buffer with as many variables as PDEs to the result file.
Definition: baseoutputmodule.hh:359
Buffer contains data associated with the grid&#39;s elements.
Definition: baseoutputmodule.hh:164
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:68
void resizeEqBuffer_(EqBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a equation specific quantity.
Definition: baseoutputmodule.hh:212
This file provides the infrastructure to retrieve run-time parameters.
The base class for writer modules.
Definition: baseoutputmodule.hh:80
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:99
Provides the magic behind the eWoms property system.
void resizeScalarBuffer_(ScalarBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a scalar quantity.
Definition: baseoutputmodule.hh:170
Simplifies writing multi-file VTK datasets.
VTK output module for the fluid composition.
Definition: vtkprimaryvarsmodule.hh:60
void processElement(const ElementContext &elemCtx)
Modify the internal buffers according to the intensive quantities relevant for an element...
Definition: vtkprimaryvarsmodule.hh:113
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkprimaryvarsmodule.hh:84
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 allocBuffers()
Allocate memory for the scalar fields we would like to write to the VTK file.
Definition: vtkprimaryvarsmodule.hh:98
const GridView & gridView() const
Return the grid view for which the simulation is done.
Definition: simulator.hh:183