version 3.8
variables.hh
Go to the documentation of this file.
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//
13#ifndef DUMUX_COMMON_VARIABLES_HH
14#define DUMUX_COMMON_VARIABLES_HH
15
16#include <type_traits>
17
18#include <dune/common/typetraits.hh>
20
21namespace Dumux::Experimental {
22
39template<class X>
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
52public:
54 using SolutionVector = X;
55
57 using Scalar = typename ScalarT<X>::type;
58
61
63 explicit Variables() : x_(), t_(0.0) {}
64
66 explicit Variables(const SolutionVector& x,
67 const TimeLevel& t = TimeLevel{0.0})
68 : x_(x), t_(t)
69 {}
70
73 const TimeLevel& t = TimeLevel{0.0})
74 : x_(std::move(x)), t_(t)
75 {}
76
78 template<class Initializer,
79 std::enable_if_t<(std::is_invocable_r_v<void, Initializer, X&>), int> = 0>
80 explicit Variables(const Initializer& initializeSolution,
81 const TimeLevel& timeLevel = TimeLevel{0.0})
82 : t_(timeLevel)
83 {
84 initializeSolution(x_);
85 }
86
88 const TimeLevel& timeLevel() const
89 { return t_; }
90
92 const SolutionVector& dofs() const { return x_; }
93
95 SolutionVector& dofs() { return x_; }
96
98 void update(const SolutionVector& x)
99 { x_ = x; }
100
102 void updateTime(const TimeLevel& t)
103 { t_ = t; }
104
106 void update(const SolutionVector& x,
107 const TimeLevel& t)
108 {
109 x_ = x;
110 t_ = t;
111 }
112
113private:
115 TimeLevel t_;
116};
117
118} // end namespace Dumux::Experimental
119
120#endif
Class that represents a time level during time integration.
Definition: timelevel.hh:22
Class that represents the variables of a model. We assume that models are formulated on the basis of ...
Definition: variables.hh:41
void update(const SolutionVector &x, const TimeLevel &t)
Update the state to a new solution & time level.
Definition: variables.hh:106
void update(const SolutionVector &x)
Update the state to a new solution.
Definition: variables.hh:98
void updateTime(const TimeLevel &t)
Update the time level only.
Definition: variables.hh:102
const SolutionVector & dofs() const
Return reference to the solution.
Definition: variables.hh:92
const TimeLevel & timeLevel() const
Return the time level.
Definition: variables.hh:88
Variables(const Initializer &initializeSolution, const TimeLevel &timeLevel=TimeLevel{0.0})
Construction from initializer lambda.
Definition: variables.hh:80
Variables(const SolutionVector &x, const TimeLevel &t=TimeLevel{0.0})
Construction from a solution.
Definition: variables.hh:66
Variables(SolutionVector &&x, const TimeLevel &t=TimeLevel{0.0})
Construction from a solution.
Definition: variables.hh:72
Variables()
Default constructor.
Definition: variables.hh:63
X SolutionVector
export the type of solution vector
Definition: variables.hh:54
typename ScalarT< X >::type Scalar
export the underlying scalar type
Definition: variables.hh:57
SolutionVector & dofs()
Non-const access still required for privar switch (TODO: Remove dependency)
Definition: variables.hh:95
Definition: experimental/assembly/cclocalassembler.hh:36
Class that represents a time level during time integration.