3.4
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 *****************************************************************************/
24#ifndef DUMUX_COMMON_VARIABLES_HH
25#define DUMUX_COMMON_VARIABLES_HH
26
27#include <type_traits>
28
29#include <dune/common/typetraits.hh>
31
33
49template<class X>
51{
52 template<class T, bool indexable = Dune::IsIndexable<T>::value>
53 struct ScalarT { using type = T; };
54
55 template<class T>
56 struct ScalarT<T, true>
57 {
58 using Element = std::decay_t<decltype(std::declval<T>()[0])>;
59 using type = typename ScalarT<Element>::type;
60 };
61
62public:
64 using SolutionVector = X;
65
67 using Scalar = typename ScalarT<X>::type;
68
71
73 explicit Variables() : x_(), t_(0.0) {}
74
76 explicit Variables(const SolutionVector& x,
77 const TimeLevel& t = TimeLevel{0.0})
78 : x_(x), t_(t)
79 {}
80
83 const TimeLevel& t = TimeLevel{0.0})
84 : x_(std::move(x)), t_(t)
85 {}
86
88 template<class Initializer,
89 std::enable_if_t<(std::is_invocable_r_v<void, Initializer, X&>), int> = 0>
90 explicit Variables(const Initializer& initializeSolution,
91 const TimeLevel& timeLevel = TimeLevel{0.0})
92 : t_(timeLevel)
93 {
94 initializeSolution(x_);
95 }
96
98 const TimeLevel& timeLevel() const
99 { return t_; }
100
102 const SolutionVector& dofs() const { return x_; }
103
105 SolutionVector& dofs() { return x_; }
106
108 void update(const SolutionVector& x)
109 { x_ = x; }
110
112 void updateTime(const TimeLevel& t)
113 { t_ = t; }
114
116 void update(const SolutionVector& x,
117 const TimeLevel& t)
118 {
119 x_ = x;
120 t_ = t;
121 }
122
123private:
125 TimeLevel t_;
126};
127
128} // end namespace Dumux::Experimental
129
130#endif
Class that represents a time level during time integration.
Definition: variables.hh:32
Class that represents the variables of a model. We assume that models are formulated on the basis of ...
Definition: variables.hh:51
void update(const SolutionVector &x, const TimeLevel &t)
Update the state to a new solution & time level.
Definition: variables.hh:116
void update(const SolutionVector &x)
Update the state to a new solution.
Definition: variables.hh:108
void updateTime(const TimeLevel &t)
Update the time level only.
Definition: variables.hh:112
const SolutionVector & dofs() const
Return reference to the solution.
Definition: variables.hh:102
const TimeLevel & timeLevel() const
Return the time level.
Definition: variables.hh:98
Variables(const Initializer &initializeSolution, const TimeLevel &timeLevel=TimeLevel{0.0})
Construction from initializer lambda.
Definition: variables.hh:90
Variables(const SolutionVector &x, const TimeLevel &t=TimeLevel{0.0})
Construction from a solution.
Definition: variables.hh:76
Variables(SolutionVector &&x, const TimeLevel &t=TimeLevel{0.0})
Construction from a solution.
Definition: variables.hh:82
Variables()
Default constructor.
Definition: variables.hh:73
X SolutionVector
export the type of solution vector
Definition: variables.hh:64
typename ScalarT< X >::type Scalar
export the underlying scalar type
Definition: variables.hh:67
SolutionVector & dofs()
Non-const access still required for privar switch (TODO: Remove dependency)
Definition: variables.hh:105
Class that represents a time level during time integration.
Definition: timelevel.hh:34