3#include <deal.II/grid/grid_generator.h>
4#include <deal.II/grid/grid_out.h>
5#include <deal.II/grid/grid_tools.h>
6#include <deal.II/grid/manifold_lib.h>
7#include <deal.II/grid/tria.h>
8#include <deal.II/grid/tria_description.h>
32template <
int dim,
int spacedim>
40 const bool inner_circle)
42 const auto embed_point = [](
const double x,
const double y) -> Point<2> {
43 return Point<2>(x, y);
46 const auto vertices = [&]() -> std::vector<Point<2>> {
50 p + embed_point(-1., -1.) * (r / std::numbers::sqrt2),
51 p + embed_point(+1., -1.) * (r / std::numbers::sqrt2),
52 p + embed_point(-1., +1.) * (r / std::numbers::sqrt2),
53 p + embed_point(+1., +1.) * (r / std::numbers::sqrt2),
55 p + embed_point(-1., +1.) * (R / std::numbers::sqrt2),
56 p + embed_point(+1., +1.) * (R / std::numbers::sqrt2),
57 p + embed_point(-1., -1.) * (R / std::numbers::sqrt2),
58 p + embed_point(+1., -1.) * (R / std::numbers::sqrt2),
63 p + embed_point(0, -r),
64 p + embed_point(0, +r),
67 p + embed_point(std::sqrt(r * r - a * a / 4), -a / 2),
68 p + embed_point(std::sqrt(r * r - a * a / 4), +a / 2),
71 p + embed_point(-(std::sqrt(R * R - a * a / 4)), +a / 2),
72 p + embed_point(-(std::sqrt(R * R - a * a / 4)), -a / 2),
73 p + embed_point(+(std::sqrt(R * R - a * a / 4)), -a / 2),
74 p + embed_point(+(std::sqrt(R * R - a * a / 4)), +a / 2),
76 p + embed_point(0, -R),
77 p + embed_point(0, +R),
80 p + embed_point(0, +a / 2),
81 p + embed_point(0, -a / 2)};
86 p + embed_point(-1., -1.) * (r / std::numbers::sqrt2),
87 p + embed_point(+1., -1.) * (r / std::numbers::sqrt2),
88 p + embed_point(-1., +1.) * (r / std::numbers::sqrt2),
89 p + embed_point(+1., +1.) * (r / std::numbers::sqrt2),
91 p + embed_point(-1., -1.) * R,
92 p + embed_point(+1., -1.) * R,
93 p + embed_point(-1., +1.) * R,
94 p + embed_point(+1., +1.) * R,
99 p + embed_point(0, -r),
100 p + embed_point(0, +r),
103 p + embed_point(std::sqrt(r * r - a * a / 4), -a / 2),
104 p + embed_point(std::sqrt(r * r - a * a / 4), +a / 2),
107 p + embed_point(-R, +a / 2),
108 p + embed_point(-R, -a / 2),
109 p + embed_point(+R, -a / 2),
110 p + embed_point(+R, +a / 2),
112 p + embed_point(0, -R),
113 p + embed_point(0, +R),
116 p + embed_point(0, +a / 2),
117 p + embed_point(0, -a / 2)};
120 std::vector<CellData<2>> cells(16, CellData<2>());
121 static constexpr int circle_cell_vertices[16][4] = {
141 for (
unsigned int i = 0; i < 16; ++i)
143 for (
unsigned int j = 0; j < 4; ++j)
144 cells[i].vertices[j] = circle_cell_vertices[i][j];
147 tria.create_triangulation(std::vector<Point<2>>(std::begin(vertices),
151 tria.set_all_manifold_ids_on_boundary(0);
152 tria.set_manifold(0, SphericalManifold<2, 2>(p));
153 tria.set_manifold(1, FlatManifold<2, 2>());
160template <
int dim,
int spacedim>
162 const std::string &grid_arguments)
164 const std::vector<std::string> arguments =
165 Utilities::split_string_list(grid_arguments,
':');
167 rectangle_width = std::stod(arguments[0]);
168 rectangle_length = std::stod(arguments[1]);
169 outer_radius = std::stod(arguments[2]);
170 inner_length = std::stod(arguments[3]);
171 bottom_height = std::stod(arguments[4]);
172 middle_height = std::stod(arguments[5]);
173 top_height = std::stod(arguments[6]);
174 bottom_resolution = std::stoi(arguments[7]);
175 middle_resolution = std::stoi(arguments[8]);
176 top_resolution = std::stoi(arguments[9]);
177 inner_circle = (arguments[10] ==
"true");
180template <
int dim,
int spacedim>
183 Triangulation<dim, spacedim> &triangulation)
203 inner_length > rectangle_width / 2,
205 "The inner shape is not bigger than the rectangle that crosses the cylinder along the x-axis. This situations leads to the generation of inverted cells"));
208 inner_length < outer_radius,
210 "The internal radius is greater than the external radius. This situations leads to the generation of inverted cells"));
217 inner_length > rectangle_width / 2,
219 "The square side is too small compared to the width of the waveguide. This situations leads to the generation of inverted cells"));
222 inner_length < outer_radius / (std::sqrt(2)),
224 "The inner square length is greater than the external radius. This situations leads to the generation of inverted cells"));
228 if constexpr (!(dim == 3 && spacedim == 3))
231 ExcMessage(
"GridPipeAndWaveguide is only supported in 3D."));
245 Triangulation<2> rect;
246 GridGenerator::hyper_rectangle(
247 rect, Point<2>(0.0, 0.0), Point<2>(rectangle_length, rectangle_width));
251 Triangulation<2> disk;
253 const Point<2> center(rectangle_length +
254 sqrt(outer_radius * outer_radius -
255 rectangle_width * rectangle_width / 4),
256 rectangle_width / 2);
257 detailed_circle(disk,
265 Triangulation<2> merged;
269 GridGenerator::merge_triangulations(rect, disk, merged, 1e-12,
false);
272 Triangulation<2, 2> base;
273 detailed_circle(base,
282 Triangulation<2, 2> top;
293 Triangulation<3> extruded_base;
294 Triangulation<3> extruded_middle;
295 Triangulation<3> extruded_top;
296 GridGenerator::extrude_triangulation(base,
300 GridGenerator::extrude_triangulation(merged,
304 GridGenerator::extrude_triangulation(top,
313 auto attach_cylindrical_manifold_id = [&](Triangulation<3> &tria,
315 for (
const auto &cell : tria.active_cell_iterators())
316 if (cell->center()[0] >= rectangle_length - 1e-6)
319 for (
const auto f : cell->face_indices())
320 if (cell->face(f)->at_boundary())
322 const Point<3> face_center = cell->face(f)->center();
323 if (std::abs(face_center[2]) > 1e-10 &&
324 std::abs(face_center[2] - height) > 1e-10)
328 cell->set_all_manifold_ids(1);
332 attach_cylindrical_manifold_id(extruded_base, bottom_height);
333 attach_cylindrical_manifold_id(extruded_middle, middle_height);
334 attach_cylindrical_manifold_id(extruded_top, top_height);
338 const Point<3> center_3d(center[0], center[1], 0.0);
339 const Tensor<1, 3> axis({0.0, 0.0, 1.0});
340 extruded_base.set_manifold(1, CylindricalManifold<3>(axis, center_3d));
341 extruded_middle.set_manifold(1, CylindricalManifold<3>(axis, center_3d));
342 extruded_top.set_manifold(1, CylindricalManifold<3>(axis, center_3d));
347 Tensor<1, 3> shift_down;
350 shift_down[2] = -bottom_height;
352 GridTools::shift(shift_down, extruded_base);
355 Tensor<1, 3> shift_up;
358 shift_up[2] = +middle_height;
360 GridTools::shift(shift_up, extruded_top);
364 std::vector<const Triangulation<3, 3> *> parts = {&extruded_base,
368 GridGenerator::merge_triangulations(
376 triangulation.set_manifold(1, CylindricalManifold<3>(axis, center_3d));
393 for (
auto &cell : triangulation.active_cell_iterators())
396 for (
const auto f : cell->face_indices())
398 if (cell->face(f)->at_boundary())
400 const Point<3> face_center = cell->face(f)->center();
401 if (face_center[0] <= 1e-6)
402 cell->face(f)->set_boundary_id(0);
403 else if (face_center[2] <= -bottom_height + 1e-6)
404 cell->face(f)->set_boundary_id(1);
405 else if (face_center[2] >= middle_height + top_height - 1e-6)
406 cell->face(f)->set_boundary_id(2);
408 cell->face(f)->set_boundary_id(
413 if (cell->center()[0] <= rectangle_length)
414 cell->set_material_id(1);
416 cell->set_material_id(0);
Generates a 3D mesh of a waveguide embedded in a cylindrical cavity in which a liquid flows.