version 3.10-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-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_VOLUMEVARIABLES_HH
13#define DUMUX_DISCRETIZATION_CVFE_GRID_VOLUMEVARIABLES_HH
14
15#include <vector>
16#include <type_traits>
17
19
20// make the local view function available whenever we use this class
24
25namespace Dumux {
26
27template<class P, class VV>
29{
30 using Problem = P;
31 using VolumeVariables = VV;
32
33 template<class GridVolumeVariables, bool cachingEnabled>
35};
36
41template<class Traits, bool enableCaching>
43
44// specialization in case of storing the volume variables
45template<class Traits>
46class CVFEGridVolumeVariables<Traits, /*cachingEnabled*/true>
47{
49
50public:
52 using Problem = typename Traits::Problem;
53
55 using VolumeVariables = typename Traits::VolumeVariables;
56
58 static constexpr bool cachingEnabled = true;
59
61 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
62
63 CVFEGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
64
65 template<class GridGeometry, class SolutionVector>
66 void update(const GridGeometry& gridGeometry, const SolutionVector& sol)
67 {
68 volumeVariables_.resize(gridGeometry.gridView().size(0));
69 Dumux::parallelFor(gridGeometry.gridView().size(0), [&, &problem = problem()](const std::size_t eIdx)
70 {
71 const auto element = gridGeometry.element(eIdx);
72 const auto fvGeometry = localView(gridGeometry).bindElement(element);
73
74 // get the element solution
75 auto elemSol = elementSolution(element, sol, gridGeometry);
76
77 // update the volvars of the element
78 volumeVariables_[eIdx].resize(fvGeometry.numScv());
79 for (const auto& scv : scvs(fvGeometry))
80 volumeVariables_[eIdx][scv.indexInElement()].update(elemSol, problem, element, scv);
81 });
82 }
83
84 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
85 const VolumeVariables& volVars(const SubControlVolume& scv) const
86 { return volumeVariables_[scv.elementIndex()][scv.indexInElement()]; }
87
88 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
89 VolumeVariables& volVars(const SubControlVolume& scv)
90 { return volumeVariables_[scv.elementIndex()][scv.indexInElement()]; }
91
92 const VolumeVariables& volVars(const std::size_t eIdx, const std::size_t scvIdx) const
93 { return volumeVariables_[eIdx][scvIdx]; }
94
95 VolumeVariables& volVars(const std::size_t eIdx, const std::size_t scvIdx)
96 { return volumeVariables_[eIdx][scvIdx]; }
97
98 const Problem& problem() const
99 { return *problemPtr_; }
100
101private:
102 const Problem* problemPtr_;
103 std::vector<std::vector<VolumeVariables>> volumeVariables_;
104};
105
106
107// Specialization when the current volume variables are not stored
108template<class Traits>
109class CVFEGridVolumeVariables<Traits, /*cachingEnabled*/false>
110{
112
113public:
115 using Problem = typename Traits::Problem;
116
118 using VolumeVariables = typename Traits::VolumeVariables;
119
121 static constexpr bool cachingEnabled = false;
122
124 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
125
126 CVFEGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
127
128 template<class GridGeometry, class SolutionVector>
129 void update(const GridGeometry& gridGeometry, const SolutionVector& sol) {}
130
131 const Problem& problem() const
132 { return *problemPtr_;}
133
134private:
135 const Problem* problemPtr_;
136};
137
138} // end namespace Dumux
139
140#endif
The local (stencil) volume variables class for control-volume finite element.
Definition: cvfe/elementvolumevariables.hh:31
Definition: cvfe/gridvolumevariables.hh:110
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: cvfe/gridvolumevariables.hh:129
typename Traits::VolumeVariables VolumeVariables
export the volume variables type
Definition: cvfe/gridvolumevariables.hh:118
typename Traits::Problem Problem
export the problem type
Definition: cvfe/gridvolumevariables.hh:115
CVFEGridVolumeVariables(const Problem &problem)
Definition: cvfe/gridvolumevariables.hh:126
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: cvfe/gridvolumevariables.hh:124
const Problem & problem() const
Definition: cvfe/gridvolumevariables.hh:131
Definition: cvfe/gridvolumevariables.hh:47
CVFEGridVolumeVariables(const Problem &problem)
Definition: cvfe/gridvolumevariables.hh:63
const VolumeVariables & volVars(const std::size_t eIdx, const std::size_t scvIdx) const
Definition: cvfe/gridvolumevariables.hh:92
VolumeVariables & volVars(const std::size_t eIdx, const std::size_t scvIdx)
Definition: cvfe/gridvolumevariables.hh:95
typename Traits::VolumeVariables VolumeVariables
export the volume variables type
Definition: cvfe/gridvolumevariables.hh:55
const Problem & problem() const
Definition: cvfe/gridvolumevariables.hh:98
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: cvfe/gridvolumevariables.hh:66
typename Traits::Problem Problem
export the problem type
Definition: cvfe/gridvolumevariables.hh:52
const VolumeVariables & volVars(const SubControlVolume &scv) const
Definition: cvfe/gridvolumevariables.hh:85
VolumeVariables & volVars(const SubControlVolume &scv)
Definition: cvfe/gridvolumevariables.hh:89
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: cvfe/gridvolumevariables.hh:61
Base class for the grid volume variables.
Definition: cvfe/gridvolumevariables.hh:42
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
Parallel for loop (multithreading)
Definition: cvfe/gridvolumevariables.hh:29
VV VolumeVariables
Definition: cvfe/gridvolumevariables.hh:31
P Problem
Definition: cvfe/gridvolumevariables.hh:30