3.6-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/ftraits.hh>
29#include <dune/common/exceptions.hh>
31
32namespace Dumux {
33
38template<class PrimaryVariables, class StateType>
39class SwitchablePrimaryVariables : public PrimaryVariables
40{
41 using ParentType = PrimaryVariables;
42public:
44 using ParentType::ParentType;
46 using ParentType::operator=;
47
49 StateType state() const
50 {
51 if (!stateIsSet_)
52 DUNE_THROW(Dune::InvalidStateException, "Model demands setting a primary variable state (like a phase presence)"
53 << " but none was set! Use its setState method to set the state.");
54
55 return state_;
56 }
57
59 void setState(StateType state)
60 {
61 // NOTE: we use a copy instead of a reference in the signature to
62 // avoid linker errors related to passing a static variable to this function
63 state_ = std::move(state);
64 stateIsSet_ = true;
65 }
66
69 {
70 stateIsSet_ = false;
71 }
72
73private:
74 StateType state_;
75 bool stateIsSet_{false};
76};
77
82template<class PrimaryVariables, class StateType>
83struct NumEqVectorTraits<SwitchablePrimaryVariables<PrimaryVariables, StateType>>
84{
85 static constexpr std::size_t numEq = PrimaryVariables::size();
86 using type = PrimaryVariables;
87};
88
89} // end namespace Dumux
90
91// specialize field traits for this type
92namespace Dune {
93
94template <class PrimaryVariables, class StateType>
95struct FieldTraits<Dumux::SwitchablePrimaryVariables<PrimaryVariables, StateType>>
96: public FieldTraits<PrimaryVariables>
97{};
98
99} // end namespace Dune
100
101#endif
A helper to deduce a vector with the same size as numbers of equations.
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
Definition: deprecated.hh:149
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:40
void invalidateState()
Invalidate the state.
Definition: switchableprimaryvariables.hh:68
StateType state() const
Ask for the state of this primary variable object, e.g. the phase presence.
Definition: switchableprimaryvariables.hh:49
void setState(StateType state)
Set the state of this primary variable object, e.g. the phase presence.
Definition: switchableprimaryvariables.hh:59
PrimaryVariables type
Definition: switchableprimaryvariables.hh:86