version 3.11-dev
cvfe/gridvolumevariables.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_VOLUMEVARIABLES_HH
13#define DUMUX_DISCRETIZATION_CVFE_GRID_VOLUMEVARIABLES_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 {
28
29template<class P, class VV>
31{
32 using Problem = P;
33 using VolumeVariables = VV;
34
35 template<class GridVolumeVariables, bool cachingEnabled>
37};
38
43template<class Traits, bool enableCaching>
45
46// specialization in case of storing the volume variables
47template<class Traits>
48class CVFEGridVolumeVariables<Traits, /*cachingEnabled*/true>
49{
51
52public:
54 using Problem = typename Traits::Problem;
55
57 using VolumeVariables = typename Traits::VolumeVariables;
58
60 static constexpr bool cachingEnabled = true;
61
63 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
64
66 using MutableLocalView = LocalView::MutableView;
67
68 CVFEGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
69
70 template<class GridGeometry, class SolutionVector>
71 void update(const GridGeometry& gridGeometry, const SolutionVector& sol)
72 {
73 volumeVariables_.resize(gridGeometry.gridView().size(0));
74 Dumux::parallelFor(gridGeometry.gridView().size(0), [&, &problem = problem()](const std::size_t eIdx)
75 {
76 const auto element = gridGeometry.element(eIdx);
77 const auto fvGeometry = localView(gridGeometry).bindElement(element);
78
79 // get the element solution
80 auto elemSol = elementSolution(element, sol, gridGeometry);
81
82 // update the volvars of the element
83 volumeVariables_[eIdx].resize(fvGeometry.numScv());
84 for (const auto& scv : scvs(fvGeometry))
85 volumeVariables_[eIdx][scv.indexInElement()].update(elemSol, problem, element, scv);
86 });
87 }
88
89 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
90 const VolumeVariables& volVars(const ScvOrLocalDof& scvOrLocalDof) const
91 {
92 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
93 return volumeVariables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.index()];
94 else
95 return volumeVariables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.indexInElement()];
96 }
97
98 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
99 VolumeVariables& volVars(const ScvOrLocalDof& scvOrLocalDof)
100 {
101 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
102 return volumeVariables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.index()];
103 else
104 return volumeVariables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.indexInElement()];
105 }
106
107 const VolumeVariables& volVars(const std::size_t eIdx, const std::size_t scvIdx) const
108 { return volumeVariables_[eIdx][scvIdx]; }
109
110 VolumeVariables& volVars(const std::size_t eIdx, const std::size_t scvIdx)
111 { return volumeVariables_[eIdx][scvIdx]; }
112
113 const Problem& problem() const
114 { return *problemPtr_; }
115
116private:
117 const Problem* problemPtr_;
118 std::vector<std::vector<VolumeVariables>> volumeVariables_;
119};
120
121
122// Specialization when the current volume variables are not stored
123template<class Traits>
124class CVFEGridVolumeVariables<Traits, /*cachingEnabled*/false>
125{
127
128public:
130 using Problem = typename Traits::Problem;
131
133 using VolumeVariables = typename Traits::VolumeVariables;
134
136 static constexpr bool cachingEnabled = false;
137
139 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
140
142 using MutableLocalView = LocalView::MutableView;
143
144 CVFEGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
145
146 template<class GridGeometry, class SolutionVector>
147 void update(const GridGeometry& gridGeometry, const SolutionVector& sol) {}
148
149 const Problem& problem() const
150 { return *problemPtr_;}
151
152private:
153 const Problem* problemPtr_;
154};
155
156} // end namespace Dumux
157
158#endif
The local (stencil) volume variables class for control-volume finite element.
Definition: cvfe/elementvolumevariables.hh:32
Definition: cvfe/gridvolumevariables.hh:125
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: cvfe/gridvolumevariables.hh:147
typename Traits::VolumeVariables VolumeVariables
export the volume variables type
Definition: cvfe/gridvolumevariables.hh:133
typename Traits::Problem Problem
export the problem type
Definition: cvfe/gridvolumevariables.hh:130
CVFEGridVolumeVariables(const Problem &problem)
Definition: cvfe/gridvolumevariables.hh:144
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: cvfe/gridvolumevariables.hh:139
const Problem & problem() const
Definition: cvfe/gridvolumevariables.hh:149
LocalView::MutableView MutableLocalView
export the type of the mutable local view
Definition: cvfe/gridvolumevariables.hh:142
Definition: cvfe/gridvolumevariables.hh:49
CVFEGridVolumeVariables(const Problem &problem)
Definition: cvfe/gridvolumevariables.hh:68
const VolumeVariables & volVars(const std::size_t eIdx, const std::size_t scvIdx) const
Definition: cvfe/gridvolumevariables.hh:107
VolumeVariables & volVars(const std::size_t eIdx, const std::size_t scvIdx)
Definition: cvfe/gridvolumevariables.hh:110
typename Traits::VolumeVariables VolumeVariables
export the volume variables type
Definition: cvfe/gridvolumevariables.hh:57
const VolumeVariables & volVars(const ScvOrLocalDof &scvOrLocalDof) const
Definition: cvfe/gridvolumevariables.hh:90
const Problem & problem() const
Definition: cvfe/gridvolumevariables.hh:113
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: cvfe/gridvolumevariables.hh:71
typename Traits::Problem Problem
export the problem type
Definition: cvfe/gridvolumevariables.hh:54
VolumeVariables & volVars(const ScvOrLocalDof &scvOrLocalDof)
Definition: cvfe/gridvolumevariables.hh:99
LocalView::MutableView MutableLocalView
export the type of the mutable local view
Definition: cvfe/gridvolumevariables.hh:66
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: cvfe/gridvolumevariables.hh:63
Base class for the grid volume variables.
Definition: cvfe/gridvolumevariables.hh:44
The local element solution class for control-volume finite element methods.
The local volume 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: adapt.hh:17
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition: localdof.hh:79
Parallel for loop (multithreading)
Definition: cvfe/gridvolumevariables.hh:31
VV VolumeVariables
Definition: cvfe/gridvolumevariables.hh:33
P Problem
Definition: cvfe/gridvolumevariables.hh:32