GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/assembly/volvardeflectionhelper_.hh
Date: 2025-05-17 19:20:33
Exec Total Coverage
Lines: 34 34 100.0%
Functions: 552 556 99.3%
Branches: 30 34 88.2%

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 Volume variables deflection helper.
11 */
12
13 #ifndef DUMUX_ASSEMBLY_VOLVARS_DEFLECTION_HELPER_HH
14 #define DUMUX_ASSEMBLY_VOLVARS_DEFLECTION_HELPER_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 {
25
26 template<class GridVolumeVariables, class FVElementGeometry>
27 class VolVarsDeflectionHelper
28 {
29 using ElementVariables = typename GridVolumeVariables::LocalView;
30 using VolumeVariables = typename ElementVariables::VolumeVariables;
31
32 static constexpr int maxNumLocalDofs = Detail::LocalDofs::maxNumLocalDofs<FVElementGeometry>();
33
34 public:
35 13083911 VolVarsDeflectionHelper(GridVolumeVariables& gridVolumeVariables,
36 ElementVariables& elementVariables,
37 const FVElementGeometry& fvGeometry,
38 bool deflectAllVariables)
39 13083911 : gridVolumeVariables_(gridVolumeVariables)
40 13083911 , elementVariables_(elementVariables)
41 13083911 , fvGeometry_(fvGeometry)
42
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 697104 times.
13083911 , deflectAll_(deflectAllVariables)
43 {
44
2/2
✓ Branch 0 taken 604200 times.
✓ Branch 1 taken 10523342 times.
13083911 if (deflectAll_)
45
2/2
✓ Branch 0 taken 1208400 times.
✓ Branch 1 taken 604200 times.
1812600 for (const auto& scv : scvs(fvGeometry))
46 1208400 origVolVars_.push_back(accessor_(scv));
47 13083911 }
48
49 template<class LocalDof>
50 43729102 void setCurrent(const LocalDof& localDof)
51 {
52
2/2
✓ Branch 0 taken 37028530 times.
✓ Branch 1 taken 1208400 times.
43729102 if (!deflectAll_)
53 {
54
1/2
✓ Branch 0 taken 2655678 times.
✗ Branch 1 not taken.
42520702 origVolVars_.clear();
55
4/4
✓ Branch 0 taken 2655678 times.
✓ Branch 1 taken 34372852 times.
✓ Branch 2 taken 37028530 times.
✓ Branch 3 taken 2655678 times.
93376914 for(const auto& scv : scvs(fvGeometry_, localDof))
56 42520702 origVolVars_.push_back(accessor_(scv));
57 }
58 43729102 }
59
60 template<class ElementSolution, class LocalDof, class Problem>
61 94406664 void deflect(const ElementSolution& elemSol,
62 const LocalDof& localDof,
63 const Problem& problem)
64 {
65
2/2
✓ Branch 0 taken 3625200 times.
✓ Branch 1 taken 83060004 times.
94406664 if (deflectAll_)
66
2/2
✓ Branch 0 taken 7250400 times.
✓ Branch 1 taken 3625200 times.
10875600 for (const auto& scv : scvs(fvGeometry_))
67 7250400 accessor_(scv).update(elemSol, problem, fvGeometry_.element(), scv);
68 else
69 {
70
4/4
✓ Branch 0 taken 3220070 times.
✓ Branch 1 taken 79839934 times.
✓ Branch 2 taken 83060004 times.
✓ Branch 3 taken 3220070 times.
193940662 for(const auto& scv : scvs(fvGeometry_, localDof))
71
1/2
✓ Branch 1 taken 6939552 times.
✗ Branch 2 not taken.
90781464 accessor_(scv).update(elemSol, problem, fvGeometry_.element(), scv);
72 }
73 94406664 }
74
75 template<class LocalDof>
76 93060744 void restore(const LocalDof& localDof)
77 {
78
2/2
✓ Branch 0 taken 81714084 times.
✓ Branch 1 taken 3625200 times.
93060744 if (!deflectAll_)
79 {
80 89435544 unsigned int idx = 0;
81
4/4
✓ Branch 0 taken 3220070 times.
✓ Branch 1 taken 78494014 times.
✓ Branch 2 taken 81714084 times.
✓ Branch 3 taken 3220070 times.
191248822 for(const auto& scv : scvs(fvGeometry_, localDof))
82 {
83 89435544 accessor_(scv) = origVolVars_[idx];
84 89435544 idx++;
85 }
86 }
87 else
88
2/2
✓ Branch 0 taken 7250400 times.
✓ Branch 1 taken 3625200 times.
10875600 for (const auto& scv : scvs(fvGeometry_))
89 7250400 accessor_(scv) = origVolVars_[scv.indexInElement()];
90 93060744 }
91
92 private:
93 template<class SCV>
94 217511818 VolumeVariables& accessor_(const SCV& scv)
95 {
96 if constexpr (GridVolumeVariables::cachingEnabled)
97 107572930 return gridVolumeVariables_.volVars(scv);
98 else
99
1/2
✓ Branch 2 taken 6939552 times.
✗ Branch 3 not taken.
109938888 return elementVariables_[scv];
100 }
101
102 GridVolumeVariables& gridVolumeVariables_;
103 ElementVariables& elementVariables_;
104 const FVElementGeometry& fvGeometry_;
105 const bool deflectAll_;
106 Dune::ReservedVector<VolumeVariables, maxNumLocalDofs> origVolVars_;
107 };
108
109 } // end namespace Dumux::Detail
110
111 #endif // DOXYGEN
112
113 #endif
114