GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/facecentered/staggered/gridvolumevariables.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 12 20 60.0%
Functions: 38 80 47.5%
Branches: 12 28 42.9%

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 FaceCenteredStaggeredDiscretization
10 * \brief The grid volume variables class for face-centered staggered models
11 */
12 #ifndef DUMUX_DISCRETIZATION_FACECENTERED_GRID_VOLUMEVARIABLES_HH
13 #define DUMUX_DISCRETIZATION_FACECENTERED_GRID_VOLUMEVARIABLES_HH
14
15 #include <vector>
16 #include <type_traits>
17
18 #include <dumux/parallel/parallel_for.hh>
19
20 // make the local view function available whenever we use this class
21 #include <dumux/discretization/localview.hh>
22 #include <dumux/discretization/facecentered/staggered/elementsolution.hh>
23 #include <dumux/discretization/facecentered/staggered/elementvolumevariables.hh>
24
25 namespace Dumux {
26
27 template<class P, class VV>
28 struct FaceCenteredStaggeredDefaultGridVolumeVariablesTraits
29 {
30 using Problem = P;
31 using VolumeVariables = VV;
32
33 template<class GridVolumeVariables, bool cachingEnabled>
34 using LocalView = FaceCenteredStaggeredElementVolumeVariables<GridVolumeVariables, cachingEnabled>;
35 };
36
37 /*!
38 * \ingroup FaceCenteredStaggeredDiscretization
39 * \brief Base class for the grid volume variables
40 * \note This class has a cached version and a non-cached version
41 * \tparam Traits the traits class injecting the problem, volVar and elemVolVars type
42 * \tparam cachingEnabled if the cache is enabled
43 */
44 template<class Traits, bool cachingEnabled = false>
45 class FaceCenteredStaggeredGridVolumeVariables;
46
47 //! specialization in case of storing the volume variables
48 template<class Traits>
49
1/2
✓ Branch 3 taken 160 times.
✗ Branch 4 not taken.
216 class FaceCenteredStaggeredGridVolumeVariables<Traits, /*cachingEnabled*/true>
50 {
51 using ThisType = FaceCenteredStaggeredGridVolumeVariables<Traits, true>;
52
53 public:
54 //! export the problem type
55 using Problem = typename Traits::Problem;
56
57 //! export the volume variables type
58 using VolumeVariables = typename Traits::VolumeVariables;
59
60 //! make it possible to query if caching is enabled
61 static constexpr bool cachingEnabled = true;
62
63 //! export the type of the local view
64 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
65
66 FaceCenteredStaggeredGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
67
68 template<class GridGeometry, class SolutionVector>
69 758 void update(const GridGeometry& gridGeometry, const SolutionVector& sol)
70 {
71 1516 volumeVariables_.resize(gridGeometry.numScv());
72 1519 Dumux::parallelFor(gridGeometry.gridView().size(0), [&, &problem = problem()](const std::size_t eIdx)
73 {
74 2911262 const auto element = gridGeometry.element(eIdx);
75
2/4
✓ Branch 1 taken 5304 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5304 times.
✗ Branch 5 not taken.
5811916 const auto fvGeometry = localView(gridGeometry).bindElement(element);
76
1/2
✓ Branch 1 taken 5304 times.
✗ Branch 2 not taken.
2905958 const auto elemSol = elementSolution(element, sol, gridGeometry);
77
78
4/4
✓ Branch 1 taken 11633968 times.
✓ Branch 2 taken 2905958 times.
✓ Branch 3 taken 11633968 times.
✓ Branch 4 taken 2905958 times.
26173894 for (const auto& scv : scvs(fvGeometry))
79 34901904 volumeVariables_[scv.index()].update(elemSol, problem, element, scv);
80 });
81 758 }
82
83 const VolumeVariables& volVars(const std::size_t scvIdx) const
84 4712314872 { return volumeVariables_[scvIdx]; }
85
86 VolumeVariables& volVars(const std::size_t scvIdx)
87 { return volumeVariables_[scvIdx]; }
88
89 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
90 const VolumeVariables& volVars(const SubControlVolume scv) const
91 { return volumeVariables_[scv.index()]; }
92
93 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
94 VolumeVariables& volVars(const SubControlVolume scv)
95
4/4
✓ Branch 0 taken 85 times.
✓ Branch 1 taken 59551227 times.
✓ Branch 2 taken 85 times.
✓ Branch 3 taken 59551227 times.
119102624 { return volumeVariables_[scv.index()]; }
96
97 // required for compatibility with the box method
98 const VolumeVariables& volVars(const std::size_t scvIdx, const std::size_t localIdx) const
99 { return volumeVariables_[scvIdx]; }
100
101 // required for compatibility with the box method
102 VolumeVariables& volVars(const std::size_t scvIdx, const std::size_t localIdx)
103 { return volumeVariables_[scvIdx]; }
104
105 //! The problem we are solving
106 const Problem& problem() const
107 { return *problemPtr_; }
108
109 private:
110 const Problem* problemPtr_;
111 std::vector<VolumeVariables> volumeVariables_;
112 };
113
114
115 //! Specialization when the current volume variables are not stored globally
116 template<class Traits>
117 class FaceCenteredStaggeredGridVolumeVariables<Traits, /*cachingEnabled*/false>
118 {
119 using ThisType = FaceCenteredStaggeredGridVolumeVariables<Traits, false>;
120
121 public:
122 //! export the problem type
123 using Problem = typename Traits::Problem;
124
125 //! export the volume variables type
126 using VolumeVariables = typename Traits::VolumeVariables;
127
128 //! make it possible to query if caching is enabled
129 static constexpr bool cachingEnabled = false;
130
131 //! export the type of the local view
132 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
133
134 FaceCenteredStaggeredGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
135
136 template<class GridGeometry, class SolutionVector>
137 void update(const GridGeometry& gridGeometry, const SolutionVector& sol) {}
138
139 //! The problem we are solving
140 const Problem& problem() const
141 { return *problemPtr_;}
142
143 private:
144 const Problem* problemPtr_;
145 };
146
147 } // end namespace Dumux
148
149 #endif
150