version 3.10-dev
discretization/cvfe/gridfluxvariablescache.hh
Go to the documentation of this file.
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//
12#ifndef DUMUX_DISCRETIZATION_CVFE_GRID_FLUXVARSCACHE_HH
13#define DUMUX_DISCRETIZATION_CVFE_GRID_FLUXVARSCACHE_HH
14
16
17// make the local view function available whenever we use this class
20
21namespace Dumux {
22
27template<class P, class FVC>
29{
30 using Problem = P;
31 using FluxVariablesCache = FVC;
32
33 template<class GridFluxVariablesCache, bool cachingEnabled>
35};
36
42template<class Problem,
43 class FluxVariablesCache,
44 bool cachingEnabled = false,
47
53template<class P, class FVC, class Traits>
54class CVFEGridFluxVariablesCache<P, FVC, true, Traits>
55{
56 using Problem = typename Traits::Problem;
58
59public:
61 using FluxVariablesCache = typename Traits::FluxVariablesCache;
62
64 static constexpr bool cachingEnabled = true;
65
67 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
68
69 CVFEGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
70
71 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
72 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 if (forceUpdate)
79 {
80 fluxVarsCache_.resize(gridGeometry.gridView().size(0));
81 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 const auto element = gridGeometry.element(eIdx);
85 const auto fvGeometry = localView(gridGeometry).bind(element);
86 const auto elemVolVars = localView(gridVolVars).bind(element, fvGeometry, sol);
87
88 // only update shape functions for fluxes if update is forced
89 fluxVarsCache_[eIdx].resize(fvGeometry.numScvf());
90 for (const auto& scvf : scvfs(fvGeometry))
91 cache(eIdx, scvf.index()).update(problem, element, fvGeometry, elemVolVars, scvf);
92 });
93 }
94 }
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 const Problem& problem() const
111 { return *problemPtr_; }
112
113 // access operator
114 const FluxVariablesCache& cache(std::size_t eIdx, std::size_t scvfIdx) const
115 { return fluxVarsCache_[eIdx][scvfIdx]; }
116
117 // access operator
118 FluxVariablesCache& cache(std::size_t eIdx, std::size_t scvfIdx)
119 { return fluxVarsCache_[eIdx][scvfIdx]; }
120
121private:
122 // currently bound element
123 const Problem* problemPtr_;
124 std::vector<std::vector<FluxVariablesCache>> fluxVarsCache_;
125};
126
131template<class P, class FVC, class Traits>
132class CVFEGridFluxVariablesCache<P, FVC, false, Traits>
133{
134 using Problem = typename Traits::Problem;
136
137public:
139 using FluxVariablesCache = typename Traits::FluxVariablesCache;
140
142 static constexpr bool cachingEnabled = false;
143
145 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
146
147 CVFEGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
148
149 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
150 void update(const GridGeometry& gridGeometry,
151 const GridVolumeVariables& gridVolVars,
152 const SolutionVector& sol,
153 bool forceUpdate = false) {}
154
155 const Problem& problem() const
156 { return *problemPtr_; }
157
158private:
159 const Problem* problemPtr_;
160};
161
162} // end namespace Dumux
163
164#endif
The flux variables caches for an element.
Definition: discretization/cvfe/elementfluxvariablescache.hh:31
Flux variable caches on a gridview with grid caching disabled.
Definition: discretization/cvfe/gridfluxvariablescache.hh:133
CVFEGridFluxVariablesCache(const Problem &problem)
Definition: discretization/cvfe/gridfluxvariablescache.hh:147
const Problem & problem() const
Definition: discretization/cvfe/gridfluxvariablescache.hh:155
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/cvfe/gridfluxvariablescache.hh:145
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/cvfe/gridfluxvariablescache.hh:139
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
Definition: discretization/cvfe/gridfluxvariablescache.hh:150
Flux variable caches on a gridview with grid caching enabled.
Definition: discretization/cvfe/gridfluxvariablescache.hh:55
FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx)
Definition: discretization/cvfe/gridfluxvariablescache.hh:118
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/cvfe/gridfluxvariablescache.hh:61
const Problem & problem() const
Definition: discretization/cvfe/gridfluxvariablescache.hh:110
void updateElement(const typename FVElementGeometry::Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Definition: discretization/cvfe/gridfluxvariablescache.hh:97
const FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx) const
Definition: discretization/cvfe/gridfluxvariablescache.hh:114
CVFEGridFluxVariablesCache(const Problem &problem)
Definition: discretization/cvfe/gridfluxvariablescache.hh:69
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/cvfe/gridfluxvariablescache.hh:67
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
Definition: discretization/cvfe/gridfluxvariablescache.hh:72
Flux variable caches on a gridview.
Definition: discretization/cvfe/gridfluxvariablescache.hh:46
Global flux variable cache.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
void parallelFor(const std::size_t count, const FunctorType &functor)
A parallel for loop (multithreading)
Definition: parallel_for.hh:160
Free function to get the local view of a grid cache object.
Definition: adapt.hh:17
Parallel for loop (multithreading)
Flux variable caches traits.
Definition: discretization/cvfe/gridfluxvariablescache.hh:29
P Problem
Definition: discretization/cvfe/gridfluxvariablescache.hh:30
FVC FluxVariablesCache
Definition: discretization/cvfe/gridfluxvariablescache.hh:31