254 const double r_inlet = g.
r_inlet;
255 const double L_inlet = g.
L_inlet;
256 const double z_inlet = g.
z_inlet;
265 Triangulation<3> vessel;
266 build_vessel(vessel, g);
271 GridTools::rotate(Tensor<1, 3>({0., 0., 1.}),
272 numbers::PI_4 / std::pow(2.0, global_refinements),
274 vessel.refine_global(global_refinements);
276 Triangulation<3> flat_vessel;
277 GridGenerator::flatten_triangulation(vessel, flat_vessel);
283 std::vector<Point<3>> vertices = flat_vessel.get_vertices();
284 std::vector<CellData<3>> cells;
285 for (
const auto &cell : flat_vessel.active_cell_iterators())
287 CellData<3> cell_data;
288 for (
const unsigned int v : GeometryInfo<3>::vertex_indices())
289 cell_data.vertices[v] = cell->vertex_index(v);
290 cell_data.material_id = vessel_material_id;
291 cells.push_back(cell_data);
307 double inlet_axis_z = z_inlet;
308 bool axis_z_locked =
false;
310 const auto grow_inlet = [&](
const double direction ) {
312 const auto is_wall_face = [&](
const Point<3> &c) {
313 const double r_xy = std::sqrt(c[0] * c[0] + c[1] * c[1]);
314 return std::abs(r_xy - R_chamber) <= 0.15 * R_chamber &&
315 c[2] > 1e-4 * R_chamber &&
316 c[2] < z_chamber_top - 1e-4 * R_chamber && direction * c[0] > 0.0;
327 const double target_z = axis_z_locked ? inlet_axis_z : z_inlet;
328 const Point<3> ideal(direction * R_chamber, 0.0, target_z);
329 double best = std::numeric_limits<double>::max();
330 std::array<unsigned int, 4> f0{};
333 for (
const auto &cell : flat_vessel.active_cell_iterators())
334 for (
const unsigned int f : GeometryInfo<3>::face_indices())
336 const auto face = cell->face(f);
337 if (!face->at_boundary() || !is_wall_face(face->center()))
339 const double d = (face->center() - ideal).norm();
343 f0_center = face->center();
344 for (
unsigned int i = 0; i < 4; ++i)
345 f0[i] = face->vertex_index(i);
350 return std::size_t(0);
351 inlet_axis_z = f0_center[2];
352 axis_z_locked =
true;
354 const std::set<unsigned int> f0_vertices(f0.begin(), f0.end());
355 std::vector<std::array<unsigned int, 4>> port_faces;
356 for (
const auto &cell : flat_vessel.active_cell_iterators())
357 for (
const unsigned int f : GeometryInfo<3>::face_indices())
359 const auto face = cell->face(f);
360 if (!face->at_boundary() || !is_wall_face(face->center()))
363 for (
unsigned int i = 0; i < 4; ++i)
364 if (f0_vertices.count(face->vertex_index(i)))
368 std::array<unsigned int, 4> vids;
369 for (
unsigned int i = 0; i < 4; ++i)
370 vids[i] = face->vertex_index(i);
371 port_faces.push_back(vids);
376 std::set<unsigned int> patch_vertices;
377 for (
const auto &face : port_faces)
378 for (
const unsigned int vid : face)
379 patch_vertices.insert(vid);
383 for (
const unsigned int vid : patch_vertices)
385 a_max = std::max(a_max, std::abs(vertices[vid][1]));
386 b_max = std::max(b_max, std::abs(vertices[vid][2] - inlet_axis_z));
395 const double dL = L_inlet / n_pipe_layers;
396 std::map<unsigned int, std::vector<unsigned int>> column;
397 for (
const unsigned int vid : patch_vertices)
399 const double u = (a_max > 0.0) ? vertices[vid][1] / a_max : 0.0;
401 (b_max > 0.0) ? (vertices[vid][2] - inlet_axis_z) / b_max : 0.0;
402 const double disk_y = u * std::sqrt(std::max(0.0, 1.0 - 0.5 * v * v));
403 const double disk_z = v * std::sqrt(std::max(0.0, 1.0 - 0.5 * u * u));
404 const double ty = r_inlet * disk_y;
405 const double tz = inlet_axis_z + r_inlet * disk_z;
407 std::vector<unsigned int> col(n_pipe_layers + 1);
408 const double x_wall =
409 std::sqrt(std::max(0.0, R_chamber * R_chamber - ty * ty));
410 vertices[vid] = Point<3>(direction * x_wall, ty, tz);
412 for (
unsigned int j = 1; j <= n_pipe_layers; ++j)
414 vertices.emplace_back(direction * (R_chamber + j * dL), ty, tz);
415 col[j] =
static_cast<unsigned int>(vertices.size() - 1);
417 column[vid] = std::move(col);
425 for (
const auto &face : port_faces)
427 const bool is_core_column =
428 std::set<unsigned int>(face.begin(), face.end()) == f0_vertices;
429 for (
unsigned int j = 1; j <= n_pipe_layers; ++j)
432 for (
unsigned int i = 0; i < 4; ++i)
434 hex.vertices[i] = column[face[i]][j - 1];
435 hex.vertices[i + 4] = column[face[i]][j];
438 is_core_column ? pipe_core_material_id : pipe_material_id;
439 cells.push_back(hex);
443 return port_faces.size();
451 constexpr std::size_t expected_port_faces = 9;
452 const std::size_t n_port_faces_pos = grow_inlet(+1.0);
453 const std::size_t n_port_faces_neg = grow_inlet(-1.0);
455 n_port_faces_pos == expected_port_faces &&
456 n_port_faces_neg == expected_port_faces,
458 "Failed to build the impinging-jet inlet pipes: expected a 3x3 wall-face "
459 "patch (9 faces) for each inlet, but did not obtain one. This can happen "
460 "for extreme geometry parameters (e.g. an inlet axis too close to the "
461 "chamber floor or dome) or if the discretisation is changed."));
466 GridTools::invert_cells_with_negative_measure(vertices, cells);
467 GridTools::consistently_order_cells(cells);
469 triangulation.create_triangulation(vertices, cells, SubCellData());
482 const auto is_axial_opening = [](
const auto &face,
const auto &cell) {
483 const Tensor<1, 3> outward = face->center() - cell->center();
484 return std::abs(outward[0]) > 0.6 * outward.norm();
488 for (
const auto &cell : triangulation.active_cell_iterators())
489 if (cell->material_id() == vessel_material_id)
490 for (
const unsigned int f : GeometryInfo<3>::face_indices())
492 const auto face = cell->face(f);
493 if (!face->at_boundary())
496 const Point<3> c = face->center();
497 if (c[2] < z_outlet_bottom + 1e-4 * R_chamber)
500 face->set_boundary_id(outlet_boundary_id);
501 face->set_all_manifold_ids(numbers::flat_manifold_id);
503 else if (c[2] > z_chamber_top + 1e-4 * R_chamber)
506 face->set_boundary_id(wall_boundary_id);
507 face->set_all_manifold_ids(dome_manifold_id);
512 face->set_boundary_id(wall_boundary_id);
513 face->set_all_manifold_ids(cylinder_z_manifold_id);
529 for (
const auto &cell : triangulation.active_cell_iterators())
530 if (cell->material_id() == pipe_material_id)
531 cell->set_all_manifold_ids(inlet_manifold_id);
535 for (
const auto &cell : triangulation.active_cell_iterators())
536 if (cell->material_id() == pipe_core_material_id)
537 cell->set_all_manifold_ids(numbers::flat_manifold_id);
544 for (
const auto &cell : triangulation.active_cell_iterators())
545 if (cell->material_id() == pipe_material_id ||
546 cell->material_id() == pipe_core_material_id)
547 for (
const unsigned int f : GeometryInfo<3>::face_indices())
549 const auto face = cell->face(f);
550 if (!face->at_boundary())
557 if (is_axial_opening(face, cell))
559 face->set_boundary_id(face->center()[0] > 0.0 ?
562 face->set_all_manifold_ids(numbers::flat_manifold_id);
566 face->set_boundary_id(wall_boundary_id);
567 face->set_all_manifold_ids(inlet_manifold_id);
573 for (
const auto &cell : triangulation.active_cell_iterators())
574 cell->set_material_id(0);
582 const double z_shift = -inlet_axis_z;
583 GridTools::shift(Tensor<1, 3>({0., 0., z_shift}), triangulation);
598 const Point<3> dome_center(0., 0., z_dome_center + z_shift);
600 triangulation.set_manifold(cylinder_z_manifold_id,
601 CylindricalManifold<3>(Tensor<1, 3>({0., 0., 1.}),
602 Point<3>(0., 0., 0.)));
603 triangulation.set_manifold(dome_manifold_id,
604 SphericalManifold<3>(dome_center));
605 triangulation.set_manifold(inlet_manifold_id,
606 CylindricalManifold<3>(Tensor<1, 3>({1., 0., 0.}),
607 Point<3>(0., 0., 0.)));