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 EXADG_POISSON_OVERSET_GRIDS_USER_INTERFACE_APPLICATION_BASE_H_
23#define 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 typename dealii::Utilities::MPI::RemotePointEvaluation<dim>::AdditionalData rpe_data;
77 std::vector<bool> marked_vertices = {};
78 rpe_data.tolerance = 1.e-10;
79 rpe_data.marked_vertices = [marked_vertices]() { return marked_vertices; };
80
81 dealii::Utilities::MPI::RemotePointEvaluation<dim> rpe =
82 dealii::Utilities::MPI::RemotePointEvaluation<dim>(rpe_data);
83 rpe.reinit(points, tria_src, mapping_src);
84
85 // check which points have been found and whether a face on dst-side is located inside the src
86 // triangulation
87 for(auto iter = id_to_vector_index.begin(); iter != id_to_vector_index.end(); ++iter)
88 {
89 unsigned int const begin = iter->second;
90 unsigned int const end =
91 (iter + 1 != id_to_vector_index.end()) ? (iter + 1)->second : points.size();
92
93 bool inside = true;
94 for(unsigned int i = begin; i < end; ++i)
95 {
96 inside = (inside and rpe.point_found(i));
97 }
98
99 if(inside)
100 {
101 auto const & [cell, f] = iter->first;
102 cell->face(f)->set_boundary_id(bid);
103 }
104 }
105}
106
107template<int dim, int n_components, typename Number>
108class Domain
109{
110public:
111 static unsigned int const rank =
112 (n_components == 1) ? 0 : ((n_components == dim) ? 1 : dealii::numbers::invalid_unsigned_int);
113
114 typedef typename std::vector<
115 dealii::GridTools::PeriodicFacePair<typename dealii::Triangulation<dim>::cell_iterator>>
116 PeriodicFaces;
117
118 virtual void
119 add_parameters(dealii::ParameterHandler & prm, std::vector<std::string> const & subsection_names)
120 {
121 for(auto & name : subsection_names)
122 {
123 prm.enter_subsection(name);
124 }
125
126 resolution.add_parameters(prm);
127 output_parameters.add_parameters(prm);
128
129 for(auto & name : subsection_names)
130 {
131 (void)name;
132 prm.leave_subsection();
133 }
134 }
135
136 Domain(std::string parameter_file, MPI_Comm const & comm)
137 : mpi_comm(comm),
138 pcout(std::cout, dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0),
139 parameter_file(parameter_file)
140 {
141 }
142
143 virtual ~Domain()
144 {
145 }
146
147 void
148 setup_pre(std::shared_ptr<Grid<dim>> & grid,
149 std::shared_ptr<dealii::Mapping<dim>> & mapping,
150 std::shared_ptr<MultigridMappings<dim, Number>> & multigrid_mappings,
151 std::vector<std::string> const & subsection_names)
152 {
153 // parameters
154 parse_parameters(subsection_names);
155
156 // set resolution parameters
157 param.grid.n_refine_global = this->resolution.refine_space;
158 param.degree = this->resolution.degree;
159
160 set_parameters();
161 param.check();
162 param.print(pcout, "List of parameters:");
163
164 // grid
165 grid = std::make_shared<Grid<dim>>();
166 create_grid(*grid, mapping, multigrid_mappings);
167 print_grid_info(pcout, *grid);
168 }
169
170 void
171 setup_post(std::shared_ptr<Grid<dim> const> const & grid)
172 {
173 // boundary conditions
174 boundary_descriptor = std::make_shared<BoundaryDescriptor<rank, dim>>();
175 set_boundary_descriptor();
176 verify_boundary_conditions(*boundary_descriptor, *grid);
177
178 // field functions
179 field_functions = std::make_shared<FieldFunctions<dim>>();
180 set_field_functions();
181 }
182
183 virtual std::shared_ptr<Poisson::PostProcessorBase<dim, n_components, Number>>
184 create_postprocessor() const = 0;
185
186 Parameters const &
187 get_parameters() const
188 {
189 return param;
190 }
191
192 std::shared_ptr<BoundaryDescriptor<rank, dim> const>
193 get_boundary_descriptor() const
194 {
195 return boundary_descriptor;
196 }
197
198 std::shared_ptr<FieldFunctions<dim> const>
199 get_field_functions() const
200 {
201 return field_functions;
202 }
203
204protected:
205 virtual void
206 parse_parameters(std::vector<std::string> const & subsection_names)
207 {
208 dealii::ParameterHandler prm;
209 this->add_parameters(prm, subsection_names);
210 prm.parse_input(parameter_file, "", true, true);
211 }
212
213 MPI_Comm const mpi_comm;
214
215 dealii::ConditionalOStream pcout;
216
217 Parameters param;
218
219 std::shared_ptr<BoundaryDescriptor<rank, dim>> boundary_descriptor;
220 std::shared_ptr<FieldFunctions<dim>> field_functions;
221
222 std::string parameter_file;
223
225
226 OutputParameters output_parameters;
227
228private:
229 virtual void
230 set_parameters() = 0;
231
232 virtual void
233 create_grid(Grid<dim> & grid,
234 std::shared_ptr<dealii::Mapping<dim>> & mapping,
235 std::shared_ptr<MultigridMappings<dim, Number>> & multigrid_mappings) = 0;
236
237 virtual void
238 set_boundary_descriptor() = 0;
239
240 virtual void
241 set_field_functions() = 0;
242};
243
244template<int dim, int n_components, typename Number>
245class ApplicationBase
246{
247public:
248 ApplicationBase(std::string parameter_file, MPI_Comm const & comm)
249 : mpi_comm(comm), parameter_file(parameter_file)
250 {
251 }
252
253 void
254 add_parameters(dealii::ParameterHandler & prm)
255 {
256 AssertThrow(domain1.get(), dealii::ExcMessage("Domain 1 is uninitialized."));
257 AssertThrow(domain2.get(), dealii::ExcMessage("Domain 2 is uninitialized."));
258
259 domain1->add_parameters(prm, {"Domain1"});
260 domain2->add_parameters(prm, {"Domain2"});
261 }
262
263 virtual ~ApplicationBase()
264 {
265 }
266
267 std::shared_ptr<Domain<dim, n_components, Number>> domain1, domain2;
268
269 // use "-1" since max() is defined invalid by deal.II
270 dealii::types::boundary_id boundary_id_overlap =
271 std::numeric_limits<dealii::types::boundary_id>::max() - 1;
272
273protected:
274 MPI_Comm const mpi_comm;
275
276private:
277 std::string parameter_file;
278};
279
280} // namespace OversetGrids
281} // namespace Poisson
282} // namespace ExaDG
283
284#endif /* EXADG_POISSON_OVERSET_GRIDS_USER_INTERFACE_APPLICATION_BASE_H_ */
Definition grid.h:40
Definition grid.h:84
Definition parameters.h:38
Definition driver.cpp:33
Definition output_parameters.h:34
Definition resolution_parameters.h:83