GCC Code Coverage Report


Directory: gridformat/
File: gridformat/grid/grid.hpp
Date: 2024-11-20 14:41:59
Exec Total Coverage
Lines: 52 53 98.1%
Functions: 709 715 99.2%
Branches: 31 46 67.4%

Line Branch Exec Source
1 // SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
2 // SPDX-License-Identifier: MIT
3 /*!
4 * \file
5 * \ingroup Grid
6 * \brief Defines the grid interface
7 */
8 #ifndef GRIDFORMAT_GRID_GRID_HPP_
9 #define GRIDFORMAT_GRID_GRID_HPP_
10
11 #include <ranges>
12 #include <concepts>
13 #include <cassert>
14 #include <numeric>
15 #include <algorithm>
16 #include <unordered_map>
17
18 #include <gridformat/common/ranges.hpp>
19 #include <gridformat/common/concepts.hpp>
20 #include <gridformat/common/flat_index_mapper.hpp>
21
22 #include <gridformat/grid/cell_type.hpp>
23 #include <gridformat/grid/traits.hpp>
24 #include <gridformat/grid/type_traits.hpp>
25 #include <gridformat/grid/concepts.hpp>
26
27 namespace GridFormat {
28
29 #ifndef DOXYGEN
30 namespace GridDetail {
31
32 template<typename T, std::size_t dim>
33 18995 std::array<std::array<T, dim>, dim> standard_basis() {
34 std::array<std::array<T, dim>, dim> result;
35
1/2
✓ Branch 2 taken 754 times.
✗ Branch 3 not taken.
45774 std::ranges::for_each(result, [&] (auto& b) { std::ranges::fill(b, T{0.0}); });
36
2/2
✓ Branch 0 taken 26779 times.
✓ Branch 1 taken 9681 times.
71799 for (std::size_t i = 0; i < dim; ++i)
37 52804 result[i][i] = 1.0;
38 18995 return result;
39 }
40
41 } // namespace GridDetail
42 #endif // DOXYGEN
43
44 //! \addtogroup Grid
45 //! \{
46
47 template<GridDetail::ExposesPointRange Grid>
48 1104193 std::ranges::range decltype(auto) points(const Grid& grid) {
49 1104193 return Traits::Points<Grid>::get(grid);
50 }
51
52 template<GridDetail::ExposesCellRange Grid>
53 1036468 std::ranges::range decltype(auto) cells(const Grid& grid) {
54 1036468 return Traits::Cells<Grid>::get(grid);
55 }
56
57 template<GridDetail::ExposesPointId Grid>
58 489578 std::integral auto id(const Grid& grid, const Point<Grid>& point) {
59 489578 return Traits::PointId<Grid, Point<Grid>>::get(grid, point);
60 }
61
62 template<GridDetail::ExposesPointCoordinates Grid>
63 2787298 std::ranges::range decltype(auto) coordinates(const Grid& grid, const Point<Grid>& point) {
64 2787298 return Traits::PointCoordinates<Grid, Point<Grid>>::get(grid, point);
65 }
66
67 template<GridDetail::ExposesCellPoints Grid>
68 628283 std::ranges::range decltype(auto) points(const Grid& grid, const Cell<Grid>& cell) {
69 628283 return Traits::CellPoints<Grid, Cell<Grid>>::get(grid, cell);
70 }
71
72 template<GridDetail::ExposesCellType Grid>
73 246255 CellType type(const Grid& grid, const Cell<Grid>& cell) {
74 246255 return Traits::CellType<Grid, Cell<Grid>>::get(grid, cell);
75 }
76
77 template<typename Grid>
78 requires(GridDetail::ExposesNumberOfCells<Grid> or
79 GridDetail::ExposesCellRange<Grid>)
80 937372 std::size_t number_of_cells(const Grid& grid) {
81 if constexpr (GridDetail::ExposesNumberOfCells<Grid>)
82 6877 return Traits::NumberOfCells<Grid>::get(grid);
83 else
84
2/4
✓ Branch 1 taken 2306 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2306 times.
✗ Branch 5 not taken.
930495 return Ranges::size(cells(grid));
85 }
86
87 template<typename Grid>
88 requires(GridDetail::ExposesNumberOfPoints<Grid> or
89 GridDetail::ExposesPointRange<Grid>)
90 971380 std::size_t number_of_points(const Grid& grid) {
91 if constexpr (GridDetail::ExposesNumberOfPoints<Grid>)
92 6800 return Traits::NumberOfPoints<Grid>::get(grid);
93 else
94
2/4
✓ Branch 1 taken 3350 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3350 times.
✗ Branch 5 not taken.
964580 return Ranges::size(points(grid));
95 }
96
97 template<typename Grid>
98 requires(GridDetail::ExposesNumberOfCellPoints<Grid> or
99 GridDetail::ExposesCellPoints<Grid>)
100 361812 std::size_t number_of_points(const Grid& grid, const Cell<Grid>& cell) {
101 if constexpr (GridDetail::ExposesNumberOfCellPoints<Grid>)
102 77784 return Traits::NumberOfCellPoints<Grid, Cell<Grid>>::get(grid, cell);
103 else
104
2/4
✓ Branch 1 taken 153606 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 24838 times.
✗ Branch 5 not taken.
284028 return Ranges::size(points(grid, cell));
105 }
106
107 template<GridDetail::ExposesExtents Grid>
108 186384 Concepts::StaticallySizedRange decltype(auto) extents(const Grid& grid) {
109 186384 return Traits::Extents<Grid>::get(grid);
110 }
111
112 template<GridDetail::ExposesExtents Grid>
113 81265 auto point_extents(const Grid& grid) {
114
1/2
✓ Branch 1 taken 127 times.
✗ Branch 2 not taken.
81265 std::ranges::range auto result = extents(grid);
115
1/2
✓ Branch 1 taken 9781 times.
✗ Branch 2 not taken.
192814 std::ranges::for_each(result, [] (std::integral auto& ext) { ext++; });
116 81265 return result;
117 }
118
119 template<GridDetail::ExposesOrigin Grid>
120 5138 Concepts::StaticallySizedRange decltype(auto) origin(const Grid& grid) {
121 5138 return Traits::Origin<Grid>::get(grid);
122 }
123
124 template<GridDetail::ExposesOrdinates Grid>
125 24702 Concepts::MDRange<1> decltype(auto) ordinates(const Grid& grid, unsigned dir) {
126 24702 return Traits::Ordinates<Grid>::get(grid, dir);
127 }
128
129 template<GridDetail::ExposesSpacing Grid>
130 10711 Concepts::StaticallySizedRange decltype(auto) spacing(const Grid& grid) {
131 10711 return Traits::Spacing<Grid>::get(grid);
132 }
133
134 template<Concepts::StructuredEntitySet Grid>
135 10891 Concepts::StaticallySizedMDRange<2> decltype(auto) basis(const Grid& grid) {
136 static constexpr std::size_t dim = dimension<Grid>;
137 if constexpr (GridDetail::ExposesBasis<Grid>) {
138 using ResultType = std::remove_cvref_t<decltype(Traits::Basis<Grid>::get(grid))>;
139 static_assert(static_size<ResultType> == dim);
140 static_assert(static_size<std::ranges::range_value_t<ResultType>> == dim);
141 124 return Traits::Basis<Grid>::get(grid);
142 }
143 else {
144 10767 return GridDetail::standard_basis<CoordinateType<Grid>, dim>();
145 }
146 }
147
148 template<GridDetail::ExposesCellLocation Grid>
149 1010164 Concepts::StaticallySizedRange decltype(auto) location(const Grid& grid, const Cell<Grid>& c) {
150 1010164 return Traits::Location<Grid, Cell<Grid>>::get(grid, c);
151 }
152
153 template<GridDetail::ExposesPointLocation Grid>
154 requires(not std::same_as<Cell<Grid>, Point<Grid>>) // avoid ambiguity if cell & point type are the same
155 1663100 Concepts::StaticallySizedRange decltype(auto) location(const Grid& grid, const Point<Grid>& p) {
156 1663100 return Traits::Location<Grid, Point<Grid>>::get(grid, p);
157 }
158
159 template<GridDetail::ExposesPointRange Grid> requires(GridDetail::ExposesPointId<Grid>)
160 1653 std::unordered_map<std::size_t, std::size_t> make_point_id_map(const Grid& grid) {
161 1653 std::size_t i = 0;
162 1653 std::unordered_map<std::size_t, std::size_t> point_id_to_running_idx;
163
13/15
✓ Branch 1 taken 344 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 344 times.
✓ Branch 5 taken 10836 times.
✓ Branch 6 taken 655 times.
✓ Branch 7 taken 307 times.
✓ Branch 8 taken 4380 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 27158 times.
✓ Branch 11 taken 18222 times.
✓ Branch 12 taken 126 times.
✓ Branch 13 taken 27284 times.
✓ Branch 14 taken 92 times.
✓ Branch 15 taken 15826 times.
✓ Branch 16 taken 126 times.
96499 for (const auto& p : points(grid)) {
164
3/4
✓ Branch 1 taken 20206 times.
✓ Branch 2 taken 5825 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2054 times.
94800 assert(id(grid, p) >= 0);
165
4/7
✓ Branch 1 taken 20206 times.
✓ Branch 2 taken 36010 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20206 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20206 times.
✗ Branch 8 not taken.
94800 point_id_to_running_idx[id(grid, p)] = i++;
166 }
167 1653 return point_id_to_running_idx;
168 }
169
170 //! \} group Grid
171
172 } // namespace GridFormat
173
174 #endif // GRIDFORMAT_GRID_GRID_HPP_
175