3.4
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
switchableprimaryvariables.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_SWITCHABLE_PRIMARY_VARIABLES_HH
26#define DUMUX_SWITCHABLE_PRIMARY_VARIABLES_HH
27
28#include <dune/common/exceptions.hh>
30
31namespace Dumux {
32
37template<class PrimaryVariables, class StateType>
38class SwitchablePrimaryVariables : public PrimaryVariables
39{
40 using ParentType = PrimaryVariables;
41public:
43 using ParentType::ParentType;
45 using ParentType::operator=;
46
48 StateType state() const
49 {
50 if (!stateIsSet_)
51 DUNE_THROW(Dune::InvalidStateException, "Model demands setting a primary variable state (like a phase presence)"
52 << " but none was set! Use its setState method to set the state.");
53
54 return state_;
55 }
56
58 void setState(StateType state)
59 {
60 // NOTE: we use a copy instead of a reference in the signature to
61 // avoid linker errors related to passing a static variable to this function
62 state_ = std::move(state);
63 stateIsSet_ = true;
64 }
65
68 {
69 stateIsSet_ = false;
70 }
71
72private:
73 StateType state_;
74 bool stateIsSet_{false};
75};
76
81template<class PrimaryVariables, class StateType>
82struct NumEqVectorTraits<SwitchablePrimaryVariables<PrimaryVariables, StateType>>
83{
84 static constexpr std::size_t numEq = PrimaryVariables::size();
85 using type = PrimaryVariables;
86};
87
88} // end namespace Dumux
89
90#endif
A helper to deduce a vector with the same size as numbers of equations.
Definition: adapt.hh:29
Definition: numeqvector.hh:33
static constexpr std::size_t numEq
Definition: numeqvector.hh:34
A primary variable vector with a state to allow variable switches.
Definition: switchableprimaryvariables.hh:39
void invalidateState()
Invalidate the state.
Definition: switchableprimaryvariables.hh:67
StateType state() const
Ask for the state of this primary variable object, e.g. the phase presence.
Definition: switchableprimaryvariables.hh:48
void setState(StateType state)
Set the state of this primary variable object, e.g. the phase presence.
Definition: switchableprimaryvariables.hh:58
PrimaryVariables type
Definition: switchableprimaryvariables.hh:85