GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/porenetwork/2p/gridfluxvariablescache.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 4 6 66.7%
Functions: 0 1 0.0%
Branches: 3 10 30.0%

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 PNMTwoPModel
10 * \brief Global flux variable cache
11 */
12 #ifndef DUMUX_PNM_2P_GRID_FLUXVARSCACHE_HH
13 #define DUMUX_PNM_2P_GRID_FLUXVARSCACHE_HH
14
15 #include <dumux/common/parameters.hh>
16 #include <dumux/discretization/localview.hh>
17 #include <dumux/discretization/cvfe/gridfluxvariablescache.hh>
18 #include "elementfluxvariablescache.hh"
19 #include "invasionstate.hh"
20
21 namespace Dumux::PoreNetwork {
22
23 /*!
24 * \ingroup PNMTwoPModel
25 * \brief Flux variable caches traits
26 */
27 template<class P, class FVC, class IS = TwoPInvasionState<P>>
28 struct PNMTwoPDefaultGridFVCTraits
29 {
30 using Problem = P;
31 using FluxVariablesCache = FVC;
32 using InvasionState = IS;
33
34 template<class GridFluxVariablesCache, bool cachingEnabled>
35 using LocalView = PNMTwoPElementFluxVariablesCache<GridFluxVariablesCache, cachingEnabled>;
36 };
37
38 /*!
39 * \ingroup PNMTwoPModel
40 * \brief Flux variable caches on a gridview
41 * \note The class is specialized for a version with and without grid caching
42 */
43 template<class Problem,
44 class FluxVariablesCache,
45 bool cachingEnabled,
46 class Traits>
47 class PNMTwoPGridFluxVariablesCache;
48
49 /*!
50 * \ingroup PNMTwoPModel
51 * \brief The grid flux variables cache for the two-phase PNM hodling the invasion state of the throats
52 * \note The flux caches of the gridview are stored which is memory intensive but faster
53 */
54 template<class P, class FVC, class Traits>
55 class PNMTwoPGridFluxVariablesCache<P, FVC, true, Traits>
56 {
57 using Problem = typename Traits::Problem;
58 using ThisType = PNMTwoPGridFluxVariablesCache<P, FVC, true, Traits>;
59 using InvasionState = typename Traits::InvasionState;
60
61 public:
62 //! export the flux variable cache type
63 using FluxVariablesCache = typename Traits::FluxVariablesCache;
64
65 //! make it possible to query if caching is enabled
66 static constexpr bool cachingEnabled = true;
67
68 //! export the type of the local view
69 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
70
71 PNMTwoPGridFluxVariablesCache(const Problem& problem)
72 : problemPtr_(&problem)
73 , invasionState_(problem) {}
74
75 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
76 void update(const GridGeometry& gridGeometry,
77 const GridVolumeVariables& gridVolVars,
78 const SolutionVector& sol,
79 bool forceUpdate = true)
80 {
81 fluxVarsCache_.resize(gridGeometry.gridView().size(0));
82 auto fvGeometry = localView(gridGeometry);
83 auto elemVolVars = localView(gridVolVars);
84 for (const auto& element : elements(gridGeometry.gridView()))
85 {
86 auto eIdx = gridGeometry.elementMapper().index(element);
87
88 // bind the geometries and volume variables to the element (all the elements in stencil)
89 fvGeometry.bind(element);
90 elemVolVars.bind(element, fvGeometry, sol);
91
92 for (auto&& scvf : scvfs(fvGeometry))
93 cache(eIdx, scvf.index()).update(problem(), element, fvGeometry, elemVolVars, scvf, invasionState().invaded(element));
94 }
95 }
96
97 template<class FVElementGeometry, class ElementVolumeVariables>
98 void updateElement(const typename FVElementGeometry::Element& element,
99 const FVElementGeometry& fvGeometry,
100 const ElementVolumeVariables& elemVolVars)
101 {
102 if constexpr (FluxVariablesCache::isSolDependent)
103 {
104 const auto eIdx = fvGeometry.gridGeometry().elementMapper().index(element);
105 for (const auto& scvf : scvfs(fvGeometry))
106 cache(eIdx, scvf.index()).update(problem(), element, fvGeometry, elemVolVars, scvf, invasionState().invaded(element));
107 }
108 }
109
110 const Problem& problem() const
111 { return *problemPtr_; }
112
113 // access operator
114 const FluxVariablesCache& cache(std::size_t eIdx, [[maybe_unused]] std::size_t scvfIdx) const
115 { return fluxVarsCache_[eIdx]; }
116
117 // access operator
118 FluxVariablesCache& cache(std::size_t eIdx, [[maybe_unused]] std::size_t scvfIdx)
119 { return fluxVarsCache_[eIdx]; }
120
121 const InvasionState& invasionState() const
122 { return invasionState_; }
123
124 InvasionState& invasionState()
125 { return invasionState_; }
126
127 private:
128 const Problem* problemPtr_;
129 std::vector<FluxVariablesCache> fluxVarsCache_;
130 InvasionState invasionState_;
131 };
132
133 /*!
134 * \ingroup PNMTwoPModel
135 * \brief The grid flux variables cache for the two-phase PNM hodling the invasion state of the throats
136 * \note The flux caches of the gridview are stored which is memory intensive but faster
137 */
138 template<class P, class FVC, class Traits>
139 class PNMTwoPGridFluxVariablesCache<P, FVC, false, Traits>
140 {
141 using Problem = typename Traits::Problem;
142 using ThisType = PNMTwoPGridFluxVariablesCache<P, FVC, false, Traits>;
143 using InvasionState = typename Traits::InvasionState;
144
145 public:
146 //! export the flux variable cache type
147 using FluxVariablesCache = typename Traits::FluxVariablesCache;
148
149 //! make it possible to query if caching is enabled
150 static constexpr bool cachingEnabled = false;
151
152 //! export the type of the local view
153 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
154
155 4 PNMTwoPGridFluxVariablesCache(const Problem& problem)
156 : problemPtr_(&problem)
157
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 , invasionState_(problem) {}
158
159 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
160 void update(const GridGeometry& gridGeometry,
161 const GridVolumeVariables& gridVolVars,
162 const SolutionVector& sol,
163 bool forceUpdate = true) {}
164
165 const Problem& problem() const
166 { return *problemPtr_; }
167
168 const InvasionState& invasionState() const
169
2/8
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 7 times.
✓ Branch 11 taken 179 times.
960457 { return invasionState_; }
170
171 InvasionState& invasionState()
172 2087 { return invasionState_; }
173
174 private:
175 const Problem* problemPtr_;
176 InvasionState invasionState_;
177 };
178 } // end namespace Dumux::PoreNetwork
179
180 #endif
181