GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/io/grid/gridmanager_sp.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 31 34 91.2%
Functions: 2 2 100.0%
Branches: 30 126 23.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-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 InputOutput
10 * \brief Grid manager specialization for SPGrid
11 */
12 #ifndef DUMUX_IO_GRID_MANAGER_SP_HH
13 #define DUMUX_IO_GRID_MANAGER_SP_HH
14
15 #include <type_traits>
16
17 // SPGrid specific includes
18 #if HAVE_DUNE_SPGRID
19 #include <dune/grid/spgrid.hh>
20 #include <dune/grid/spgrid/dgfparser.hh>
21 #endif
22
23 #ifndef DUMUX_IO_GRID_MANAGER_BASE_HH
24 #include <dumux/io/grid/gridmanager_base.hh>
25 #endif
26 #include <dumux/io/grid/periodicgridtraits.hh>
27
28 namespace Dumux {
29
30 #if HAVE_DUNE_SPGRID
31
32 /*!
33 * \ingroup InputOutput
34 * \brief Provides a grid manager for SPGrid
35 *
36 * The following keys are recognized:
37 * - File : A DGF or gmsh file to load from, type detection by file extension
38 *
39 */
40 template<class ct, int dim, template< int > class Ref, class Comm>
41
3/6
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
26 class GridManager<Dune::SPGrid<ct, dim, Ref, Comm>>
42 : public GridManagerBase<Dune::SPGrid<ct, dim, Ref, Comm>>
43 {
44 public:
45 using Grid = Dune::SPGrid<ct, dim, Ref, Comm>;
46 using ParentType = GridManagerBase<Grid>;
47
48 /*!
49 * \brief Make the grid. This is implemented by specializations of this method.
50 */
51 12 void init(const std::string& paramGroup = "")
52 {
53 12 const auto overlap = getParamFromGroup<int>(paramGroup, "Grid.Overlap", 1);
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (overlap == 0)
55
0/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
12 DUNE_THROW(Dune::NotImplemented, "dune-spgrid does currently not support zero overlap!");
56
57 // try to create it from file
58
2/2
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 2 times.
24 if (hasParamInGroup(paramGroup, "Grid.File"))
59 {
60
1/2
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 ParentType::makeGridFromDgfFile(getParamFromGroup<std::string>(paramGroup, "Grid.File"));
61 10 ParentType::maybeRefineGrid(paramGroup);
62 10 ParentType::loadBalance();
63 10 return;
64 }
65 // Didn't find a way to construct the grid
66
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 else if (hasParamInGroup(paramGroup, "Grid.UpperRight"))
67 {
68 using GlobalPosition = Dune::FieldVector<ct, dim>;
69 4 const auto lowerLeft = getParamFromGroup<GlobalPosition>(paramGroup, "Grid.LowerLeft", GlobalPosition(0.0));
70 2 const auto upperRight = getParamFromGroup<GlobalPosition>(paramGroup, "Grid.UpperRight");
71
72 using IntArray = std::array<int, dim>;
73 2 IntArray cells; cells.fill(1);
74 2 cells = getParamFromGroup<IntArray>(paramGroup, "Grid.Cells", cells);
75
76 2 const auto periodic = getParamFromGroup<std::bitset<dim>>(paramGroup, "Grid.Periodic", std::bitset<dim>{});
77 2 init(lowerLeft, upperRight, cells, paramGroup, overlap, periodic);
78 }
79 else
80 {
81 const auto prefix = paramGroup.empty() ? paramGroup : paramGroup + ".";
82
0/30
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
12 DUNE_THROW(ParameterException, "Please supply a grid file in " << prefix << "Grid.File or " << prefix << "Grid.UpperRight/Cells.");
83 }
84 }
85
86 3 void init(const Dune::FieldVector<ct, dim>& lowerLeft,
87 const Dune::FieldVector<ct, dim>& upperRight,
88 const std::array<int, dim>& cells,
89 const std::string& paramGroup = "",
90 const int overlap = 1,
91 const std::bitset<dim> periodic = std::bitset<dim>{})
92 {
93
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (overlap == 0)
94 DUNE_THROW(Dune::NotImplemented, "dune-spgrid does currently not support zero overlap!");
95 using IntArray = std::array<int, dim>;
96 3 IntArray spOverlap; spOverlap.fill(overlap);
97 using Domain = typename Grid::Domain;
98 3 std::vector< typename Domain::Cube > cubes;
99
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 cubes.push_back( typename Domain::Cube( lowerLeft, upperRight ) );
100
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
3 Domain domain( cubes, typename Domain::Topology( static_cast<unsigned int>(periodic.to_ulong()) ) );
101
3/8
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
3 ParentType::gridPtr() = std::make_shared<Grid>( domain, cells, spOverlap );
102
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 ParentType::maybeRefineGrid(paramGroup);
103
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 ParentType::loadBalance();
104 3 }
105 };
106
107 template<class ct, int dim, template< int > class Ref, class Comm>
108 struct PeriodicGridTraits<Dune::SPGrid<ct, dim, Ref, Comm>>
109 {
110 private:
111 using Grid = Dune::SPGrid<ct, dim, Ref, Comm>;
112 public:
113 struct SupportsPeriodicity : public std::true_type {};
114
115
3/6
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
22 PeriodicGridTraits(const Grid& grid) {};
116
117 1143212 bool isPeriodic (const typename Grid::LeafIntersection& intersection) const
118 {
119
8/8
✓ Branch 0 taken 1019798 times.
✓ Branch 1 taken 882 times.
✓ Branch 2 taken 122206 times.
✓ Branch 3 taken 1018184 times.
✓ Branch 4 taken 2308 times.
✓ Branch 5 taken 880 times.
✓ Branch 6 taken 160024 times.
✓ Branch 7 taken 1848 times.
2286330 return intersection.neighbor() && intersection.boundary();
120 }
121 };
122
123 #endif // HAVE_DUNE_SPGRID
124
125 } // end namespace Dumux
126
127 #endif
128