3.4
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
pnmvtkoutputmodule.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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program 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 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
25#ifndef DUMUX_PNM_VTK_OUTPUT_MODULE_HH
26#define DUMUX_PNM_VTK_OUTPUT_MODULE_HH
27
29#include "velocityoutput.hh"
30
31namespace Dumux::PoreNetwork {
32
37template<class GridVariables, class FluxVariables, class SolutionVector>
38class VtkOutputModule : public Dumux::VtkOutputModule<GridVariables, SolutionVector>
39{
41 using Scalar = typename GridVariables::Scalar;
42 using FluxVarsCache = typename GridVariables::GridFluxVariablesCache::FluxVariablesCache;
43
44 struct ThroatFluxDataInfo { std::function<Scalar(const FluxVariables&, const FluxVarsCache&)> get; std::string name; };
45
46public:
47
49 VtkOutputModule(const GridVariables& gridVariables,
50 const SolutionVector& sol,
51 const std::string& name,
52 const std::string& paramGroup = "",
53 Dune::VTK::DataMode dm = Dune::VTK::conforming,
54 bool verbose = true)
56 {
57 if constexpr (GridVariables::VolumeVariables::numFluidPhases() >= 1)
58 {
59 // enable velocity output per default
61 this->addVelocityOutput(std::make_shared<VelocityOutput>(gridVariables));
62 }
63 }
64
68 void addFluxVariable(std::function<Scalar(const FluxVariables&, const FluxVarsCache&)>&& f, const std::string& name)
69 {
70 throatFluxDataInfo_.push_back(ThroatFluxDataInfo{f, name});
71 const auto numElems = problem().gridGeometry().gridView().size(0);
72 throatFluxData_.push_back(std::vector<Scalar>(numElems));
73 ParentType::addField(throatFluxData_.back(), throatFluxDataInfo_.back().name, Vtk::FieldType::element);
74 }
75
77 void write(double time, Dune::VTK::OutputType type = Dune::VTK::ascii)
78 {
79 const auto gridView = problem().gridGeometry().gridView();
80 const auto numElems = gridView.size(0);
81
82 // resize all fields
83 for (auto& data : throatFluxData_)
84 data.resize(numElems);
85
86 // iterate over all elements
87 for (const auto& element : elements(gridView, Dune::Partitions::interior))
88 {
89 // make sure FVElementGeometry & vol vars are bound to the element
90 auto fvElementGeometry = localView(problem().gridGeometry());
91 fvElementGeometry.bindElement(element);
92
93 const auto eIdx = problem().gridGeometry().elementMapper().index(element);
94
95 auto elemVolVars = localView(this->gridVariables().curGridVolVars());
96 auto elemFluxVarsCache = localView(this->gridVariables().gridFluxVarsCache());
97
98 elemVolVars.bind(element, fvElementGeometry, this->sol());
99 elemFluxVarsCache.bind(element, fvElementGeometry, elemVolVars);
100
101 // treat the throat flux related data
102 std::size_t dataIdx = 0;
103 for (auto&& scvf : scvfs(fvElementGeometry))
104 {
105 if (!scvf.boundary())
106 {
107 FluxVariables fluxVars;
108 fluxVars.init(problem(), element, fvElementGeometry, elemVolVars, scvf, elemFluxVarsCache);
109
110 dataIdx = 0;
111 for(auto& data : throatFluxData_)
112 data[eIdx] = throatFluxDataInfo_[dataIdx++].get(fluxVars, elemFluxVarsCache[scvf]);
113 }
114 }
115 }
116
117 // call the ParentType's write method to write out all data
118 ParentType::write(time, type);
119
120 // empty the data containers in order to save some memory
121 auto clearAndShrink = [] (auto& data)
122 {
123 data.clear();
124 data.shrink_to_fit();
125 };
126
127 for (auto& data : throatFluxData_)
128 clearAndShrink(data);
129 }
130
132 const auto& problem() const { return ParentType::problem(); }
133
134private:
135 std::vector<ThroatFluxDataInfo> throatFluxDataInfo_;
136 std::list<std::vector<Scalar>> throatFluxData_;
137};
138
139} //namespace Dumux::PoreNetwork
140
141#endif
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
Definition: discretization/porenetwork/fvelementgeometry.hh:33
Velocity output for implicit (porous media) models.
Definition: io/velocityoutput.hh:41
A VTK output module to simplify writing dumux simulation data to VTK format.
Definition: io/vtkoutputmodule.hh:61
const std::string & paramGroup() const
the parameter group for getting parameter from the parameter tree
Definition: io/vtkoutputmodule.hh:96
void write(double time, Dune::VTK::OutputType type=Dune::VTK::ascii)
Definition: io/vtkoutputmodule.hh:173
const std::string & name() const
Definition: io/vtkoutputmodule.hh:195
bool verbose() const
Definition: io/vtkoutputmodule.hh:194
void addField(const Vector &v, const std::string &name, Vtk::FieldType fieldType=Vtk::FieldType::automatic)
Add a scalar or vector valued vtk field.
Definition: io/vtkoutputmodule.hh:109
A VTK output module to simplify writing dumux simulation data to VTK format.
Definition: io/vtkoutputmodule.hh:307
const auto & problem() const
Definition: io/vtkoutputmodule.hh:385
const GridVariables & gridVariables() const
Definition: io/vtkoutputmodule.hh:386
void addVelocityOutput(std::shared_ptr< VelocityOutputType > velocityOutput)
Add a velocity output policy.
Definition: io/vtkoutputmodule.hh:360
const SolutionVector & sol() const
Definition: io/vtkoutputmodule.hh:388
const GridGeometry & gridGeometry() const
Definition: io/vtkoutputmodule.hh:387
Adds vtk output fields specific to pore-network models.
Definition: pnmvtkoutputmodule.hh:39
void write(double time, Dune::VTK::OutputType type=Dune::VTK::ascii)
Gather and process all required data and write them to a vtk file.
Definition: pnmvtkoutputmodule.hh:77
VtkOutputModule(const GridVariables &gridVariables, const SolutionVector &sol, const std::string &name, const std::string &paramGroup="", Dune::VTK::DataMode dm=Dune::VTK::conforming, bool verbose=true)
The constructor.
Definition: pnmvtkoutputmodule.hh:49
void addFluxVariable(std::function< Scalar(const FluxVariables &, const FluxVarsCache &)> &&f, const std::string &name)
Definition: pnmvtkoutputmodule.hh:68
const auto & problem() const
Return a reference to the problem.
Definition: pnmvtkoutputmodule.hh:132
Velocity output for porous media models.
A VTK output module to simplify writing dumux simulation data to VTK format.