Loading...
Searching...
No Matches
baseoutputmodule.hh
Go to the documentation of this file.
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
#ifndef EWOMS_BASE_OUTPUT_MODULE_HH
#define EWOMS_BASE_OUTPUT_MODULE_HH
#include <dune/common/fvector.hh>
#include <dune/istl/bvector.hh>
#include <opm/models/common/multiphasebaseproperties.hh>
#include <opm/models/discretization/common/fvbaseproperties.hh>
#include <opm/models/io/baseoutputwriter.hh>
#include <opm/models/utils/basicproperties.hh>
#include <opm/models/utils/parametersystem.hpp>
#include <opm/models/utils/propertysystem.hh>
#include <algorithm>
#include <array>
#include <cstdio>
#include <stdexcept>
#include <string>
namespace Opm::Properties {
template <class TypeTag, class MyTypeTag>
struct FluidSystem;
} // namespace Opm::Properties
namespace Opm {
template<class TypeTag>
class BaseOutputModule
{
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
using Model = GetPropType<TypeTag, Properties::Model>;
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
using GridView = GetPropType<TypeTag, Properties::GridView>;
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
using DiscBaseOutputModule = GetPropType<TypeTag, Properties::DiscBaseOutputModule>;
enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
enum { dim = GridView::dimension };
enum { dimWorld = GridView::dimensionworld };
using Vector = BaseOutputWriter::Vector;
using Tensor = BaseOutputWriter::Tensor;
public:
using ScalarBuffer = BaseOutputWriter::ScalarBuffer;
using VectorBuffer = BaseOutputWriter::VectorBuffer;
using TensorBuffer = BaseOutputWriter::TensorBuffer;
using EqBuffer = std::array<ScalarBuffer, numEq>;
using PhaseBuffer = std::array<ScalarBuffer, numPhases>;
using ComponentBuffer = std::array<ScalarBuffer, numComponents>;
using PhaseComponentBuffer = std::array<std::array<ScalarBuffer, numComponents>, numPhases>;
using PhaseVectorBuffer = std::array<VectorBuffer, numPhases>;
BaseOutputModule(const Simulator& simulator)
: simulator_(simulator)
{}
virtual ~BaseOutputModule()
{}
virtual void allocBuffers() = 0;
virtual void processElement(const ElementContext& elemCtx) = 0;
virtual void commitBuffers(BaseOutputWriter& writer) = 0;
virtual bool needExtensiveQuantities() const
{ return false; }
protected:
enum class BufferType {
Dof,
Vertex,
Element,
};
void resizeScalarBuffer_(ScalarBuffer& buffer, BufferType bufferType)
{
buffer.resize(this->getBufferSize(bufferType));
std::fill(buffer.begin(), buffer.end(), 0.0);
}
void resizeTensorBuffer_(TensorBuffer& buffer, BufferType bufferType)
{
buffer.resize(this->getBufferSize(bufferType));
const Tensor nullMatrix(dimWorld, dimWorld, 0.0);
std::fill(buffer.begin(), buffer.end(), nullMatrix);
}
void resizeVectorBuffer_(VectorBuffer& buffer, BufferType bufferType)
{
buffer.resize(this->getBufferSize(bufferType));
Vector zerovector(dimWorld,0.0);
zerovector = 0.0;
std::fill(buffer.begin(), buffer.end(), zerovector);
}
void resizeEqBuffer_(EqBuffer& buffer, BufferType bufferType)
{
const std::size_t n = this->getBufferSize(bufferType);
for (unsigned i = 0; i < numEq; ++i) {
buffer[i].resize(n);
std::fill(buffer[i].begin(), buffer[i].end(), 0.0);
}
}
void resizePhaseBuffer_(PhaseBuffer& buffer, BufferType bufferType)
{
const std::size_t n = this->getBufferSize(bufferType);
for (unsigned i = 0; i < numPhases; ++i) {
buffer[i].resize(n);
std::fill(buffer[i].begin(), buffer[i].end(), 0.0);
}
}
void resizeComponentBuffer_(ComponentBuffer& buffer, BufferType bufferType)
{
const std::size_t n = this->getBufferSize(bufferType);
for (unsigned i = 0; i < numComponents; ++i) {
buffer[i].resize(n);
std::fill(buffer[i].begin(), buffer[i].end(), 0.0);
}
}
void resizePhaseComponentBuffer_(PhaseComponentBuffer& buffer, BufferType bufferType)
{
const std::size_t n = this->getBufferSize(bufferType);
for (unsigned i = 0; i < numPhases; ++i) {
for (unsigned j = 0; j < numComponents; ++j) {
buffer[i][j].resize(n);
std::fill(buffer[i][j].begin(), buffer[i][j].end(), 0.0);
}
}
}
void commitScalarBuffer_(BaseOutputWriter& baseWriter,
const char *name,
ScalarBuffer& buffer,
BufferType bufferType)
{
switch (bufferType) {
case BufferType::Dof:
DiscBaseOutputModule::attachScalarDofData_(baseWriter, buffer, name);
break;
case BufferType::Vertex:
attachScalarVertexData_(baseWriter, buffer, name);
break;
case BufferType::Element:
attachScalarElementData_(baseWriter, buffer, name);
break;
default: throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
}
}
void commitVectorBuffer_(BaseOutputWriter& baseWriter,
const char *name,
VectorBuffer& buffer,
BufferType bufferType)
{
switch (bufferType) {
case BufferType::Dof:
DiscBaseOutputModule::attachVectorDofData_(baseWriter, buffer, name);
break;
case BufferType::Vertex:
attachVectorVertexData_(baseWriter, buffer, name);
break;
case BufferType::Element:
attachVectorElementData_(baseWriter, buffer, name);
break;
default: throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
}
}
void commitTensorBuffer_(BaseOutputWriter& baseWriter,
const char *name,
TensorBuffer& buffer,
BufferType bufferType)
{
switch (bufferType) {
case BufferType::Dof:
DiscBaseOutputModule::attachTensorDofData_(baseWriter, buffer, name);
break;
case BufferType::Vertex:
attachTensorVertexData_(baseWriter, buffer, name);
break;
case BufferType::Element:
attachTensorElementData_(baseWriter, buffer, name);
break;
default: throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
}
}
void commitPriVarsBuffer_(BaseOutputWriter& baseWriter,
const char *pattern,
EqBuffer& buffer,
BufferType bufferType)
{
char name[512];
for (unsigned i = 0; i < numEq; ++i) {
const std::string eqName = simulator_.model().primaryVarName(i);
snprintf(name, 512, pattern, eqName.c_str());
this->commitScalarBuffer_(baseWriter, name, buffer[i], bufferType);
}
}
void commitEqBuffer_(BaseOutputWriter& baseWriter,
const char *pattern,
EqBuffer& buffer,
BufferType bufferType)
{
char name[512];
for (unsigned i = 0; i < numEq; ++i) {
snprintf(name, 512, pattern, std::to_string(i).c_str());
this->commitScalarBuffer_(baseWriter, name, buffer[i], bufferType);
}
}
void commitPhaseBuffer_(BaseOutputWriter& baseWriter,
const char *pattern,
PhaseBuffer& buffer,
BufferType bufferType)
{
char name[512];
for (unsigned i = 0; i < numPhases; ++i) {
snprintf(name, 512, pattern, FluidSystem::phaseName(i).data());
this->commitScalarBuffer_(baseWriter, name, buffer[i], bufferType);
}
}
void commitComponentBuffer_(BaseOutputWriter& baseWriter,
const char *pattern,
ComponentBuffer& buffer,
BufferType bufferType)
{
char name[512];
for (unsigned i = 0; i < numComponents; ++i) {
snprintf(name, 512, pattern, FluidSystem::componentName(i).data());
this->commitScalarBuffer_(baseWriter, name, buffer[i], bufferType);
}
}
void commitPhaseComponentBuffer_(BaseOutputWriter& baseWriter,
const char *pattern,
PhaseComponentBuffer& buffer,
BufferType bufferType)
{
char name[512];
for (unsigned i = 0; i < numPhases; ++i) {
for (unsigned j = 0; j < numComponents; ++j) {
snprintf(name, 512, pattern,
FluidSystem::phaseName(i).data(),
FluidSystem::componentName(j).data());
this->commitScalarBuffer_(baseWriter, name, buffer[i][j], bufferType);
}
}
}
void attachScalarElementData_(BaseOutputWriter& baseWriter,
ScalarBuffer& buffer,
const char *name)
{ baseWriter.attachScalarElementData(buffer, name); }
void attachScalarVertexData_(BaseOutputWriter& baseWriter,
ScalarBuffer& buffer,
const char *name)
{ baseWriter.attachScalarVertexData(buffer, name); }
void attachVectorElementData_(BaseOutputWriter& baseWriter,
VectorBuffer& buffer,
const char *name)
{ baseWriter.attachVectorElementData(buffer, name); }
void attachVectorVertexData_(BaseOutputWriter& baseWriter,
VectorBuffer& buffer,
const char *name)
{ baseWriter.attachVectorVertexData(buffer, name); }
void attachTensorElementData_(BaseOutputWriter& baseWriter,
TensorBuffer& buffer,
const char *name)
{ baseWriter.attachTensorElementData(buffer, name); }
void attachTensorVertexData_(BaseOutputWriter& baseWriter,
TensorBuffer& buffer,
const char *name)
{ baseWriter.attachTensorVertexData(buffer, name); }
std::size_t getBufferSize(BufferType bufferType) const
{
switch (bufferType) {
case BufferType::Vertex: return simulator_.gridView().size(dim);
case BufferType::Element: return simulator_.gridView().size(0);
case BufferType::Dof: return simulator_.model().numGridDof();
default: throw std::logic_error("bufferType must be one of Dof, Vertex or Element");
}
}
const Simulator& simulator_;
};
} // namespace Opm
#endif
baseoutputwriter.hh
The base class for all output writers.
basicproperties.hh
Defines a type tags and some fundamental properties all models.
Opm::BaseOutputModule::commitEqBuffer_
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
Opm::BaseOutputModule::commitPhaseComponentBuffer_
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
Opm::BaseOutputModule::resizeScalarBuffer_
void resizeScalarBuffer_(ScalarBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a scalar quantity.
Definition baseoutputmodule.hh:157
Opm::BaseOutputModule::commitComponentBuffer_
void commitComponentBuffer_(BaseOutputWriter &baseWriter, const char *pattern, ComponentBuffer &buffer, BufferType bufferType)
Add a component-specific buffer to the result file.
Definition baseoutputmodule.hh:353
Opm::BaseOutputModule::needExtensiveQuantities
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
Opm::BaseOutputModule::resizeEqBuffer_
void resizeEqBuffer_(EqBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a equation specific quantity.
Definition baseoutputmodule.hh:185
Opm::BaseOutputModule::commitVectorBuffer_
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
Opm::BaseOutputModule::commitPriVarsBuffer_
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
Opm::BaseOutputModule::BufferType
BufferType
Definition baseoutputmodule.hh:143
Opm::BaseOutputModule::BufferType::Element
@ Element
Buffer contains data associated with the grid's elements.
Definition baseoutputmodule.hh:151
Opm::BaseOutputModule::BufferType::Dof
@ Dof
Buffer contains data associated with the degrees of freedom.
Definition baseoutputmodule.hh:145
Opm::BaseOutputModule::BufferType::Vertex
@ Vertex
Buffer contains data associated with the grid's vertices.
Definition baseoutputmodule.hh:148
Opm::BaseOutputModule::commitTensorBuffer_
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
Opm::BaseOutputModule::processElement
virtual void processElement(const ElementContext &elemCtx)=0
Modify the internal buffers according to the intensive quanties relevant for an element.
Opm::BaseOutputModule::resizePhaseComponentBuffer_
void resizePhaseComponentBuffer_(PhaseComponentBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a phase and component specific buffer.
Definition baseoutputmodule.hh:224
Opm::BaseOutputModule::resizeTensorBuffer_
void resizeTensorBuffer_(TensorBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a tensorial quantity.
Definition baseoutputmodule.hh:166
Opm::BaseOutputModule::commitPhaseBuffer_
void commitPhaseBuffer_(BaseOutputWriter &baseWriter, const char *pattern, PhaseBuffer &buffer, BufferType bufferType)
Add a phase-specific buffer to the result file.
Definition baseoutputmodule.hh:337
Opm::BaseOutputModule::commitBuffers
virtual void commitBuffers(BaseOutputWriter &writer)=0
Add all buffers to the VTK output writer.
Opm::BaseOutputModule::commitScalarBuffer_
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
Opm::BaseOutputModule::allocBuffers
virtual void allocBuffers()=0
Allocate memory for the scalar fields we would like to write to disk.
Opm::BaseOutputModule::resizeComponentBuffer_
void resizeComponentBuffer_(ComponentBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a component specific quantity.
Definition baseoutputmodule.hh:211
Opm::BaseOutputModule::resizePhaseBuffer_
void resizePhaseBuffer_(PhaseBuffer &buffer, BufferType bufferType)
Allocate the space for a buffer storing a phase-specific quantity.
Definition baseoutputmodule.hh:198
Opm::BaseOutputWriter
The base class for all output writers.
Definition baseoutputwriter.hh:46
Opm::BaseOutputWriter::attachScalarElementData
virtual void attachScalarElementData(ScalarBuffer &buf, std::string_view name)=0
Add a scalar element centered quantity to the output.
fvbaseproperties.hh
Declare the properties used by the infrastructure code of the finite volume discretizations.
multiphasebaseproperties.hh
Defines the common properties required by the porous medium multi-phase models.
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::GetPropType
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
Opm::getPropValue
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:240
parametersystem.hpp
This file provides the infrastructure to retrieve run-time parameters.
propertysystem.hh
The Opm property system, traits with inheritance.
Opm::Properties::FluidSystem
The fluid systems including the information about the phases.
Definition multiphasebaseproperties.hh:79