baseoutputmodule.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_BASE_OUTPUT_MODULE_HH
28#define EWOMS_BASE_OUTPUT_MODULE_HH
29
30#include <dune/common/fvector.hh>
31
32#include <dune/istl/bvector.hh>
33
35
37
39
43
44#include <algorithm>
45#include <array>
46#include <cstdio>
47#include <stdexcept>
48#include <string>
49
50namespace Opm::Properties {
51
52template <class TypeTag, class MyTypeTag>
53struct FluidSystem;
54
55} // namespace Opm::Properties
56
57namespace Opm {
58
66template<class TypeTag>
68{
76
77 enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
78 enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
79 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
80 enum { dim = GridView::dimension };
81 enum { dimWorld = GridView::dimensionworld };
82 using Vector = BaseOutputWriter::Vector;
83 using Tensor = BaseOutputWriter::Tensor;
84
85public:
89
90 using EqBuffer = std::array<ScalarBuffer, numEq>;
91 using PhaseBuffer = std::array<ScalarBuffer, numPhases>;
92 using ComponentBuffer = std::array<ScalarBuffer, numComponents>;
93 using PhaseComponentBuffer = std::array<std::array<ScalarBuffer, numComponents>, numPhases>;
94
95 using PhaseVectorBuffer = std::array<VectorBuffer, numPhases>;
96
97 BaseOutputModule(const Simulator& simulator)
98 : simulator_(simulator)
99 {}
100
102 {}
103
112 virtual void allocBuffers() = 0;
113
122 virtual void processElement(const ElementContext& elemCtx) = 0;
123
127 virtual void commitBuffers(BaseOutputWriter& writer) = 0;
128
139 virtual bool needExtensiveQuantities() const
140 { return false; }
141
142protected:
143 enum class BufferType {
145 Dof,
146
148 Vertex,
149
151 Element,
152 };
153
158 {
159 buffer.resize(this->getBufferSize(bufferType));
160 std::fill(buffer.begin(), buffer.end(), 0.0);
161 }
162
167 {
168 buffer.resize(this->getBufferSize(bufferType));
169 const Tensor nullMatrix(dimWorld, dimWorld, 0.0);
170 std::fill(buffer.begin(), buffer.end(), nullMatrix);
171 }
172
174 {
175 buffer.resize(this->getBufferSize(bufferType));
176 Vector zerovector(dimWorld,0.0);
177 zerovector = 0.0;
178 std::fill(buffer.begin(), buffer.end(), zerovector);
179 }
180
185 void resizeEqBuffer_(EqBuffer& buffer, BufferType bufferType)
186 {
187 const std::size_t n = this->getBufferSize(bufferType);
188 for (unsigned i = 0; i < numEq; ++i) {
189 buffer[i].resize(n);
190 std::fill(buffer[i].begin(), buffer[i].end(), 0.0);
191 }
192 }
193
198 void resizePhaseBuffer_(PhaseBuffer& buffer, BufferType bufferType)
199 {
200 const std::size_t n = this->getBufferSize(bufferType);
201 for (unsigned i = 0; i < numPhases; ++i) {
202 buffer[i].resize(n);
203 std::fill(buffer[i].begin(), buffer[i].end(), 0.0);
204 }
205 }
206
212 {
213 const std::size_t n = this->getBufferSize(bufferType);
214 for (unsigned i = 0; i < numComponents; ++i) {
215 buffer[i].resize(n);
216 std::fill(buffer[i].begin(), buffer[i].end(), 0.0);
217 }
218 }
219
225 {
226 const std::size_t n = this->getBufferSize(bufferType);
227 for (unsigned i = 0; i < numPhases; ++i) {
228 for (unsigned j = 0; j < numComponents; ++j) {
229 buffer[i][j].resize(n);
230 std::fill(buffer[i][j].begin(), buffer[i][j].end(), 0.0);
231 }
232 }
233 }
234
239 const char *name,
240 ScalarBuffer& buffer,
241 BufferType bufferType)
242 {
243 switch (bufferType) {
244 case BufferType::Dof:
245 DiscBaseOutputModule::attachScalarDofData_(baseWriter, buffer, name);
246 break;
248 attachScalarVertexData_(baseWriter, buffer, name);
249 break;
251 attachScalarElementData_(baseWriter, buffer, name);
252 break;
253 default: throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
254 }
255 }
256
261 const char *name,
262 VectorBuffer& buffer,
263 BufferType bufferType)
264 {
265 switch (bufferType) {
266 case BufferType::Dof:
267 DiscBaseOutputModule::attachVectorDofData_(baseWriter, buffer, name);
268 break;
270 attachVectorVertexData_(baseWriter, buffer, name);
271 break;
273 attachVectorElementData_(baseWriter, buffer, name);
274 break;
275 default: throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
276 }
277 }
278
283 const char *name,
284 TensorBuffer& buffer,
285 BufferType bufferType)
286 {
287 switch (bufferType) {
288 case BufferType::Dof:
289 DiscBaseOutputModule::attachTensorDofData_(baseWriter, buffer, name);
290 break;
292 attachTensorVertexData_(baseWriter, buffer, name);
293 break;
295 attachTensorElementData_(baseWriter, buffer, name);
296 break;
297 default: throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
298 }
299 }
300
305 const char *pattern,
306 EqBuffer& buffer,
307 BufferType bufferType)
308 {
309 char name[512];
310 for (unsigned i = 0; i < numEq; ++i) {
311 const std::string eqName = simulator_.model().primaryVarName(i);
312 snprintf(name, 512, pattern, eqName.c_str());
313
314 this->commitScalarBuffer_(baseWriter, name, buffer[i], bufferType);
315 }
316 }
317
322 const char *pattern,
323 EqBuffer& buffer,
324 BufferType bufferType)
325 {
326 char name[512];
327 for (unsigned i = 0; i < numEq; ++i) {
328 snprintf(name, 512, pattern, std::to_string(i).c_str());
329
330 this->commitScalarBuffer_(baseWriter, name, buffer[i], bufferType);
331 }
332 }
333
338 const char *pattern,
339 PhaseBuffer& buffer,
340 BufferType bufferType)
341 {
342 char name[512];
343 for (unsigned i = 0; i < numPhases; ++i) {
344 snprintf(name, 512, pattern, FluidSystem::phaseName(i).data());
345
346 this->commitScalarBuffer_(baseWriter, name, buffer[i], bufferType);
347 }
348 }
349
354 const char *pattern,
355 ComponentBuffer& buffer,
356 BufferType bufferType)
357 {
358 char name[512];
359 for (unsigned i = 0; i < numComponents; ++i) {
360 snprintf(name, 512, pattern, FluidSystem::componentName(i).data());
361
362 this->commitScalarBuffer_(baseWriter, name, buffer[i], bufferType);
363 }
364 }
365
370 const char *pattern,
371 PhaseComponentBuffer& buffer,
372 BufferType bufferType)
373 {
374 char name[512];
375 for (unsigned i = 0; i < numPhases; ++i) {
376 for (unsigned j = 0; j < numComponents; ++j) {
377 snprintf(name, 512, pattern,
378 FluidSystem::phaseName(i).data(),
379 FluidSystem::componentName(j).data());
380
381 this->commitScalarBuffer_(baseWriter, name, buffer[i][j], bufferType);
382 }
383 }
384 }
385
387 ScalarBuffer& buffer,
388 const char *name)
389 { baseWriter.attachScalarElementData(buffer, name); }
390
392 ScalarBuffer& buffer,
393 const char *name)
394 { baseWriter.attachScalarVertexData(buffer, name); }
395
397 VectorBuffer& buffer,
398 const char *name)
399 { baseWriter.attachVectorElementData(buffer, name); }
400
402 VectorBuffer& buffer,
403 const char *name)
404 { baseWriter.attachVectorVertexData(buffer, name); }
405
407 TensorBuffer& buffer,
408 const char *name)
409 { baseWriter.attachTensorElementData(buffer, name); }
410
412 TensorBuffer& buffer,
413 const char *name)
414 { baseWriter.attachTensorVertexData(buffer, name); }
415
416 std::size_t getBufferSize(BufferType bufferType) const
417 {
418 switch (bufferType) {
419 case BufferType::Vertex: return simulator_.gridView().size(dim);
420 case BufferType::Element: return simulator_.gridView().size(0);
421 case BufferType::Dof: return simulator_.model().numGridDof();
422 default: throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
423 }
424 }
425
426 const Simulator& simulator_;
427};
428
429} // namespace Opm
430
431#endif
Defines a type tags and some fundamental properties all models.
The base class for writer modules.
Definition: baseoutputmodule.hh:68
BaseOutputWriter::ScalarBuffer ScalarBuffer
Definition: baseoutputmodule.hh:86
void commitEqBuffer_(BaseOutputWriter &baseWriter, const char *pattern, EqBuffer &buffer, BufferType bufferType)
Add a buffer with as many variables as PDEs to the result file.
Definition: baseoutputmodule.hh:321
void commitPhaseComponentBuffer_(BaseOutputWriter &baseWriter, const char *pattern, PhaseComponentBuffer &buffer, BufferType bufferType)
Add a phase and component specific quantities to the output.
Definition: baseoutputmodule.hh:369
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 commitComponentBuffer_(BaseOutputWriter &baseWriter, const char *pattern, ComponentBuffer &buffer, BufferType bufferType)
Add a component-specific buffer to the result file.
Definition: baseoutputmodule.hh:353
void attachVectorElementData_(BaseOutputWriter &baseWriter, VectorBuffer &buffer, const char *name)
Definition: baseoutputmodule.hh:396
virtual bool needExtensiveQuantities() const
Returns true iff the module needs to access the extensive quantities of a context to do its job.
Definition: baseoutputmodule.hh:139
std::size_t getBufferSize(BufferType bufferType) const
Definition: baseoutputmodule.hh:416
const Simulator & simulator_
Definition: baseoutputmodule.hh:426
std::array< VectorBuffer, numPhases > PhaseVectorBuffer
Definition: baseoutputmodule.hh:95
std::array< ScalarBuffer, numComponents > ComponentBuffer
Definition: baseoutputmodule.hh:92
std::array< ScalarBuffer, numPhases > PhaseBuffer
Definition: baseoutputmodule.hh:91
void resizeEqBuffer_(EqBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a equation specific quantity.
Definition: baseoutputmodule.hh:185
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
void commitPriVarsBuffer_(BaseOutputWriter &baseWriter, const char *pattern, EqBuffer &buffer, BufferType bufferType)
Add a buffer with as many variables as PDEs to the result file.
Definition: baseoutputmodule.hh:304
void attachScalarElementData_(BaseOutputWriter &baseWriter, ScalarBuffer &buffer, const char *name)
Definition: baseoutputmodule.hh:386
void attachVectorVertexData_(BaseOutputWriter &baseWriter, VectorBuffer &buffer, const char *name)
Definition: baseoutputmodule.hh:401
BufferType
Definition: baseoutputmodule.hh:143
@ Element
Buffer contains data associated with the grid's elements.
@ Dof
Buffer contains data associated with the degrees of freedom.
@ Vertex
Buffer contains data associated with the grid's vertices.
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
std::array< std::array< ScalarBuffer, numComponents >, numPhases > PhaseComponentBuffer
Definition: baseoutputmodule.hh:93
BaseOutputWriter::VectorBuffer VectorBuffer
Definition: baseoutputmodule.hh:87
virtual void processElement(const ElementContext &elemCtx)=0
Modify the internal buffers according to the intensive quanties relevant for an element.
BaseOutputModule(const Simulator &simulator)
Definition: baseoutputmodule.hh:97
void resizePhaseComponentBuffer_(PhaseComponentBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a phase and component specific buffer.
Definition: baseoutputmodule.hh:224
void resizeTensorBuffer_(TensorBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a tensorial quantity.
Definition: baseoutputmodule.hh:166
void attachScalarVertexData_(BaseOutputWriter &baseWriter, ScalarBuffer &buffer, const char *name)
Definition: baseoutputmodule.hh:391
void commitPhaseBuffer_(BaseOutputWriter &baseWriter, const char *pattern, PhaseBuffer &buffer, BufferType bufferType)
Add a phase-specific buffer to the result file.
Definition: baseoutputmodule.hh:337
virtual void commitBuffers(BaseOutputWriter &writer)=0
Add all buffers to the VTK output writer.
void attachTensorElementData_(BaseOutputWriter &baseWriter, TensorBuffer &buffer, const char *name)
Definition: baseoutputmodule.hh:406
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
virtual ~BaseOutputModule()
Definition: baseoutputmodule.hh:101
virtual void allocBuffers()=0
Allocate memory for the scalar fields we would like to write to disk.
void attachTensorVertexData_(BaseOutputWriter &baseWriter, TensorBuffer &buffer, const char *name)
Definition: baseoutputmodule.hh:411
void resizeComponentBuffer_(ComponentBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a component specific quantity.
Definition: baseoutputmodule.hh:211
void resizePhaseBuffer_(PhaseBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a phase-specific quantity.
Definition: baseoutputmodule.hh:198
std::array< ScalarBuffer, numEq > EqBuffer
Definition: baseoutputmodule.hh:90
The base class for all output writers.
Definition: baseoutputwriter.hh:46
virtual void attachVectorElementData(VectorBuffer &buf, std::string_view name)=0
Add a vectorial element centered quantity to the output.
Dune::DynamicVector< double > Vector
Definition: baseoutputwriter.hh:50
virtual void attachTensorElementData(TensorBuffer &buf, std::string_view name)=0
Add a tensorial element centered quantity to the output.
std::vector< Tensor > TensorBuffer
Definition: baseoutputwriter.hh:52
virtual void attachScalarVertexData(ScalarBuffer &buf, std::string_view name)=0
Add a scalar vertex centered vector field to the output.
virtual void attachVectorVertexData(VectorBuffer &buf, std::string_view name)=0
Add a vectorial vertex centered vector field to the output.
virtual void attachScalarElementData(ScalarBuffer &buf, std::string_view name)=0
Add a scalar element centered quantity to the output.
Dune::DynamicMatrix< double > Tensor
Definition: baseoutputwriter.hh:49
virtual void attachTensorVertexData(TensorBuffer &buf, std::string_view name)=0
Add a tensorial vertex centered tensor field to the output.
std::vector< Vector > VectorBuffer
Definition: baseoutputwriter.hh:53
std::vector< Scalar > ScalarBuffer
Definition: baseoutputwriter.hh:51
Declare the properties used by the infrastructure code of the finite volume discretizations.
Defines the common properties required by the porous medium multi-phase models.
Definition: blackoilmodel.hh:79
Definition: blackoilboundaryratevector.hh:39
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
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.