ExaDG
Loading...
Searching...
No Matches
grid.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2021 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef INCLUDE_EXADG_GRID_GRID_H_
23#define INCLUDE_EXADG_GRID_GRID_H_
24
25// deal.II
26#include <deal.II/grid/grid_tools.h>
27#include <deal.II/grid/tria.h>
28
29// ExaDG
30#include <exadg/grid/mapping_dof_vector.h>
31
32namespace ExaDG
33{
38template<int dim>
39class Grid
40{
41public:
42 typedef typename std::vector<
43 dealii::GridTools::PeriodicFacePair<typename dealii::Triangulation<dim>::cell_iterator>>
44 PeriodicFacePairs;
45
49 std::shared_ptr<dealii::Triangulation<dim>> triangulation;
50
54 PeriodicFacePairs periodic_face_pairs;
55
63 std::vector<std::shared_ptr<dealii::Triangulation<dim> const>> coarse_triangulations;
64
72 std::vector<PeriodicFacePairs> coarse_periodic_face_pairs;
73};
74
82template<int dim, typename Number>
84{
85public:
89 MultigridMappings(std::shared_ptr<dealii::Mapping<dim>> mapping,
90 std::shared_ptr<dealii::Mapping<dim>> mapping_coarse_levels)
91 : mapping_fine_level(mapping),
92 mapping_coarse_levels(mapping_coarse_levels),
93 degree_coarse_mappings(1)
94 {
95 }
96
100 MultigridMappings(std::shared_ptr<MappingDoFVector<dim, Number>> mapping_dof_vector,
101 unsigned int const degree_coarse_mappings)
102 : mapping_dof_vector_fine_level(mapping_dof_vector),
103 degree_coarse_mappings(degree_coarse_mappings)
104 {
105 }
106
110 void
111 initialize_coarse_mappings(Grid<dim> const & grid, unsigned int const n_h_levels)
112 {
113 // we need to initialize mappings for coarse levels only if we have a mapping of type
114 // MappingDoFVector
115 if(mapping_dof_vector_fine_level.get())
116 {
117 if(n_h_levels > 1)
118 {
119 mapping_dof_vector_coarse_levels.resize(n_h_levels - 1);
120
122 }
123 }
124 else // standard dealii::Mapping
125 {
126 AssertThrow(mapping_fine_level.get(),
127 dealii::ExcMessage("Fine-level mapping is uninitialized."));
128
129 // when using standard dealii::Mapping's, there is nothing to do, i.e. we assume that all the
130 // mappings have been set up prior to calling the constructor of this class.
131 }
132 }
133
137 dealii::Mapping<dim> const &
138 get_mapping(unsigned int const h_level, unsigned int const n_h_levels) const
139 {
140 if(mapping_dof_vector_fine_level.get()) // ExaDG::MappingDoFVector
141 {
142 // fine level
143 if(h_level == n_h_levels - 1)
144 {
145 return *(mapping_dof_vector_fine_level->get_mapping());
146 }
147 else // coarse levels
148 {
149 AssertThrow(h_level < mapping_dof_vector_coarse_levels.size(),
150 dealii::ExcMessage("Vector of coarse mappings seems to have incorrect size."));
151
152 return *(mapping_dof_vector_coarse_levels[h_level]->get_mapping());
153 }
154 }
155 else // standard dealii::Mapping
156 {
157 // use mapping_fine_level on the fine level or on all levels if mapping_coarse_levels is
158 // uninitialized
159 if(h_level == n_h_levels - 1 or not(mapping_coarse_levels.get()))
160 {
161 AssertThrow(mapping_fine_level.get(),
162 dealii::ExcMessage("Fine-level mapping is uninitialized."));
163
164 return *mapping_fine_level;
165 }
166 else // coarse levels
167 {
168 AssertThrow(mapping_coarse_levels.get(),
169 dealii::ExcMessage("mapping_coarse_levels is uninitialized."));
170
171 return *mapping_coarse_levels;
172 }
173 }
174 }
175
185 std::function<void(
186 std::shared_ptr<dealii::Triangulation<dim> const> const & fine_triangulation,
187 std::vector<std::shared_ptr<dealii::Triangulation<dim> const>> const & coarse_triangulations)>
189 [&](std::shared_ptr<dealii::Triangulation<dim> const> const & fine_triangulation,
190 std::vector<std::shared_ptr<dealii::Triangulation<dim> const>> const &
191 coarse_triangulations) {
192 AssertThrow(
193 mapping_dof_vector_fine_level.get(),
194 dealii::ExcMessage(
195 "Coarse mappings can not be initialized because fine level mapping is invalid."));
196
197 MappingTools::initialize_coarse_mappings<dim, Number>(mapping_dof_vector_coarse_levels,
198 degree_coarse_mappings,
199 mapping_dof_vector_fine_level,
200 fine_triangulation,
201 coarse_triangulations);
202 };
203
204private:
208 std::shared_ptr<dealii::Mapping<dim>> mapping_fine_level;
209
215 std::shared_ptr<dealii::Mapping<dim>> mapping_coarse_levels;
216
220 std::shared_ptr<MappingDoFVector<dim, Number>> mapping_dof_vector_fine_level;
221
226 std::vector<std::shared_ptr<MappingDoFVector<dim, Number>>> mapping_dof_vector_coarse_levels;
227
232 unsigned int const degree_coarse_mappings;
233};
234
235} // namespace ExaDG
236
237
238#endif /* INCLUDE_EXADG_GRID_GRID_H_ */
Definition grid.h:40
PeriodicFacePairs periodic_face_pairs
Definition grid.h:54
std::shared_ptr< dealii::Triangulation< dim > > triangulation
Definition grid.h:49
std::vector< PeriodicFacePairs > coarse_periodic_face_pairs
Definition grid.h:72
std::vector< std::shared_ptr< dealii::Triangulation< dim > const > > coarse_triangulations
Definition grid.h:63
Definition mapping_dof_vector.h:54
Definition grid.h:84
void initialize_coarse_mappings(Grid< dim > const &grid, unsigned int const n_h_levels)
Definition grid.h:111
MultigridMappings(std::shared_ptr< dealii::Mapping< dim > > mapping, std::shared_ptr< dealii::Mapping< dim > > mapping_coarse_levels)
Definition grid.h:89
MultigridMappings(std::shared_ptr< MappingDoFVector< dim, Number > > mapping_dof_vector, unsigned int const degree_coarse_mappings)
Definition grid.h:100
std::function< void(std::shared_ptr< dealii::Triangulation< dim > const > const &fine_triangulation, std::vector< std::shared_ptr< dealii::Triangulation< dim > const > > const &coarse_triangulations) lambda_initialize_coarse_mappings)
Definition grid.h:188
dealii::Mapping< dim > const & get_mapping(unsigned int const h_level, unsigned int const n_h_levels) const
Definition grid.h:138
Definition driver.cpp:33