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 CVFEDiscretization | ||
10 | * \brief Variables deflection policy | ||
11 | */ | ||
12 | |||
13 | #ifndef DUMUX_DISCRETIZATION_CVFE_VARIABLES_DEFLECTION_POLICY_HH | ||
14 | #define DUMUX_DISCRETIZATION_CVFE_VARIABLES_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 | namespace Dumux::Detail::CVFE { | ||
23 | |||
24 | template<class MutableVariablesView, class FVElementGeometry> | ||
25 | class VariablesDeflectionPolicy | ||
26 | { | ||
27 | using Variables = typename MutableVariablesView::Variables; | ||
28 | static constexpr int maxNumLocalDofs = Detail::LocalDofs::maxNumLocalDofs<FVElementGeometry>(); | ||
29 | |||
30 | public: | ||
31 | 327356 | VariablesDeflectionPolicy(MutableVariablesView elementVariables, | |
32 | const FVElementGeometry& fvGeometry, | ||
33 | bool deflectAllVariables) | ||
34 | 327356 | : elementVariables_(elementVariables) | |
35 | 327356 | , fvGeometry_(fvGeometry) | |
36 | 327356 | , deflectAll_(deflectAllVariables) | |
37 | { | ||
38 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 327356 times.
|
327356 | if (deflectAll_) |
39 | ✗ | for (const auto& localDof : localDofs(fvGeometry)) | |
40 | ✗ | origVariables_.push_back(elementVariables_[localDof]); | |
41 | 327356 | } | |
42 | |||
43 | template<class LocalDof> | ||
44 | 1442092 | void store(const LocalDof& localDof) | |
45 | { | ||
46 |
1/2✓ Branch 0 taken 1442092 times.
✗ Branch 1 not taken.
|
1442092 | if (!deflectAll_) |
47 | { | ||
48 | 1442092 | origVariables_.clear(); | |
49 | 1442092 | origVariables_.push_back(elementVariables_[localDof]); | |
50 | } | ||
51 | } | ||
52 | |||
53 | template<class ElementSolution, class LocalDof, class Problem> | ||
54 | 2904944 | void update(const ElementSolution& elemSol, | |
55 | const LocalDof& localDof, | ||
56 | const Problem& problem) | ||
57 | { | ||
58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2904944 times.
|
2904944 | if (deflectAll_) |
59 | ✗ | for (const auto& localDofI : localDofs(fvGeometry_)) | |
60 | ✗ | elementVariables_[localDofI].update(elemSol, problem, fvGeometry_, localDofI); | |
61 | else | ||
62 | { | ||
63 | 2904944 | elementVariables_[localDof].update(elemSol, problem, fvGeometry_, localDof); | |
64 | } | ||
65 | 2904944 | } | |
66 | |||
67 | template<class LocalDof> | ||
68 | 2904944 | void restore(const LocalDof& localDof) | |
69 | { | ||
70 |
1/2✓ Branch 0 taken 2904944 times.
✗ Branch 1 not taken.
|
2904944 | if (!deflectAll_) |
71 | 2904944 | elementVariables_[localDof] = origVariables_[0]; | |
72 | else | ||
73 | { | ||
74 | ✗ | int idx = 0; | |
75 | ✗ | for (const auto& localDofI : localDofs(fvGeometry_)) | |
76 | { | ||
77 | ✗ | elementVariables_[localDofI] = origVariables_[idx]; | |
78 | ✗ | idx++; | |
79 | } | ||
80 | } | ||
81 | 2904944 | } | |
82 | |||
83 | private: | ||
84 | MutableVariablesView elementVariables_; | ||
85 | const FVElementGeometry& fvGeometry_; | ||
86 | const bool deflectAll_; | ||
87 | Dune::ReservedVector<Variables, maxNumLocalDofs> origVariables_; | ||
88 | }; | ||
89 | |||
90 | } // end namespace Dumux::Detail::CVFE | ||
91 | |||
92 | #endif | ||
93 |