ExaDG
Loading...
Searching...
No Matches
application_base.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_POISSON_OVERSET_GRIDS_USER_INTERFACE_APPLICATION_BASE_H_
23#define INCLUDE_EXADG_POISSON_OVERSET_GRIDS_USER_INTERFACE_APPLICATION_BASE_H_
24
25// deal.II
26#include <deal.II/grid/grid_tools_cache.h>
27
28// ExaDG
29#include <exadg/poisson/user_interface/application_base.h>
30
31namespace ExaDG
32{
33namespace Poisson
34{
35namespace OversetGrids
36{
42template<int dim>
43void
44set_boundary_ids_overlap_region(dealii::Triangulation<dim> const & tria_dst,
45 dealii::types::boundary_id const & bid,
46 dealii::Mapping<dim> const & mapping_src,
47 dealii::Triangulation<dim> const & tria_src)
48{
49 std::vector<dealii::Point<dim>> points;
50 using CellIteratorType = typename dealii::Triangulation<dim>::cell_iterator;
51 using Id = std::tuple<CellIteratorType /* cell */, unsigned int /*face*/>;
52 std::vector<std::pair<Id, unsigned int /* first_point_in_vector */>> id_to_vector_index;
53
54 // fill vector of points for all boundary faces
55 for(auto cell : tria_dst.cell_iterators())
56 {
57 for(auto const & f : cell->face_indices())
58 {
59 if(cell->face(f)->at_boundary())
60 {
61 for(auto const & v : cell->face(f)->vertex_indices())
62 {
63 if(v == 0)
64 {
65 Id const id = std::make_tuple(cell, f);
66 id_to_vector_index.push_back({id, points.size()});
67 }
68
69 points.push_back(cell->face(f)->vertex(v));
70 }
71 }
72 }
73 }
74
75 // create and reinit RemotePointEvaluation: find points on src-side
76 std::vector<bool> marked_vertices = {};
77 double const tolerance = 1.e-10;
78
79 dealii::Utilities::MPI::RemotePointEvaluation<dim> rpe =
80 dealii::Utilities::MPI::RemotePointEvaluation<dim>(tolerance,
81 false
82#if DEAL_II_VERSION_GTE(9, 4, 0)
83 ,
84 0,
85 [marked_vertices]() {
86 return marked_vertices;
87 }
88#endif
89 );
90
91 rpe.reinit(points, tria_src, mapping_src);
92
93 // check which points have been found and whether a face on dst-side is located inside the src
94 // triangulation
95 for(auto iter = id_to_vector_index.begin(); iter != id_to_vector_index.end(); ++iter)
96 {
97 unsigned int const begin = iter->second;
98 unsigned int const end =
99 (iter + 1 != id_to_vector_index.end()) ? (iter + 1)->second : points.size();
100
101 bool inside = true;
102 for(unsigned int i = begin; i < end; ++i)
103 {
104 inside = (inside and rpe.point_found(i));
105 }
106
107 if(inside)
108 {
109 auto const & [cell, f] = iter->first;
110 cell->face(f)->set_boundary_id(bid);
111 }
112 }
113}
114
115template<int dim, int n_components, typename Number>
117{
118public:
119 static unsigned int const rank =
120 (n_components == 1) ? 0 : ((n_components == dim) ? 1 : dealii::numbers::invalid_unsigned_int);
121
122 typedef typename std::vector<
123 dealii::GridTools::PeriodicFacePair<typename dealii::Triangulation<dim>::cell_iterator>>
124 PeriodicFaces;
125
126 virtual void
127 add_parameters(dealii::ParameterHandler & prm, std::vector<std::string> const & subsection_names)
128 {
129 for(auto & name : subsection_names)
130 {
131 prm.enter_subsection(name);
132 }
133
134 resolution.add_parameters(prm);
135 output_parameters.add_parameters(prm);
136
137 for(auto & name : subsection_names)
138 {
139 (void)name;
140 prm.leave_subsection();
141 }
142 }
143
144 Domain(std::string parameter_file, MPI_Comm const & comm)
145 : mpi_comm(comm),
146 pcout(std::cout, dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0),
147 parameter_file(parameter_file)
148 {
149 }
150
151 virtual ~Domain()
152 {
153 }
154
155 void
156 setup_pre(std::shared_ptr<Grid<dim>> & grid,
157 std::shared_ptr<dealii::Mapping<dim>> & mapping,
158 std::shared_ptr<MultigridMappings<dim, Number>> & multigrid_mappings,
159 std::vector<std::string> const & subsection_names)
160 {
161 // parameters
162 parse_parameters(subsection_names);
163
164 // set resolution parameters
165 param.grid.n_refine_global = this->resolution.refine_space;
166 param.degree = this->resolution.degree;
167
168 set_parameters();
169 param.check();
170 param.print(pcout, "List of parameters:");
171
172 // grid
173 grid = std::make_shared<Grid<dim>>();
174 create_grid(*grid, mapping, multigrid_mappings);
175 print_grid_info(pcout, *grid);
176 }
177
178 void
179 setup_post(std::shared_ptr<Grid<dim> const> const & grid)
180 {
181 // boundary conditions
182 boundary_descriptor = std::make_shared<BoundaryDescriptor<rank, dim>>();
183 set_boundary_descriptor();
184 verify_boundary_conditions(*boundary_descriptor, *grid);
185
186 // field functions
187 field_functions = std::make_shared<FieldFunctions<dim>>();
188 set_field_functions();
189 }
190
191 virtual std::shared_ptr<Poisson::PostProcessorBase<dim, n_components, Number>>
192 create_postprocessor() const = 0;
193
194 Parameters const &
195 get_parameters() const
196 {
197 return param;
198 }
199
200 std::shared_ptr<BoundaryDescriptor<rank, dim> const>
201 get_boundary_descriptor() const
202 {
203 return boundary_descriptor;
204 }
205
206 std::shared_ptr<FieldFunctions<dim> const>
207 get_field_functions() const
208 {
209 return field_functions;
210 }
211
212protected:
213 virtual void
214 parse_parameters(std::vector<std::string> const & subsection_names)
215 {
216 dealii::ParameterHandler prm;
217 this->add_parameters(prm, subsection_names);
218 prm.parse_input(parameter_file, "", true, true);
219 }
220
221 MPI_Comm const mpi_comm;
222
223 dealii::ConditionalOStream pcout;
224
225 Parameters param;
226
227 std::shared_ptr<BoundaryDescriptor<rank, dim>> boundary_descriptor;
228 std::shared_ptr<FieldFunctions<dim>> field_functions;
229
230 std::string parameter_file;
231
233
234 OutputParameters output_parameters;
235
236private:
237 virtual void
238 set_parameters() = 0;
239
240 virtual void
241 create_grid(Grid<dim> & grid,
242 std::shared_ptr<dealii::Mapping<dim>> & mapping,
243 std::shared_ptr<MultigridMappings<dim, Number>> & multigrid_mappings) = 0;
244
245 virtual void
246 set_boundary_descriptor() = 0;
247
248 virtual void
249 set_field_functions() = 0;
250};
251
252template<int dim, int n_components, typename Number>
254{
255public:
256 ApplicationBase(std::string parameter_file, MPI_Comm const & comm)
257 : mpi_comm(comm), parameter_file(parameter_file)
258 {
259 }
260
261 void
262 add_parameters(dealii::ParameterHandler & prm)
263 {
264 AssertThrow(domain1.get(), dealii::ExcMessage("Domain 1 is uninitialized."));
265 AssertThrow(domain2.get(), dealii::ExcMessage("Domain 2 is uninitialized."));
266
267 domain1->add_parameters(prm, {"Domain1"});
268 domain2->add_parameters(prm, {"Domain2"});
269 }
270
271 virtual ~ApplicationBase()
272 {
273 }
274
275 std::shared_ptr<Domain<dim, n_components, Number>> domain1, domain2;
276
277 // use "-1" since max() is defined invalid by deal.II
278 dealii::types::boundary_id boundary_id_overlap =
279 std::numeric_limits<dealii::types::boundary_id>::max() - 1;
280
281protected:
282 MPI_Comm const mpi_comm;
283
284private:
285 std::string parameter_file;
286};
287
288} // namespace OversetGrids
289} // namespace Poisson
290} // namespace ExaDG
291
292#endif /* INCLUDE_EXADG_POISSON_OVERSET_GRIDS_USER_INTERFACE_APPLICATION_BASE_H_ */
Definition grid.h:40
Definition grid.h:84
Definition application_base.h:254
Definition application_base.h:117
Definition parameters.h:36
Definition driver.cpp:33
Definition output_parameters.h:32
Definition resolution_parameters.h:81