GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/examples/freeflowchannel/problem.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 25 28 89.3%
Functions: 2 4 50.0%
Branches: 42 114 36.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-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7
8 #ifndef DUMUX_EXAMPLES_FREEFLOW_CHANNEL_PROBLEM_HH
9 #define DUMUX_EXAMPLES_FREEFLOW_CHANNEL_PROBLEM_HH
10
11 // ## Initial and boundary conditions (`problem.hh`)
12 //
13 // This file contains the __problem class__ which defines the initial and boundary
14 // conditions for the Navier-Stokes single-phase flow simulation.
15 //
16 // [[content]]
17 //
18 // ### Include files
19 //
20 // Include the `NavierStokesStaggeredProblem` class, the base
21 // class from which we will derive.
22 #include <dumux/freeflow/navierstokes/staggered/problem.hh>
23 // Include the `NavierStokesBoundaryTypes` class which specifies the boundary types set in this problem.
24 #include <dumux/freeflow/navierstokes/boundarytypes.hh>
25
26 // ### The problem class
27 // We enter the problem class where all necessary boundary conditions and initial conditions are set for our simulation.
28 // As we are solving a problem related to free flow, we inherit from the base class `NavierStokesStaggeredProblem`.
29 // [[codeblock]]
30 namespace Dumux {
31
32 template <class TypeTag>
33 1 class ChannelExampleProblem : public NavierStokesStaggeredProblem<TypeTag>
34 {
35 // A few convenience aliases used throughout this class.
36 using ParentType = NavierStokesStaggeredProblem<TypeTag>;
37 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
38 using FVElementGeometry = typename GridGeometry::LocalView;
39 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
40 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
41 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
42 using BoundaryTypes = Dumux::NavierStokesBoundaryTypes<PrimaryVariables::size()>;
43 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
44
45 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
46 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
47
48 public:
49 // This is the constructor of our problem class:
50 // Within the constructor, we set the inlet velocity to a run-time specified value.
51 // If no run-time value is specified, we set the outlet pressure to 1.1e5 Pa.
52 1 ChannelExampleProblem(std::shared_ptr<const GridGeometry> gridGeometry)
53
6/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
3 : ParentType(gridGeometry)
54 {
55
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 inletVelocity_ = getParam<Scalar>("Problem.InletVelocity");
56
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 outletPressure_ = getParam<Scalar>("Problem.OutletPressure", 1.1e5);
57 1 }
58 // [[/codeblock]]
59
60 // #### Boundary conditions
61 // With the following function we define the __type of boundary conditions__ depending on the location.
62 // Three types of boundary conditions can be specified: Dirichlet, Neumann or outflow boundary conditions. On
63 // Dirichlet boundaries, the values of the primary variables need to be fixed. On Neumann boundaries,
64 // values for derivatives need to be fixed. Outflow conditions set a gradient of zero in normal direction towards the boundary
65 // for the respective primary variables (excluding pressure).
66 // When Dirichlet conditions are set for the pressure, the velocity gradient
67 // with respect to the direction normal to the boundary is automatically set to zero.
68 // [[codeblock]]
69 48626 BoundaryTypes boundaryTypesAtPos(const GlobalPosition& globalPos) const
70 {
71 48626 BoundaryTypes values;
72
73 97252 if (isInlet_(globalPos))
74 {
75 // We specify Dirichlet boundary conditions for the velocity on the left of our domain
76 7810 values.setDirichlet(Indices::velocityXIdx);
77 7810 values.setDirichlet(Indices::velocityYIdx);
78 }
79 81632 else if (isOutlet_(globalPos))
80 {
81 // We fix the pressure on the right side of the domain
82 9348 values.setDirichlet(Indices::pressureIdx);
83 }
84 else
85 {
86 // We specify Dirichlet boundary conditions for the velocity on the remaining boundaries (lower and upper wall)
87 31468 values.setDirichlet(Indices::velocityXIdx);
88 31468 values.setDirichlet(Indices::velocityYIdx);
89 }
90
91 48626 return values;
92 }
93 // [[/codeblock]]
94
95 // The following function specifies the __values on Dirichlet boundaries__.
96 // We need to define values for the primary variables (velocity and pressure).
97 // [[codeblock]]
98 PrimaryVariables dirichletAtPos(const GlobalPosition& globalPos) const
99 {
100 // Use the initial values as default Dirichlet values
101 24370 PrimaryVariables values = initialAtPos(globalPos);
102
103 // Set a no-slip condition at the top and bottom wall of the channel
104 48740 if (!isInlet_(globalPos))
105 35808 values[Indices::velocityXIdx] = 0.0;
106
107 return values;
108 }
109 // [[/codeblock]]
110
111 // The following function defines the initial conditions.
112 // [[codeblock]]
113 PrimaryVariables initialAtPos(const GlobalPosition& globalPos) const
114 {
115 42332 PrimaryVariables values;
116
117 // Set the pressure and velocity values
118
4/16
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 11928 times.
✓ Branch 5 taken 2940 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 5976 times.
✓ Branch 13 taken 1488 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
755018 values[Indices::pressureIdx] = outletPressure_;
119
4/16
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 11928 times.
✓ Branch 5 taken 2940 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 5976 times.
✓ Branch 13 taken 1488 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
755018 values[Indices::velocityXIdx] = inletVelocity_;
120
4/16
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 11928 times.
✓ Branch 5 taken 2940 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 5976 times.
✓ Branch 13 taken 1488 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
1487154 values[Indices::velocityYIdx] = 0.0;
121
122 return values;
123 }
124 // [[/codeblock]]
125
126 // The inlet is on the left side of the physical domain.
127 // [[codeblock]]
128 private:
129 bool isInlet_(const GlobalPosition& globalPos) const
130
12/36
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 11928 times.
✓ Branch 9 taken 2940 times.
✓ Branch 10 taken 11928 times.
✓ Branch 11 taken 2940 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 5976 times.
✓ Branch 25 taken 1488 times.
✓ Branch 26 taken 5976 times.
✓ Branch 27 taken 1488 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 7810 times.
✓ Branch 33 taken 40816 times.
✓ Branch 34 taken 7810 times.
✓ Branch 35 taken 40816 times.
143016 { return globalPos[0] < eps_; }
131 // [[/codeblock]]
132
133 // The outlet is on the right side of the physical domain.
134 bool isOutlet_(const GlobalPosition& globalPos) const
135
10/10
✓ Branch 0 taken 9348 times.
✓ Branch 1 taken 31468 times.
✓ Branch 2 taken 9348 times.
✓ Branch 3 taken 31468 times.
✓ Branch 4 taken 9348 times.
✓ Branch 5 taken 31468 times.
✓ Branch 6 taken 9348 times.
✓ Branch 7 taken 31468 times.
✓ Branch 8 taken 9348 times.
✓ Branch 9 taken 31468 times.
204080 { return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; }
136
137 // Finally, private variables are declared:
138 // [[codeblock]]
139 static constexpr Scalar eps_ = 1e-6;
140 Scalar inletVelocity_;
141 Scalar outletPressure_;
142
143 }; // end class definition of ChannelExampleProblem
144 } // end namespace Dumux
145 // [[/codeblock]]
146 // [[/content]]
147 #endif
148