GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/porousmediumflow/compositional/switchableprimaryvariables.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 7 10 70.0%
Functions: 5 10 50.0%
Branches: 27 47 57.4%

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-FileCopyrightInfo: 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
9/12
✗ Branch 0 not taken.
✓ Branch 1 taken 99957 times.
✓ Branch 2 taken 41 times.
✓ Branch 3 taken 8722 times.
✓ Branch 4 taken 98728 times.
✓ Branch 5 taken 22852 times.
✓ Branch 6 taken 13056 times.
✓ Branch 7 taken 2432 times.
✓ Branch 8 taken 13056 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2432 times.
✗ Branch 11 not taken.
142853036 class SwitchablePrimaryVariables : public PrimaryVariables
28 {
29 using ParentType = PrimaryVariables;
30 public:
31 //! Inherit the constructors
32
8/8
✓ Branch 0 taken 10265 times.
✓ Branch 1 taken 138795 times.
✓ Branch 2 taken 38528 times.
✓ Branch 3 taken 6338 times.
✓ Branch 4 taken 6327 times.
✓ Branch 5 taken 119 times.
✓ Branch 6 taken 119 times.
✓ Branch 7 taken 119 times.
9711880 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 152873683 StateType state() const
38 {
39
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 152873683 times.
152873683 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 152873683 return state_;
44 }
45
46 //! Set the state of this primary variable object, e.g. the phase presence.
47 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
2/2
✓ Branch 0 taken 770 times.
✓ Branch 1 taken 16170 times.
7979256 state_ = std::move(state);
52
7/7
✓ Branch 0 taken 12838 times.
✓ Branch 1 taken 7515323 times.
✓ Branch 2 taken 422584 times.
✓ Branch 3 taken 143449 times.
✓ Branch 4 taken 613975 times.
✓ Branch 5 taken 6338 times.
✓ Branch 6 taken 6208 times.
11666334 stateIsSet_ = true;
53 }
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