GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/test/freeflow/navierstokes/kovasznay/problem.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 28 36 77.8%
Functions: 5 9 55.6%
Branches: 38 56 67.9%

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 NavierStokesTests
10 * \brief Test for the staggered grid Navier-Stokes model with analytical solution (Kovasznay 1948, \cite Kovasznay1948)
11 */
12
13 #ifndef DUMUX_KOVASZNAY_TEST_PROBLEM_HH
14 #define DUMUX_KOVASZNAY_TEST_PROBLEM_HH
15
16 #include <dumux/common/properties.hh>
17 #include <dumux/common/parameters.hh>
18 #include <dumux/common/numeqvector.hh>
19
20 #include <dumux/freeflow/navierstokes/boundarytypes.hh>
21 #include <dumux/freeflow/navierstokes/staggered/problem.hh>
22
23 namespace Dumux {
24
25 /*!
26 * \ingroup NavierStokesTests
27 * \brief Test problem for the staggered grid (Kovasznay 1948, \cite Kovasznay1948)
28 *
29 * A two-dimensional Navier-Stokes flow with a periodicity in one direction
30 * is considered. The set-up represents a wake behind a two-dimensional grid
31 * and is chosen in a way such that an exact solution is available.
32 */
33 template <class TypeTag>
34 3 class KovasznayTestProblem : public NavierStokesStaggeredProblem<TypeTag>
35 {
36 using ParentType = NavierStokesStaggeredProblem<TypeTag>;
37
38 using BoundaryTypes = Dumux::NavierStokesBoundaryTypes<GetPropType<TypeTag, Properties::ModelTraits>::numEq()>;
39 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
40 using FVElementGeometry = typename GridGeometry::LocalView;
41 using SubControlVolume = typename GridGeometry::SubControlVolume;
42 using ModelTraits = GetPropType<TypeTag, Properties::ModelTraits>;
43 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
44 using NumEqVector = Dumux::NumEqVector<PrimaryVariables>;
45 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
46 using SolutionVector = GetPropType<TypeTag, Properties::SolutionVector>;
47
48 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
49 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
50
51 static constexpr auto upwindSchemeOrder = getPropValue<TypeTag, Properties::UpwindSchemeOrder>();
52
53 public:
54 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
55
56 3 KovasznayTestProblem(std::shared_ptr<const GridGeometry> gridGeometry)
57
5/14
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 3 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
9 : ParentType(gridGeometry)
58 {
59
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
6 std::cout<< "upwindSchemeOrder is: " << GridGeometry::upwindStencilOrder() << "\n";
60
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 rho_ = getParam<Scalar>("Component.LiquidDensity", 1.0);
61
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 kinematicViscosity_ = getParam<Scalar>("Component.LiquidKinematicViscosity", 1.0);
62 3 Scalar reynoldsNumber = 1.0 / kinematicViscosity_;
63 6 lambda_ = 0.5 * reynoldsNumber
64 3 - std::sqrt(reynoldsNumber * reynoldsNumber * 0.25 + 4.0 * M_PI * M_PI);
65 3 }
66
67 /*!
68 * \name Boundary conditions
69 */
70 // \{
71
72 /*!
73 * \brief Specifies which kind of boundary condition should be
74 * used for which equation on a given boundary control volume.
75 *
76 * \param globalPos The position of the center of the finite volume
77 */
78 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
79 {
80 BoundaryTypes values;
81
82 // set Dirichlet values for the velocity everywhere
83 values.setDirichlet(Indices::velocityXIdx);
84 values.setDirichlet(Indices::velocityYIdx);
85
86 return values;
87 }
88
89 /*!
90 * \brief Returns whether a fixed Dirichlet value shall be used at a given cell.
91 *
92 * \param element The finite element
93 * \param fvGeometry The finite-volume geometry
94 * \param scv The sub control volume
95 * \param pvIdx The primary variable index in the solution vector
96 */
97 bool isDirichletCell(const Element& element,
98 const FVElementGeometry& fvGeometry,
99 const SubControlVolume& scv,
100 int pvIdx) const
101 {
102 // set fixed pressure in all cells at the left boundary
103 1054130 auto isAtLeftBoundary = [&](const FVElementGeometry& fvGeometry)
104 {
105
4/4
✓ Branch 0 taken 37195 times.
✓ Branch 1 taken 470305 times.
✓ Branch 2 taken 37195 times.
✓ Branch 3 taken 470305 times.
1015000 if (fvGeometry.hasBoundaryScvf())
106 {
107
6/6
✓ Branch 0 taken 118900 times.
✓ Branch 1 taken 27235 times.
✓ Branch 2 taken 118900 times.
✓ Branch 3 taken 27235 times.
✓ Branch 4 taken 39130 times.
✓ Branch 5 taken 79770 times.
183330 for (const auto& scvf : scvfs(fvGeometry))
108
14/14
✓ Branch 0 taken 39130 times.
✓ Branch 1 taken 79770 times.
✓ Branch 2 taken 9960 times.
✓ Branch 3 taken 29170 times.
✓ Branch 4 taken 9960 times.
✓ Branch 5 taken 29170 times.
✓ Branch 6 taken 9960 times.
✓ Branch 7 taken 29170 times.
✓ Branch 8 taken 9960 times.
✓ Branch 9 taken 29170 times.
✓ Branch 10 taken 9960 times.
✓ Branch 11 taken 29170 times.
✓ Branch 12 taken 9960 times.
✓ Branch 13 taken 29170 times.
118900 if (scvf.boundary() && scvf.center()[0] < this->gridGeometry().bBoxMin()[0] + eps_)
109 9960 return true;
110 }
111 return false;
112 };
113
5/10
✓ Branch 1 taken 452040 times.
✓ Branch 2 taken 8960 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 9 taken 1000 times.
✓ Branch 10 taken 45500 times.
✓ Branch 11 taken 1000 times.
✗ Branch 12 not taken.
507500 return (isAtLeftBoundary(fvGeometry) && pvIdx == Indices::pressureIdx);
114 }
115
116 /*!
117 * \brief Returns Dirichlet boundary values at a given position.
118 *
119 * \param globalPos The global position
120 */
121 PrimaryVariables dirichletAtPos(const GlobalPosition & globalPos) const
122 {
123 // use the values of the analytical solution
124 332375 return analyticalSolution(globalPos);
125 }
126
127 /*!
128 * \brief Returns the analytical solution of the problem at a given position.
129 *
130 * \param globalPos The global position
131 * \param time A parameter for consistent signatures. It is ignored here as this is a stationary test
132 */
133 381375 PrimaryVariables analyticalSolution(const GlobalPosition& globalPos, Scalar time = 0.0) const
134 {
135 762750 Scalar x = globalPos[0];
136 762750 Scalar y = globalPos[1];
137
138 PrimaryVariables values;
139 762750 values[Indices::pressureIdx] = rho_ * 0.5 * (1.0 - std::exp(2.0 * lambda_ * x));
140 762750 values[Indices::velocityXIdx] = 1.0 - std::exp(lambda_ * x) * std::cos(2.0 * M_PI * y);
141 762750 values[Indices::velocityYIdx] = 0.5 * lambda_ / M_PI * std::exp(lambda_ * x) * std::sin(2.0 * M_PI * y);
142
143 381375 return values;
144 }
145
146 // \}
147
148 /*!
149 * \name Volume terms
150 */
151 // \{
152
153 /*!
154 * \brief Evaluates the initial value for a control volume.
155 *
156 * \param globalPos The global position
157 */
158 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
159 {
160 2648492 PrimaryVariables values;
161 2648492 values[Indices::pressureIdx] = 0.0;
162 2648492 values[Indices::velocityXIdx] = 0.0;
163 5296984 values[Indices::velocityYIdx] = 0.0;
164
165 return values;
166 }
167
168 private:
169 static constexpr Scalar eps_=1e-6;
170
171 Scalar rho_;
172 Scalar kinematicViscosity_;
173 Scalar lambda_;
174 };
175 } // end namespace Dumux
176
177 #endif
178