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
31
34
37
38namespace Opm::Parameters {
39
40struct VtkWritePrimaryVars { static constexpr bool value = false; };
41struct VtkWriteProcessRank { static constexpr bool value = false; };
42struct VtkWriteDofIndex { static constexpr bool value = false; };
43
44} // namespace Opm::Properties
45
46namespace Opm {
47
53template<class TypeTag>
55{
57
61
62 static const int vtkFormat = getPropValue<TypeTag, Properties::VtkOutputFormat>();
64
66 using EqBuffer = typename ParentType::EqBuffer;
67
68 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
69
70public:
71 VtkPrimaryVarsModule(const Simulator& simulator)
72 : ParentType(simulator)
73 { }
74
78 static void registerParameters()
79 {
80 Parameters::Register<Parameters::VtkWritePrimaryVars>
81 ("Include the primary variables into the VTK output files");
82 Parameters::Register<Parameters::VtkWriteProcessRank>
83 ("Include the MPI process rank into the VTK output files");
84 Parameters::Register<Parameters::VtkWriteDofIndex>
85 ("Include the index of the degrees of freedom into the VTK output files");
86 }
87
93 {
94 if (primaryVarsOutput_())
95 this->resizeEqBuffer_(primaryVars_);
96 if (processRankOutput_())
97 this->resizeScalarBuffer_(processRank_,
98 /*bufferType=*/ParentType::ElementBuffer);
99 if (dofIndexOutput_())
100 this->resizeScalarBuffer_(dofIndex_);
101 }
102
107 void processElement(const ElementContext& elemCtx)
108 {
109 if (!Parameters::Get<Parameters::EnableVtkOutput>()) {
110 return;
111 }
112
113 const auto& elementMapper = elemCtx.model().elementMapper();
114 unsigned elemIdx = static_cast<unsigned>(elementMapper.index(elemCtx.element()));
115 if (processRankOutput_() && !processRank_.empty())
116 processRank_[elemIdx] = static_cast<unsigned>(this->simulator_.gridView().comm().rank());
117
118 for (unsigned i = 0; i < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++i) {
119 unsigned I = elemCtx.globalSpaceIndex(i, /*timeIdx=*/0);
120 const auto& priVars = elemCtx.primaryVars(i, /*timeIdx=*/0);
121
122 if (dofIndexOutput_())
123 dofIndex_[I] = I;
124
125 for (unsigned eqIdx = 0; eqIdx < numEq; ++eqIdx) {
126 if (primaryVarsOutput_() && !primaryVars_[eqIdx].empty())
127 primaryVars_[eqIdx][I] = priVars[eqIdx];
128 }
129 }
130 }
131
136 {
137 VtkMultiWriter *vtkWriter = dynamic_cast<VtkMultiWriter*>(&baseWriter);
138 if (!vtkWriter) {
139 return;
140 }
141
142 if (primaryVarsOutput_())
143 this->commitPriVarsBuffer_(baseWriter, "PV_%s", primaryVars_);
144 if (processRankOutput_())
145 this->commitScalarBuffer_(baseWriter,
146 "process rank",
147 processRank_,
148 /*bufferType=*/ParentType::ElementBuffer);
149 if (dofIndexOutput_())
150 this->commitScalarBuffer_(baseWriter, "DOF index", dofIndex_);
151 }
152
153private:
154 static bool primaryVarsOutput_()
155 {
156 static bool val = Parameters::Get<Parameters::VtkWritePrimaryVars>();
157 return val;
158 }
159 static bool processRankOutput_()
160 {
161 static bool val = Parameters::Get<Parameters::VtkWriteProcessRank>();
162 return val;
163 }
164 static bool dofIndexOutput_()
165 {
166 static bool val = Parameters::Get<Parameters::VtkWriteDofIndex>();
167 return val;
168 }
169
170 EqBuffer primaryVars_;
171 ScalarBuffer processRank_;
172 ScalarBuffer dofIndex_;
173};
174
175} // namespace Opm
176
177#endif
The base class for writer modules.
Definition: baseoutputmodule.hh:67
BaseOutputWriter::ScalarBuffer ScalarBuffer
Definition: baseoutputmodule.hh:85
const Simulator & simulator_
Definition: baseoutputmodule.hh:434
@ ElementBuffer
Buffer contains data associated with the grid's elements.
Definition: baseoutputmodule.hh:150
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:310
void resizeEqBuffer_(EqBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a equation specific quantity.
Definition: baseoutputmodule.hh:187
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:244
std::array< ScalarBuffer, numEq > EqBuffer
Definition: baseoutputmodule.hh:89
void resizeScalarBuffer_(ScalarBuffer &buffer, BufferType bufferType=DofBuffer)
Allocate the space for a buffer storing a scalar quantity.
Definition: baseoutputmodule.hh:156
The base class for all output writers.
Definition: baseoutputwriter.hh:44
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:66
VTK output module for the fluid composition.
Definition: vtkprimaryvarsmodule.hh:55
VtkPrimaryVarsModule(const Simulator &simulator)
Definition: vtkprimaryvarsmodule.hh:71
void processElement(const ElementContext &elemCtx)
Modify the internal buffers according to the intensive quantities relevant for an element.
Definition: vtkprimaryvarsmodule.hh:107
void commitBuffers(BaseOutputWriter &baseWriter)
Add all buffers to the VTK output writer.
Definition: vtkprimaryvarsmodule.hh:135
void allocBuffers()
Allocate memory for the scalar fields we would like to write to the VTK file.
Definition: vtkprimaryvarsmodule.hh:92
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkprimaryvarsmodule.hh:78
Declare the properties used by the infrastructure code of the finite volume discretizations.
Definition: blackoilnewtonmethodparameters.hh:31
Definition: blackoilboundaryratevector.hh:37
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:235
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.
Definition: vtkprimaryvarsmodule.hh:42
static constexpr bool value
Definition: vtkprimaryvarsmodule.hh:42
Definition: vtkprimaryvarsmodule.hh:40
static constexpr bool value
Definition: vtkprimaryvarsmodule.hh:40
Definition: vtkprimaryvarsmodule.hh:41
static constexpr bool value
Definition: vtkprimaryvarsmodule.hh:41