Line | Branch | Exec | Source |
---|---|---|---|
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 | // SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder | ||
5 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
6 | // | ||
7 | /*! | ||
8 | * \file | ||
9 | * \ingroup PorousmediumflowModels | ||
10 | * \brief A primary variable vector with a state to allow variable switches. | ||
11 | */ | ||
12 | |||
13 | #ifndef DUMUX_SWITCHABLE_PRIMARY_VARIABLES_HH | ||
14 | #define DUMUX_SWITCHABLE_PRIMARY_VARIABLES_HH | ||
15 | |||
16 | #include <dune/common/ftraits.hh> | ||
17 | #include <dune/common/exceptions.hh> | ||
18 | #include <dumux/common/numeqvector.hh> | ||
19 | |||
20 | namespace Dumux { | ||
21 | |||
22 | /*! | ||
23 | * \ingroup PorousmediumflowModels | ||
24 | * \brief A primary variable vector with a state to allow variable switches. | ||
25 | */ | ||
26 | template<class PrimaryVariables, class StateType> | ||
27 |
2/3✓ Branch 0 taken 811 times.
✓ Branch 1 taken 24427 times.
✗ Branch 2 not taken.
|
68659795 | class SwitchablePrimaryVariables : public PrimaryVariables |
28 | { | ||
29 | using ParentType = PrimaryVariables; | ||
30 | public: | ||
31 | //! Inherit the constructors | ||
32 |
7/8✓ Branch 0 taken 97638 times.
✓ Branch 1 taken 188449 times.
✓ Branch 2 taken 39649 times.
✓ Branch 3 taken 7134 times.
✓ Branch 4 taken 6208 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 238 times.
✓ Branch 7 taken 238 times.
|
10222618 | using ParentType::ParentType; |
33 | //! Use the assignment operators from the field vector | ||
34 | using ParentType::operator=; | ||
35 | |||
36 | //! Ask for the state of this primary variable object, e.g. the phase presence | ||
37 | 153322461 | StateType state() const | |
38 | { | ||
39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 153322461 times.
|
153322461 | if (!stateIsSet_) |
40 | ✗ | DUNE_THROW(Dune::InvalidStateException, "Model demands setting a primary variable state (like a phase presence)" | |
41 | << " but none was set! Use its setState method to set the state."); | ||
42 | |||
43 | 153322461 | return state_; | |
44 | } | ||
45 | |||
46 | //! Set the state of this primary variable object, e.g. the phase presence. | ||
47 |
2/2✓ Branch 0 taken 770 times.
✓ Branch 1 taken 16170 times.
|
11639467 | void setState(StateType state) |
48 | { | ||
49 | // NOTE: we use a copy instead of a reference in the signature to | ||
50 | // avoid linker errors related to passing a static variable to this function | ||
51 | 10709537 | state_ = std::move(state); | |
52 |
6/6✓ Branch 0 taken 39415 times.
✓ Branch 1 taken 7835669 times.
✓ Branch 2 taken 1070 times.
✓ Branch 3 taken 732227 times.
✓ Branch 4 taken 135741 times.
✓ Branch 5 taken 6261 times.
|
9055745 | stateIsSet_ = true; |
53 | 2600716 | } | |
54 | |||
55 | //! Invalidate the state | ||
56 | void invalidateState() | ||
57 | { | ||
58 | stateIsSet_ = false; | ||
59 | } | ||
60 | |||
61 | private: | ||
62 | StateType state_; | ||
63 | bool stateIsSet_{false}; | ||
64 | }; | ||
65 | |||
66 | /*! | ||
67 | * \ingroup PorousmediumflowModels | ||
68 | * \brief The corresponding NumEqVectorTraits for the primary variables with switchable state | ||
69 | */ | ||
70 | template<class PrimaryVariables, class StateType> | ||
71 | struct NumEqVectorTraits<SwitchablePrimaryVariables<PrimaryVariables, StateType>> | ||
72 | { | ||
73 | static constexpr std::size_t numEq = PrimaryVariables::size(); | ||
74 | using type = PrimaryVariables; | ||
75 | }; | ||
76 | |||
77 | } // end namespace Dumux | ||
78 | |||
79 | // specialize field traits for this type | ||
80 | namespace Dune { | ||
81 | |||
82 | template <class PrimaryVariables, class StateType> | ||
83 | struct FieldTraits<Dumux::SwitchablePrimaryVariables<PrimaryVariables, StateType>> | ||
84 | : public FieldTraits<PrimaryVariables> | ||
85 | {}; | ||
86 | |||
87 | } // end namespace Dune | ||
88 | |||
89 | #endif | ||
90 |