version 3.11-dev
gridvariablescache.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-FileCopyrightText: 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_LOCAL_VARIABLES_HH
13#define DUMUX_DISCRETIZATION_CVFE_GRID_LOCAL_VARIABLES_HH
14
15#include <vector>
16#include <type_traits>
17
19
20#include <dumux/common/concepts/localdofs_.hh>
21
22// make the local view function available whenever we use this class
26
27namespace Dumux::Detail::CVFE {
28
29template<class P, class V>
31{
32 using Problem = P;
33 using Variables = V;
34
35 template<class GridVariablesCache, bool cachingEnabled>
37};
38
43template<class Traits, bool enableCaching>
45
46// specialization in case of storing the local variables
47template<class Traits>
48class CVFEGridVariablesCache<Traits, /*cachingEnabled*/true>
49{
51
52public:
54 using Problem = typename Traits::Problem;
55
57 using Variables = typename Traits::Variables;
58
62
64 static constexpr bool cachingEnabled = true;
65
67 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
68
70 using MutableLocalView = LocalView::MutableView;
71
72 CVFEGridVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
73
74 template<class GridGeometry, class SolutionVector>
75 void update(const GridGeometry& gridGeometry, const SolutionVector& sol)
76 {
77 variables_.resize(gridGeometry.gridView().size(0));
78 Dumux::parallelFor(gridGeometry.gridView().size(0), [&, &problem = problem()](const std::size_t eIdx)
79 {
80 const auto element = gridGeometry.element(eIdx);
81 const auto fvGeometry = localView(gridGeometry).bindElement(element);
82
83 // get the element solution
84 auto elemSol = elementSolution(element, sol, gridGeometry);
85
86 variables_[eIdx].resize(Dumux::Detail::LocalDofs::numLocalDofs(fvGeometry));
87 for (const auto& localDof : localDofs(fvGeometry))
88 variables_[eIdx][localDof.index()].update(elemSol, problem, fvGeometry, ipData(fvGeometry, localDof));
89 });
90 }
91
94 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
95 const Variables& volVars(const ScvOrLocalDof& scvOrLocalDof) const
96 {
97 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
98 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.index()];
99 else
100 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.localDofIndex()];
101 }
102
103 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
104 Variables& volVars(const ScvOrLocalDof& scvOrLocalDof)
105 {
106 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
107 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.index()];
108 else
109 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.localDofIndex()];
110 }
111
112 const Variables& volVars(const std::size_t eIdx, const std::size_t localIdx) const
113 { return variables_[eIdx][localIdx]; }
114
115 Variables& volVars(const std::size_t eIdx, const std::size_t localIdx)
116 { return variables_[eIdx][localIdx]; }
117
118 const Problem& problem() const
119 { return *problemPtr_; }
120
121private:
122 const Problem* problemPtr_;
123 std::vector<std::vector<Variables>> variables_;
124};
125
126// Specialization when the current local variables are not stored
127template<class Traits>
128class CVFEGridVariablesCache<Traits, /*cachingEnabled*/false>
129{
131
132public:
134 using Problem = typename Traits::Problem;
135
137 using Variables = typename Traits::Variables;
138
142
144 static constexpr bool cachingEnabled = false;
145
147 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
148
150 using MutableLocalView = LocalView::MutableView;
151
152 CVFEGridVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
153
154 template<class GridGeometry, class SolutionVector>
155 void update(const GridGeometry& gridGeometry, const SolutionVector& sol) {}
156
157 const Problem& problem() const
158 { return *problemPtr_;}
159
160private:
161 const Problem* problemPtr_;
162};
163
164} // end namespace Dumux
165
166#endif
The (stencil) element variables class for control-volume finite element.
Definition: elementvariables.hh:34
typename Traits::Problem Problem
export the problem type
Definition: gridvariablescache.hh:134
Variables VolumeVariables
Definition: gridvariablescache.hh:141
const Problem & problem() const
Definition: gridvariablescache.hh:157
typename Traits::Variables Variables
export the variables type
Definition: gridvariablescache.hh:137
CVFEGridVariablesCache(const Problem &problem)
Definition: gridvariablescache.hh:152
LocalView::MutableView MutableLocalView
export the type of the mutable local view
Definition: gridvariablescache.hh:150
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: gridvariablescache.hh:155
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: gridvariablescache.hh:147
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: gridvariablescache.hh:67
Variables VolumeVariables
Definition: gridvariablescache.hh:61
CVFEGridVariablesCache(const Problem &problem)
Definition: gridvariablescache.hh:72
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: gridvariablescache.hh:75
Variables & volVars(const std::size_t eIdx, const std::size_t localIdx)
Definition: gridvariablescache.hh:115
LocalView::MutableView MutableLocalView
export the type of the mutable local view
Definition: gridvariablescache.hh:70
const Problem & problem() const
Definition: gridvariablescache.hh:118
Variables & volVars(const ScvOrLocalDof &scvOrLocalDof)
Definition: gridvariablescache.hh:104
typename Traits::Problem Problem
export the problem type
Definition: gridvariablescache.hh:54
const Variables & volVars(const std::size_t eIdx, const std::size_t localIdx) const
Definition: gridvariablescache.hh:112
typename Traits::Variables Variables
export the variables type
Definition: gridvariablescache.hh:57
const Variables & volVars(const ScvOrLocalDof &scvOrLocalDof) const
Definition: gridvariablescache.hh:95
Base class for the grid local variables.
Definition: gridvariablescache.hh:44
The local element solution class for control-volume finite element methods.
The element variables class.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethods::cctpfa||GridGeometry::discMethod==DiscretizationMethods::ccmpfa, CCElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for cell-centered schemes.
Definition: cellcentered/elementsolution.hh:101
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: elementvariables.hh:24
auto localDofs(const FVElementGeometry &fvGeometry)
range over local dofs
Definition: localdof.hh:50
Parallel for loop (multithreading)
P Problem
Definition: gridvariablescache.hh:32
V Variables
Definition: gridvariablescache.hh:33