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-FileCopyrightInfo: 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 | 22 | 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 |
10/16✓ Branch 1 taken 2 times.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 17 times.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
|
22 | : 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 |
3/6✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 17 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 17 times.
|
38 | this->addVelocityOutput(std::make_shared<VelocityOutput>(gridVariables)); |
50 | } | ||
51 | 19 | } | |
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 | 100 | void addFluxVariable(std::function<Scalar(const FluxVariables&, const FluxVarsCache&)>&& f, const std::string& name) | |
57 | { | ||
58 |
1/2✓ Branch 3 taken 86 times.
✗ Branch 4 not taken.
|
100 | throatFluxDataInfo_.push_back(ThroatFluxDataInfo{f, name}); |
59 | 300 | const auto numElems = problem().gridGeometry().gridView().size(0); | |
60 |
4/10✓ Branch 1 taken 86 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 86 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 86 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 86 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
200 | throatFluxData_.push_back(std::vector<Scalar>(numElems)); |
61 | 300 | ParentType::addField(throatFluxData_.back(), throatFluxDataInfo_.back().name, Vtk::FieldType::element); | |
62 | 100 | } | |
63 | |||
64 | //! Gather and process all required data and write them to a vtk file. | ||
65 | 510 | void write(double time, Dune::VTK::OutputType type = Dune::VTK::ascii) | |
66 | { | ||
67 | 1530 | const auto gridView = problem().gridGeometry().gridView(); | |
68 | 510 | const auto numElems = gridView.size(0); | |
69 | |||
70 | // resize all fields | ||
71 |
2/2✓ Branch 0 taken 2711 times.
✓ Branch 1 taken 504 times.
|
4261 | for (auto& data : throatFluxData_) |
72 | 2731 | data.resize(numElems); | |
73 | |||
74 | 1020 | auto fvElementGeometry = localView(problem().gridGeometry()); | |
75 |
3/8✓ Branch 0 taken 257 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
1277 | auto elemVolVars = localView(this->gridVariables().curGridVolVars()); |
76 |
5/11✓ Branch 1 taken 4 times.
✓ Branch 2 taken 243 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 247 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
1526 | auto elemFluxVarsCache = localView(this->gridVariables().gridFluxVarsCache()); |
77 | // iterate over all elements | ||
78 |
8/10✓ Branch 1 taken 106862 times.
✓ Branch 2 taken 500 times.
✓ Branch 3 taken 113240 times.
✓ Branch 4 taken 504 times.
✓ Branch 5 taken 6382 times.
✓ Branch 6 taken 4 times.
✓ Branch 8 taken 6382 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 6382 times.
✗ Branch 12 not taken.
|
176428 | for (const auto& element : elements(gridView, Dune::Partitions::interior)) |
79 | { | ||
80 |
3/6✓ Branch 1 taken 6382 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6382 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6382 times.
✗ Branch 8 not taken.
|
451170 | 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 113240 times.
✗ Branch 2 not taken.
|
150390 | fvElementGeometry.bindElement(element); |
84 |
1/2✓ Branch 1 taken 113240 times.
✗ Branch 2 not taken.
|
150390 | elemVolVars.bind(element, fvElementGeometry, this->sol()); |
85 |
1/2✓ Branch 1 taken 113240 times.
✗ Branch 2 not taken.
|
150390 | elemFluxVarsCache.bind(element, fvElementGeometry, elemVolVars); |
86 | |||
87 | // treat the throat flux related data | ||
88 | std::size_t dataIdx = 0; | ||
89 |
2/2✓ Branch 0 taken 113240 times.
✓ Branch 1 taken 113240 times.
|
300780 | for (auto&& scvf : scvfs(fvElementGeometry)) |
90 | { | ||
91 | 150390 | if (!scvf.boundary()) | |
92 | { | ||
93 | 150390 | FluxVariables fluxVars; | |
94 | 150390 | fluxVars.init(problem(), element, fvElementGeometry, elemVolVars, scvf, elemFluxVarsCache); | |
95 | |||
96 | 150390 | dataIdx = 0; | |
97 |
3/4✓ Branch 0 taken 504584 times.
✓ Branch 1 taken 113240 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 504584 times.
|
1095618 | for(auto& data : throatFluxData_) |
98 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 504584 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 504584 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 285120 times.
|
3002776 | 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 504 times.
✗ Branch 2 not taken.
|
510 | ParentType::write(time, type); |
105 | |||
106 | // empty the data containers in order to save some memory | ||
107 | ✗ | auto clearAndShrink = [] (auto& data) | |
108 | { | ||
109 |
0/4✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
80 | data.clear(); |
110 |
1/4✓ Branch 0 taken 2711 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
2731 | data.shrink_to_fit(); |
111 | }; | ||
112 | |||
113 |
3/4✓ Branch 0 taken 2711 times.
✓ Branch 1 taken 504 times.
✓ Branch 2 taken 2711 times.
✗ Branch 3 not taken.
|
4261 | for (auto& data : throatFluxData_) |
114 |
1/2✓ Branch 0 taken 2711 times.
✗ Branch 1 not taken.
|
5462 | clearAndShrink(data); |
115 | 510 | } | |
116 | |||
117 | //! Return a reference to the problem | ||
118 |
11/19✓ Branch 2 taken 17 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 17 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 17 times.
✓ 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.
|
227634 | 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 |