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 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 |
1/12✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
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 | 2 | : 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 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
4 | : t_(timeLevel) |
83 | { | ||
84 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
4 | initializeSolution(x_); |
85 | 2 | } | |
86 | |||
87 | //! Return the time level | ||
88 | const TimeLevel& timeLevel() const | ||
89 | 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 |
5/10✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 15 times.
✗ Branch 13 not taken.
|
78 | SolutionVector& dofs() { return x_; } |
96 | |||
97 | //! Update the state to a new solution | ||
98 | ✗ | void update(const SolutionVector& x) | |
99 | 73 | { x_ = x; } | |
100 | |||
101 | //! Update the time level only | ||
102 | 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 |