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 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 | 50 | StaggeredGridFluxVariablesCache(const Problem& problem) | |
86 | : problemPtr_(&problem) | ||
87 |
2/4✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 50 times.
✗ Branch 5 not taken.
|
100 | , 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 | 5584 | 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 50 times.
✓ Branch 1 taken 5534 times.
|
5584 | if (FluxVariablesCacheFiller::isSolDependent || forceUpdate) |
99 | { | ||
100 | // instantiate helper class to fill the caches | ||
101 | // FluxVariablesCacheFiller filler(problem()); TODO: use proper ctor | ||
102 | 50 | FluxVariablesCacheFiller filler(problem()); | |
103 | |||
104 | 100 | fluxVarsCache_.resize(gridGeometry.numScvf()); | |
105 |
1/2✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
|
50 | auto fvGeometry = localView(gridGeometry); |
106 |
1/2✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
|
50 | auto elemVolVars = localView(gridVolVars); |
107 |
3/6✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 50 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 89442 times.
✗ Branch 7 not taken.
|
178934 | for (const auto& element : elements(gridGeometry.gridView())) |
108 | { | ||
109 | // Prepare the geometries within the elements of the stencil | ||
110 |
1/2✓ Branch 1 taken 7000 times.
✗ Branch 2 not taken.
|
89392 | fvGeometry.bind(element); |
111 |
1/2✓ Branch 1 taken 89392 times.
✗ Branch 2 not taken.
|
89392 | elemVolVars.bind(element, fvGeometry, sol); |
112 | |||
113 |
3/6✓ Branch 1 taken 7000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7000 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7000 times.
✗ Branch 8 not taken.
|
268176 | for (auto&& scvf : scvfs(fvGeometry)) |
114 | { | ||
115 | filler.fill(*this, fluxVarsCache_[scvf.index()], element, fvGeometry, elemVolVars, scvf, forceUpdate); | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | 5584 | } | |
120 | |||
121 | //! Return the StaggeredUpwindMethods | ||
122 | const UpwindScheme& staggeredUpwindMethods() const | ||
123 | { | ||
124 | 403282209 | return staggeredUpwindMethods_; | |
125 | } | ||
126 | |||
127 | ✗ | const Problem& problem() const | |
128 | ✗ | { return *problemPtr_; } | |
129 | |||
130 | // access operators in the case of caching | ||
131 | const FluxVariablesCache& operator [](std::size_t scvfIdx) const | ||
132 |
1/7✓ Branch 1 taken 138882 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
192580296 | { 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 | ✗ | StaggeredGridFluxVariablesCache(const Problem& problem) | |
178 | : problemPtr_(&problem) | ||
179 | ✗ | , staggeredUpwindMethods_(problem.paramGroup()) | |
180 | {} | ||
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 | ✗ | { 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 |