3.6-git
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 auto fvElementGeometry = localView(problem().gridGeometry());
87 auto elemVolVars = localView(this->gridVariables().curGridVolVars());
88 auto elemFluxVarsCache = localView(this->gridVariables().gridFluxVarsCache());
89 // iterate over all elements
90 for (const auto& element : elements(gridView, Dune::Partitions::interior))
91 {
92 const auto eIdx = problem().gridGeometry().elementMapper().index(element);
93
94 // make sure FVElementGeometry & vol vars are bound to the element
95 fvElementGeometry.bindElement(element);
96 elemVolVars.bind(element, fvElementGeometry, this->sol());
97 elemFluxVarsCache.bind(element, fvElementGeometry, elemVolVars);
98
99 // treat the throat flux related data
100 std::size_t dataIdx = 0;
101 for (auto&& scvf : scvfs(fvElementGeometry))
102 {
103 if (!scvf.boundary())
104 {
105 FluxVariables fluxVars;
106 fluxVars.init(problem(), element, fvElementGeometry, elemVolVars, scvf, elemFluxVarsCache);
107
108 dataIdx = 0;
109 for(auto& data : throatFluxData_)
110 data[eIdx] = throatFluxDataInfo_[dataIdx++].get(fluxVars, elemFluxVarsCache[scvf]);
111 }
112 }
113 }
114
115 // call the ParentType's write method to write out all data
116 ParentType::write(time, type);
117
118 // empty the data containers in order to save some memory
119 auto clearAndShrink = [] (auto& data)
120 {
121 data.clear();
122 data.shrink_to_fit();
123 };
124
125 for (auto& data : throatFluxData_)
126 clearAndShrink(data);
127 }
128
130 const auto& problem() const { return ParentType::problem(); }
131
132private:
133 std::vector<ThroatFluxDataInfo> throatFluxDataInfo_;
134 std::list<std::vector<Scalar>> throatFluxData_;
135};
136
137} //namespace Dumux::PoreNetwork
138
139#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:34
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:91
void write(double time, Dune::VTK::OutputType type=Dune::VTK::ascii)
Definition: io/vtkoutputmodule.hh:177
const std::string & name() const
Definition: io/vtkoutputmodule.hh:199
bool verbose() const
Definition: io/vtkoutputmodule.hh:198
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:104
A VTK output module to simplify writing dumux simulation data to VTK format.
Definition: io/vtkoutputmodule.hh:312
const auto & problem() const
Definition: io/vtkoutputmodule.hh:395
const GridVariables & gridVariables() const
Definition: io/vtkoutputmodule.hh:396
void addVelocityOutput(std::shared_ptr< VelocityOutputType > velocityOutput)
Add a velocity output policy.
Definition: io/vtkoutputmodule.hh:370
const SolutionVector & sol() const
Definition: io/vtkoutputmodule.hh:398
const GridGeometry & gridGeometry() const
Definition: io/vtkoutputmodule.hh:397
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:130
TODO: docme!
A VTK output module to simplify writing dumux simulation data to VTK format.