3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
25#ifndef DUMUX_COMMON_VARIABLES_HH
26#define DUMUX_COMMON_VARIABLES_HH
27
28#include <type_traits>
29
30#include <dune/common/typetraits.hh>
32
34
51template<class X>
53{
54 template<class T, bool indexable = Dune::IsIndexable<T>::value>
55 struct ScalarT { using type = T; };
56
57 template<class T>
58 struct ScalarT<T, true>
59 {
60 using Element = std::decay_t<decltype(std::declval<T>()[0])>;
61 using type = typename ScalarT<Element>::type;
62 };
63
64public:
66 using SolutionVector = X;
67
69 using Scalar = typename ScalarT<X>::type;
70
73
75 explicit Variables() : x_(), t_(0.0) {}
76
78 explicit Variables(const SolutionVector& x,
79 const TimeLevel& t = TimeLevel{0.0})
80 : x_(x), t_(t)
81 {}
82
85 const TimeLevel& t = TimeLevel{0.0})
86 : x_(std::move(x)), t_(t)
87 {}
88
90 template<class Initializer,
91 std::enable_if_t<(std::is_invocable_r_v<void, Initializer, X&>), int> = 0>
92 explicit Variables(const Initializer& initializeSolution,
93 const TimeLevel& timeLevel = TimeLevel{0.0})
94 : t_(timeLevel)
95 {
96 initializeSolution(x_);
97 }
98
100 const TimeLevel& timeLevel() const
101 { return t_; }
102
104 const SolutionVector& dofs() const { return x_; }
105
107 SolutionVector& dofs() { return x_; }
108
110 void update(const SolutionVector& x)
111 { x_ = x; }
112
114 void updateTime(const TimeLevel& t)
115 { t_ = t; }
116
118 void update(const SolutionVector& x,
119 const TimeLevel& t)
120 {
121 x_ = x;
122 t_ = t;
123 }
124
125private:
127 TimeLevel t_;
128};
129
130} // end namespace Dumux::Experimental
131
132#endif
Class that represents a time level during time integration.
Definition: variables.hh:33
Class that represents the variables of a model. We assume that models are formulated on the basis of ...
Definition: variables.hh:53
void update(const SolutionVector &x, const TimeLevel &t)
Update the state to a new solution & time level.
Definition: variables.hh:118
void update(const SolutionVector &x)
Update the state to a new solution.
Definition: variables.hh:110
void updateTime(const TimeLevel &t)
Update the time level only.
Definition: variables.hh:114
const SolutionVector & dofs() const
Return reference to the solution.
Definition: variables.hh:104
const TimeLevel & timeLevel() const
Return the time level.
Definition: variables.hh:100
Variables(const Initializer &initializeSolution, const TimeLevel &timeLevel=TimeLevel{0.0})
Construction from initializer lambda.
Definition: variables.hh:92
Variables(const SolutionVector &x, const TimeLevel &t=TimeLevel{0.0})
Construction from a solution.
Definition: variables.hh:78
Variables(SolutionVector &&x, const TimeLevel &t=TimeLevel{0.0})
Construction from a solution.
Definition: variables.hh:84
Variables()
Default constructor.
Definition: variables.hh:75
X SolutionVector
export the type of solution vector
Definition: variables.hh:66
typename ScalarT< X >::type Scalar
export the underlying scalar type
Definition: variables.hh:69
SolutionVector & dofs()
Non-const access still required for privar switch (TODO: Remove dependency)
Definition: variables.hh:107
Class that represents a time level during time integration.
Definition: timelevel.hh:34