GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/test/porousmediumflow/2pnc/diffusion/problem.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 23 23 100.0%
Functions: 2 2 100.0%
Branches: 17 24 70.8%

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 TwoPNCTests
10 * \brief Problem of a diffusion
11 * problem which uses the isothermal 2p2c box model.
12 */
13 #ifndef DUMUX_TWOPNC_DIFFUSION_PROBLEM_HH
14 #define DUMUX_TWOPNC_DIFFUSION_PROBLEM_HH
15
16 #include <dumux/common/properties.hh>
17 #include <dumux/common/parameters.hh>
18 #include <dumux/common/boundarytypes.hh>
19 #include <dumux/common/numeqvector.hh>
20
21 #include <dumux/porousmediumflow/problem.hh>
22
23 namespace Dumux {
24
25 /*!
26 * \ingroup TwoPNCTests
27 * \brief Problem of a diffusion
28 * problem which uses the isothermal 2p2c box model.
29 */
30 template <class TypeTag>
31 2 class TwoPNCDiffusionProblem : public PorousMediumFlowProblem<TypeTag>
32 {
33 using ParentType = PorousMediumFlowProblem<TypeTag>;
34 using GridView = typename GetPropType<TypeTag, Properties::GridGeometry>::GridView;
35 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
36 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
37
38 enum {
39 // Grid and world dimension
40 dim = GridView::dimension,
41 dimWorld = GridView::dimensionworld
42 };
43
44 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
45 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
46 using NumEqVector = Dumux::NumEqVector<PrimaryVariables>;
47 using BoundaryTypes = Dumux::BoundaryTypes<GetPropType<TypeTag, Properties::ModelTraits>::numEq()>;
48 using Element = typename GridView::template Codim<0>::Entity;
49 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
50 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
51
52 //! Property that defines whether mole or mass fractions are used
53 static constexpr bool useMoles = getPropValue<TypeTag, Properties::UseMoles>();
54
55 public:
56 2 TwoPNCDiffusionProblem(std::shared_ptr<const GridGeometry> gridGeometry)
57
3/6
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
6 : ParentType(gridGeometry)
58 {
59 // initialize the tables of the fluid system
60 FluidSystem::init();
61
62
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
2 name_ = getParam<std::string>("Problem.Name");
63
64 // stating in the console whether mole or mass fractions are used
65 if(useMoles)
66 {
67
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 std::cout<<"problem uses mole-fractions"<<std::endl;
68 }
69 else
70 {
71 std::cout<<"problem uses mass-fractions"<<std::endl;
72 }
73 2 }
74
75 /*!
76 * \brief Returns the problem name
77 *
78 * This is used as a prefix for files generated by the simulation.
79 */
80 2 const std::string& name() const
81
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 { return name_; }
82
83 /*!
84 * \brief Specifies which kind of boundary condition should be
85 * used for which equation on a given boundary segment
86 *
87 * \param globalPos The global position
88 */
89 67760 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
90 {
91
2/2
✓ Branch 0 taken 135520 times.
✓ Branch 1 taken 67760 times.
203280 BoundaryTypes bcTypes;
92 67760 bcTypes.setAllDirichlet();
93 67760 return bcTypes;
94 }
95
96 /*!
97 * \brief Evaluates the boundary conditions for a Dirichlet boundary segment.
98 *
99 * \param globalPos The global position
100 */
101
2/2
✓ Branch 0 taken 770 times.
✓ Branch 1 taken 16170 times.
16940 PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
102 {
103
2/2
✓ Branch 0 taken 770 times.
✓ Branch 1 taken 16170 times.
16940 PrimaryVariables priVars;
104
2/2
✓ Branch 0 taken 770 times.
✓ Branch 1 taken 16170 times.
16940 priVars.setState(Indices::firstPhaseOnly);
105 priVars[Indices::pressureIdx] = 1e5;
106 priVars[Indices::switchIdx] = 1e-5 ;
107
108
2/2
✓ Branch 0 taken 770 times.
✓ Branch 1 taken 16170 times.
16940 if (globalPos[0] < this->gridGeometry().bBoxMin()[0] + eps_)
109 priVars[Indices::switchIdx] = 1e-3;
110
111 return priVars;
112 }
113
114 /*!
115 * \brief Evaluates the boundary conditions for a Neumann boundary segment.
116 *
117 * For this method, the \a priVars parameter stores the mass flux
118 * in normal direction of each component. Negative values mean influx.
119 * \param globalPos The global position
120 *
121 * \note The units must be according to either using mole or mass fractions (mole/(m^2*s) or kg/(m^2*s)).
122 */
123 NumEqVector neumannAtPos(const GlobalPosition& globalPos) const
124 {
125 NumEqVector values(0.0);
126 return values;
127 }
128
129 /*!
130 * \brief Evaluates the initial values for a control volume.
131 *
132 * \param globalPos The global position
133 */
134 500 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
135 {
136 500 return initial_(globalPos);
137 }
138
139
140 private:
141 /*!
142 * \brief Evaluates the initial values for a control volume.
143 *
144 * The internal method for the initial condition
145 *
146 * \param globalPos The global position
147 */
148 500 PrimaryVariables initial_(const GlobalPosition &globalPos) const
149 {
150 500 PrimaryVariables priVars(0.0);
151 500 priVars.setState(Indices::firstPhaseOnly);
152
153 //mole-fraction formulation
154 500 priVars[Indices::switchIdx] = 1e-5;
155 500 priVars[Indices::pressureIdx] = 1e5;
156 return priVars;
157 }
158
159 static constexpr Scalar eps_ = 1e-6;
160
161 std::string name_ ;
162 };
163
164 } // end namespace Dumux
165
166 #endif
167