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 StaggeredDiscretization | ||
10 | * \copydoc Dumux::StaggeredGridFluxVariablesCache | ||
11 | */ | ||
12 | #ifndef DUMUX_DISCRETIZATION_STAGGERED_GRID_FLUXVARSCACHE_HH | ||
13 | #define DUMUX_DISCRETIZATION_STAGGERED_GRID_FLUXVARSCACHE_HH | ||
14 | |||
15 | // make the local view function available whenever we use this class | ||
16 | #include <dumux/discretization/localview.hh> | ||
17 | #include <dumux/discretization/staggered/elementfluxvariablescache.hh> | ||
18 | |||
19 | #include <dumux/freeflow/staggeredupwindmethods.hh> | ||
20 | |||
21 | namespace Dumux { | ||
22 | |||
23 | /*! | ||
24 | * \ingroup StaggeredDiscretization | ||
25 | * \brief Traits class to be used for the StaggeredGridVFluxVariablesCache. | ||
26 | * \tparam P The problem type | ||
27 | * \tparam FVC The flux variables cache type | ||
28 | */ | ||
29 | template<class P, class FVC, class FVCF, int upwOrder> | ||
30 | struct StaggeredDefaultGridFluxVariablesCacheTraits | ||
31 | { | ||
32 | using Problem = P; | ||
33 | using FluxVariablesCache = FVC; | ||
34 | using FluxVariablesCacheFiller = FVCF; | ||
35 | |||
36 | template<class GridFluxVariablesCache, bool cachingEnabled> | ||
37 | using LocalView = StaggeredElementFluxVariablesCache<GridFluxVariablesCache, cachingEnabled>; | ||
38 | static constexpr int upwindSchemeOrder = upwOrder; | ||
39 | }; | ||
40 | |||
41 | /*! | ||
42 | * \ingroup StaggeredDiscretization | ||
43 | * \brief Flux variables cache class for staggered models | ||
44 | */ | ||
45 | template<class Problem, | ||
46 | class FluxVariablesCache, | ||
47 | class FluxVariablesCacheFiller, | ||
48 | bool EnableGridFluxVariablesCache = false, | ||
49 | int upwindSchemeOrder = 1, | ||
50 | class Traits = StaggeredDefaultGridFluxVariablesCacheTraits<Problem, FluxVariablesCache, FluxVariablesCacheFiller, upwindSchemeOrder>> | ||
51 | class StaggeredGridFluxVariablesCache; | ||
52 | |||
53 | /*! | ||
54 | * \ingroup StaggeredDiscretization | ||
55 | * \brief Flux variables cache class for staggered models. | ||
56 | Specialization in case of storing the flux cache. | ||
57 | */ | ||
58 | template<class P, class FVC, class FVCF, int upwindSchemeOrder, class TheTraits> | ||
59 | class StaggeredGridFluxVariablesCache<P, FVC, FVCF, true, upwindSchemeOrder, TheTraits> | ||
60 | { | ||
61 | using Problem = typename TheTraits::Problem; | ||
62 | using ThisType = StaggeredGridFluxVariablesCache<P, FVC, FVCF, true, upwindSchemeOrder, TheTraits>; | ||
63 | |||
64 | //! the flux variable cache filler type | ||
65 | using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller; | ||
66 | public: | ||
67 | //! the flux var cache traits | ||
68 | using Traits = TheTraits; | ||
69 | |||
70 | //! export the flux variable cache type | ||
71 | using FluxVariablesCache = typename Traits::FluxVariablesCache; | ||
72 | using Scalar = typename FluxVariablesCache::Scalar; | ||
73 | |||
74 | static constexpr bool useHigherOrder = upwindSchemeOrder > 1; | ||
75 | |||
76 | //! export upwind scheme | ||
77 | using UpwindScheme = StaggeredUpwindMethods<Scalar, upwindSchemeOrder>; | ||
78 | |||
79 | //! make it possible to query if caching is enabled | ||
80 | static constexpr bool cachingEnabled = true; | ||
81 | |||
82 | //! export the type of the local view | ||
83 | using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>; | ||
84 | |||
85 | 51 | StaggeredGridFluxVariablesCache(const Problem& problem) | |
86 | 51 | : problemPtr_(&problem) | |
87 |
1/2✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
|
51 | , staggeredUpwindMethods_(problem.paramGroup()) |
88 | {} | ||
89 | |||
90 | // When global caching is enabled, precompute transmissibilities and stencils for all the scv faces | ||
91 | template<class GridGeometry, class GridVolumeVariables, class SolutionVector> | ||
92 | 5619 | void update(const GridGeometry& gridGeometry, | |
93 | const GridVolumeVariables& gridVolVars, | ||
94 | const SolutionVector& sol, | ||
95 | bool forceUpdate = false) | ||
96 | { | ||
97 | // only do the update if fluxes are solution dependent or if update is forced | ||
98 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 5568 times.
|
5619 | if (FluxVariablesCacheFiller::isSolDependent || forceUpdate) |
99 | { | ||
100 | // instantiate helper class to fill the caches | ||
101 | // FluxVariablesCacheFiller filler(problem()); TODO: use proper ctor | ||
102 | 51 | FluxVariablesCacheFiller filler(problem()); | |
103 | |||
104 | 51 | fluxVarsCache_.resize(gridGeometry.numScvf()); | |
105 |
1/2✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
|
51 | auto fvGeometry = localView(gridGeometry); |
106 | 51 | auto elemVolVars = localView(gridVolVars); | |
107 |
4/8✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 89640 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7003 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 7000 times.
✗ Branch 11 not taken.
|
268878 | for (const auto& element : elements(gridGeometry.gridView())) |
108 | { | ||
109 | // Prepare the geometries within the elements of the stencil | ||
110 |
1/2✓ Branch 1 taken 89592 times.
✗ Branch 2 not taken.
|
89592 | fvGeometry.bind(element); |
111 |
1/2✓ Branch 1 taken 7000 times.
✗ Branch 2 not taken.
|
89592 | elemVolVars.bind(element, fvGeometry, sol); |
112 | |||
113 |
1/2✓ Branch 1 taken 7000 times.
✗ Branch 2 not taken.
|
89592 | for (auto&& scvf : scvfs(fvGeometry)) |
114 | { | ||
115 | filler.fill(*this, fluxVarsCache_[scvf.index()], element, fvGeometry, elemVolVars, scvf, forceUpdate); | ||
116 | } | ||
117 | } | ||
118 | 51 | } | |
119 | 5619 | } | |
120 | |||
121 | //! Return the StaggeredUpwindMethods | ||
122 | 405836084 | const UpwindScheme& staggeredUpwindMethods() const | |
123 | { | ||
124 | 405836084 | return staggeredUpwindMethods_; | |
125 | } | ||
126 | |||
127 | const Problem& problem() const | ||
128 | 51 | { return *problemPtr_; } | |
129 | |||
130 | // access operators in the case of caching | ||
131 | 148094344 | const FluxVariablesCache& operator [](std::size_t scvfIdx) const | |
132 | 166059724 | { return fluxVarsCache_[scvfIdx]; } | |
133 | |||
134 | FluxVariablesCache& operator [](std::size_t scvfIdx) | ||
135 | { return fluxVarsCache_[scvfIdx]; } | ||
136 | |||
137 | private: | ||
138 | const Problem* problemPtr_; | ||
139 | UpwindScheme staggeredUpwindMethods_; | ||
140 | |||
141 | std::vector<FluxVariablesCache> fluxVarsCache_; | ||
142 | std::vector<std::size_t> globalScvfIndices_; | ||
143 | }; | ||
144 | |||
145 | /*! | ||
146 | * \ingroup StaggeredDiscretization | ||
147 | * \brief Flux variables cache class for staggered models. | ||
148 | Specialization in case of not storing the flux cache. | ||
149 | */ | ||
150 | template<class P, class FVC, class FVCF, int upwindSchemeOrder, class TheTraits> | ||
151 | class StaggeredGridFluxVariablesCache<P, FVC, FVCF, false, upwindSchemeOrder, TheTraits> | ||
152 | { | ||
153 | using Problem = typename TheTraits::Problem; | ||
154 | using ThisType = StaggeredGridFluxVariablesCache<P, FVC, FVCF, false, upwindSchemeOrder, TheTraits>; | ||
155 | |||
156 | //! the flux variable cache filler type | ||
157 | using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller; | ||
158 | public: | ||
159 | //! the flux var cache traits | ||
160 | using Traits = TheTraits; | ||
161 | |||
162 | //! export the flux variable cache type | ||
163 | using FluxVariablesCache = typename Traits::FluxVariablesCache; | ||
164 | |||
165 | //! the scalar type | ||
166 | using Scalar = typename FluxVariablesCache::Scalar; | ||
167 | |||
168 | //! make it possible to query if caching is enabled | ||
169 | static constexpr bool cachingEnabled = false; | ||
170 | |||
171 | //! export the type of the local view | ||
172 | using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>; | ||
173 | |||
174 | //! export upwind scheme | ||
175 | using UpwindScheme = StaggeredUpwindMethods<Scalar, upwindSchemeOrder>; | ||
176 | |||
177 | 24 | StaggeredGridFluxVariablesCache(const Problem& problem) | |
178 | 24 | : problemPtr_(&problem) | |
179 |
24/48✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 1 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 1 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
|
24 | , staggeredUpwindMethods_(problem.paramGroup()) |
180 | 24 | {} | |
181 | |||
182 | // When global caching is enabled, precompute transmissibilities and stencils for all the scv faces | ||
183 | template<class GridGeometry, class GridVolumeVariables, class SolutionVector> | ||
184 | void update(const GridGeometry& gridGeometry, | ||
185 | const GridVolumeVariables& gridVolVars, | ||
186 | const SolutionVector& sol, | ||
187 | bool forceUpdate = false) {} | ||
188 | |||
189 | const Problem& problem() const | ||
190 | 600 | { return *problemPtr_; } | |
191 | |||
192 | //! Return the UpwindingMethods | ||
193 | const UpwindScheme& staggeredUpwindMethods() const | ||
194 | { | ||
195 | return staggeredUpwindMethods_; | ||
196 | } | ||
197 | |||
198 | private: | ||
199 | const Problem* problemPtr_; | ||
200 | UpwindScheme staggeredUpwindMethods_; | ||
201 | }; | ||
202 | |||
203 | } // end namespace Dumux | ||
204 | |||
205 | #endif | ||
206 |