22 if constexpr (dim == 1 || spacedim == 1)
27 "The uniform_channel_with_meshed_square_prism is only supported for <2,2> and <3,3> <dim,spacedim> specializations."));
30 else if constexpr (dim == 2 && spacedim == 3)
35 "The uniform_channel_with_meshed_square_prism is only supported for <2,2> and <3,3> <dim,spacedim> specializations."));
39 const std::vector<std::string> arguments =
40 Utilities::split_string_list(grid_arguments,
':');
42 if (arguments.size() < 5)
47 "Mandatory uniform_channel_with_meshed_square_prism parameters are (bottom left point : top right point : center of the obstacle : inner half-side : outer half-side). The points should be given as x,y and the half-sides should be single numbers. The optional parameters are (rotation_deg : pad_bottom : pad_top : pad_left : pad_right : height : n_slices : mesh_obstacle : colorize )."));
56 Point<dim>(bottom_left_coords[0], bottom_left_coords[1]) :
57 Point<dim>(bottom_left_coords[0], bottom_left_coords[1], 0.0);
59 catch (
const std::exception &e)
64 "The bottom left point should have 2 components coordinates (x,y format) because the channel is extruded in the z direction."));
72 (dim == 2) ? Point<dim>(top_right_coords[0], top_right_coords[1]) :
73 Point<dim>(top_right_coords[0], top_right_coords[1], 0.0);
75 catch (
const std::exception &e)
80 "The top right point should have 2 components coordinates (x,y format) because the channel is extruded in the z direction."));
88 this->
center = (dim == 2) ?
89 Point<dim>(center_coords[0], center_coords[1]) :
90 Point<dim>(center_coords[0], center_coords[1], 0.0);
92 catch (
const std::exception &e)
97 "The center point should have 2 components coordinates (x,y format) because the channel is extruded in the z direction."));
108 " The inner_half_side must be greater than 0 to have an object in the channel."));
113 "The outer half-side must be at least 1.5 times the inner half-side, if not the elements in the transition region will be too distorted."));
122 "The outer transition square does not fit in the channel."));
126 (arguments.size() > 5) ? Utilities::string_to_double(arguments[5]) : 0.0;
130 ExcMessage(
"The rotation angle needs to be in the range [0, 90) degrees."));
135 (arguments.size() > 6) ? Utilities::string_to_int(arguments[6]) : 0;
137 (arguments.size() > 7) ? Utilities::string_to_int(arguments[7]) : 0;
139 (arguments.size() > 8) ? Utilities::string_to_int(arguments[8]) : 0;
141 (arguments.size() > 9) ? Utilities::string_to_int(arguments[9]) : 0;
147 ExcMessage(
"Bottom padding is required because the transition "
148 "region does not reach the bottom channel boundary."));
151 ExcMessage(
"Top padding is required because the transition "
152 "region does not reach the top channel boundary."));
155 ExcMessage(
"Left padding is required because the transition "
156 "region does not reach the left channel boundary."));
159 ExcMessage(
"Right padding is required because the transition "
160 "region does not reach the right channel boundary."));
163 (arguments.size() > 10) ? Utilities::string_to_double(arguments[10]) : 1.0;
165 (arguments.size() > 11) ? Utilities::string_to_int(arguments[11]) : 2;
166 AssertThrow(
n_slices >= 2, ExcMessage(
"The minimum number of slices is 2."));
168 (arguments.size() > 12 && arguments[12] ==
"true") ? true :
false;
170 (arguments.size() > 13 && arguments[13] ==
"true") ? true :
false;
189 const types::material_id fluid_id = 0;
190 const types::material_id obstacle_id = 1;
193 Triangulation<2> obstacle_tria;
203 GridGenerator::hyper_ball_balanced(obstacle_tria,
208 GridTools::transform(
209 [&](
const Point<2> &p) {
210 const double dist = p.distance(
center);
213 if (dist <= tol_inner)
223 (std::abs(std::abs(p[0] -
center[0]) - std::abs(p[1] -
center[1])) <
230 (std::abs(std::abs(p[0] -
center[0]) - std::abs(p[1] -
center[1])) >=
242 GridTools::transform(
243 [&](
const Point<2> &p) {
244 const double x_rel = p[0] -
center[0];
245 const double y_rel = p[1] -
center[1];
246 return Point<2>(
center[0] + cos_a * x_rel - sin_a * y_rel,
247 center[1] + sin_a * x_rel + cos_a * y_rel);
259 std::array<Point<2>, 8> outer_targets;
260 for (
unsigned int k = 0; k < 8; ++k)
273 theta = (k + 1) * std::numbers::pi / 4.0;
285 theta = k * std::numbers::pi / 4.0;
293 theta = (k + 2) * std::numbers::pi / 4.0;
297 const double cx = std::cos(theta);
298 const double cy = std::sin(theta);
301 outer_targets[k] =
center + Point<2>(scale * cx, scale * cy);
307 GridTools::transform(
308 [&](
const Point<2> &p) {
309 const double dist = p.distance(
center);
317 double min_angle = -1.0;
318 Point<2> closest = outer_targets[0];
325 const Tensor<1, 2> p_normalize = (p -
center) / (p -
center).norm();
326 for (
const Point<2> &candidate : outer_targets)
328 const Tensor<1, 2> target_normalize =
330 const double cos_angle = p_normalize * target_normalize;
332 if (cos_angle > min_angle)
334 min_angle = cos_angle;
348 std::vector<double> top_x, bottom_x, left_y, right_y;
349 for (
unsigned int k = 0; k < 8; ++k)
351 const Point<2> &q = outer_targets[k];
352 const double theta = std::atan2(q[1] -
center[1], q[0] -
center[0]);
353 const double abs_cx = std::abs(std::cos(theta));
354 const double abs_cy = std::abs(std::sin(theta));
358 if (std::abs(abs_cx - abs_cy) < 1e-12)
365 if (std::cos(theta) > 0.0)
366 right_y.push_back(q[1]);
368 left_y.push_back(q[1]);
374 if (std::sin(theta) > 0.0)
375 top_x.push_back(q[0]);
377 bottom_x.push_back(q[0]);
380 std::ranges::sort(top_x);
381 std::ranges::sort(bottom_x);
382 std::ranges::sort(left_y);
383 std::ranges::sort(right_y);
392 auto make_steps = [](
const std::vector<double> &inner_coords,
396 std::vector<double> coords = {lo};
397 for (
const double c : inner_coords)
399 coords.push_back(hi);
402 std::vector<double> steps;
403 for (std::size_t i = 1; i < coords.size(); ++i)
404 steps.push_back(coords[i] - coords[i - 1]);
410 auto uniform = [](
const unsigned int n,
const double length) {
411 return std::vector<double>(n, length /
static_cast<double>(n));
415 Triangulation<2> pad_bottom_tria;
417 GridGenerator::subdivided_hyper_rectangle(
419 {make_steps(bottom_x,
427 Triangulation<2> pad_top_tria;
429 GridGenerator::subdivided_hyper_rectangle(
439 Triangulation<2> pad_left_tria;
441 GridGenerator::subdivided_hyper_rectangle(
451 Triangulation<2> pad_right_tria;
453 GridGenerator::subdivided_hyper_rectangle(
464 Triangulation<2> pad_bottom_left_corner_tria;
466 GridGenerator::subdivided_hyper_rectangle(
467 pad_bottom_left_corner_tria,
472 Triangulation<2> pad_bottom_right_corner_tria;
474 GridGenerator::subdivided_hyper_rectangle(
475 pad_bottom_right_corner_tria,
480 Triangulation<2> pad_top_left_corner_tria;
482 GridGenerator::subdivided_hyper_rectangle(
483 pad_top_left_corner_tria,
488 Triangulation<2> pad_top_right_corner_tria;
490 GridGenerator::subdivided_hyper_rectangle(
491 pad_top_right_corner_tria,
497 std::vector<const Triangulation<2> *> trias = {&obstacle_tria};
499 trias.push_back(&pad_bottom_tria);
501 trias.push_back(&pad_top_tria);
503 trias.push_back(&pad_left_tria);
505 trias.push_back(&pad_right_tria);
507 trias.push_back(&pad_bottom_left_corner_tria);
509 trias.push_back(&pad_bottom_right_corner_tria);
511 trias.push_back(&pad_top_left_corner_tria);
513 trias.push_back(&pad_top_right_corner_tria);
514 GridGenerator::merge_triangulations(trias, triangulation);
516 triangulation.reset_all_manifolds();
517 triangulation.set_all_manifold_ids(0);
522 for (
const auto &cell : triangulation.active_cell_iterators())
524 const Point<2> c = cell->center();
527 const double dx = c[0] -
center[0];
528 const double dy = c[1] -
center[1];
534 const double x_local = cos_a * dx + sin_a * dy;
535 const double y_local = -sin_a * dx + cos_a * dy;
538 const bool inside_obstacle =
542 cell->set_material_id(inside_obstacle ? obstacle_id : fluid_id);
549 std::set<typename Triangulation<2>::active_cell_iterator> obstacle_cells;
552 for (
const auto &cell : triangulation.active_cell_iterators())
554 if (cell->material_id() == obstacle_id)
555 obstacle_cells.insert(cell);
557 Triangulation<2> temp_tria;
558 GridGenerator::create_triangulation_with_removed_cells(triangulation,
561 triangulation.clear();
562 triangulation.copy_triangulation(temp_tria);
573 for (
const auto &face : triangulation.active_face_iterators())
575 if (!face->at_boundary())
577 const Point<2> fc = face->center();
580 else if (std::abs(fc[0] -
top_right[0]) < tol_x)
584 else if (std::abs(fc[1] -
top_right[1]) < tol_y)
587 face->set_boundary_id(0);