GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/freeflow/navierstokes/momentum/velocityreconstruction.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 44 44 100.0%
Functions: 54 58 93.1%
Branches: 45 70 64.3%

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 NavierStokesModel
10 * \copydoc Dumux::StaggeredVelocityReconstruction
11 */
12 #ifndef DUMUX_NAVIERSTOKES_STAGGERED_VELOCITYRECONSTRUCTION_HH
13 #define DUMUX_NAVIERSTOKES_STAGGERED_VELOCITYRECONSTRUCTION_HH
14
15 #include <numeric>
16 #include <algorithm>
17 #include <dune/common/reservedvector.hh>
18 #include <dumux/discretization/method.hh>
19
20 namespace Dumux {
21
22 /*!
23 * \ingroup NavierStokesModel
24 * \brief Helper class for reconstructing the velocity.
25 */
26 struct StaggeredVelocityReconstruction
27 {
28 //! Return the velocity vector at the center of the primal grid.
29 template<class VelocityHelper, class FVElementGeometry>
30 1008151 static auto cellCenterVelocity(const VelocityHelper& getFaceVelocity,
31 const FVElementGeometry& fvGeometry)
32 {
33 static_assert(FVElementGeometry::GridGeometry::discMethod == DiscretizationMethods::cctpfa);
34 using VelocityVector = typename FVElementGeometry::GridGeometry::GlobalCoordinate;
35 1008151 VelocityVector result(0.0);
36
37 4041862 const auto directionIndex = [&](const auto& vector)
38 {
39
13/32
✗ 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 taken 128 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7500 times.
✓ Branch 9 taken 15000 times.
✓ Branch 10 taken 2014416 times.
✓ Branch 11 taken 2014288 times.
✓ Branch 12 taken 2014288 times.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 4036076 times.
✗ 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 not taken.
✓ Branch 25 taken 1886 times.
✓ Branch 26 taken 3772 times.
✓ Branch 27 taken 1886 times.
✓ Branch 28 taken 1886 times.
✓ Branch 29 taken 1886 times.
✗ Branch 30 not taken.
✗ Branch 32 not taken.
✓ Branch 33 taken 5658 times.
10118670 return std::find_if(vector.begin(), vector.end(), [](const auto& x) { return std::abs(x) > 1e-8; } ) - vector.begin();
40 };
41
42
2/2
✓ Branch 1 taken 4024888 times.
✓ Branch 2 taken 1005322 times.
5050013 for (const auto& scvf : scvfs(fvGeometry))
43 {
44 4041862 const auto dirIdx = directionIndex(scvf.unitOuterNormal());
45 4041862 result[dirIdx] += 0.5*getFaceVelocity(fvGeometry, scvf)[dirIdx];
46 }
47 1008151 return result;
48 }
49
50 //! Return the velocity vector at dof position given an scv
51 template<class SubControlVolume, class FVElementGeometry, class VelocityHelper>
52 90380 static auto faceVelocity(const SubControlVolume& scv,
53 const FVElementGeometry& fvGeometry,
54 const VelocityHelper& getNormalVelocityDofValue)
55 {
56 90380 int axis = scv.dofAxis();
57 90380 const int dim = FVElementGeometry::GridGeometry::GridView::dimension;
58 using Scalar = typename SubControlVolume::Traits::Scalar;
59 using GlobalPosition = typename FVElementGeometry::GridGeometry::GlobalCoordinate;
60 using VelocityVector = typename FVElementGeometry::GridGeometry::GlobalCoordinate;
61 90380 VelocityVector faceVelocityVector(0.0);
62
63 // per dimension, we have at max two velocities from which we'll compute an average
64
6/6
✓ Branch 0 taken 90380 times.
✓ Branch 1 taken 90380 times.
✓ Branch 2 taken 90380 times.
✓ Branch 3 taken 90380 times.
✓ Branch 4 taken 576 times.
✓ Branch 5 taken 89804 times.
271140 std::array<Dune::ReservedVector<Scalar, 2>, dim> normalVelocities;
65
3/4
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 89804 times.
✓ Branch 3 taken 576 times.
✗ Branch 4 not taken.
91532 if (scv.boundary() && !fvGeometry.gridGeometry().dofOnPeriodicBoundary(scv.dofIndex()))
66 {
67 // iterate through the inner lateral velocities,
68
4/4
✓ Branch 1 taken 1152 times.
✓ Branch 2 taken 1152 times.
✓ Branch 4 taken 2304 times.
✓ Branch 5 taken 576 times.
7488 for (const auto& scvf : scvfs(fvGeometry, scv))
69 {
70
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 1152 times.
2304 if (scvf.isFrontal())
71 1152 continue;
72
73 // at a lateral velocity, find the inner and outer normal velocities
74
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1152 times.
1152 const auto& orthogonalScvf = fvGeometry.lateralOrthogonalScvf(scvf);
75
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1152 times.
1152 const auto& lateralScv = fvGeometry.scv(orthogonalScvf.insideScvIdx());
76 1152 auto lateralAxis = lateralScv.dofAxis();
77 1152 normalVelocities[lateralAxis].push_back( getNormalVelocityDofValue(lateralScv) ) ;
78 }
79 }
80 else
81 {
82 // Find the location of interpolation, if periodic, from both sides
83 89804 const GlobalPosition selfPosition = scv.dofPosition();
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 89804 times.
89804 GlobalPosition outsideSelfPosition = selfPosition;
85 179608 if (fvGeometry.gridGeometry().dofOnPeriodicBoundary(scv.dofIndex()))
86 12 outsideSelfPosition = fvGeometry.outsidePeriodicScv(scv).dofPosition();
87
88 // iterate through the lateral velocities to get to the normal locations
89
4/4
✓ Branch 1 taken 89804 times.
✓ Branch 2 taken 179608 times.
✓ Branch 4 taken 269412 times.
✓ Branch 5 taken 89804 times.
898040 for (const auto& scvf : scvfs(fvGeometry, scv))
90 {
91
2/2
✓ Branch 0 taken 89804 times.
✓ Branch 1 taken 179608 times.
269412 if (scvf.isFrontal())
92 continue;
93
94 // at a lateral velocity, find the inner and outer normal velocities
95
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 179608 times.
179608 const auto& orthogonalScvf = fvGeometry.lateralOrthogonalScvf(scvf);
96
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 179608 times.
179608 const auto& insideLateralScv = fvGeometry.scv(orthogonalScvf.insideScvIdx());
97 179608 const auto& outsideLateralScv = fvGeometry.scv(orthogonalScvf.outsideScvIdx());
98 179608 const auto& lateralAxis = insideLateralScv.dofAxis();
99
100 // Find the inside normal velocities
101 179608 const auto& insideNormalVelocity = getNormalVelocityDofValue(insideLateralScv);
102 179608 const auto& insideNormalPosition = insideLateralScv.dofPosition()[axis];
103
104 // Find the outside normal velocities
105 179608 const auto& outsideNormalVelocity = getNormalVelocityDofValue(outsideLateralScv);
106 179608 const auto& outsideNormalPosition = outsideLateralScv.dofPosition()[axis];
107
108 // Linear interpolation at the face plane and add to normal velocity collection
109 179608 const auto& innerDistance = std::abs(insideNormalPosition - selfPosition[axis]);
110 179608 const auto& totalDistance = std::abs(outsideNormalPosition - outsideSelfPosition[axis]) + innerDistance;
111 179608 const auto& velDiff = outsideNormalVelocity - insideNormalVelocity;
112
113 179608 normalVelocities[lateralAxis].push_back(insideNormalVelocity + (velDiff * innerDistance / totalDistance));
114 }
115 }
116
117
2/2
✓ Branch 0 taken 180760 times.
✓ Branch 1 taken 90380 times.
271140 for (int i = 0; i < faceVelocityVector.size(); i++)
118 {
119
2/2
✓ Branch 0 taken 90380 times.
✓ Branch 1 taken 90380 times.
180760 if (i == axis)
120 90380 faceVelocityVector[i] = getNormalVelocityDofValue(scv);
121 else
122 180760 faceVelocityVector[i] = std::accumulate(normalVelocities[i].begin(), normalVelocities[i].end(), 0.0) / normalVelocities[i].size();
123 }
124
125 90380 return faceVelocityVector;
126 }
127
128 };
129
130 } // end namespace Dumux
131
132 #endif // DUMUX_NAVIERSTOKES_STAGGERED_VELOCITYRECONSTRUCTION_HH
133