GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/assembly/cvfevolvarsdeflectionpolicy_.hh
Date: 2025-06-14 19:21:29
Exec Total Coverage
Lines: 33 33 100.0%
Functions: 520 524 99.2%
Branches: 28 30 93.3%

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-FileCopyrightText: 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 Assembly
10 * \brief Variables deflection policy
11 */
12
13 #ifndef DUMUX_ASSEMBLY_CVFE_VOLVARS_DEFLECTION_POLICY_HH
14 #define DUMUX_ASSEMBLY_CVFE_VOLVARS_DEFLECTION_POLICY_HH
15
16 #include <type_traits>
17 #include <dune/common/reservedvector.hh>
18
19 #include <dumux/common/typetraits/localdofs_.hh>
20 #include <dumux/discretization/cvfe/localdof.hh>
21
22 #ifndef DOXYGEN
23
24 namespace Dumux::Detail::CVFE {
25
26 template<class MutableVariablesView, class FVElementGeometry>
27 class VolVarsDeflectionPolicy
28 {
29 using VolumeVariables = typename MutableVariablesView::VolumeVariables;
30 static constexpr int maxNumLocalDofs = Detail::LocalDofs::maxNumLocalDofs<FVElementGeometry>();
31
32 public:
33 12273073 VolVarsDeflectionPolicy(MutableVariablesView elementVariables,
34 const FVElementGeometry& fvGeometry,
35 bool deflectAllVariables)
36 12273073 : elementVariables_(elementVariables)
37 12273073 , fvGeometry_(fvGeometry)
38
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 697104 times.
12273073 , deflectAll_(deflectAllVariables)
39 {
40
2/2
✓ Branch 0 taken 604200 times.
✓ Branch 1 taken 10263416 times.
12273073 if (deflectAll_)
41
2/2
✓ Branch 0 taken 1208400 times.
✓ Branch 1 taken 604200 times.
1812600 for (const auto& scv : scvs(fvGeometry))
42 1208400 origVolVars_.push_back(elementVariables_[scv]);
43 12273073 }
44
45 template<class LocalDof>
46 40233962 void store(const LocalDof& localDof)
47 {
48
2/2
✓ Branch 0 taken 35636318 times.
✓ Branch 1 taken 1208400 times.
40233962 if (!deflectAll_)
49 {
50
1/2
✓ Branch 0 taken 14702464 times.
✗ Branch 1 not taken.
39025562 origVolVars_.clear();
51
4/4
✓ Branch 0 taken 14702464 times.
✓ Branch 1 taken 21183394 times.
✓ Branch 2 taken 35636318 times.
✓ Branch 3 taken 14702464 times.
96299060 for(const auto& scv : scvs(fvGeometry_, localDof))
52 39275102 origVolVars_.push_back(elementVariables_[scv]);
53 }
54 40233962 }
55
56 template<class ElementSolution, class LocalDof, class Problem>
57 88287300 void update(const ElementSolution& elemSol,
58 const LocalDof& localDof,
59 const Problem& problem)
60 {
61
2/2
✓ Branch 0 taken 3625200 times.
✓ Branch 1 taken 80254820 times.
88287300 if (deflectAll_)
62
2/2
✓ Branch 0 taken 7250400 times.
✓ Branch 1 taken 3625200 times.
10875600 for (const auto& scv : scvs(fvGeometry_))
63 7250400 elementVariables_[scv].update(elemSol, problem, fvGeometry_.element(), scv);
64 else
65 {
66
4/4
✓ Branch 0 taken 38364582 times.
✓ Branch 1 taken 42389318 times.
✓ Branch 2 taken 80254820 times.
✓ Branch 3 taken 38364582 times.
220264222 for(const auto& scv : scvs(fvGeometry_, localDof))
67 85161180 elementVariables_[scv].update(elemSol, problem, fvGeometry_.element(), scv);
68 }
69 88287300 }
70
71 template<class LocalDof>
72 86941380 void restore(const LocalDof& localDof)
73 {
74
2/2
✓ Branch 0 taken 78908900 times.
✓ Branch 1 taken 3625200 times.
86941380 if (!deflectAll_)
75 {
76 83316180 unsigned int idx = 0;
77
4/4
✓ Branch 0 taken 37018662 times.
✓ Branch 1 taken 42389318 times.
✓ Branch 2 taken 78908900 times.
✓ Branch 3 taken 37018662 times.
208444870 for(const auto& scv : scvs(fvGeometry_, localDof))
78 {
79 83815260 elementVariables_[scv] = origVolVars_[idx];
80 83815260 idx++;
81 }
82 }
83 else
84
2/2
✓ Branch 0 taken 7250400 times.
✓ Branch 1 taken 3625200 times.
10875600 for (const auto& scv : scvs(fvGeometry_))
85 7250400 elementVariables_[scv] = origVolVars_[scv.indexInElement()];
86 86941380 }
87
88 private:
89 MutableVariablesView elementVariables_;
90 const FVElementGeometry& fvGeometry_;
91 const bool deflectAll_;
92 Dune::ReservedVector<VolumeVariables, maxNumLocalDofs> origVolVars_;
93 };
94
95 template<typename ElemVars, typename FVG>
96 using DefinesDeflectionPolicyType = typename ElemVars::template DeflectionPolicy<FVG>;
97
98 template<typename ElemVars, typename FVG>
99 constexpr inline bool definesVariablesDeflectionPolicy()
100 { return Dune::Std::is_detected<DefinesDeflectionPolicyType, ElemVars, FVG>::value; }
101
102 template<class GridVarsCache, class ElemVars, class FVG>
103 11194972 auto makeVariablesDeflectionPolicy(GridVarsCache& gridVarsCache, ElemVars& elemVars, const FVG& fvg, bool deflectAllVolVars)
104 {
105 if constexpr (definesVariablesDeflectionPolicy<ElemVars, FVG>())
106 {
107 using DeflectionPolicy = typename ElemVars::template DeflectionPolicy<FVG>;
108 327356 return DeflectionPolicy(elemVars.asMutableView(gridVarsCache), fvg, deflectAllVolVars);
109 }
110 else
111 {
112 using DeflectionPolicy = Detail::CVFE::VolVarsDeflectionPolicy<typename GridVarsCache::MutableLocalView, FVG>;
113 10867616 return DeflectionPolicy(elemVars.asMutableView(gridVarsCache), fvg, deflectAllVolVars);
114 }
115 };
116
117 } // end namespace Dumux::Detail::CVFE
118
119 #endif // DOXYGEN
120
121 #endif
122