opm-simulators
vtktpsamodule.hpp
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 2025 NORCE AS
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 
21  Consult the COPYING file in the top-level source directory of this
22  module for the precise wording of the license and the list of
23  copyright holders.
24 */
25 #ifndef VTK_TPSA_MODULE_HPP
26 #define VTK_TPSA_MODULE_HPP
27 
28 #include <opm/material/densead/Math.hpp>
29 
32 #include <opm/models/io/vtktpsaparams.hpp>
33 #include <opm/models/tpsa/tpsabaseproperties.hpp>
36 
37 
38 namespace Opm {
39 
45 template <class TypeTag>
46 class VtkTpsaModule : public BaseOutputModule<TypeTag>
47 {
49 
53 
54  static constexpr auto vtkFormat = getPropValue<TypeTag, Properties::VtkOutputFormat>();
56 
57  enum { enableMech = getPropValue<TypeTag, Properties::EnableMech>() };
58 
59  using BufferType = typename ParentType::BufferType;
60  using ScalarBuffer = typename ParentType::ScalarBuffer;
61  using VectorBuffer = typename ParentType::VectorBuffer;
62 
63 public:
69  explicit VtkTpsaModule(const Simulator& simulator)
70  : ParentType(simulator)
71  {
72  // Read runtime parameters
73  if constexpr(enableMech) {
74  params_.read();
75  }
76  }
77 
81  static void registerParameters()
82  {
83  if constexpr(enableMech) {
85  }
86  }
87 
91  void allocBuffers() override
92  {
93  // Check if vtk output is enabled
94  if (!Parameters::Get<Parameters::EnableVtkOutput>()) {
95  return;
96  }
97 
98  // Allocate buffers
99  if constexpr(enableMech) {
100  // Displacement
101  if (params_.displacementOutput_) {
102  this->resizeVectorBuffer_(displacement_, BufferType::Dof);
103  }
104 
105  // Rotation
106  if (params_.rotationOutput_) {
107  this->resizeVectorBuffer_(rotation_, BufferType::Dof);
108  }
109 
110  // Solid pressure
111  if (params_.solidPressureOutput_) {
112  this->resizeScalarBuffer_(solidPres_, BufferType::Dof);
113  }
114  }
115  }
116 
122  void processElement(const ElementContext& elemCtx) override
123  {
124  // Check if vtk output is enabled
125  if (!Parameters::Get<Parameters::EnableVtkOutput>()) {
126  return;
127  }
128 
129  if constexpr(enableMech) {
130  // Assign quantities from material state
131  const auto& problem = elemCtx.problem();
132  const auto& geoMechModel = problem.geoMechModel();
133  for (unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) {
134  const unsigned globalDofIdx = elemCtx.globalSpaceIndex(dofIdx, /*timeIdx=*/0);
135  const auto& materialState = geoMechModel.materialState(globalDofIdx, /*timeIdx=*/0);
136 
137  // Loop over x-, y- and z-dir (corresponding to dirIdx = 0, 1, 2)
138  for (int dirIdx = 0; dirIdx < 3; ++dirIdx) {
139  // Displacement
140  if (params_.displacementOutput_) {
141  displacement_[globalDofIdx][dirIdx] = scalarValue(materialState.displacement(dirIdx));
142  }
143 
144  // Rotation
145  if (params_.rotationOutput_) {
146  rotation_[globalDofIdx][dirIdx] = scalarValue(materialState.rotation(dirIdx));
147  }
148  }
149 
150  // Solid pressure
151  if (params_.solidPressureOutput_) {
152  solidPres_[globalDofIdx] = scalarValue(materialState.solidPressure());
153  }
154  }
155  }
156  }
157 
163  void commitBuffers(BaseOutputWriter& baseWriter) override
164  {
165  // Check if writer exists or mechanics output is enabled
166  if (!dynamic_cast<VtkMultiWriter*>(&baseWriter)) {
167  return;
168  }
169 
170  if constexpr(enableMech) {
171  // Displacement
172  if (params_.displacementOutput_) {
173  this->commitVectorBuffer_(baseWriter, "displacement", displacement_, BufferType::Dof);
174  }
175 
176  // Rotation
177  if (params_.rotationOutput_) {
178  this->commitVectorBuffer_(baseWriter, "rotation", rotation_, BufferType::Dof);
179  }
180 
181  // Solid pressure
182  if (params_.solidPressureOutput_) {
183  this->commitScalarBuffer_(baseWriter, "solid_pressure", solidPres_, BufferType::Dof);
184  }
185  }
186  }
187 
188 private:
189  VtkTpsaParams params_{};
190 
191  VectorBuffer displacement_{};
192  VectorBuffer rotation_{};
193  ScalarBuffer solidPres_{};
194 }; // class VtkTpsaModule
195 
196 } // namespace Opm
197 
198 #endif
VtkTpsaModule(const Simulator &simulator)
Constructor.
Definition: vtktpsamodule.hpp:69
VTK output module for TPSA quantities.
Definition: vtktpsamodule.hpp:46
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:233
void commitScalarBuffer_(BaseOutputWriter &baseWriter, const char *name, ScalarBuffer &buffer, BufferType bufferType)
Add a buffer containing scalar quantities to the result file.
Definition: baseoutputmodule.hh:238
This file provides the infrastructure to retrieve run-time parameters.
The base class for writer modules.
Definition: baseoutputmodule.hh:67
The base class for writer modules.
BufferType
Definition: baseoutputmodule.hh:143
static void registerParameters()
Register runtime parameters.
Definition: vtktpsamodule.hpp:81
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:64
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
The base class for all output writers.
Definition: baseoutputwriter.hh:45
void commitBuffers(BaseOutputWriter &baseWriter) override
Add buffers to VTK writer.
Definition: vtktpsamodule.hpp:163
void read()
Read runtime parameters.
Definition: vtktpsaparams.cpp:47
static void registerParameters()
Register runtime parameters.
Definition: vtktpsaparams.cpp:34
void allocBuffers() override
Allocate memory for output.
Definition: vtktpsamodule.hpp:91
void resizeScalarBuffer_(ScalarBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a scalar quantity.
Definition: baseoutputmodule.hh:157
The Opm property system, traits with inheritance.
Simplifies writing multi-file VTK datasets.
void commitVectorBuffer_(BaseOutputWriter &baseWriter, const char *name, VectorBuffer &buffer, BufferType bufferType)
Add a buffer containing vectorial quantities to the result file.
Definition: baseoutputmodule.hh:260
Parameters for VtkTpsaOutputModule.
Definition: vtktpsaparams.hpp:43
void processElement(const ElementContext &elemCtx) override
Assign quantities to output buffers.
Definition: vtktpsamodule.hpp:122