Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
grids.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
13#include <core/grids.h>
14#include <core/utilities.h>
15
16#include <deal.II/base/conditional_ostream.h>
17#include <deal.II/base/mpi.h>
18#include <deal.II/base/types.h>
19
20#include <deal.II/grid/grid_generator.h>
21#include <deal.II/grid/grid_in.h>
22#include <deal.II/grid/grid_tools.h>
23#include <deal.II/grid/tria.h>
24
25#include <algorithm>
26#include <fstream>
27#include <iostream>
28#include <numbers>
29#include <string>
30
31
32/**
33 * @brief Warn when a mesh scaling factor is applied to a grid which carries curved manifolds
34 *
35 * Meshes generated by deal.II (type = dealii) or by Lethe's built-in generators
36 * (type = lethe) may carry curved manifolds attached to the triangulation.
37 * GridTools::scale moves the vertices but does not scale their attached
38 * manifolds, so a scale factor other than 1 can leave the manifolds
39 * inconsistent with the mesh and distort curved geometries under refinement.
40 * The scaling is still applied, but the user is warned so that the resulting
41 * mesh can be checked; such geometries can alternatively be scaled through
42 * the grid arguments.
43 *
44 * Grids whose cells and faces all use the flat manifold, such as the
45 * hyper_cube or hyper_rectangle grids commonly used to delimit a mesh
46 * refinement box, are invariant under scaling and do not trigger the warning.
47 * Neither do gmsh meshes, which carry no manifold.
48 *
49 * @param[in] mesh_parameters The mesh parameters used to generate the grid
50 *
51 * @param[in] triangulation The triangulation the grid was attached to. It must
52 * already carry its manifold ids, hence the check is made after the grid
53 * generation.
54 */
55template <int dim, int spacedim>
56static void
58 const Parameters::Mesh<dim, spacedim> &mesh_parameters,
59 const Triangulation<dim, spacedim> &triangulation)
60{
61 if (mesh_parameters.scale == 1.0 ||
63 return;
64
65 const std::vector<types::manifold_id> &manifold_ids =
66 triangulation.get_manifold_ids();
67 const bool has_curved_manifold =
68 std::any_of(manifold_ids.begin(),
69 manifold_ids.end(),
70 [](const types::manifold_id id) {
71 return id != numbers::flat_manifold_id;
72 });
73 if (!has_curved_manifold)
74 return;
75
76 // The triangulation of a refinement box is serial, and its communicator is
77 // consequently MPI_COMM_SELF. MPI_COMM_WORLD is used instead to ensure that
78 // the warning is printed by a single process in every case.
79 const ConditionalOStream pcout(
80 std::cout, Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0);
81 pcout
82 << "WARNING: a mesh 'scale' factor of " << mesh_parameters.scale
83 << " is being applied to a '"
85 "dealii" :
86 "lethe")
87 << "' grid. \nScaling moves the mesh vertices but not the curved "
88 "manifolds attached to the triangulation, which can distort the "
89 "geometry under refinement. \nVerify the resulting mesh, or dimension "
90 "the geometry through the grid arguments instead."
91 << std::endl;
92}
93
94template <int dim, int spacedim>
95void
97 Triangulation<dim, spacedim> &triangulation,
98 const Parameters::Mesh<dim, spacedim> &mesh_parameters)
99
100{
101 // GMSH input
103 {
104 // The mesh file is checked here, before the branch below, so that every
105 // rank raises the same error. The simplex branch reads the file from
106 // within a lambda that is only run by the root of each group of
107 // processes, and a check placed there would leave the other ranks
108 // waiting.
109 check_file_exists(mesh_parameters.file_name,
110 "gmsh mesh file given by 'subsection mesh' - "
111 "'set file name'");
112
113 if (mesh_parameters.simplex)
114 {
115 auto comm = triangulation.get_mpi_communicator();
116 std::string file_name = mesh_parameters.file_name;
117
118 auto construction_data = TriangulationDescription::Utilities::
119 create_description_from_triangulation_in_groups<dim, spacedim>(
120 [file_name](dealii::Triangulation<dim, spacedim> &basetria) {
121 GridIn<dim, spacedim> grid_in;
122 grid_in.attach_triangulation(basetria);
123 std::ifstream input_file(file_name);
124
125 grid_in.read_msh(input_file);
126 },
127 [](dealii::Triangulation<dim, spacedim> &basetria,
128 const MPI_Comm comm,
129 const unsigned int /*group_size*/) {
130#if defined(DEAL_II_WITH_METIS)
131 GridTools::partition_triangulation(
132 Utilities::MPI::n_mpi_processes(comm),
133 basetria,
134 SparsityTools::Partitioner::metis);
135#elif defined(DEAL_II_WITH_ZOLTAN)
136 GridTools::partition_triangulation(
137 Utilities::MPI::n_mpi_processes(comm),
138 basetria,
139 SparsityTools::Partitioner::zoltan);
140#else
141 AssertThrow(
142 false,
143 ExcMessage(
144 "Parallel simulation with simplex meshes require that deal.II be compiled with either Metis or Zoltan"));
145#endif
146 },
147 comm,
148 Utilities::MPI::n_mpi_processes(comm) /* group size */,
149 dealii::Triangulation<dim, spacedim>::none);
150
151 triangulation.create_triangulation(construction_data);
152 GridTools::scale(mesh_parameters.scale, triangulation);
153 }
154 else
155 {
156 GridIn<dim, spacedim> grid_in;
157 grid_in.attach_triangulation(triangulation);
158 std::ifstream input_file(mesh_parameters.file_name);
159 grid_in.read_msh(input_file);
160 GridTools::scale(mesh_parameters.scale, triangulation);
161 }
162 }
163 // Dealii grids
164 else if (mesh_parameters.type ==
166 {
167 if (mesh_parameters.simplex)
168 {
169 Triangulation<dim, spacedim> temporary_quad_triangulation;
170 GridGenerator::generate_from_name_and_arguments(
171 temporary_quad_triangulation,
172 mesh_parameters.grid_type,
173 mesh_parameters.grid_arguments);
174
175 // Scale, rotate, and translate the mesh. The transformation is
176 // applied to the quad/hex mesh, before it is refined and converted
177 // to simplices, exactly as it is applied before the refinement of a
178 // quad/hex mesh.
179 apply_mesh_transformation(mesh_parameters,
180 temporary_quad_triangulation);
181
182 // initial refinement
183 const unsigned int initial_refinement =
184 mesh_parameters.initial_refinement;
185 temporary_quad_triangulation.refine_global(initial_refinement);
186
187 // flatten the triangulation
188 Triangulation<dim, spacedim> flat_temp_quad_triangulation;
189 GridGenerator::flatten_triangulation(temporary_quad_triangulation,
190 flat_temp_quad_triangulation);
191
192 Triangulation<dim, spacedim> temporary_tri_triangulation(
193 Triangulation<dim, spacedim>::limit_level_difference_at_vertices);
194 GridGenerator::convert_hypercube_to_simplex_mesh(
195 flat_temp_quad_triangulation, temporary_tri_triangulation);
196
197 GridTools::partition_triangulation_zorder(
198 Utilities::MPI::n_mpi_processes(
199 triangulation.get_mpi_communicator()),
200 temporary_tri_triangulation);
201 GridTools::partition_multigrid_levels(temporary_tri_triangulation);
202
203 // extract relevant information from distributed triangulation
204 auto construction_data = TriangulationDescription::Utilities::
205 create_description_from_triangulation(
206 temporary_tri_triangulation,
207 triangulation.get_mpi_communicator(),
208 TriangulationDescription::Settings::
209 construct_multigrid_hierarchy);
210 triangulation.create_triangulation(construction_data);
211 }
212 else
213 {
214 GridGenerator::generate_from_name_and_arguments(
215 triangulation,
216 mesh_parameters.grid_type,
217 mesh_parameters.grid_arguments);
218
219 // Scale, rotate, and translate mesh
220 apply_mesh_transformation(mesh_parameters, triangulation);
221 }
222
223 // deal.II colorize some meshes material ID in a way that is not
224 // compatible with the way we use material ID and boundary ID in Lethe
225 // (e.g. GridGenerator ::subdivided_hyper_rectangle). Therefore, we reset
226 // all material IDs to zero for dealii meshes.
227 for (const auto &cell : triangulation.active_cell_iterators())
228 cell->set_material_id(0);
229 }
230
231 else if (mesh_parameters.type == Parameters::Mesh<dim, spacedim>::Type::lethe)
232 {
233 std::string grid_type = mesh_parameters.grid_type;
234
235 // Customizable cylinder mesh
236 if (grid_type.starts_with("cylinder_"))
237 {
238 AssertThrow(
239 !mesh_parameters.simplex,
240 ExcMessage(
241 "Unsupported mesh type - custom cylinder mesh with simplex is not supported. Use a dealii cylinder to use simplex mesh."));
242
243 GridCylinder<dim, spacedim> grid(grid_type,
244 mesh_parameters.grid_arguments);
245 grid.make_grid(triangulation);
246
247 GridTools::scale(mesh_parameters.scale, triangulation);
248 }
249 // Periodic Hills grid
250 else if (grid_type == "periodic_hills")
251 {
252 AssertThrow(
253 !mesh_parameters.simplex,
254 ExcMessage(
255 "Unsupported mesh type - periodic hills mesh with simplex is not supported"));
256
258 grid.make_grid(triangulation);
259
260 GridTools::scale(mesh_parameters.scale, triangulation);
261 }
262 else if (grid_type == "fichera_oven")
263 {
264 AssertThrow(
265 !mesh_parameters.simplex,
266 ExcMessage(
267 "Unsupported mesh type - Fichera oven mesh with simplex is not supported"));
268
270 grid.make_grid(triangulation);
271
272 GridTools::scale(mesh_parameters.scale, triangulation);
273 }
274 else if (grid_type == "birmingham_fluidized_bed")
275 {
276 AssertThrow(
277 !mesh_parameters.simplex,
278 ExcMessage(
279 "Unsupported mesh type - Birmingham fluidized bed mesh with simplex is not supported"));
280
282 mesh_parameters.grid_arguments);
283 grid.make_grid(triangulation);
284
285 GridTools::scale(mesh_parameters.scale, triangulation);
286 }
287 else if (grid_type == "impinging_jet_mixer")
288 {
289 AssertThrow(
290 !mesh_parameters.simplex,
291 ExcMessage(
292 "Unsupported mesh type - impinging jet mixer mesh with simplex is not supported"));
293
295 mesh_parameters.grid_arguments);
296 grid.make_grid(triangulation);
297
298 GridTools::scale(mesh_parameters.scale, triangulation);
299 }
300 else if (grid_type == "uniform_channel_with_meshed_cylinder")
301 {
302 AssertThrow(
303 !mesh_parameters.simplex,
304 ExcMessage(
305 "Unsupported mesh type - uniform_channel_with_meshed_cylinder mesh with simplex is not supported"));
306
308 mesh_parameters.grid_arguments);
309 grid.make_grid(triangulation);
310
311 GridTools::scale(mesh_parameters.scale, triangulation);
312 }
313 else if (grid_type == "uniform_channel_with_meshed_square_prism")
314 {
315 AssertThrow(
316 !mesh_parameters.simplex,
317 ExcMessage(
318 "Unsupported mesh type - uniform_channel_with_meshed_square_prism mesh with simplex is not supported"));
319
321 mesh_parameters.grid_arguments);
322 grid.make_grid(triangulation);
323
324 GridTools::scale(mesh_parameters.scale, triangulation);
325 }
326 else if (grid_type == "pipe_and_waveguide")
327 {
328 AssertThrow(
329 !mesh_parameters.simplex,
330 ExcMessage(
331 "Unsupported mesh type - pipe_and_waveguide mesh with simplex is not supported"));
332
334 mesh_parameters.grid_arguments);
335 grid.make_grid(triangulation);
336
337 GridTools::scale(mesh_parameters.scale, triangulation);
338 }
339 else if (grid_type == "cube_merged")
340 {
341 AssertThrow(
342 !mesh_parameters.simplex,
343 ExcMessage(
344 "Unsupported mesh type - cube_merged mesh with simplex is not supported"));
345
346 GridCubeMerged<dim, spacedim> grid(mesh_parameters.grid_arguments);
347 grid.make_grid(triangulation);
348
349 GridTools::scale(mesh_parameters.scale, triangulation);
350 }
351
352 else
353 {
354 AssertThrow(false,
355 ExcMessage(
356 "Unsupported mesh type - mesh will not be created"));
357 }
358 }
359
360 warn_if_scaling_curved_manifolds(mesh_parameters, triangulation);
361}
362
363
364
365template <int dim, int spacedim>
366void
368 parallel::DistributedTriangulationBase<dim, spacedim> &triangulation,
369 const Parameters::PeriodicBoundaries &periodic_boundaries)
370
371{
372 // Setup periodic boundary conditions. Each periodic pair is stored once,
373 // keyed by the principal boundary id of the pair.
374 for (auto const &[id, periodic_boundary] : periodic_boundaries)
375 {
376 auto triangulation_ptr = &triangulation;
377
378 std::vector<GridTools::PeriodicFacePair<
379 typename Triangulation<dim, spacedim>::cell_iterator>>
380 periodicity_vector;
381 GridTools::collect_periodic_faces(
382 *dynamic_cast<Triangulation<dim, spacedim> *>(triangulation_ptr),
383 id,
384 periodic_boundary.neighbor_id,
385 periodic_boundary.direction,
386 periodicity_vector);
387 triangulation.add_periodicity(periodicity_vector);
388 }
389}
390
391
392
393/**
394 * @brief Apply the initial refinement described by the mesh parameters
395 *
396 * This is the refinement carried out once, right after the grid has been
397 * attached to the triangulation. Nothing is refined when restarting, since the
398 * mesh stored in the checkpoint has already been refined.
399 *
400 * @param[in] mesh_parameters The mesh parameters used to decide how the
401 * triangulation is refined
402 *
403 * @param[in] restart Flag indicating whether this is a restart
404 *
405 * @param[in,out] triangulation The triangulation which must be refined
406 */
407template <int dim, int spacedim>
408static void
410 const Parameters::Mesh<dim, spacedim> &mesh_parameters,
411 const bool restart,
412 parallel::DistributedTriangulationBase<dim, spacedim> &triangulation)
413{
414 // Refinement of simplex meshes isn't possible yet. For dealii simplex meshes,
415 // the initial refinement was already applied to the quad/hex mesh from which
416 // the simplex mesh was generated, within attach_grid_to_triangulation.
417 if (mesh_parameters.simplex)
418 return;
419
420 // On a restart, the triangulation is subsequently replaced by the one stored
421 // in the checkpoint, which already carries its refinement.
422 if (restart)
423 return;
424
425 if (mesh_parameters.refine_until_target_size)
426 {
427 const double minimal_cell_size =
428 GridTools::minimal_cell_diameter(triangulation);
429 const double target_size = mesh_parameters.target_size;
430 const unsigned int number_refinement =
431 static_cast<unsigned int>(std::floor(
432 std::log(minimal_cell_size / target_size) / std::numbers::ln2));
433 triangulation.refine_global(number_refinement);
434 }
435 else
436 {
437 triangulation.refine_global(mesh_parameters.initial_refinement);
439 mesh_parameters.boundaries_to_refine,
440 mesh_parameters.initial_refinement_at_boundaries,
441 triangulation);
442 }
443}
444
445template <int dim, int spacedim>
446void
448 parallel::DistributedTriangulationBase<dim, spacedim> &triangulation,
449 const Parameters::Mesh<dim, spacedim> &mesh_parameters,
450 const Parameters::Manifolds &manifolds_parameters,
451 const bool restart,
452 const Parameters::PeriodicBoundaries &periodic_boundaries)
453{
454 attach_grid_to_triangulation(triangulation, mesh_parameters);
455
456 setup_periodic_boundary_conditions(triangulation, periodic_boundaries);
457
458 // If the mesh is a GMSH mesh, we need to manually set the manifold id
459 // of the face to be that of the boundary
460 // ID, otherwise, we will be unable to use external manifold.
461 // This is done manually by looping through all faces and giving them a
462 // manifold id if there is a manifold associated with this number.
464 {
465 // Gather all the manifold ids within a set
466 std::set<int> manifold_ids;
467 for (const unsigned int id : manifolds_parameters.ids)
468 manifold_ids.insert(id);
469
470 // Reset all the manifolds manually and force them to zero
471 triangulation.reset_all_manifolds();
472
473 // If the parameter file forces the occurrence of manifold,
474 // loop over the faces of the triangulation. If the face of the
475 // triangulation has a boundary id which corresponds to a manifold id
476 // identified within the parameter file, then fix the manifold id of
477 // this face manually to be that of the boundary id. In the past, this
478 // was done by default for every face, but since 2023-12 this throws
479 // (rightfully) an error in deal.II
480 if (manifolds_parameters.ids.size() > 0)
481 {
482 for (const auto &face : triangulation.active_face_iterators())
483 {
484 if (face->at_boundary() &&
485 manifold_ids.contains(face->boundary_id()))
486 face->set_all_manifold_ids(face->boundary_id());
487 }
488 }
489 }
490
491 // Finally attach the manifolds to the triangulation
492 // Right now this should only occur for GMSH mesh, but the function is
493 // generic enough.
494 attach_manifolds_to_triangulation(triangulation, manifolds_parameters);
495
496 apply_initial_refinement(mesh_parameters, restart, triangulation);
497}
498
499template <int dim, int spacedim>
500void
502 parallel::DistributedTriangulationBase<dim, spacedim> &triangulation,
503 const Parameters::Mesh<dim, spacedim> &mesh_parameters,
504 const Parameters::Manifolds &manifolds_parameters,
505 const bool restart,
506 const Parameters::PeriodicBoundaries &periodic_boundaries,
507 const Parameters::Mortar<dim> &mortar_parameters)
508{
509 // If linear mortar manager, only two-dimensional cases are supported
510 if (mortar_parameters.interface_type ==
512 if constexpr (dim == 3)
513 AssertThrow(
514 false,
515 ExcMessage(
516 "The linear mortar interface type supports only two-dimensional cases at the moment."));
517
518 // Check if stator and rotor meshes are of the same type
519 AssertThrow(
520 mesh_parameters.type == mortar_parameters.rotor_mesh->type,
521 ExcMessage(
522 "The mesh types for the rotor and stator geometries must be the same."));
523
524 // Since the rotor and stator meshes are read separately, a dummy
525 // triangulation is created for each part of the domain and then merged
526
527 // Stator triangulation
528 Triangulation<dim> stator_temp_tria;
529 attach_grid_to_triangulation(stator_temp_tria, mesh_parameters);
530
531 // Rotor triangulation
532 Triangulation<dim> rotor_temp_tria;
533 attach_grid_to_triangulation(rotor_temp_tria, *mortar_parameters.rotor_mesh);
534
535 // Add a flag to cells on the rotor and stator triangulations; this will be
536 // needed when attributing them an angular velocity. We use the material_id
537 // flag because it won't be erased when the triangulations are merged.
538 for (const auto &cell : rotor_temp_tria.active_cell_iterators())
539 cell->set_material_id(1);
540
541 for (const auto &cell : stator_temp_tria.active_cell_iterators())
542 cell->set_material_id(0);
543
545 {
546 // Get stator manifold ids without flat id
547 unsigned int stator_ids_no_flat = 0;
548 for (const auto &id : stator_temp_tria.get_manifold_ids())
549 {
550 if (id != numbers::flat_manifold_id)
551 stator_ids_no_flat++;
552 }
553
554 // Get rotor manifold ids without flat id
555 unsigned int rotor_ids_no_flat = 0;
556 for (const auto &id : rotor_temp_tria.get_manifold_ids())
557 {
558 if (id != numbers::flat_manifold_id)
559 rotor_ids_no_flat++;
560 }
561
562 // Shift rotor boundary IDs #
563 unsigned int n_boundary_ids_stator =
564 stator_temp_tria.get_boundary_ids().size();
565 for (const auto &face : rotor_temp_tria.active_face_iterators())
566 if (face->at_boundary())
567 face->set_boundary_id(face->boundary_id() + n_boundary_ids_stator);
568
569 // Keep track of modified IDs in faces and lines
570 std::vector<bool> changed_manifold_ids_faces(
571 rotor_temp_tria.n_active_faces(), false);
572 std::vector<bool> changed_manifold_ids_lines(
573 rotor_temp_tria.n_active_lines(), false);
574
575 // Shift rotor manifold IDs #
576 for (const auto &cell : rotor_temp_tria.active_cell_iterators())
577 {
578 if (cell->manifold_id() != numbers::flat_manifold_id)
579 cell->set_manifold_id(cell->manifold_id() + stator_ids_no_flat);
580 for (const auto &face : cell->face_iterators())
581 {
582 if (face->manifold_id() != numbers::flat_manifold_id &&
583 !changed_manifold_ids_faces[face->index()])
584 {
585 face->set_manifold_id(face->manifold_id() +
586 stator_ids_no_flat);
587 changed_manifold_ids_faces[face->index()] = true;
588 }
589 if constexpr (dim == 3)
590 {
591 for (const auto line_index : cell->line_indices())
592 {
593 if (cell->line(line_index)->manifold_id() !=
594 numbers::flat_manifold_id &&
595 !changed_manifold_ids_lines[line_index])
596 cell->line(line_index)
597 ->set_manifold_id(
598 cell->line(line_index)->manifold_id() +
599 stator_ids_no_flat);
600 changed_manifold_ids_lines[line_index] = true;
601 }
602 }
603 }
604 }
605
606 // Store rotor manifolds in shifted IDs #
607 for (unsigned int m = 0; m < rotor_temp_tria.get_manifold_ids().size();
608 m++)
609 {
610 unsigned int temp = rotor_temp_tria.get_manifold_ids()[m];
611 if (temp != numbers::flat_manifold_id)
612 rotor_temp_tria.set_manifold(m + stator_ids_no_flat,
613 rotor_temp_tria.get_manifold(m));
614 }
615
616 // Merge triangulations
617 GridGenerator::merge_triangulations(
618 stator_temp_tria, rotor_temp_tria, triangulation, 0.0, true, true);
619
620 // Attach manifolds to merged triangulation
621 unsigned int n = 0;
622 for (unsigned int i = 0; i < stator_ids_no_flat; i++)
623 {
624 triangulation.set_manifold(n, stator_temp_tria.get_manifold(i));
625 n++;
626 }
627 for (unsigned int j = stator_ids_no_flat;
628 j < stator_ids_no_flat + rotor_ids_no_flat;
629 j++)
630 {
631 triangulation.set_manifold(n, rotor_temp_tria.get_manifold(j));
632 n++;
633 }
634 }
635 else if (mesh_parameters.type == Parameters::Mesh<dim, spacedim>::Type::gmsh)
636 {
637 // Merge triangulations
638 GridGenerator::merge_triangulations(
639 stator_temp_tria, rotor_temp_tria, triangulation, 0.0, true, true);
640
641 // Gather all the manifold ids within a set
642 std::set<int> manifold_ids;
643 for (const unsigned int id : manifolds_parameters.ids)
644 manifold_ids.insert(id);
645
646 // Reset all the manifolds manually and force them to zero
647 triangulation.reset_all_manifolds();
648
649 // Set manifolds
650 if (manifolds_parameters.ids.size() > 0)
651 {
652 for (const auto &face : triangulation.active_face_iterators())
653 {
654 if (face->at_boundary() &&
655 manifold_ids.contains(face->boundary_id()))
656 face->set_all_manifold_ids(face->boundary_id());
657 }
658 }
659
660 // Attach manifolds to rotor-stator triangulation
661 attach_manifolds_to_triangulation(triangulation, manifolds_parameters);
662 }
663 else
664 throw std::runtime_error(
665 "Unsupported mesh type - mesh will not be created");
666
667 // Setup boundary conditions
668 setup_periodic_boundary_conditions(triangulation, periodic_boundaries);
669
670 // Initial mesh refinement
671 apply_initial_refinement(mesh_parameters, restart, triangulation);
672
673 // Faces at rotor-stator interface
674 unsigned int n_faces_rotor_interface = 0;
675 unsigned int n_faces_stator_interface = 0;
676
677 // Check number of faces at the rotor-stator interface
678 for (const auto &cell : triangulation.active_cell_iterators())
679 if (cell->is_locally_owned())
680 for (const auto face_no : cell->face_indices())
681 if (cell->face(face_no)->at_boundary())
682 {
683 if (cell->face(face_no)->boundary_id() ==
684 mortar_parameters.rotor_boundary_id)
685 n_faces_rotor_interface++;
686 if (cell->face(face_no)->boundary_id() ==
687 mortar_parameters.stator_boundary_id)
688 n_faces_stator_interface++;
689 }
690
691 // Total number of faces
692 const unsigned int n_faces_rotor_interface_total =
693 Utilities::MPI::sum(n_faces_rotor_interface,
694 triangulation.get_mpi_communicator());
695 const unsigned int n_faces_stator_interface_total =
696 Utilities::MPI::sum(n_faces_stator_interface,
697 triangulation.get_mpi_communicator());
698
699 AssertThrow(
700 n_faces_rotor_interface_total == n_faces_stator_interface_total,
701 ExcMessage(
702 "The number of faces at the rotor interface ID #" +
703 std::to_string(mortar_parameters.rotor_boundary_id) + " (" +
704 std::to_string(n_faces_rotor_interface_total) +
705 ") is different from the number of faces at the stator interface ID #" +
706 std::to_string(mortar_parameters.stator_boundary_id) + " (" +
707 std::to_string(n_faces_stator_interface_total) + ")."));
708}
709
710template <int dim, int spacedim>
711void
713 const Parameters::Mesh<dim, spacedim> &box_mesh_parameters,
714 Triangulation<dim, spacedim> &box_triangulation)
715{
716 attach_grid_to_triangulation(box_triangulation, box_mesh_parameters);
717
718 // The initial refinement of a simplex dealii box mesh has already been
719 // applied to the quad/hex mesh it was generated from, within
720 // attach_grid_to_triangulation. Applying it again here would refine the box
721 // twice.
722 if (!box_mesh_parameters.simplex)
723 box_triangulation.refine_global(box_mesh_parameters.initial_refinement);
724}
725
726template <int dim, int spacedim>
727void
729 const Parameters::Mesh<dim, spacedim> &mesh_parameters,
730 Triangulation<dim, spacedim> &triangulation)
731{
732 // Mesh scaling
733 GridTools::scale(mesh_parameters.scale, triangulation);
734 if constexpr (spacedim == 2)
735 {
736 // Box mesh rotation around the origin of the system coordinates
737 GridTools::rotate(mesh_parameters.rotation_angle, triangulation);
738
739 // Box mesh translation
740 GridTools::shift(mesh_parameters.translation, triangulation);
741 }
742 else if constexpr (spacedim == 3)
743 {
744 // Box mesh rotation
745 GridTools::rotate(mesh_parameters.rotation_axis,
746 mesh_parameters.rotation_angle,
747 triangulation);
748
749 // Box mesh translation
750 GridTools::shift(mesh_parameters.translation, triangulation);
751 }
752}
753
754
755template void
756attach_grid_to_triangulation(Triangulation<2> &triangulation,
757 const Parameters::Mesh<2> &mesh_parameters);
758template void
759attach_grid_to_triangulation(Triangulation<3> &triangulation,
760 const Parameters::Mesh<3> &mesh_parameters);
761template void
762attach_grid_to_triangulation(Triangulation<2, 3> &triangulation,
763 const Parameters::Mesh<2, 3> &mesh_parameters);
764
765
766template void
768 parallel::DistributedTriangulationBase<2, 2> &triangulation,
769 const Parameters::PeriodicBoundaries &periodic_boundaries);
770template void
772 parallel::DistributedTriangulationBase<2, 3> &triangulation,
773 const Parameters::PeriodicBoundaries &periodic_boundaries);
774template void
776 parallel::DistributedTriangulationBase<3, 3> &triangulation,
777 const Parameters::PeriodicBoundaries &periodic_boundaries);
778
779template void
781 parallel::DistributedTriangulationBase<2> &triangulation,
782 const Parameters::Mesh<2> &mesh_parameters,
783 const Parameters::Manifolds &manifolds_parameters,
784 const bool restart,
785 const Parameters::PeriodicBoundaries &periodic_boundaries);
786template void
788 parallel::DistributedTriangulationBase<3> &triangulation,
789 const Parameters::Mesh<3> &mesh_parameters,
790 const Parameters::Manifolds &manifolds_parameters,
791 const bool restart,
792 const Parameters::PeriodicBoundaries &periodic_boundaries);
793template void
795 parallel::DistributedTriangulationBase<2, 3> &triangulation,
796 const Parameters::Mesh<2, 3> &mesh_parameters,
797 const Parameters::Manifolds &manifolds_parameters,
798 const bool restart,
799 const Parameters::PeriodicBoundaries &periodic_boundaries);
800
801template void
803 parallel::DistributedTriangulationBase<2> &triangulation,
804 const Parameters::Mesh<2> &mesh_parameters,
805 const Parameters::Manifolds &manifolds_parameters,
806 const bool restart,
807 const Parameters::PeriodicBoundaries &periodic_boundaries,
808 const Parameters::Mortar<2> &mortar_parameters);
809template void
811 parallel::DistributedTriangulationBase<3> &triangulation,
812 const Parameters::Mesh<3> &mesh_parameters,
813 const Parameters::Manifolds &manifolds_parameters,
814 const bool restart,
815 const Parameters::PeriodicBoundaries &periodic_boundaries,
816 const Parameters::Mortar<3> &mortar_parameters);
817
818template void
820 const Parameters::Mesh<2> &box_mesh_parameters,
821 Triangulation<2, 2> &box_triangulation);
822template void
824 const Parameters::Mesh<2, 3> &box_mesh_parameters,
825 Triangulation<2, 3> &box_triangulation);
826template void
828 const Parameters::Mesh<3> &box_mesh_parameters,
829 Triangulation<3, 3> &box_triangulation);
830
831template void
833 Triangulation<2, 2> &triangulation);
834template void
836 Triangulation<2, 3> &triangulation);
837template void
839 Triangulation<3, 3> &triangulation);
Generates a 3D mesh for the Birmingham fluidized bed geometry.
void make_grid(Triangulation< dim, spacedim > &triangulation)
Generate the Birmingham fluidized bed mesh.
Class that creates a custom geometry that combines an extruded plate with a hole and an inner cylinde...
void make_grid(Triangulation< dim, spacedim > &triangulation)
Generate the merged cube mesh.
Generates a 3D Fichera oven mesh by removing cells from a subdivided hyper-rectangle.
void make_grid(Triangulation< dim, spacedim > &triangulation)
Generate the Fichera oven mesh by removing cells from a subdivided hyper-rectangle.
Generates a 3D mesh for an impinging-jet mixer geometry.
void make_grid(Triangulation< dim, spacedim > &triangulation)
Generate the impinging-jet mixer mesh.
Class that creates a hyper_rectangle and transforms it to obtain the hill geometry with the hill_geom...
void make_grid(Triangulation< dim, spacedim > &triangulation)
make_grid. The make_grid function generates a hyper rectangle of the size of the domain and then tran...
Generates a 3D mesh of a waveguide embedded in a cylindrical cavity in which a liquid flows.
Generates a rectangular channel mesh with a meshed cylinder obstacle. By default, this geometry defin...
void make_grid(Triangulation< dim, spacedim > &triangulation)
Generate the 2D or 3D channel mesh with a meshed cylinder and attach manifold objects for proper mesh...
Generates a rectangular channel mesh with a meshed square obstacle in 2D (extruded to a square prism ...
void make_grid(Triangulation< dim, spacedim > &triangulation)
Generate the 2D/3D channel mesh with a meshed square obstacle.
Manifolds - This class manages attaching manifolds to faces when a manual attachment is required (for...
Definition manifolds.h:25
std::vector< unsigned int > ids
Definition manifolds.h:38
Mesh - Parameters that control mesh reading and mesh generation.
unsigned int initial_refinement_at_boundaries
bool simplex
Allow the use of a simplex mesh.
std::string file_name
File name of the mesh.
Tensor< 1, spacedim > translation
double target_size
Target size when automatically refining initial mesh.
Tensor< 1, spacedim > rotation_axis
bool refine_until_target_size
Enable fixing initial refinement from a target size.
std::vector< int > boundaries_to_refine
List of boundary ids to refine.
unsigned int initial_refinement
Initial refinement level of primitive mesh.
std::string grid_arguments
Arguments of the GridTools.
std::string grid_type
Name of the grid in GridTools.
double scale
Rescale the grid by the scale factor.
void check_file_exists(const std::string &file_name, const std::string &file_description)
Verify that a file that Lethe must read exists and can be opened, and raise an error stated in the us...
Definition utilities.cc:225
void setup_periodic_boundary_conditions(parallel::DistributedTriangulationBase< dim, spacedim > &triangulation, const Parameters::PeriodicBoundaries &periodic_boundaries)
Modifies the triangulation to set up its periodic boundary conditions.
Definition grids.cc:367
void apply_mesh_transformation(const Parameters::Mesh< dim, spacedim > &mesh_parameters, Triangulation< dim, spacedim > &triangulation)
Apply scaling, rotation and translation to the mesh in the listed order.
Definition grids.cc:728
static void warn_if_scaling_curved_manifolds(const Parameters::Mesh< dim, spacedim > &mesh_parameters, const Triangulation< dim, spacedim > &triangulation)
Warn when a mesh scaling factor is applied to a grid which carries curved manifolds.
Definition grids.cc:57
void attach_grid_to_triangulation(Triangulation< dim, spacedim > &triangulation, const Parameters::Mesh< dim, spacedim > &mesh_parameters)
Attaches a grid to a triangulation using mesh parameters.
Definition grids.cc:96
static void apply_initial_refinement(const Parameters::Mesh< dim, spacedim > &mesh_parameters, const bool restart, parallel::DistributedTriangulationBase< dim, spacedim > &triangulation)
Apply the initial refinement described by the mesh parameters.
Definition grids.cc:409
void read_mesh_and_manifolds(parallel::DistributedTriangulationBase< dim, spacedim > &triangulation, const Parameters::Mesh< dim, spacedim > &mesh_parameters, const Parameters::Manifolds &manifolds_parameters, const bool restart, const Parameters::PeriodicBoundaries &periodic_boundaries)
Completely sets up a mesh and its manifolds.
Definition grids.cc:447
void build_refinement_box_triangulation(const Parameters::Mesh< dim, spacedim > &box_mesh_parameters, Triangulation< dim, spacedim > &box_triangulation)
Build the triangulation which delimits a mesh refinement box.
Definition grids.cc:712
void read_mesh_and_manifolds_for_stator_and_rotor(parallel::DistributedTriangulationBase< dim, spacedim > &triangulation, const Parameters::Mesh< dim, spacedim > &mesh_parameters, const Parameters::Manifolds &manifolds_parameters, const bool restart, const Parameters::PeriodicBoundaries &periodic_boundaries, const Parameters::Mortar< dim > &mortar_parameters)
Completely sets up a mesh and its manifolds for rotor-stator domains.
Definition grids.cc:501
void refine_triangulation_at_boundaries(const std::vector< int > &boundary_ids, const unsigned int n_refinement, parallel::DistributedTriangulationBase< dim, spacedim > &triangulation)
Refine a mesh around specific boundary ids.
Definition grids.h:122
void attach_manifolds_to_triangulation(parallel::DistributedTriangulationBase< dim, spacedim > &triangulation, const Parameters::Manifolds manifolds)
Attaches manifold to boundaries of the triangulation.
Definition manifolds.cc:110
std::map< dealii::types::boundary_id, PeriodicBoundary > PeriodicBoundaries
The periodic boundary pairs of a simulation, keyed by the principal (first) boundary id of each pair.
Mortar - Defines parameters used to construct mortar elements.
unsigned int stator_boundary_id
Boundary ID # of the stator at the rotor-stator interface.
unsigned int rotor_boundary_id
Boundary ID # of the rotor at the rotor-stator interface.
std::shared_ptr< Mesh< dim > > rotor_mesh
Mesh parameters for the rotor part.
enum Parameters::Mortar::InterfaceType interface_type