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