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  Copyright (C) 2010-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_PRIMARY_VARS_MODULE_HH
26 #define EWOMS_VTK_PRIMARY_VARS_MODULE_HH
27 
30 
33 
34 namespace Ewoms {
35 namespace Properties {
36 // create new type tag for the VTK primary variables output
37 NEW_TYPE_TAG(VtkPrimaryVars);
38 
39 // create the property tags needed for the primary variables module
40 NEW_PROP_TAG(VtkWritePrimaryVars);
41 NEW_PROP_TAG(VtkWriteProcessRank);
42 NEW_PROP_TAG(VtkWriteDofIndex);
43 NEW_PROP_TAG(VtkOutputFormat);
44 
45 SET_BOOL_PROP(VtkPrimaryVars, VtkWritePrimaryVars, false);
46 SET_BOOL_PROP(VtkPrimaryVars, VtkWriteProcessRank, false);
47 SET_BOOL_PROP(VtkPrimaryVars, VtkWriteDofIndex, false);
48 } // namespace Properties
49 
55 template<class TypeTag>
56 class VtkPrimaryVarsModule : public BaseOutputModule<TypeTag>
57 {
59 
60  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
61  typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
62  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
63 
64  static const int vtkFormat = GET_PROP_VALUE(TypeTag, VtkOutputFormat);
66 
67  typedef typename ParentType::ScalarBuffer ScalarBuffer;
68  typedef typename ParentType::EqBuffer EqBuffer;
69 
70  enum { numEq = GET_PROP_VALUE(TypeTag, NumEq) };
71 
72 public:
73  VtkPrimaryVarsModule(const Simulator &simulator)
74  : ParentType(simulator)
75  { }
76 
80  static void registerParameters()
81  {
82  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWritePrimaryVars,
83  "Include the primary variables in the VTK output files");
84  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteProcessRank,
85  "Include the MPI process rank in the VTK output files");
86  EWOMS_REGISTER_PARAM(TypeTag, bool, VtkWriteDofIndex,
87  "Include the index of the degrees of freedom in the VTK output files");
88  }
89 
94  void allocBuffers()
95  {
96  if (primaryVarsOutput_())
97  this->resizeEqBuffer_(primaryVars_);
98  if (processRankOutput_())
99  this->resizeScalarBuffer_(processRank_,
100  /*bufferType=*/ParentType::ElementBuffer);
101  if (dofIndexOutput_())
102  this->resizeScalarBuffer_(dofIndex_);
103  }
104 
109  void processElement(const ElementContext &elemCtx)
110  {
111  const auto &elementMapper = elemCtx.model().elementMapper();
112 #if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 4)
113  int elemIdx = elementMapper.index(elemCtx.element());
114 #else
115  int elemIdx = elementMapper .map(elemCtx.element());
116 #endif
117  if (processRankOutput_() && !processRank_.empty())
118  processRank_[elemIdx] = this->simulator_.gridView().comm().rank();
119 
120  for (int i = 0; i < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++i) {
121  int I = elemCtx.globalSpaceIndex(i, /*timeIdx=*/0);
122  const auto &priVars = elemCtx.primaryVars(i, /*timeIdx=*/0);
123 
124  if (dofIndexOutput_())
125  dofIndex_[I] = I;
126 
127  for (int eqIdx = 0; eqIdx < numEq; ++eqIdx) {
128  if (primaryVarsOutput_() && !primaryVars_[eqIdx].empty())
129  primaryVars_[eqIdx][I] = priVars[eqIdx];
130  }
131  }
132  }
133 
137  void commitBuffers(BaseOutputWriter &baseWriter)
138  {
139  VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
140  if (!vtkWriter) {
141  return;
142  }
143 
144  if (primaryVarsOutput_())
145  this->commitPriVarsBuffer_(baseWriter, "PV_%s", primaryVars_);
146  if (processRankOutput_())
147  this->commitScalarBuffer_(baseWriter,
148  "process rank",
149  processRank_,
150  /*bufferType=*/ParentType::ElementBuffer);
151  if (dofIndexOutput_())
152  this->commitScalarBuffer_(baseWriter, "DOF index", dofIndex_);
153  }
154 
155 private:
156  static bool primaryVarsOutput_()
157  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWritePrimaryVars); }
158  static bool processRankOutput_()
159  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteProcessRank); }
160  static bool dofIndexOutput_()
161  { return EWOMS_GET_PARAM(TypeTag, bool, VtkWriteDofIndex); }
162 
163  EqBuffer primaryVars_;
164  ScalarBuffer processRank_;
165  ScalarBuffer dofIndex_;
166 };
167 
168 } // namespace Ewoms
169 
170 #endif
Buffer contains data associated with the grid's elements.
Definition: baseoutputmodule.hh:142
void allocBuffers()
Allocate memory for the scalar fields we would like to write to the VTK file.
Definition: vtkprimaryvarsmodule.hh:94
VtkPrimaryVarsModule(const Simulator &simulator)
Definition: vtkprimaryvarsmodule.hh:73
void resizeScalarBuffer_(ScalarBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a scalar quantity.
Definition: baseoutputmodule.hh:148
void commitBuffers(BaseOutputWriter &baseWriter)
Add all buffers to the VTK output writer.
Definition: vtkprimaryvarsmodule.hh:137
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:468
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:337
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkprimaryvarsmodule.hh:80
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
void resizeEqBuffer_(EqBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a equation specific quantity.
Definition: baseoutputmodule.hh:190
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:64
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
VTK output module for the fluid composition.
Definition: vtkprimaryvarsmodule.hh:56
GridView & gridView()
Return the grid view for which the simulation is done.
Definition: simulator.hh:164
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.
void processElement(const ElementContext &elemCtx)
Modify the internal buffers according to the intensive quantities relevant for an element...
Definition: vtkprimaryvarsmodule.hh:109
The base class for writer modules.
Definition: baseoutputmodule.hh:71
const Simulator & simulator_
Definition: baseoutputmodule.hh:487
std::array< ScalarBuffer, numEq > EqBuffer
Definition: baseoutputmodule.hh:94
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