vtktpsamodule.hpp
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 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 <dune/common/dynmatrix.hh>
29#include <dune/common/fvector.hh>
30
31#include <opm/material/densead/Math.hpp>
32
39
40namespace Opm {
41
47template <class TypeTag>
48class VtkTpsaModule : public BaseOutputModule<TypeTag>
49{
51
56
57 static constexpr auto vtkFormat = getPropValue<TypeTag, Properties::VtkOutputFormat>();
59
60 enum { enableMech = getPropValue<TypeTag, Properties::EnableMech>() };
61
62 using BufferType = typename ParentType::BufferType;
66
67 using SymTensor = Dune::FieldVector<Scalar, 6>;
68 using Tensor = Dune::DynamicMatrix<Scalar>;
69
70public:
76 explicit VtkTpsaModule(const Simulator& simulator)
77 : ParentType(simulator)
78 {
79 // Read runtime parameters
80 if constexpr(enableMech) {
81 params_.read();
82 }
83 }
84
88 static void registerParameters()
89 {
90 if constexpr(enableMech) {
92 }
93 }
94
98 void allocBuffers() override
99 {
100 // Check if vtk output is enabled
101 if (!Parameters::Get<Parameters::EnableVtkOutput>()) {
102 return;
103 }
104
105 // Allocate buffers
106 if constexpr(enableMech) {
107 // Displacement
108 if (params_.displacementOutput_) {
109 this->resizeVectorBuffer_(displacement_, BufferType::Dof);
110 }
111
112 // Rotation
113 if (params_.rotationOutput_) {
114 this->resizeVectorBuffer_(rotation_, BufferType::Dof);
115 }
116
117 // Solid pressure
118 if (params_.solidPressureOutput_) {
119 this->resizeScalarBuffer_(solidPres_, BufferType::Dof);
120 }
121
122 // Potential pressure force
123 if (params_.potPresForceOutput_) {
124 this->resizeScalarBuffer_(potPresForce_, BufferType::Dof);
125 }
126
127 // Stress
128 if (params_.stressOutput_) {
129 this->resizeTensorBuffer_(stress_, BufferType::Dof);
130 }
131
132 // Stress (without potential fracture contributions)
133 if (params_.delStressOutput_) {
134 this->resizeTensorBuffer_(delStress_, BufferType::Dof);
135 }
136
137 // Stress (without potential pressure/temperature/fracture forces)
138 if (params_.linStressOutput_) {
139 this->resizeTensorBuffer_(linStress_, BufferType::Dof);
140 }
141
142 // Strain
143 if (params_.strainOutput_) {
144 this->resizeTensorBuffer_(strain_, BufferType::Dof);
145 }
146 }
147 }
148
154 void processElement(const ElementContext& elemCtx) override
155 {
156 // Check if vtk output is enabled
157 if (!Parameters::Get<Parameters::EnableVtkOutput>()) {
158 return;
159 }
160
161 if constexpr(enableMech) {
162 // Assign quantities from material state
163 const auto& problem = elemCtx.problem();
164 const auto& geoMechModel = problem.geoMechModel();
165 const auto& faceStressInfo = geoMechModel.linearizer().getStressInfo();
166 for (unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) {
167 const unsigned globalDofIdx = elemCtx.globalSpaceIndex(dofIdx, /*timeIdx=*/0);
168 const auto& materialState = geoMechModel.materialState(globalDofIdx, /*timeIdx=*/0);
169
170 // Loop over x-, y- and z-dir (corresponding to dirIdx = 0, 1, 2)
171 for (int dirIdx = 0; dirIdx < 3; ++dirIdx) {
172 // Displacement
173 if (params_.displacementOutput_) {
174 displacement_[globalDofIdx][dirIdx] = scalarValue(materialState.displacement(dirIdx));
175 }
176
177 // Rotation
178 if (params_.rotationOutput_) {
179 rotation_[globalDofIdx][dirIdx] = scalarValue(materialState.rotation(dirIdx));
180 }
181 }
182
183 // Solid pressure
184 if (params_.solidPressureOutput_) {
185 solidPres_[globalDofIdx] = scalarValue(materialState.solidPressure());
186 }
187
188 // Potential pressure force
189 if (params_.potPresForceOutput_) {
190 potPresForce_[globalDofIdx] =
191 geoMechModel.mechPotentialPressForce(globalDofIdx);
192 }
193
194 // Stress
195 if (params_.stressOutput_ && !faceStressInfo.empty()) {
196 SymTensor stressSymTensor = geoMechModel.stress(globalDofIdx, true);
197 Tensor& stressTensor = stress_[globalDofIdx];
198 setTensorFromVoigt_(stressTensor, stressSymTensor);
199 }
200
201 // Stress (without potential fracture contributions)
202 if (params_.delStressOutput_ && !faceStressInfo.empty()) {
203 SymTensor delStressSymTensor = geoMechModel.delstress(globalDofIdx);
204 Tensor& delStressTensor = delStress_[globalDofIdx];
205 setTensorFromVoigt_(delStressTensor, delStressSymTensor);
206 }
207
208 // Stress (without potential pressure/temperature/fracture forces)
209 if (params_.linStressOutput_ && !faceStressInfo.empty()) {
210 SymTensor linStressSymTensor = geoMechModel.linstress(globalDofIdx);
211 Tensor& linStressTensor = linStress_[globalDofIdx];
212 setTensorFromVoigt_(linStressTensor, linStressSymTensor);
213 }
214
215 // Strain
216 if (params_.strainOutput_ && !faceStressInfo.empty()) {
217 SymTensor strainSymTensor = geoMechModel.strain(globalDofIdx, true);
218 Tensor& strainTensor = strain_[globalDofIdx];
219 setTensorFromVoigt_(strainTensor, strainSymTensor);
220 }
221 }
222 }
223 }
224
230 void commitBuffers(BaseOutputWriter& baseWriter) override
231 {
232 // Check if writer exists or mechanics output is enabled
233 if (!dynamic_cast<VtkMultiWriter*>(&baseWriter)) {
234 return;
235 }
236
237 if constexpr(enableMech) {
238 // Displacement
239 if (params_.displacementOutput_) {
240 this->commitVectorBuffer_(baseWriter, "displacement", displacement_, BufferType::Dof);
241 }
242
243 // Rotation
244 if (params_.rotationOutput_) {
245 this->commitVectorBuffer_(baseWriter, "rotation", rotation_, BufferType::Dof);
246 }
247
248 // Solid pressure
249 if (params_.solidPressureOutput_) {
250 this->commitScalarBuffer_(baseWriter, "solid_pressure", solidPres_, BufferType::Dof);
251 }
252
253 if (params_.potPresForceOutput_) {
254 this->commitScalarBuffer_(baseWriter,
255 "potentialPressureForce",
256 potPresForce_,
257 BufferType::Dof);
258 }
259
260 if (params_.stressOutput_) {
261 this->commitTensorBuffer_(baseWriter, "stress", stress_, BufferType::Dof);
262 }
263
264 if (params_.delStressOutput_) {
265 this->commitTensorBuffer_(baseWriter, "delStress", delStress_, BufferType::Dof);
266 }
267
268 if (params_.linStressOutput_) {
269 this->commitTensorBuffer_(baseWriter, "linStress", linStress_, BufferType::Dof);
270 }
271
272 if (params_.strainOutput_) {
273 this->commitTensorBuffer_(baseWriter, "strain", strain_, BufferType::Dof);
274 }
275 }
276 }
277
278private:
279 static void setTensorFromVoigt_(Tensor& tensor, const SymTensor& symTensor)
280 {
281 // Diagonal terms
282 for (std::size_t i = 0; i < 3; ++i) {
283 tensor[i][i] = symTensor[i];
284 }
285
286 // Off-diagonal terms
287 tensor[0][1] = symTensor[5];
288 tensor[0][2] = symTensor[4];
289 tensor[1][2] = symTensor[3];
290 for (std::size_t i = 0; i < 3; ++i) {
291 for (std::size_t j = 0; j < 3; ++j) {
292 if (i > j) {
293 tensor[i][j] = tensor[j][i];
294 }
295 }
296 }
297 }
298
299 VtkTpsaParams params_{};
300
301 VectorBuffer displacement_{};
302 VectorBuffer rotation_{};
303
304 ScalarBuffer solidPres_{};
305 ScalarBuffer potPresForce_{};
306
307 TensorBuffer stress_{};
308 TensorBuffer delStress_{};
309 TensorBuffer linStress_{};
310 TensorBuffer strain_{};
311}; // class VtkTpsaModule
312
313} // namespace Opm
314
315#endif
The base class for writer modules.
Definition: baseoutputmodule.hh:68
BaseOutputWriter::ScalarBuffer ScalarBuffer
Definition: baseoutputmodule.hh:86
void resizeScalarBuffer_(ScalarBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a scalar quantity.
Definition: baseoutputmodule.hh:157
void resizeVectorBuffer_(VectorBuffer &buffer, BufferType bufferType)
Definition: baseoutputmodule.hh:173
BaseOutputWriter::TensorBuffer TensorBuffer
Definition: baseoutputmodule.hh:88
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
BufferType
Definition: baseoutputmodule.hh:143
void commitTensorBuffer_(BaseOutputWriter &baseWriter, const char *name, TensorBuffer &buffer, BufferType bufferType)
Add a buffer containing tensorial quantities to the result file.
Definition: baseoutputmodule.hh:282
BaseOutputWriter::VectorBuffer VectorBuffer
Definition: baseoutputmodule.hh:87
void resizeTensorBuffer_(TensorBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a tensorial quantity.
Definition: baseoutputmodule.hh:166
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
The base class for all output writers.
Definition: baseoutputwriter.hh:46
Simplifies writing multi-file VTK datasets.
Definition: vtkmultiwriter.hh:65
VTK output module for TPSA quantities.
Definition: vtktpsamodule.hpp:49
static void registerParameters()
Register runtime parameters.
Definition: vtktpsamodule.hpp:88
void allocBuffers() override
Allocate memory for output.
Definition: vtktpsamodule.hpp:98
VtkTpsaModule(const Simulator &simulator)
Constructor.
Definition: vtktpsamodule.hpp:76
void commitBuffers(BaseOutputWriter &baseWriter) override
Add buffers to VTK writer.
Definition: vtktpsamodule.hpp:230
void processElement(const ElementContext &elemCtx) override
Assign quantities to output buffers.
Definition: vtktpsamodule.hpp:154
Definition: blackoilbioeffectsmodules.hh:45
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
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.
bool solidPressureOutput_
Definition: vtktpsaparams.hpp:55
bool stressOutput_
Definition: vtktpsaparams.hpp:56
static void registerParameters()
bool displacementOutput_
Definition: vtktpsaparams.hpp:53
bool linStressOutput_
Definition: vtktpsaparams.hpp:58
bool potPresForceOutput_
Definition: vtktpsaparams.hpp:60
bool rotationOutput_
Definition: vtktpsaparams.hpp:54
bool delStressOutput_
Definition: vtktpsaparams.hpp:57
bool strainOutput_
Definition: vtktpsaparams.hpp:59