GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/experimental/common/variables.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 15 15 100.0%
Functions: 2 2 100.0%
Branches: 19 32 59.4%

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 Experimental
10 * \ingroup Core
11 * \copydoc Dumux::Experimental::Variables
12 */
13 #ifndef DUMUX_COMMON_VARIABLES_HH
14 #define DUMUX_COMMON_VARIABLES_HH
15
16 #include <type_traits>
17
18 #include <dune/common/typetraits.hh>
19 #include <dumux/experimental/timestepping/timelevel.hh>
20
21 namespace Dumux::Experimental {
22
23 /*!
24 * \ingroup Experimental
25 * \ingroup Core
26 * \brief Class that represents the variables of a model.
27 * We assume that models are formulated on the basis of primary and
28 * possibly secondary variables, where the latter may non-linearly
29 * depend on the former. Variables in Dumux represent the state of
30 * a numerical solution of a model, consisting of all primary/secondary
31 * variables and, if a transient problem is modeled, time information.
32 *
33 * This class defines the interface that is expected of variable classes,
34 * and it provides the implementation for models that do not require storing
35 * any additional information besides the primary variables and (optionally)
36 * time.
37 * \tparam X The type used for solution vectors, i.e. all primary variables.
38 */
39 template<class X>
40 class Variables
41 {
42 template<class T, bool indexable = Dune::IsIndexable<T>::value>
43 struct ScalarT { using type = T; };
44
45 template<class T>
46 struct ScalarT<T, true>
47 {
48 using Element = std::decay_t<decltype(std::declval<T>()[0])>;
49 using type = typename ScalarT<Element>::type;
50 };
51
52 public:
53 //! export the type of solution vector
54 using SolutionVector = X;
55
56 //! export the underlying scalar type
57 using Scalar = typename ScalarT<X>::type;
58
59 //! export the time representation
60 using TimeLevel = Dumux::Experimental::TimeLevel<Scalar>;
61
62 //! Default constructor
63 explicit Variables() : x_(), t_(0.0) {}
64
65 //! Construction from a solution
66 7 explicit Variables(const SolutionVector& x,
67 const TimeLevel& t = TimeLevel{0.0})
68 7 : x_(x), t_(t)
69 {}
70
71 //! Construction from a solution
72 1 explicit Variables(SolutionVector&& x,
73 const TimeLevel& t = TimeLevel{0.0})
74 1 : x_(std::move(x)), t_(t)
75 {}
76
77 //! Construction from initializer lambda
78 template<class Initializer,
79 std::enable_if_t<(std::is_invocable_r_v<void, Initializer, X&>), int> = 0>
80 4 explicit Variables(const Initializer& initializeSolution,
81 const TimeLevel& timeLevel = TimeLevel{0.0})
82
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
4 : t_(timeLevel)
83 {
84
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
4 initializeSolution(x_);
85 4 }
86
87 //! Return the time level
88 const TimeLevel& timeLevel() const
89
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
30 { return t_; }
90
91 //! Return reference to the solution
92 53 const SolutionVector& dofs() const { return x_; }
93
94 //! Non-const access still required for privar switch (TODO: Remove dependency)
95
10/18
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✓ Branch 4 taken 15 times.
✓ Branch 7 taken 15 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 15 times.
147 SolutionVector& dofs() { return x_; }
96
97 //! Update the state to a new solution
98 73 void update(const SolutionVector& x)
99 73 { x_ = x; }
100
101 //! Update the time level only
102 15 void updateTime(const TimeLevel& t)
103 15 { t_ = t; }
104
105 //! Update the state to a new solution & time level
106 void update(const SolutionVector& x,
107 const TimeLevel& t)
108 {
109 x_ = x;
110 t_ = t;
111 }
112
113 private:
114 SolutionVector x_;
115 TimeLevel t_;
116 };
117
118 } // end namespace Dumux::Experimental
119
120 #endif
121