GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/test/freeflow/navierstokes/channel/pipe/problem.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 44 51 86.3%
Functions: 5 10 50.0%
Branches: 98 134 73.1%

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_TEST_FREEFLOW_PIPE_PROBLEM_HH
9 #define DUMUX_TEST_FREEFLOW_PIPE_PROBLEM_HH
10
11 #include <dumux/common/parameters.hh>
12 #include <dumux/common/properties.hh>
13
14 #include <dumux/freeflow/navierstokes/momentum/fluxhelper.hh>
15 #include <dumux/freeflow/navierstokes/scalarfluxhelper.hh>
16 #include <dumux/freeflow/navierstokes/mass/1p/advectiveflux.hh>
17
18 namespace Dumux {
19 /*!
20 * \ingroup NavierStokesTests
21 * \brief Freeflow problem for pipe flow
22 * Simulation of a radially-symmetric pipe flow with circular cross-section
23 */
24 template <class TypeTag, class BaseProblem>
25 class FreeFlowPipeProblem : public BaseProblem
26 {
27 using ParentType = BaseProblem;
28 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
29 using FVElementGeometry = typename GridGeometry::LocalView;
30 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
31 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
32 using GridView = typename GridGeometry::GridView;
33 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
34 using ModelTraits = GetPropType<TypeTag, Properties::ModelTraits>;
35 using Element = typename GridView::template Codim<0>::Entity;
36 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
37 using InitialValues = typename ParentType::InitialValues;
38 using Sources = typename ParentType::Sources;
39 using DirichletValues = typename ParentType::DirichletValues;
40 using BoundaryFluxes = typename ParentType::BoundaryFluxes;
41 using BoundaryTypes = typename ParentType::BoundaryTypes;
42 using CouplingManager = GetPropType<TypeTag, Properties::CouplingManager>;
43
44 public:
45 using Indices = typename ModelTraits::Indices;
46
47 12 FreeFlowPipeProblem(std::shared_ptr<const GridGeometry> gridGeometry, std::shared_ptr<CouplingManager> couplingManager)
48
8/24
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 6 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 6 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 6 times.
✓ Branch 18 taken 6 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 6 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
48 : ParentType(gridGeometry, couplingManager)
49
50 {
51
3/6
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
24 name_ = getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name");
52
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 meanInletVelocity_ = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.MeanInletVelocity");
53
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 initialPressure_ = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.InitialPressure");
54
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 const Scalar nu = getParam<Scalar>("Component.LiquidKinematicViscosity");
55
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 rho_ = getParam<Scalar>("Component.LiquidDensity");
56 12 mu_ = nu*rho_;
57
58 72 pipeRadius_ = this->gridGeometry().bBoxMax()[0] - this->gridGeometry().bBoxMin()[0];
59 72 pipeLength_ = this->gridGeometry().bBoxMax()[1] - this->gridGeometry().bBoxMin()[1];
60 12 eps_ = 1e-7*pipeRadius_;
61
62
2/4
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
24 std::cout << "-- Reynolds number: " << 2*pipeRadius_*meanInletVelocity_/nu << std::endl;
63 12 }
64
65 const std::string& name() const
66 {
67
2/4
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
12 return name_;
68 }
69
70 /*!
71 * \brief Specifies which kind of boundary condition should be
72 * used for which equation on a given boundary segment.
73 */
74 52408 BoundaryTypes boundaryTypesAtPos(const GlobalPosition& globalPos) const
75 {
76
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46340 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13860 times.
112608 BoundaryTypes values;
77
78 if constexpr (ParentType::isMomentumProblem())
79 {
80 204872 if (onLowerBoundary_(globalPos) || onOuterBoundary_(globalPos))
81 values.setAllDirichlet();
82 52408 else if (onInnerBoundary_(globalPos))
83 {
84 23824 values.setDirichlet(Indices::velocityXIdx);
85 23824 values.setNeumann(Indices::momentumYBalanceIdx);
86 }
87 else
88 values.setAllNeumann();
89 }
90 else
91
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46340 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13860 times.
60200 values.setAllNeumann();
92
93 52408 return values;
94 }
95
96 /*!
97 * \brief Evaluates the boundary conditions for a Neumann control volume.
98 *
99 * \param element The element for which the Neumann boundary condition is set
100 * \param fvGeometry The fvGeometry
101 * \param elemVolVars The element volume variables
102 * \param elemFaceVars The element face variables
103 * \param scvf The boundary sub control volume face
104 */
105 template<class ElementVolumeVariables, class ElementFluxVariablesCache>
106 195592 BoundaryFluxes neumann(const Element& element,
107 const FVElementGeometry& fvGeometry,
108 const ElementVolumeVariables& elemVolVars,
109 const ElementFluxVariablesCache& elemFluxVarsCache,
110 const SubControlVolumeFace& scvf) const
111 {
112
2/2
✓ Branch 0 taken 44170 times.
✓ Branch 1 taken 2170 times.
195592 BoundaryFluxes values(0.0);
113
2/2
✓ Branch 0 taken 86062 times.
✓ Branch 1 taken 11734 times.
195592 const auto& globalPos = scvf.ipGlobal();
114
115 if constexpr (ParentType::isMomentumProblem())
116 {
117 205824 if (onInnerBoundary_(globalPos))
118 83784 return values; // zero shear stress at symmetry axis
119 38256 if (onUpperBoundary_(globalPos))
120 38256 values = NavierStokesMomentumBoundaryFluxHelper::fixedPressureMomentumFlux(*this, fvGeometry, scvf, elemVolVars, elemFluxVarsCache, analyticalPressure(globalPos), true /*zeroNormalVelocityGradient*/);
121 }
122 else
123 {
124 using FluxHelper = NavierStokesScalarBoundaryFluxHelper<AdvectiveFlux<ModelTraits>>;
125 362040 if (onLowerBoundary_(globalPos) || onUpperBoundary_(globalPos))
126 8680 values = FluxHelper::scalarOutflowFlux(*this, element, fvGeometry, scvf, elemVolVars);
127 }
128
129 111808 return values;
130 }
131
132 /*!
133 * \brief Evaluates the initial value for a control volume.
134 *
135 * \param globalPos The global position
136 */
137 InitialValues initialAtPos(const GlobalPosition& globalPos) const
138 {
139 63770 InitialValues values(0.0);
140 if constexpr (ParentType::isMomentumProblem())
141 42770 return values;
142 else
143 21000 values[Indices::pressureIdx] = initialPressure_;
144
145 return values;
146 }
147
148 DirichletValues dirichletAtPos(const GlobalPosition& globalPos) const
149 16194 { return analyticalSolution(globalPos); }
150
151 DirichletValues analyticalSolution(const GlobalPosition& globalPos, Scalar time = 0.0) const
152 {
153
2/2
✓ Branch 1 taken 116 times.
✓ Branch 2 taken 83884 times.
84000 DirichletValues values(0.0);
154
155 // paraboloid velocity profile
156 if constexpr (ParentType::isMomentumProblem())
157 {
158 const auto r = globalPos[0] - this->gridGeometry().bBoxMin()[0];
159 values[Indices::velocityXIdx] = 0.0;
160 values[Indices::velocityYIdx] = 2.0*meanInletVelocity_*(1.0 - r*r/(pipeRadius_*pipeRadius_));
161 }
162 else
163 168000 values[Indices::pressureIdx] = analyticalPressure(globalPos);
164
165 return values;
166 }
167
168 Scalar analyticalPressure(const GlobalPosition& globalPos) const
169 {
170
2/2
✓ Branch 2 taken 116 times.
✓ Branch 3 taken 83884 times.
93564 const auto y = globalPos[1];
171
2/2
✓ Branch 2 taken 116 times.
✓ Branch 3 taken 83884 times.
93564 return (pipeLength_-y)*meanInletVelocity_*8.0*mu_/(pipeRadius_*pipeRadius_);
172 }
173
174 Scalar analyticalMassFlux() const
175 {
176 return meanInletVelocity_ * M_PI * pipeRadius_*pipeRadius_ * rho_;
177 }
178
179 private:
180 bool onInnerBoundary_(const GlobalPosition &globalPos) const
181
20/20
✓ Branch 0 taken 41892 times.
✓ Branch 1 taken 9564 times.
✓ Branch 2 taken 41892 times.
✓ Branch 3 taken 9564 times.
✓ Branch 4 taken 41892 times.
✓ Branch 5 taken 9564 times.
✓ Branch 6 taken 41892 times.
✓ Branch 7 taken 9564 times.
✓ Branch 8 taken 41892 times.
✓ Branch 9 taken 9564 times.
✓ Branch 10 taken 1190 times.
✓ Branch 11 taken 11912 times.
✓ Branch 12 taken 1190 times.
✓ Branch 13 taken 11912 times.
✓ Branch 14 taken 1190 times.
✓ Branch 15 taken 11912 times.
✓ Branch 16 taken 1190 times.
✓ Branch 17 taken 11912 times.
✓ Branch 18 taken 1190 times.
✓ Branch 19 taken 11912 times.
322790 { return globalPos[0] < this->gridGeometry().bBoxMin()[0] + eps_; }
182
183 bool onOuterBoundary_(const GlobalPosition &globalPos) const
184
10/10
✓ Branch 0 taken 11912 times.
✓ Branch 1 taken 13102 times.
✓ Branch 2 taken 11912 times.
✓ Branch 3 taken 13102 times.
✓ Branch 4 taken 11912 times.
✓ Branch 5 taken 13102 times.
✓ Branch 6 taken 11912 times.
✓ Branch 7 taken 13102 times.
✓ Branch 8 taken 11912 times.
✓ Branch 9 taken 13102 times.
125070 { return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; }
185
186 bool onLowerBoundary_(const GlobalPosition &globalPos) const
187
20/20
✓ Branch 0 taken 44170 times.
✓ Branch 1 taken 2170 times.
✓ Branch 2 taken 44170 times.
✓ Branch 3 taken 2170 times.
✓ Branch 4 taken 44170 times.
✓ Branch 5 taken 2170 times.
✓ Branch 6 taken 44170 times.
✓ Branch 7 taken 2170 times.
✓ Branch 8 taken 44170 times.
✓ Branch 9 taken 2170 times.
✓ Branch 10 taken 25014 times.
✓ Branch 11 taken 1190 times.
✓ Branch 12 taken 25014 times.
✓ Branch 13 taken 1190 times.
✓ Branch 14 taken 25014 times.
✓ Branch 15 taken 1190 times.
✓ Branch 16 taken 25014 times.
✓ Branch 17 taken 1190 times.
✓ Branch 18 taken 25014 times.
✓ Branch 19 taken 1190 times.
362720 { return globalPos[1] < this->gridGeometry().bBoxMin()[1] + eps_; }
188
189 bool onUpperBoundary_(const GlobalPosition &globalPos) const
190
15/20
✓ Branch 0 taken 9564 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9564 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9564 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9564 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9564 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2170 times.
✓ Branch 11 taken 42000 times.
✓ Branch 12 taken 2170 times.
✓ Branch 13 taken 42000 times.
✓ Branch 14 taken 2170 times.
✓ Branch 15 taken 42000 times.
✓ Branch 16 taken 2170 times.
✓ Branch 17 taken 42000 times.
✓ Branch 18 taken 2170 times.
✓ Branch 19 taken 42000 times.
268670 { return globalPos[1] > this->gridGeometry().bBoxMax()[1] - eps_; }
191
192 std::string name_;
193 Scalar initialPressure_;
194 Scalar meanInletVelocity_;
195 Scalar mu_;
196 Scalar rho_;
197 Scalar pipeRadius_, pipeLength_;
198 Scalar eps_;
199 };
200
201 } // end namespace Dumux
202
203 #endif
204