3.2-git
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>
29
30namespace Dumux {
31
36template<class PrimaryVariables, class StateType>
37class SwitchablePrimaryVariables : public PrimaryVariables
38{
39 using ParentType = PrimaryVariables;
40public:
42 using ParentType::ParentType;
44 using ParentType::operator=;
45
47 StateType state() const
48 {
49 if (!stateIsSet_)
50 DUNE_THROW(Dune::InvalidStateException, "Model demands setting a primary variable state (like a phase presence)"
51 << " but none was set! Use its setState method to set the state.");
52
53 return state_;
54 }
55
57 void setState(StateType state)
58 {
59 // NOTE: we use a copy instead of a reference in the signature to
60 // avoid linker errors related to passing a static variable to this function
61 state_ = std::move(state);
62 stateIsSet_ = true;
63 }
64
67 {
68 stateIsSet_ = false;
69 }
70
71private:
72 StateType state_;
73 bool stateIsSet_{false};
74};
75
76} // end namespace Dumux
77
78#endif
Definition: adapt.hh:29
A primary variable vector with a state to allow variable switches.
Definition: switchableprimaryvariables.hh:38
void invalidateState()
Invalidate the state.
Definition: switchableprimaryvariables.hh:66
StateType state() const
Ask for the state of this primary variable object, e.g. the phase presence.
Definition: switchableprimaryvariables.hh:47
void setState(StateType state)
Set the state of this primary variable object, e.g. the phase presence.
Definition: switchableprimaryvariables.hh:57