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 InputOutput | ||
10 | * \brief Grid manager specialization for FoamGrid | ||
11 | */ | ||
12 | #ifndef DUMUX_IO_GRID_MANAGER_FOAM_HH | ||
13 | #define DUMUX_IO_GRID_MANAGER_FOAM_HH | ||
14 | |||
15 | // FoamGrid specific includes | ||
16 | #if HAVE_DUNE_FOAMGRID | ||
17 | #include <dune/foamgrid/foamgrid.hh> | ||
18 | #include <dune/foamgrid/dgffoam.hh> | ||
19 | #endif | ||
20 | |||
21 | #ifndef DUMUX_IO_GRID_MANAGER_BASE_HH | ||
22 | #include <dumux/io/grid/gridmanager_base.hh> | ||
23 | #endif | ||
24 | |||
25 | #include <dumux/common/gridcapabilities.hh> | ||
26 | |||
27 | namespace Dumux { | ||
28 | |||
29 | #if HAVE_DUNE_FOAMGRID | ||
30 | |||
31 | /*! | ||
32 | * \ingroup InputOutput | ||
33 | * \brief Provides a grid manager for FoamGrids | ||
34 | * from information in the input file | ||
35 | * | ||
36 | * All keys are expected to be in group GridParameterGroup. | ||
37 | |||
38 | * The following keys are recognized: | ||
39 | * - File : A DGF or gmsh file to load from, type detection by file extension | ||
40 | * - Verbosity : whether the grid construction should output to standard out | ||
41 | * - LowerLeft : lowerLeft corner of a structured grid | ||
42 | * - UpperRight : upperright corner of a structured grid | ||
43 | * - Cells : number of elements in a structured grid | ||
44 | * | ||
45 | */ | ||
46 | template<int dim, int dimworld> | ||
47 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
22 | class GridManager<Dune::FoamGrid<dim, dimworld>> |
48 | : public GridManagerBase<Dune::FoamGrid<dim, dimworld>> | ||
49 | { | ||
50 | public: | ||
51 | using Grid = Dune::FoamGrid<dim, dimworld>; | ||
52 | using ParentType = GridManagerBase<Grid>; | ||
53 | |||
54 | /*! | ||
55 | * \brief Make the grid. This is implemented by specializations of this method. | ||
56 | */ | ||
57 | 11 | void init(const std::string& modelParamGroup = "") | |
58 | { | ||
59 | // try to create it from file | ||
60 |
6/14✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 11 times.
✓ Branch 11 taken 11 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 11 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
33 | if (hasParamInGroup(modelParamGroup, "Grid.File")) |
61 | { | ||
62 |
3/6✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
11 | ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup); |
63 | 11 | ParentType::maybeRefineGrid(modelParamGroup); | |
64 | 11 | ParentType::loadBalance(); | |
65 | 11 | return; | |
66 | } | ||
67 | |||
68 | // Then look for the necessary keys to construct a structured grid from the input file | ||
69 | ✗ | else if (hasParamInGroup(modelParamGroup, "Grid.UpperRight")) | |
70 | { | ||
71 | ✗ | ParentType::template makeStructuredGrid<dim, dimworld>(ParentType::CellType::Simplex, modelParamGroup); | |
72 | ✗ | ParentType::maybeRefineGrid(modelParamGroup); | |
73 | ✗ | ParentType::loadBalance(); | |
74 | } | ||
75 | |||
76 | // Didn't find a way to construct the grid | ||
77 | else | ||
78 | { | ||
79 | ✗ | const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + "."; | |
80 | ✗ | DUNE_THROW(ParameterException, "Please supply one of the parameters " | |
81 | << prefix + "Grid.UpperRight" | ||
82 | << ", or a grid file in " << prefix + "Grid.File"); | ||
83 | |||
84 | } | ||
85 | } | ||
86 | }; | ||
87 | |||
88 | /*! | ||
89 | * \ingroup InputOutput | ||
90 | * \brief Provides a grid manager for FoamGrids of dim 1 | ||
91 | * from information in the input file | ||
92 | * | ||
93 | * All keys are expected to be in group GridParameterGroup. | ||
94 | |||
95 | * The following keys are recognized: | ||
96 | * - File : A DGF or gmsh file to load from, type detection by file extension | ||
97 | * - Verbosity : whether the grid construction should output to standard out | ||
98 | * - LowerLeft : lowerLeft corner of a structured grid | ||
99 | * - UpperRight : upperright corner of a structured grid | ||
100 | * - Cells : number of elements in a structured grid | ||
101 | * | ||
102 | */ | ||
103 | template<int dimworld> | ||
104 |
1/4✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
74 | class GridManager<Dune::FoamGrid<1, dimworld>> |
105 | : public GridManagerBase<Dune::FoamGrid<1, dimworld>> | ||
106 | { | ||
107 | public: | ||
108 | using Grid = Dune::FoamGrid<1, dimworld>; | ||
109 | using ParentType = GridManagerBase<Grid>; | ||
110 | |||
111 | /*! | ||
112 | * \brief Make the grid. This is implemented by specializations of this method. | ||
113 | */ | ||
114 | 37 | void init(const std::string& modelParamGroup = "") | |
115 | { | ||
116 | // try to create it from file | ||
117 |
8/14✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 37 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 37 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 37 times.
✓ Branch 11 taken 18 times.
✓ Branch 12 taken 19 times.
✓ Branch 13 taken 18 times.
✓ Branch 14 taken 19 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
|
111 | if (hasParamInGroup(modelParamGroup, "Grid.File")) |
118 | { | ||
119 |
3/6✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
18 | ParentType::makeGridFromFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File"), modelParamGroup); |
120 | 18 | ParentType::maybeRefineGrid(modelParamGroup); | |
121 | 18 | ParentType::loadBalance(); | |
122 | 18 | return; | |
123 | } | ||
124 | |||
125 | // The required parameters | ||
126 | using GlobalPosition = Dune::FieldVector<typename Grid::ctype, dimworld>; | ||
127 | 19 | const auto upperRight = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.UpperRight"); | |
128 | 38 | const auto lowerLeft = getParamFromGroup<GlobalPosition>(modelParamGroup, "Grid.LowerLeft", GlobalPosition(0.0)); | |
129 | using CellArray = std::array<unsigned int, 1>; | ||
130 | 19 | const auto cells = getParamFromGroup<CellArray>(modelParamGroup, "Grid.Cells", std::array<unsigned int, 1>{{1}}); | |
131 | |||
132 | // make the grid (structured interval grid in dimworld space) | ||
133 | 57 | Dune::GridFactory<Grid> factory; | |
134 | |||
135 | 19 | constexpr auto geomType = Dune::GeometryTypes::line; | |
136 | |||
137 | // create a step vector | ||
138 | 19 | GlobalPosition step = upperRight; | |
139 | 57 | step -= lowerLeft, step /= cells[0]; | |
140 | |||
141 | // create the vertices | ||
142 | 19 | GlobalPosition globalPos = lowerLeft; | |
143 |
4/4✓ Branch 0 taken 384 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 384 times.
✓ Branch 3 taken 19 times.
|
1171 | for (unsigned int vIdx = 0; vIdx <= cells[0]; vIdx++, globalPos += step) |
144 |
1/2✓ Branch 1 taken 384 times.
✗ Branch 2 not taken.
|
384 | factory.insertVertex(globalPos); |
145 | |||
146 | // create the cells | ||
147 |
4/4✓ Branch 0 taken 365 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 365 times.
✓ Branch 3 taken 19 times.
|
768 | for(unsigned int eIdx = 0; eIdx < cells[0]; eIdx++) |
148 |
4/10✓ Branch 1 taken 365 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 365 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 365 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 365 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
1460 | factory.insertElement(geomType, {eIdx, eIdx+1}); |
149 | |||
150 |
6/16✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 19 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 19 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 19 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 19 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
19 | ParentType::gridPtr() = std::shared_ptr<Grid>(factory.createGrid()); |
151 |
1/2✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
|
19 | ParentType::maybeRefineGrid(modelParamGroup); |
152 |
1/2✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
|
19 | ParentType::loadBalance(); |
153 | } | ||
154 | }; | ||
155 | |||
156 | namespace Grid::Capabilities { | ||
157 | |||
158 | // To the best of our knowledge FoamGrid is view thread-safe | ||
159 | // This specialization can be removed after we depend on Dune release 2.9 in which this is guaranteed by FoamGrid itself | ||
160 | template<int dim, int dimworld> | ||
161 | struct MultithreadingSupported<Dune::FoamGrid<dim, dimworld>> | ||
162 | { | ||
163 | template<class GV> | ||
164 | ✗ | static bool eval(const GV&) // default is independent of the grid view | |
165 | ✗ | { return true; } | |
166 | }; | ||
167 | |||
168 | } // end namespace Grid::Capabilities | ||
169 | |||
170 | #endif // HAVE_DUNE_FOAMGRID | ||
171 | |||
172 | } // end namespace Dumux | ||
173 | |||
174 | #endif | ||
175 |