Line | Branch | Exec | Source |
---|---|---|---|
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 | // SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder | ||
5 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
6 | // | ||
7 | /*! | ||
8 | * \file | ||
9 | * \ingroup PoreNetworkModels | ||
10 | * \copydoc Dumux::PoreNetwork::VtkOutputModule | ||
11 | */ | ||
12 | |||
13 | #ifndef DUMUX_PNM_VTK_OUTPUT_MODULE_HH | ||
14 | #define DUMUX_PNM_VTK_OUTPUT_MODULE_HH | ||
15 | |||
16 | #include <dumux/io/vtkoutputmodule.hh> | ||
17 | #include "velocityoutput.hh" | ||
18 | |||
19 | namespace Dumux::PoreNetwork { | ||
20 | |||
21 | /*! | ||
22 | * \ingroup PoreNetworkModels | ||
23 | * \brief Adds vtk output fields specific to pore-network models. | ||
24 | */ | ||
25 | template<class GridVariables, class FluxVariables, class SolutionVector> | ||
26 | class VtkOutputModule : public Dumux::VtkOutputModule<GridVariables, SolutionVector> | ||
27 | { | ||
28 | using ParentType = Dumux::VtkOutputModule<GridVariables, SolutionVector>; | ||
29 | using Scalar = typename GridVariables::Scalar; | ||
30 | using FluxVarsCache = typename GridVariables::GridFluxVariablesCache::FluxVariablesCache; | ||
31 | |||
32 | struct ThroatFluxDataInfo { std::function<Scalar(const FluxVariables&, const FluxVarsCache&)> get; std::string name; }; | ||
33 | |||
34 | public: | ||
35 | |||
36 | //! The constructor | ||
37 | 26 | VtkOutputModule(const GridVariables& gridVariables, | |
38 | const SolutionVector& sol, | ||
39 | const std::string& name, | ||
40 | const std::string& paramGroup = "", | ||
41 | Dune::VTK::DataMode dm = Dune::VTK::conforming, | ||
42 | bool verbose = true) | ||
43 |
3/5✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 1 taken 2 times.
|
26 | : ParentType(gridVariables, sol, name, paramGroup, dm, verbose) |
44 | { | ||
45 | if constexpr (GridVariables::VolumeVariables::numFluidPhases() >= 1) | ||
46 | { | ||
47 | // enable velocity output per default | ||
48 | using VelocityOutput = VelocityOutput<GridVariables, FluxVariables>; | ||
49 |
2/4✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
|
46 | this->addVelocityOutput(std::make_shared<VelocityOutput>(gridVariables)); |
50 | } | ||
51 | 23 | } | |
52 | |||
53 | //! Output a scalar flux variable related to pore throats. This is basically a wrapper for the ParentType's addField method. | ||
54 | //! \param f A function taking a Problem, FluxVariables and FluxVarsCache object and returning the desired scalar | ||
55 | //! \param name The name of the vtk field | ||
56 | 116 | void addFluxVariable(std::function<Scalar(const FluxVariables&, const FluxVarsCache&)>&& f, const std::string& name) | |
57 | { | ||
58 | 116 | throatFluxDataInfo_.push_back(ThroatFluxDataInfo{f, name}); | |
59 | 116 | const auto numElems = problem().gridGeometry().gridView().size(0); | |
60 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 102 times.
|
232 | throatFluxData_.push_back(std::vector<Scalar>(numElems)); |
61 | 116 | ParentType::addField(throatFluxData_.back(), throatFluxDataInfo_.back().name, Vtk::FieldType::element); | |
62 | 348 | } | |
63 | |||
64 | //! Gather and process all required data and write them to a vtk file. | ||
65 | 580 | void write(double time, Dune::VTK::OutputType type = Dune::VTK::ascii) | |
66 | { | ||
67 | 580 | const auto gridView = problem().gridGeometry().gridView(); | |
68 | 580 | const auto numElems = gridView.size(0); | |
69 | |||
70 | // resize all fields | ||
71 |
2/2✓ Branch 0 taken 2991 times.
✓ Branch 1 taken 574 times.
|
3591 | for (auto& data : throatFluxData_) |
72 | 3011 | data.resize(numElems); | |
73 | |||
74 | 580 | auto fvElementGeometry = localView(problem().gridGeometry()); | |
75 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
580 | auto elemVolVars = localView(this->gridVariables().curGridVolVars()); |
76 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
837 | auto elemFluxVarsCache = localView(this->gridVariables().gridFluxVarsCache()); |
77 | // iterate over all elements | ||
78 |
4/4✓ Branch 1 taken 113310 times.
✓ Branch 2 taken 570 times.
✓ Branch 3 taken 6382 times.
✓ Branch 4 taken 4 times.
|
301500 | for (const auto& element : elements(gridView, Dune::Partitions::interior)) |
79 | { | ||
80 |
1/2✓ Branch 1 taken 6382 times.
✗ Branch 2 not taken.
|
150460 | const auto eIdx = problem().gridGeometry().elementMapper().index(element); |
81 | |||
82 | // make sure FVElementGeometry & vol vars are bound to the element | ||
83 |
1/2✓ Branch 1 taken 113310 times.
✗ Branch 2 not taken.
|
150460 | fvElementGeometry.bindElement(element); |
84 |
2/4✓ Branch 1 taken 113310 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 113310 times.
✗ Branch 5 not taken.
|
300920 | elemVolVars.bind(element, fvElementGeometry, this->sol()); |
85 | 300920 | elemFluxVarsCache.bind(element, fvElementGeometry, elemVolVars); | |
86 | |||
87 | // treat the throat flux related data | ||
88 | 300920 | std::size_t dataIdx = 0; | |
89 |
2/2✓ Branch 0 taken 113310 times.
✓ Branch 1 taken 113310 times.
|
300920 | for (auto&& scvf : scvfs(fvElementGeometry)) |
90 | { | ||
91 | if (!scvf.boundary()) | ||
92 | { | ||
93 | 150460 | FluxVariables fluxVars; | |
94 | 150460 | fluxVars.init(problem(), element, fvElementGeometry, elemVolVars, scvf, elemFluxVarsCache); | |
95 | |||
96 | 150460 | dataIdx = 0; | |
97 |
2/2✓ Branch 0 taken 504864 times.
✓ Branch 1 taken 113310 times.
|
795188 | for(auto& data : throatFluxData_) |
98 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 504864 times.
|
1289456 | data[eIdx] = throatFluxDataInfo_[dataIdx++].get(fluxVars, elemFluxVarsCache[scvf]); |
99 | } | ||
100 | } | ||
101 | } | ||
102 | |||
103 | // call the ParentType's write method to write out all data | ||
104 |
1/2✓ Branch 1 taken 574 times.
✗ Branch 2 not taken.
|
580 | ParentType::write(time, type); |
105 | |||
106 | // empty the data containers in order to save some memory | ||
107 | 3011 | auto clearAndShrink = [] (auto& data) | |
108 | { | ||
109 |
1/2✓ Branch 0 taken 2991 times.
✗ Branch 1 not taken.
|
3011 | data.clear(); |
110 | 3011 | data.shrink_to_fit(); | |
111 | }; | ||
112 | |||
113 |
3/4✓ Branch 0 taken 2991 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2991 times.
✓ Branch 3 taken 574 times.
|
3591 | for (auto& data : throatFluxData_) |
114 | 3011 | clearAndShrink(data); | |
115 | 903 | } | |
116 | |||
117 | //! Return a reference to the problem | ||
118 |
11/19✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 2 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
✓ Branch 22 taken 4368 times.
✗ Branch 23 not taken.
✓ Branch 26 taken 2014 times.
✗ Branch 27 not taken.
✓ Branch 2 taken 21 times.
✓ Branch 5 taken 21 times.
✓ Branch 8 taken 21 times.
|
227942 | const auto& problem() const { return ParentType::problem(); } |
119 | |||
120 | private: | ||
121 | std::vector<ThroatFluxDataInfo> throatFluxDataInfo_; | ||
122 | std::list<std::vector<Scalar>> throatFluxData_; | ||
123 | }; | ||
124 | |||
125 | } //namespace Dumux::PoreNetwork | ||
126 | |||
127 | #endif | ||
128 |