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 CVFEDiscretization | ||
10 | * \brief Global flux variable cache | ||
11 | */ | ||
12 | #ifndef DUMUX_DISCRETIZATION_CVFE_GRID_FLUXVARSCACHE_HH | ||
13 | #define DUMUX_DISCRETIZATION_CVFE_GRID_FLUXVARSCACHE_HH | ||
14 | |||
15 | #include <dumux/parallel/parallel_for.hh> | ||
16 | |||
17 | // make the local view function available whenever we use this class | ||
18 | #include <dumux/discretization/localview.hh> | ||
19 | #include <dumux/discretization/cvfe/elementfluxvariablescache.hh> | ||
20 | |||
21 | namespace Dumux { | ||
22 | |||
23 | /*! | ||
24 | * \ingroup CVFEDiscretization | ||
25 | * \brief Flux variable caches traits | ||
26 | */ | ||
27 | template<class P, class FVC> | ||
28 | struct CVFEDefaultGridFVCTraits | ||
29 | { | ||
30 | using Problem = P; | ||
31 | using FluxVariablesCache = FVC; | ||
32 | |||
33 | template<class GridFluxVariablesCache, bool cachingEnabled> | ||
34 | using LocalView = CVFEElementFluxVariablesCache<GridFluxVariablesCache, cachingEnabled>; | ||
35 | }; | ||
36 | |||
37 | /*! | ||
38 | * \ingroup CVFEDiscretization | ||
39 | * \brief Flux variable caches on a gridview | ||
40 | * \note The class is specialized for a version with and without grid caching | ||
41 | */ | ||
42 | template<class Problem, | ||
43 | class FluxVariablesCache, | ||
44 | bool cachingEnabled = false, | ||
45 | class Traits = CVFEDefaultGridFVCTraits<Problem, FluxVariablesCache> > | ||
46 | class CVFEGridFluxVariablesCache; | ||
47 | |||
48 | /*! | ||
49 | * \ingroup CVFEDiscretization | ||
50 | * \brief Flux variable caches on a gridview with grid caching enabled | ||
51 | * \note The flux caches of the gridview are stored which is memory intensive but faster | ||
52 | */ | ||
53 | template<class P, class FVC, class Traits> | ||
54 | class CVFEGridFluxVariablesCache<P, FVC, true, Traits> | ||
55 | { | ||
56 | using Problem = typename Traits::Problem; | ||
57 | using ThisType = CVFEGridFluxVariablesCache<P, FVC, true, Traits>; | ||
58 | |||
59 | public: | ||
60 | //! export the flux variable cache type | ||
61 | using FluxVariablesCache = typename Traits::FluxVariablesCache; | ||
62 | |||
63 | //! make it possible to query if caching is enabled | ||
64 | static constexpr bool cachingEnabled = true; | ||
65 | |||
66 | //! export the type of the local view | ||
67 | using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>; | ||
68 | |||
69 |
2/4✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
67 | CVFEGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {} |
70 | |||
71 | template<class GridGeometry, class GridVolumeVariables, class SolutionVector> | ||
72 | 3948 | void update(const GridGeometry& gridGeometry, | |
73 | const GridVolumeVariables& gridVolVars, | ||
74 | const SolutionVector& sol, | ||
75 | bool forceUpdate = false) | ||
76 | { | ||
77 | // Here, we do not do anything unless it is a forced update | ||
78 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 3803 times.
|
3948 | if (forceUpdate) |
79 | { | ||
80 | 83 | fluxVarsCache_.resize(gridGeometry.gridView().size(0)); | |
81 | 415281 | Dumux::parallelFor(gridGeometry.gridView().size(0), [&, &problem = problem()](const std::size_t eIdx) | |
82 | { | ||
83 | // Prepare the geometries within the elements of the stencil | ||
84 | 358349 | const auto element = gridGeometry.element(eIdx); | |
85 |
4/8✓ Branch 1 taken 36387 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 36387 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 10400 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 10400 times.
✗ Branch 10 not taken.
|
405136 | const auto fvGeometry = localView(gridGeometry).bind(element); |
86 |
2/4✓ Branch 1 taken 36387 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10400 times.
✗ Branch 5 not taken.
|
358349 | const auto elemVolVars = localView(gridVolVars).bind(element, fvGeometry, sol); |
87 | |||
88 | // only update shape functions for fluxes if update is forced | ||
89 |
2/4✓ Branch 1 taken 36387 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10400 times.
✗ Branch 5 not taken.
|
358349 | fluxVarsCache_[eIdx].resize(fvGeometry.numScvf()); |
90 |
4/4✓ Branch 0 taken 1442873 times.
✓ Branch 1 taken 251130 times.
✓ Branch 2 taken 467018 times.
✓ Branch 3 taken 107219 times.
|
2268240 | for (const auto& scvf : scvfs(fvGeometry)) |
91 |
2/4✓ Branch 1 taken 164475 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 53640 times.
✗ Branch 5 not taken.
|
2128006 | cache(eIdx, scvf.index()).update(problem, element, fvGeometry, elemVolVars, scvf); |
92 | 46787 | }); | |
93 | } | ||
94 | 3948 | } | |
95 | |||
96 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
97 | void updateElement(const typename FVElementGeometry::Element& element, | ||
98 | const FVElementGeometry& fvGeometry, | ||
99 | const ElementVolumeVariables& elemVolVars) | ||
100 | { | ||
101 | if constexpr (FluxVariablesCache::isSolDependent) | ||
102 | { | ||
103 | const auto eIdx = fvGeometry.gridGeometry().elementMapper().index(element); | ||
104 | fluxVarsCache_[eIdx].resize(fvGeometry.numScvf()); | ||
105 | for (const auto& scvf : scvfs(fvGeometry)) | ||
106 | cache(eIdx, scvf.index()).update(problem(), element, fvGeometry, elemVolVars, scvf); | ||
107 | } | ||
108 | } | ||
109 | |||
110 | 67 | const Problem& problem() const | |
111 | 67 | { return *problemPtr_; } | |
112 | |||
113 | // access operator | ||
114 | 343582726 | const FluxVariablesCache& cache(std::size_t eIdx, std::size_t scvfIdx) const | |
115 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 138800268 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 740772 times.
|
343582726 | { return fluxVarsCache_[eIdx][scvfIdx]; } |
116 | |||
117 | // access operator | ||
118 | 1909891 | FluxVariablesCache& cache(std::size_t eIdx, std::size_t scvfIdx) | |
119 |
2/4✓ Branch 1 taken 164475 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 53640 times.
✗ Branch 5 not taken.
|
1909891 | { return fluxVarsCache_[eIdx][scvfIdx]; } |
120 | |||
121 | private: | ||
122 | // currently bound element | ||
123 | const Problem* problemPtr_; | ||
124 | std::vector<std::vector<FluxVariablesCache>> fluxVarsCache_; | ||
125 | }; | ||
126 | |||
127 | /*! | ||
128 | * \ingroup CVFEDiscretization | ||
129 | * \brief Flux variable caches on a gridview with grid caching disabled | ||
130 | */ | ||
131 | template<class P, class FVC, class Traits> | ||
132 | class CVFEGridFluxVariablesCache<P, FVC, false, Traits> | ||
133 | { | ||
134 | using Problem = typename Traits::Problem; | ||
135 | using ThisType = CVFEGridFluxVariablesCache<P, FVC, false, Traits>; | ||
136 | |||
137 | public: | ||
138 | //! export the flux variable cache type | ||
139 | using FluxVariablesCache = typename Traits::FluxVariablesCache; | ||
140 | |||
141 | //! make it possible to query if caching is enabled | ||
142 | static constexpr bool cachingEnabled = false; | ||
143 | |||
144 | //! export the type of the local view | ||
145 | using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>; | ||
146 | |||
147 |
4/8✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
190 | CVFEGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {} |
148 | |||
149 | template<class GridGeometry, class GridVolumeVariables, class SolutionVector> | ||
150 | 2 | void update(const GridGeometry& gridGeometry, | |
151 | const GridVolumeVariables& gridVolVars, | ||
152 | const SolutionVector& sol, | ||
153 | bool forceUpdate = false) {} | ||
154 | |||
155 | 40125368 | const Problem& problem() const | |
156 | 40125368 | { return *problemPtr_; } | |
157 | |||
158 | private: | ||
159 | const Problem* problemPtr_; | ||
160 | }; | ||
161 | |||
162 | } // end namespace Dumux | ||
163 | |||
164 | #endif | ||
165 |