deal.II version GIT relicensing-2659-g040196caa3 2025-02-18 14:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
grid_generator.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 1999 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
17
21
27#include <deal.II/grid/tria.h>
30
32
33#include <array>
34#include <cmath>
35#include <limits>
36
37
39
40// work around the problem that doxygen for some reason lists all template
41// specializations in this file
42#ifndef DOXYGEN
43
44namespace GridGenerator
45{
46 namespace Airfoil
47 {
49 // airfoil configuration
50 : airfoil_type("NACA")
51 , naca_id("2412")
52 , joukowski_center(-0.1, 0.14)
53 , airfoil_length(1.0)
54 // far field
55 , height(30.0)
56 , length_b2(15.0)
57 // mesh
58 , incline_factor(0.35)
59 , bias_factor(2.5)
60 , refinements(2)
61 , n_subdivision_x_0(3)
62 , n_subdivision_x_1(2)
63 , n_subdivision_x_2(5)
64 , n_subdivision_y(3)
65 , airfoil_sampling_factor(2)
66 {
67 Assert(
68 airfoil_length <= height,
70 "Mesh is to small to enclose airfoil! Choose larger field or smaller"
71 " chord length!"));
73 ExcMessage("incline_factor has to be in [0,1)!"));
74 }
75
76
77
78 void
79 AdditionalData::add_parameters(ParameterHandler &prm)
80 {
81 prm.enter_subsection("FarField");
82 {
83 prm.add_parameter(
84 "Height",
85 height,
86 "Mesh height measured from airfoil nose to horizontal boundaries");
87 prm.add_parameter(
88 "LengthB2",
89 length_b2,
90 "Length measured from airfoil leading edge to vertical outlet boundary");
91 prm.add_parameter(
92 "InclineFactor",
93 incline_factor,
94 "Define obliqueness of the vertical mesh around the airfoil");
95 }
96 prm.leave_subsection();
97
98 prm.enter_subsection("AirfoilType");
99 {
100 prm.add_parameter(
101 "Type",
102 airfoil_type,
103 "Type of airfoil geometry, either NACA or Joukowski airfoil",
104 Patterns::Selection("NACA|Joukowski"));
105 }
106 prm.leave_subsection();
107
108 prm.enter_subsection("NACA");
109 {
110 prm.add_parameter("NacaId", naca_id, "Naca serial number");
111 }
112 prm.leave_subsection();
113
114 prm.enter_subsection("Joukowski");
115 {
116 prm.add_parameter("Center",
117 joukowski_center,
118 "Joukowski circle center coordinates");
119 prm.add_parameter("AirfoilLength",
120 airfoil_length,
121 "Joukowski airfoil length leading to trailing edge");
122 }
123 prm.leave_subsection();
124
125 prm.enter_subsection("Mesh");
126 {
127 prm.add_parameter("Refinements",
128 refinements,
129 "Number of global refinements");
130 prm.add_parameter(
131 "NumberSubdivisionX0",
132 n_subdivision_x_0,
133 "Number of subdivisions along the airfoil in blocks with material ID 1 and 4");
134 prm.add_parameter(
135 "NumberSubdivisionX1",
136 n_subdivision_x_1,
137 "Number of subdivisions along the airfoil in blocks with material ID 2 and 5");
138 prm.add_parameter(
139 "NumberSubdivisionX2",
140 n_subdivision_x_2,
141 "Number of subdivisions in horizontal direction on the right of the trailing edge, i.e., blocks with material ID 3 and 6");
142 prm.add_parameter("NumberSubdivisionY",
143 n_subdivision_y,
144 "Number of subdivisions normal to airfoil");
145 prm.add_parameter(
146 "BiasFactor",
147 bias_factor,
148 "Factor to obtain a finer mesh at the airfoil surface");
149 }
150 prm.leave_subsection();
151 }
152
153
154 namespace
155 {
159 class MeshGenerator
160 {
161 public:
162 // IDs of the mesh blocks
163 static const unsigned int id_block_1 = 1;
164 static const unsigned int id_block_2 = 2;
165 static const unsigned int id_block_3 = 3;
166 static const unsigned int id_block_4 = 4;
167 static const unsigned int id_block_5 = 5;
168 static const unsigned int id_block_6 = 6;
169
173 MeshGenerator(const AdditionalData &data)
174 : refinements(data.refinements)
175 , n_subdivision_x_0(data.n_subdivision_x_0)
176 , n_subdivision_x_1(data.n_subdivision_x_1)
177 , n_subdivision_x_2(data.n_subdivision_x_2)
178 , n_subdivision_y(data.n_subdivision_y)
179 , height(data.height)
180 , length_b2(data.length_b2)
181 , incline_factor(data.incline_factor)
182 , bias_factor(data.bias_factor)
183 , edge_length(1.0)
184 , n_cells_x_0(Utilities::pow(2, refinements) * n_subdivision_x_0)
185 , n_cells_x_1(Utilities::pow(2, refinements) * n_subdivision_x_1)
186 , n_cells_x_2(Utilities::pow(2, refinements) * n_subdivision_x_2)
187 , n_cells_y(Utilities::pow(2, refinements) * n_subdivision_y)
189 // create points on the airfoil
191 // call either the 'joukowski' or 'naca' static member function
192 data.airfoil_type == "Joukowski" ?
193 joukowski(data.joukowski_center,
195 data.airfoil_sampling_factor) :
196 (data.airfoil_type == "NACA" ?
197 naca(data.naca_id,
199 data.airfoil_sampling_factor) :
200 std::array<std::vector<Point<2>>, 2>{
201 {std::vector<Point<2>>{Point<2>(0), Point<2>(1)},
202 std::vector<Point<2>>{
203 Point<2>(0),
204 Point<2>(
205 1)}}} /* dummy vector since we are asserting later*/),
206 data.airfoil_length))
209 , nose_x(airfoil_1D[0].front()[0])
210 , tail_x(airfoil_1D[0].back()[0])
211 , tail_y(airfoil_1D[0].back()[1])
214 , gamma(std::atan(height /
216 // points on coarse grid
217 // coarse grid has to be symmetric in respect to x-axis to allow
218 // periodic BC and make sure that interpolate() works
219 , A(nose_x - edge_length, 0)
220 , B(nose_x, 0)
222 , D(center_mesh, height)
224 , F(center_mesh, -height)
225 , G(tail_x, height)
226 , H(tail_x, 0)
227 , I(tail_x, -height)
228 , J(tail_x + length_b2, 0)
229 , K(J[0], G[1])
230 , L(J[0], I[1])
231 {
232 Assert(data.airfoil_type == "Joukowski" ||
233 data.airfoil_type == "NACA",
234 ExcMessage("Unknown airfoil type."));
235 }
236
240 void
243 std::vector<GridTools::PeriodicFacePair<
245 {
247
249
250 if (periodic_faces != nullptr)
251 {
253 tria_grid, 5, 4, 1, *periodic_faces);
254 tria_grid.add_periodicity(*periodic_faces);
255 }
256
257 tria_grid.refine_global(refinements);
259 }
260
264 void
267 std::vector<GridTools::PeriodicFacePair<
269 {
272
273 AssertThrow(false, ExcMessage("Not implemented, yet!")); // TODO [PM]
274 }
275
276 private:
277 // number of global refinements
278 const unsigned int refinements;
279
280 // number of subdivisions of coarse grid in blocks 1 and 4
281 const unsigned int n_subdivision_x_0;
282
283 // number of subdivisions of coarse grid in blocks 2 and 5
284 const unsigned int n_subdivision_x_1;
285
286 // number of subdivisions of coarse grid in blocks 3 and 6
287 const unsigned int n_subdivision_x_2;
288
289 // number of subdivisions of coarse grid in all blocks (normal to
290 // airfoil or in y-direction, respectively)
291 const unsigned int n_subdivision_y;
292
293 // height of mesh, i.e. length JK or JL and radius of semicircle
294 // (C-Mesh) that arises after interpolation in blocks 1 and 4
295 const double height;
296
297 // length block 3 and 6
298 const double length_b2;
299
300 // factor to move points G and I horizontal to the right, i.e. make
301 // faces HG and HI inclined instead of vertical
302 const double incline_factor;
303
304 // bias factor (if factor goes to zero than equal y = x)
305 const double bias_factor;
306
307 // x-distance between coarse grid vertices A and B, i.e. used only once;
308 const double edge_length;
309
310 // number of cells (after refining) in block 1 and 4 along airfoil
311 const unsigned int n_cells_x_0;
312
313 // number of cells (after refining) in block 2 and 5 along airfoil
314 const unsigned int n_cells_x_1;
315
316 // number of cells (after refining) in block 3 and 6 in x-direction
317 const unsigned int n_cells_x_2;
318
319 // number of cells (after refining) in all blocks normal to airfoil or
320 // in y-direction, respectively
321 const unsigned int n_cells_y;
322
323 // number of airfoil points on each side
324 const unsigned int n_points_on_each_side;
325
326 // vector containing upper/lower airfoil points. First and last point
327 // are identical
328 const std::array<std::vector<Point<2>>, 2> airfoil_1D;
329
330 // x-coordinate of n-th airfoilpoint where n indicates number of cells
331 // in block 1. end_b0_x_u = end_b0_x_l for symmetric airfoils
332 const double end_b0_x_u;
333
334 // x-coordinate of n-th airfoilpoint where n indicates number of cells
335 // in block 4. end_b0_x_u = end_b0_x_l for symmetric airfoils
336 const double end_b0_x_l;
337
338 // x-coordinate of first airfoil point in airfoil_1d[0] and
339 // airfoil_1d[1]
340 const double nose_x;
341
342 // x-coordinate of last airfoil point in airfoil_1d[0] and airfoil_1d[1]
343 const double tail_x;
344
345 // y-coordinate of last airfoil point in airfoil_1d[0] and airfoil_1d[1]
346 const double tail_y;
347
348 // x-coordinate of C,D,E,F indicating ending of blocks 1 and 4 or
349 // beginning of blocks 2 and 5, respectively
350 const double center_mesh;
351
352 // length of blocks 2 and 5
353 const double length_b1_x;
354
355 // angle enclosed between faces DAB and FAB
356 const double gamma;
357
358
359
380 const Point<2> A, B, C, D, E, F, G, H, I, J, K, L;
381
382
383
419 static std::array<std::vector<Point<2>>, 2>
421 const unsigned int number_points,
422 const unsigned int factor)
423 {
424 std::array<std::vector<Point<2>>, 2> airfoil_1D;
425 const unsigned int total_points = 2 * number_points - 2;
426 const unsigned int n_airfoilpoints = factor * total_points;
427 // joukowski points on the entire airfoil, i.e. upper and lower side
428 const auto jouk_points =
430
431 // vectors to collect airfoil points on either upper or lower side
432 std::vector<Point<2>> upper_points;
433 std::vector<Point<2>> lower_points;
434
435 {
436 // find point on nose and point on tail
437 unsigned int nose_index = 0;
438 unsigned int tail_index = 0;
439 double nose_x_coordinate = 0;
440 double tail_x_coordinate = 0;
441
442
443 // find index in vector to nose point (min) and tail point (max)
444 for (unsigned int i = 0; i < jouk_points.size(); ++i)
445 {
446 if (jouk_points[i][0] < nose_x_coordinate)
447 {
449 nose_index = i;
450 }
451 if (jouk_points[i][0] > tail_x_coordinate)
452 {
454 tail_index = i;
455 }
456 }
457
458 // copy point on upper side of airfoil
459 for (unsigned int i = tail_index; i < jouk_points.size(); ++i)
460 upper_points.emplace_back(jouk_points[i]);
461 for (unsigned int i = 0; i <= nose_index; ++i)
462 upper_points.emplace_back(jouk_points[i]);
463 std::reverse(upper_points.begin(), upper_points.end());
464
465 // copy point on lower side of airfoil
466 lower_points.insert(lower_points.end(),
467 jouk_points.begin() + nose_index,
468 jouk_points.begin() + tail_index + 1);
469 }
470
473
474 // move nose to origin
475 auto move_nose_to_origin = [](std::vector<Point<2>> &vector) {
476 const double nose_x_pos = vector.front()[0];
477 for (auto &i : vector)
478 i[0] -= nose_x_pos;
479 };
480
483
484 return airfoil_1D;
485 }
486
511 static std::vector<Point<2>>
512 joukowski_circle(const Point<2> &center,
513 const unsigned int number_points)
514 {
515 std::vector<Point<2>> circle_points;
516
517 // Create Circle with number_points - points
518 // unsigned int number_points = 2 * points_per_side - 2;
519
520 // Calculate radius so that point (x=1|y=0) is enclosed - requirement
521 // for Joukowski transform
522 const double radius = std::sqrt(center[1] * center[1] +
523 (1 - center[0]) * (1 - center[0]));
524 const double radius_test = std::sqrt(
525 center[1] * center[1] + (1 + center[0]) * (1 + center[0]));
526 // Make sure point (x=-1|y=0) is enclosed by the circle
529 radius_test < radius,
531 "Error creating lower circle: Circle for Joukowski-transform does"
532 " not enclose point zeta = -1! Choose different center "
533 "coordinate."));
534 // Create a full circle with radius 'radius' around Point 'center' of
535 // (number_points) equidistant points.
536 const double theta = 2 * numbers::PI / number_points;
537 // first point is leading edge then counterclockwise
538 for (unsigned int i = 0; i < number_points; ++i)
539 circle_points.emplace_back(center[0] - radius * cos(i * theta),
540 center[1] - radius * sin(i * theta));
541
542 return circle_points;
543 }
544
553 static std::vector<Point<2>>
554 joukowski_transform(const std::vector<Point<2>> &circle_points)
555 {
556 std::vector<Point<2>> joukowski_points(circle_points.size());
557
558 // transform each point
559 for (unsigned int i = 0; i < circle_points.size(); ++i)
560 {
561 const double chi = circle_points[i][0];
562 const double eta = circle_points[i][1];
563 const std::complex<double> zeta(chi, eta);
564 const std::complex<double> z = zeta + 1. / zeta;
565
566 joukowski_points[i] = {real(z), imag(z)};
567 }
568 return joukowski_points;
569 }
570
587 static std::array<std::vector<Point<2>>, 2>
588 naca(const std::string &serialnumber,
589 const unsigned int number_points,
590 const unsigned int factor)
591 {
592 // number of non_equidistant airfoilpoints among which will be
593 // interpolated
594 const unsigned int n_airfoilpoints = factor * number_points;
595
596 // create equidistant airfoil points for upper and lower side
602 number_points)}};
603 }
604
616 static std::vector<Point<2>>
617 naca_create_points(const std::string &serialnumber,
618 const unsigned int number_points,
619 const bool is_upper)
620 {
621 Assert(serialnumber.size() == 4,
622 ExcMessage("This NACA-serial number is not implemented!"));
623
626 is_upper);
627 }
628
643 static std::vector<Point<2>>
644 naca_create_points_4_digits(const std::string &serialnumber,
645 const unsigned int number_points,
646 const bool is_upper)
647 {
648 // conversion string (char * ) to int
649 const unsigned int digit_0 = (serialnumber[0] - '0');
650 const unsigned int digit_1 = (serialnumber[1] - '0');
651 const unsigned int digit_2 = (serialnumber[2] - '0');
652 const unsigned int digit_3 = (serialnumber[3] - '0');
653
654 const unsigned int digit_23 = 10 * digit_2 + digit_3;
655
656 // maximum thickness in percentage of the cord
657 const double t = static_cast<double>(digit_23) / 100.0;
658
659 std::vector<Point<2>> naca_points;
660
661 if (digit_0 == 0 && digit_1 == 0) // is symmetric
662 for (unsigned int i = 0; i < number_points; ++i)
663 {
664 const double x = i * 1 / (1.0 * number_points - 1);
665 const double y_t =
666 5 * t *
667 (0.2969 * std::sqrt(x) - 0.126 * x -
668 0.3516 * Utilities::fixed_power<2>(x) +
669 0.2843 * Utilities::fixed_power<3>(x) -
670 0.1036 * Utilities::fixed_power<4>(
671 x)); // half thickness at a position x
672
673 if (is_upper)
674 naca_points.emplace_back(x, +y_t);
675 else
676 naca_points.emplace_back(x, -y_t);
677 }
678 else // is asymmetric
679 for (unsigned int i = 0; i < number_points; ++i)
680 {
681 const double m = 1.0 * digit_0 / 100; // max. chamber
682 const double p = 1.0 * digit_1 / 10; // location of max. chamber
683 const double x = i * 1 / (1.0 * number_points - 1);
684
685 const double y_c =
686 (x <= p) ?
687 m / Utilities::fixed_power<2>(p) *
688 (2 * p * x - Utilities::fixed_power<2>(x)) :
689 m / Utilities::fixed_power<2>(1 - p) *
690 ((1 - 2 * p) + 2 * p * x - Utilities::fixed_power<2>(x));
691
692 const double dy_c =
693 (x <= p) ? 2 * m / Utilities::fixed_power<2>(p) * (p - x) :
694 2 * m / Utilities::fixed_power<2>(1 - p) * (p - x);
695
696 const double y_t =
697 5 * t *
698 (0.2969 * std::sqrt(x) - 0.126 * x -
699 0.3516 * Utilities::fixed_power<2>(x) +
700 0.2843 * Utilities::fixed_power<3>(x) -
701 0.1036 * Utilities::fixed_power<4>(
702 x)); // half thickness at a position x
703
704 const double theta = std::atan(dy_c);
705
706 if (is_upper)
707 naca_points.emplace_back(x - y_t * std::sin(theta),
708 y_c + y_t * std::cos(theta));
709 else
710 naca_points.emplace_back(x + y_t * std::sin(theta),
711 y_c - y_t * std::cos(theta));
712 }
713
714 return naca_points;
715 }
716
717
718
727 static std::array<std::vector<Point<2>>, 2>
728 set_airfoil_length(const std::array<std::vector<Point<2>>, 2> &input,
729 const double desired_len)
730 {
731 std::array<std::vector<Point<2>>, 2> output;
732 output[0] = set_airfoil_length(input[0], desired_len);
733 output[1] = set_airfoil_length(input[1], desired_len);
734
735 return output;
736 }
737
745 static std::vector<Point<2>>
746 set_airfoil_length(const std::vector<Point<2>> &input,
747 const double desired_len)
748 {
749 std::vector<Point<2>> output = input;
750
751 const double scale =
752 desired_len / input.front().distance(input.back());
753
754 for (auto &x : output)
755 x *= scale;
756
757 return output;
758 }
759
770 static std::vector<Point<2>>
772 const std::vector<Point<2>> &non_equidistant_points,
773 const unsigned int number_points)
774 {
775 const unsigned int n_points =
777 .size(); // number provided airfoilpoints to interpolate
778
779 // calculate arclength
780 std::vector<double> arclength_L(non_equidistant_points.size(), 0);
781 for (unsigned int i = 0; i < non_equidistant_points.size() - 1; ++i)
782 arclength_L[i + 1] =
783 arclength_L[i] +
785
786
787 const auto airfoil_length =
788 arclength_L.back(); // arclength upper or lower side
789 const auto deltaX = airfoil_length / (number_points - 1);
790
791 // Create equidistant points: keep the first (and last) point
792 // unchanged
793 std::vector<Point<2>> equidist(
794 number_points); // number_points is required points on each side for
795 // mesh
797 equidist[number_points - 1] = non_equidistant_points[n_points - 1];
798
799
800 // loop over all subsections
801 for (unsigned int j = 0, i = 1; j < n_points - 1; ++j)
802 {
803 // get reference left and right end of this section
804 const auto Lj = arclength_L[j];
805 const auto Ljp = arclength_L[j + 1];
806
807 while (Lj <= i * deltaX && i * deltaX <= Ljp &&
808 i < number_points - 1)
809 {
810 equidist[i] = Point<2>((i * deltaX - Lj) / (Ljp - Lj) *
814 ++i;
815 }
816 }
817 return equidist;
818 }
819
820
821
828 void
830 {
831 // create vector of serial triangulations for each block and
832 // temporary storage for merging them
833 std::vector<Triangulation<2>> trias(10);
834
835 // helper function to create a subdivided quadrilateral
836 auto make = [](Triangulation<2> &tria,
837 const std::vector<Point<2>> &corner_vertices,
838 const std::vector<unsigned int> &repetitions,
839 const unsigned int material_id) {
840 // create subdivided rectangle with corner points (-1,-1)
841 // and (+1, +1). It serves as reference system
844 {-1, -1},
845 {+1, +1});
846
847 // move all vertices to the correct position
848 for (auto it = tria.begin_vertex(); it < tria.end_vertex(); ++it)
849 {
850 auto &point = it->vertex();
851 const double xi = point[0];
852 const double eta = point[1];
853
854 // bilinear mapping
855 point = 0.25 * ((1 - xi) * (1 - eta) * corner_vertices[0] +
856 (1 + xi) * (1 - eta) * corner_vertices[1] +
857 (1 - xi) * (1 + eta) * corner_vertices[2] +
858 (1 + xi) * (1 + eta) * corner_vertices[3]);
859 }
860
861 // set material id of block
862 for (auto cell : tria.active_cell_iterators())
863 cell->set_material_id(material_id);
864 };
865
866 // create a subdivided quadrilateral for each block (see last number
867 // of block id)
868 make(trias[0],
869 {A, B, D, C},
870 {n_subdivision_y, n_subdivision_x_0},
871 id_block_1);
872 make(trias[1],
873 {F, E, A, B},
874 {n_subdivision_y, n_subdivision_x_0},
875 id_block_4);
876 make(trias[2],
877 {C, H, D, G},
878 {n_subdivision_x_1, n_subdivision_y},
879 id_block_2);
880 make(trias[3],
881 {F, I, E, H},
882 {n_subdivision_x_1, n_subdivision_y},
883 id_block_5);
884 make(trias[4],
885 {H, J, G, K},
886 {n_subdivision_x_2, n_subdivision_y},
887 id_block_3);
888 make(trias[5],
889 {I, L, H, J},
890 {n_subdivision_x_2, n_subdivision_y},
891 id_block_6);
892
893
894 // merge triangulation (warning: do not change the order here since
895 // this might change the face ids)
901 }
902
903 /*
904 * Loop over all (cells and) boundary faces of a given triangulation
905 * and set the boundary_ids depending on the material_id of the cell and
906 * the face number. The resulting boundary_ids are:
907 * - 0: inlet
908 * - 1: outlet
909 * - 2: upper airfoil surface (aka. suction side)
910 * - 3, lower airfoil surface (aka. pressure side),
911 * - 4: upper far-field side
912 * - 5: lower far-field side
913 */
914 static void
916 {
917 for (auto cell : tria.active_cell_iterators())
918 for (const unsigned int f : GeometryInfo<2>::face_indices())
919 {
920 if (cell->face(f)->at_boundary() == false)
921 continue;
922
923 const auto mid = cell->material_id();
924
925 if ((mid == id_block_1 && f == 0) ||
926 (mid == id_block_4 && f == 0))
927 cell->face(f)->set_boundary_id(0); // inlet
928 else if ((mid == id_block_3 && f == 0) ||
929 (mid == id_block_6 && f == 2))
930 cell->face(f)->set_boundary_id(1); // outlet
931 else if ((mid == id_block_1 && f == 1) ||
932 (mid == id_block_2 && f == 1))
933 cell->face(f)->set_boundary_id(2); // upper airfoil side
934 else if ((mid == id_block_4 && f == 1) ||
935 (mid == id_block_5 && f == 3))
936 cell->face(f)->set_boundary_id(3); // lower airfoil side
937 else if ((mid == id_block_2 && f == 0) ||
938 (mid == id_block_3 && f == 2))
939 cell->face(f)->set_boundary_id(4); // upper far-field side
940 else if ((mid == id_block_5 && f == 2) ||
941 (mid == id_block_6 && f == 0))
942 cell->face(f)->set_boundary_id(5); // lower far-field side
943 else
945 }
946 }
947
948 /*
949 * Interpolate all vertices of the given triangulation onto the airfoil
950 * geometry, depending on the material_id of the block.
951 * Due to symmetry of coarse grid in respect to
952 * x-axis (by definition of points A-L), blocks 1&4, 2&4 and 3&6 can be
953 * interpolated with the same geometric computations Consider a
954 * bias_factor and incline_factor during interpolation to obtain a more
955 * dense mesh next to airfoil geometry and receive an inclined boundary
956 * between block 2&3 and 5&6, respectively
957 */
958 void
959 interpolate(Triangulation<2> &tria) const
960 {
961 // array storing the information if a vertex was processed
962 std::vector<bool> vertex_processed(tria.n_vertices(), false);
963
964 // rotation matrix for clockwise rotation of block 1 by angle gamma
969
970 // horizontal offset in order to place coarse-grid node A in the
971 // origin
972 const Point<2, double> horizontal_offset(A[0], 0.0);
973
974 // Move block 1 so that face BC coincides the x-axis
976 std::sin(gamma) * edge_length);
977
978 // loop over vertices of all cells
979 for (const auto &cell : tria.cell_iterators())
980 for (const unsigned int v : GeometryInfo<2>::vertex_indices())
981 {
982 // vertex has been already processed: nothing to do
983 if (vertex_processed[cell->vertex_index(v)])
984 continue;
985
986 // mark vertex as processed
987 vertex_processed[cell->vertex_index(v)] = true;
988
989 auto &node = cell->vertex(v);
990
991 // distinguish blocks
992 if (cell->material_id() == id_block_1 ||
993 cell->material_id() == id_block_4) // block 1 and 4
994 {
995 // step 1: rotate block 1 clockwise by gamma and move block
996 // 1 so that A[0] is on y-axis so that faces AD and BC are
997 // horizontal. This simplifies the computation of the
998 // required indices for interpolation (all x-nodes are
999 // positive) Move trapeze to be in first quadrant by adding
1000 // trapeze_offset
1002 if (cell->material_id() == id_block_1)
1003 {
1007 }
1008 // step 1: rotate block 4 counterclockwise and move down so
1009 // that trapeze is located in fourth quadrant (subtracting
1010 // trapeze_offset)
1011 else if (cell->material_id() == id_block_4)
1012 {
1016 }
1017 // step 2: compute indices ix and iy and interpolate
1018 // trapezoid to a rectangle of length pi/2.
1019 {
1020 const double trapeze_height =
1021 std::sin(gamma) * edge_length;
1022 const double L = height / std::sin(gamma);
1023 const double l_a = std::cos(gamma) * edge_length;
1024 const double l_b = trapeze_height * std::tan(gamma);
1025 const double x1 = std::abs(node_[1]) / std::tan(gamma);
1026 const double x2 = L - l_a - l_b;
1027 const double x3 = std::abs(node_[1]) * std::tan(gamma);
1028 const double Dx = x1 + x2 + x3;
1029 const double deltax =
1030 (trapeze_height - std::abs(node_[1])) / std::tan(gamma);
1031 const double dx = Dx / n_cells_x_0;
1032 const double dy = trapeze_height / n_cells_y;
1033 const int ix =
1034 static_cast<int>(std::round((node_[0] - deltax) / dx));
1035 const int iy =
1036 static_cast<int>(std::round(std::abs(node_[1]) / dy));
1037
1038 node_[0] = numbers::PI / 2 * (1.0 * ix) / n_cells_x_0;
1039 node_[1] = height * (1.0 * iy) / n_cells_y;
1040 }
1041
1042 // step 3: Interpolation between semicircle (of C-Mesh) and
1043 // airfoil contour
1044 {
1045 const double dx = numbers::PI / 2 / n_cells_x_0;
1046 const double dy = height / n_cells_y;
1047 const int ix =
1048 static_cast<int>(std::round(node_[0] / dx));
1049 const int iy =
1050 static_cast<int>(std::round(node_[1] / dy));
1051 const double alpha =
1052 bias_alpha(1 - (1.0 * iy) / n_cells_y);
1053 const double theta = node_[0];
1054 const Point<2> p(-height * std::cos(theta) + center_mesh,
1055 ((cell->material_id() == id_block_1) ?
1056 (height) :
1057 (-height)) *
1058 std::sin(theta));
1059 node = airfoil_1D[(
1060 (cell->material_id() == id_block_1) ? (0) : (1))]
1061 [ix] *
1062 alpha +
1063 p * (1 - alpha);
1064 }
1065 }
1066 else if (cell->material_id() == id_block_2 ||
1067 cell->material_id() == id_block_5) // block 2 and 5
1068 {
1069 // geometric parameters and indices for interpolation
1070 Assert(
1071 (std::abs(D[1] - C[1]) == std::abs(F[1] - E[1])) &&
1072 (std::abs(C[1]) == std::abs(E[1])) &&
1073 (std::abs(G[1]) == std::abs(I[1])),
1074 ExcMessage(
1075 "Points D,C,G and E,F,I are not defined symmetric to "
1076 "x-axis, which is required to interpolate block 2"
1077 " and 5 with same geometric computations."));
1078 const double l_y = D[1] - C[1];
1079 const double l_h = D[1] - l_y;
1080 const double by = -l_h / length_b1_x * (node[0] - H[0]);
1081 const double dy = (height - by) / n_cells_y;
1082 const int iy = static_cast<int>(
1083 std::round((std::abs(node[1]) - by) / dy));
1084 const double dx = length_b1_x / n_cells_x_1;
1085 const int ix = static_cast<int>(
1086 std::round(std::abs(node[0] - center_mesh) / dx));
1087
1088 const double alpha = bias_alpha(1 - (1.0 * iy) / n_cells_y);
1089 // define points on upper/lower horizontal far field side,
1090 // i.e. face DG or FI. Incline factor to move points G and I
1091 // to the right by distance incline_factor*length_b2
1092 const Point<2> p(ix * dx + center_mesh +
1093 incline_factor * length_b2 * ix /
1095 ((cell->material_id() == id_block_2) ?
1096 (height) :
1097 (-height)));
1098 // interpolate between y = height and upper airfoil points
1099 // (block2) or y = -height and lower airfoil points (block5)
1100 node = airfoil_1D[(
1101 (cell->material_id() == id_block_2) ? (0) : (1))]
1102 [n_cells_x_0 + ix] *
1103 alpha +
1104 p * (1 - alpha);
1105 }
1106 else if (cell->material_id() == id_block_3 ||
1107 cell->material_id() == id_block_6) // block 3 and 6
1108 {
1109 // compute indices ix and iy
1110 const double dx = length_b2 / n_cells_x_2;
1111 const double dy = height / n_cells_y;
1112 const int ix = static_cast<int>(
1113 std::round(std::abs(node[0] - H[0]) / dx));
1114 const int iy =
1115 static_cast<int>(std::round(std::abs(node[1]) / dy));
1116
1117 const double alpha_y = bias_alpha(1 - 1.0 * iy / n_cells_y);
1118 const double alpha_x =
1119 bias_alpha(1 - (static_cast<double>(ix)) / n_cells_x_2);
1120 // define on upper/lower horizontal far field side at y =
1121 // +/- height, i.e. face GK or IL incline factor to move
1122 // points G and H to the right
1123 const Point<2> p1(J[0] - (1 - incline_factor) * length_b2 *
1124 (alpha_x),
1125 ((cell->material_id() == id_block_3) ?
1126 (height) :
1127 (-height)));
1128 // define points on HJ but use tail_y as y-coordinate, in
1129 // case last airfoil point has y =/= 0
1130 const Point<2> p2(J[0] - alpha_x * length_b2, tail_y);
1131 node = p1 * (1 - alpha_y) + p2 * alpha_y;
1132 }
1133 else
1134 {
1135 Assert(false,
1136 ExcIndexRange(cell->material_id(),
1137 id_block_1,
1138 id_block_6));
1139 }
1140 }
1141 }
1142
1143
1144 /*
1145 * This function returns a bias factor 'alpha' which is used to make the
1146 * mesh more tight in close distance of the airfoil.
1147 * It is a bijective function mapping from [0,1] onto [0,1] where values
1148 * near 1 are made tighter.
1149 */
1150 double
1151 bias_alpha(double alpha) const
1152 {
1153 return std::tanh(bias_factor * alpha) / std::tanh(bias_factor);
1154 }
1155 };
1156 } // namespace
1157
1158
1159
1160 void
1162 Triangulation<2, 2> &tria,
1163 std::vector<GridTools::PeriodicFacePair<
1165 const AdditionalData &additional_data)
1166 {
1167 MeshGenerator mesh_generator(additional_data);
1168 // Cast the triangulation to the right type so that the right
1169 // specialization of the function create_triangulation is picked up.
1170 if (auto *parallel_tria =
1172 &tria))
1173 mesh_generator.create_triangulation(*parallel_tria, periodic_faces);
1174 else if (auto *parallel_tria = dynamic_cast<
1176 &tria))
1177 mesh_generator.create_triangulation(*parallel_tria, periodic_faces);
1178 else
1179 mesh_generator.create_triangulation(tria, periodic_faces);
1180 }
1181
1182 template <>
1183 void
1184 create_triangulation(Triangulation<1, 1> &, const AdditionalData &)
1185 {
1186 Assert(false, ExcMessage("Airfoils only exist for 2D and 3d!"));
1187 }
1188
1189
1190
1191 template <>
1192 void
1194 std::vector<GridTools::PeriodicFacePair<
1196 const AdditionalData &)
1197 {
1198 Assert(false, ExcMessage("Airfoils only exist for 2D and 3d!"));
1199 }
1200
1201
1202
1203 template <>
1204 void
1206 const AdditionalData &additional_data)
1207 {
1208 internal_create_triangulation(tria, nullptr, additional_data);
1209 }
1210
1211
1212
1213 template <>
1214 void
1216 Triangulation<2, 2> &tria,
1217 std::vector<GridTools::PeriodicFacePair<
1219 const AdditionalData &additional_data)
1220 {
1221 internal_create_triangulation(tria, &periodic_faces, additional_data);
1222 }
1223
1224
1225
1226 template <>
1227 void
1229 Triangulation<3, 3> &tria,
1230 std::vector<GridTools::PeriodicFacePair<
1232 const AdditionalData &additional_data)
1233 {
1234 Assert(false, ExcMessage("3d airfoils are not implemented yet!"));
1235 (void)tria;
1236 (void)additional_data;
1238 }
1239 } // namespace Airfoil
1240
1241
1242 namespace
1243 {
1248 template <int dim, int spacedim>
1249 void
1251 {
1252 // there is nothing to do in 1d
1253 if (dim > 1)
1254 {
1255 // there is only one cell, so
1256 // simple task
1258 tria.begin();
1259 for (auto f : GeometryInfo<dim>::face_indices())
1260 cell->face(f)->set_boundary_id(f);
1261 }
1262 }
1263
1264
1265
1266 template <int spacedim>
1267 void
1269 const Point<spacedim> &,
1270 const Point<spacedim> &,
1271 const double)
1272 {
1274 tria.begin();
1275 cell != tria.end();
1276 ++cell)
1277 if (cell->center()[0] > 0)
1278 cell->set_material_id(1);
1279 // boundary indicators are set to
1280 // 0 (left) and 1 (right) by default.
1281 }
1282
1283
1284
1285 template <int dim, int spacedim>
1286 void
1288 const Point<spacedim> &p1,
1289 const Point<spacedim> &p2,
1290 const double epsilon)
1291 {
1292 // run through all faces and check
1293 // if one of their center coordinates matches
1294 // one of the corner points. Comparisons
1295 // are made using an epsilon which
1296 // should be smaller than the smallest cell
1297 // diameter.
1298
1300 tria.begin_face(),
1301 endface =
1302 tria.end_face();
1303 for (; face != endface; ++face)
1304 if (face->at_boundary())
1305 if (face->boundary_id() == 0)
1306 {
1307 const Point<spacedim> center(face->center());
1308
1309 if (std::abs(center[0] - p1[0]) < epsilon)
1310 face->set_boundary_id(0);
1311 else if (std::abs(center[0] - p2[0]) < epsilon)
1312 face->set_boundary_id(1);
1313 else if (dim > 1 && std::abs(center[1] - p1[1]) < epsilon)
1314 face->set_boundary_id(2);
1315 else if (dim > 1 && std::abs(center[1] - p2[1]) < epsilon)
1316 face->set_boundary_id(3);
1317 else if (dim > 2 && std::abs(center[2] - p1[2]) < epsilon)
1318 face->set_boundary_id(4);
1319 else if (dim > 2 && std::abs(center[2] - p2[2]) < epsilon)
1320 face->set_boundary_id(5);
1321 else
1322 // triangulation says it
1323 // is on the boundary,
1324 // but we could not find
1325 // on which boundary.
1327 }
1328
1329 for (const auto &cell : tria.cell_iterators())
1330 {
1331 types::material_id id = 0;
1332 for (unsigned int d = 0; d < dim; ++d)
1333 if (cell->center()[d] > 0)
1334 id += (1 << d);
1335 cell->set_material_id(id);
1336 }
1337 }
1338
1339
1344 template <int spacdim>
1345 void
1347 const Point<spacdim> &,
1348 const double,
1349 const double)
1350 {
1351 // In spite of receiving geometrical
1352 // data, we do this only based on
1353 // topology.
1354
1355 // For the mesh based on cube,
1356 // this is highly irregular
1357 for (auto cell = tria.begin(); cell != tria.end(); ++cell)
1358 {
1359 Assert(cell->face(2)->at_boundary(), ExcInternalError());
1360 cell->face(2)->set_all_boundary_ids(1);
1361 }
1362 }
1363
1364
1369 void
1371 const Point<3> &,
1372 const double,
1373 const double)
1374 {
1375 // the following uses a good amount
1376 // of knowledge about the
1377 // orientation of cells. this is
1378 // probably not good style...
1379 if (tria.n_cells() == 6)
1380 {
1381 Triangulation<3>::cell_iterator cell = tria.begin();
1382
1383 Assert(cell->face(4)->at_boundary(), ExcInternalError());
1384 cell->face(4)->set_all_boundary_ids(1);
1385
1386 ++cell;
1387 Assert(cell->face(2)->at_boundary(), ExcInternalError());
1388 cell->face(2)->set_all_boundary_ids(1);
1389
1390 ++cell;
1391 Assert(cell->face(2)->at_boundary(), ExcInternalError());
1392 cell->face(2)->set_all_boundary_ids(1);
1393
1394 ++cell;
1395 Assert(cell->face(0)->at_boundary(), ExcInternalError());
1396 cell->face(0)->set_all_boundary_ids(1);
1397
1398 ++cell;
1399 Assert(cell->face(2)->at_boundary(), ExcInternalError());
1400 cell->face(2)->set_all_boundary_ids(1);
1401
1402 ++cell;
1403 Assert(cell->face(0)->at_boundary(), ExcInternalError());
1404 cell->face(0)->set_all_boundary_ids(1);
1405 }
1406 else if (tria.n_cells() == 12)
1407 {
1408 // again use some internal
1409 // knowledge
1410 for (Triangulation<3>::cell_iterator cell = tria.begin();
1411 cell != tria.end();
1412 ++cell)
1413 {
1414 Assert(cell->face(5)->at_boundary(), ExcInternalError());
1415 cell->face(5)->set_all_boundary_ids(1);
1416 }
1417 }
1418 else if (tria.n_cells() == 96)
1419 {
1420 // the 96-cell hypershell is based on a once refined 12-cell
1421 // mesh. consequently, since the outer faces all are face_no==5
1422 // above, so they are here (unless they are in the interior). Use
1423 // this to assign boundary indicators, but also make sure that we
1424 // encounter exactly 48 such faces
1425 unsigned int count = 0;
1426 for (const auto &cell : tria.cell_iterators())
1427 if (cell->face(5)->at_boundary())
1428 {
1429 cell->face(5)->set_all_boundary_ids(1);
1430 ++count;
1431 }
1432 (void)count;
1433 Assert(count == 48, ExcInternalError());
1434 }
1435 else
1437 }
1438
1439
1440
1446 void
1448 const Point<3> &center,
1449 const double inner_radius,
1450 const double outer_radius)
1451 {
1452 if (tria.n_cells() != 3)
1454
1455 double middle = (outer_radius - inner_radius) / 2e0 + inner_radius;
1456 double eps = 1e-3 * middle;
1457 Triangulation<3>::cell_iterator cell = tria.begin();
1458
1459 for (; cell != tria.end(); ++cell)
1460 for (const unsigned int f : GeometryInfo<3>::face_indices())
1461 {
1462 if (!cell->face(f)->at_boundary())
1463 continue;
1464
1465 double radius = cell->face(f)->center().norm() - center.norm();
1466 if (std::fabs(cell->face(f)->center()[0]) <
1467 eps) // x = 0 set boundary 2
1468 {
1469 cell->face(f)->set_boundary_id(2);
1470 for (unsigned int j = 0; j < GeometryInfo<3>::lines_per_face;
1471 ++j)
1472 if (cell->face(f)->line(j)->at_boundary())
1473 if (std::fabs(cell->face(f)->line(j)->vertex(0).norm() -
1474 cell->face(f)->line(j)->vertex(1).norm()) >
1475 eps)
1476 cell->face(f)->line(j)->set_boundary_id(2);
1477 }
1478 else if (std::fabs(cell->face(f)->center()[1]) <
1479 eps) // y = 0 set boundary 3
1480 {
1481 cell->face(f)->set_boundary_id(3);
1482 for (unsigned int j = 0; j < GeometryInfo<3>::lines_per_face;
1483 ++j)
1484 if (cell->face(f)->line(j)->at_boundary())
1485 if (std::fabs(cell->face(f)->line(j)->vertex(0).norm() -
1486 cell->face(f)->line(j)->vertex(1).norm()) >
1487 eps)
1488 cell->face(f)->line(j)->set_boundary_id(3);
1489 }
1490 else if (std::fabs(cell->face(f)->center()[2]) <
1491 eps) // z = 0 set boundary 4
1492 {
1493 cell->face(f)->set_boundary_id(4);
1494 for (unsigned int j = 0; j < GeometryInfo<3>::lines_per_face;
1495 ++j)
1496 if (cell->face(f)->line(j)->at_boundary())
1497 if (std::fabs(cell->face(f)->line(j)->vertex(0).norm() -
1498 cell->face(f)->line(j)->vertex(1).norm()) >
1499 eps)
1500 cell->face(f)->line(j)->set_boundary_id(4);
1501 }
1502 else if (radius < middle) // inner radius set boundary 0
1503 {
1504 cell->face(f)->set_boundary_id(0);
1505 for (unsigned int j = 0; j < GeometryInfo<3>::lines_per_face;
1506 ++j)
1507 if (cell->face(f)->line(j)->at_boundary())
1508 if (std::fabs(cell->face(f)->line(j)->vertex(0).norm() -
1509 cell->face(f)->line(j)->vertex(1).norm()) <
1510 eps)
1511 cell->face(f)->line(j)->set_boundary_id(0);
1512 }
1513 else if (radius > middle) // outer radius set boundary 1
1514 {
1515 cell->face(f)->set_boundary_id(1);
1516 for (unsigned int j = 0; j < GeometryInfo<3>::lines_per_face;
1517 ++j)
1518 if (cell->face(f)->line(j)->at_boundary())
1519 if (std::fabs(cell->face(f)->line(j)->vertex(0).norm() -
1520 cell->face(f)->line(j)->vertex(1).norm()) <
1521 eps)
1522 cell->face(f)->line(j)->set_boundary_id(1);
1523 }
1524 else
1526 }
1527 }
1528
1529 } // namespace
1530
1531
1532 template <int dim, int spacedim>
1533 void
1535 const Point<dim> &p_1,
1536 const Point<dim> &p_2,
1537 const bool colorize)
1538 {
1539 // First, extend dimensions from dim to spacedim and
1540 // normalize such that p1 is lower in all coordinate
1541 // directions. Additional entries will be 0.
1543 for (unsigned int i = 0; i < dim; ++i)
1544 {
1545 p1[i] = std::min(p_1[i], p_2[i]);
1546 p2[i] = std::max(p_1[i], p_2[i]);
1547 }
1548
1549 std::vector<Point<spacedim>> vertices(GeometryInfo<dim>::vertices_per_cell);
1550 switch (dim)
1551 {
1552 case 1:
1553 vertices[0] = p1;
1554 vertices[1] = p2;
1555 break;
1556 case 2:
1557 vertices[0] = vertices[1] = p1;
1558 vertices[2] = vertices[3] = p2;
1559
1560 vertices[1][0] = p2[0];
1561 vertices[2][0] = p1[0];
1562 break;
1563 case 3:
1564 vertices[0] = vertices[1] = vertices[2] = vertices[3] = p1;
1565 vertices[4] = vertices[5] = vertices[6] = vertices[7] = p2;
1566
1567 vertices[1][0] = p2[0];
1568 vertices[2][1] = p2[1];
1569 vertices[3][0] = p2[0];
1570 vertices[3][1] = p2[1];
1571
1572 vertices[4][0] = p1[0];
1573 vertices[4][1] = p1[1];
1574 vertices[5][1] = p1[1];
1575 vertices[6][0] = p1[0];
1576
1577 break;
1578 default:
1580 }
1581
1582 // Prepare cell data
1583 std::vector<CellData<dim>> cells(1);
1584 for (const unsigned int i : GeometryInfo<dim>::vertex_indices())
1585 cells[0].vertices[i] = i;
1586 cells[0].material_id = 0;
1587
1588 tria.create_triangulation(vertices, cells, SubCellData());
1589
1590 // Assign boundary indicators
1591 if (colorize)
1593 }
1594
1595
1596
1597 template <int dim, int spacedim>
1598 void
1600 const double left,
1601 const double right,
1602 const bool colorize)
1603 {
1604 Assert(left < right,
1605 ExcMessage("Invalid left-to-right bounds of hypercube"));
1606
1607 Point<dim> p1, p2;
1608 for (unsigned int i = 0; i < dim; ++i)
1609 {
1610 p1[i] = left;
1611 p2[i] = right;
1612 }
1613 hyper_rectangle(tria, p1, p2, colorize);
1614 }
1615
1616
1617
1618 template <int dim>
1619 void
1620 simplex(Triangulation<dim> &tria, const std::vector<Point<dim>> &vertices)
1621 {
1622 AssertDimension(vertices.size(), dim + 1);
1623 Assert(dim > 1, ExcNotImplemented());
1624 Assert(dim < 4, ExcNotImplemented());
1625
1626# ifdef DEBUG
1628 for (unsigned int d = 0; d < dim; ++d)
1629 for (unsigned int c = 1; c <= dim; ++c)
1630 vector_matrix[c - 1][d] = vertices[c][d] - vertices[0][d];
1632 ExcMessage("Vertices of simplex must form a right handed system"));
1633# endif
1634
1635 // Set up the vertices by first copying into points.
1636 std::vector<Point<dim>> points = vertices;
1637 Point<dim> center;
1638 // Compute the edge midpoints and add up everything to compute the
1639 // center point.
1640 for (unsigned int i = 0; i <= dim; ++i)
1641 {
1642 points.push_back(0.5 * (points[i] + points[(i + 1) % (dim + 1)]));
1643 center += points[i];
1644 }
1645 if (dim > 2)
1646 {
1647 // In 3d, we have some more edges to deal with
1648 for (unsigned int i = 1; i < dim; ++i)
1649 points.push_back(0.5 * (points[i - 1] + points[i + 1]));
1650 // And we need face midpoints
1651 for (unsigned int i = 0; i <= dim; ++i)
1652 points.push_back(1. / 3. *
1653 (points[i] + points[(i + 1) % (dim + 1)] +
1654 points[(i + 2) % (dim + 1)]));
1655 }
1656 points.push_back((1. / (dim + 1)) * center);
1657
1658 std::vector<CellData<dim>> cells(dim + 1);
1659 switch (dim)
1660 {
1661 case 2:
1662 AssertDimension(points.size(), 7);
1663 cells[0].vertices[0] = 0;
1664 cells[0].vertices[1] = 3;
1665 cells[0].vertices[2] = 5;
1666 cells[0].vertices[3] = 6;
1667 cells[0].material_id = 0;
1668
1669 cells[1].vertices[0] = 3;
1670 cells[1].vertices[1] = 1;
1671 cells[1].vertices[2] = 6;
1672 cells[1].vertices[3] = 4;
1673 cells[1].material_id = 0;
1674
1675 cells[2].vertices[0] = 5;
1676 cells[2].vertices[1] = 6;
1677 cells[2].vertices[2] = 2;
1678 cells[2].vertices[3] = 4;
1679 cells[2].material_id = 0;
1680 break;
1681 case 3:
1682 AssertDimension(points.size(), 15);
1683 cells[0].vertices[0] = 0;
1684 cells[0].vertices[1] = 4;
1685 cells[0].vertices[2] = 8;
1686 cells[0].vertices[3] = 10;
1687 cells[0].vertices[4] = 7;
1688 cells[0].vertices[5] = 13;
1689 cells[0].vertices[6] = 12;
1690 cells[0].vertices[7] = 14;
1691 cells[0].material_id = 0;
1692
1693 cells[1].vertices[0] = 4;
1694 cells[1].vertices[1] = 1;
1695 cells[1].vertices[2] = 10;
1696 cells[1].vertices[3] = 5;
1697 cells[1].vertices[4] = 13;
1698 cells[1].vertices[5] = 9;
1699 cells[1].vertices[6] = 14;
1700 cells[1].vertices[7] = 11;
1701 cells[1].material_id = 0;
1702
1703 cells[2].vertices[0] = 8;
1704 cells[2].vertices[1] = 10;
1705 cells[2].vertices[2] = 2;
1706 cells[2].vertices[3] = 5;
1707 cells[2].vertices[4] = 12;
1708 cells[2].vertices[5] = 14;
1709 cells[2].vertices[6] = 6;
1710 cells[2].vertices[7] = 11;
1711 cells[2].material_id = 0;
1712
1713 cells[3].vertices[0] = 7;
1714 cells[3].vertices[1] = 13;
1715 cells[3].vertices[2] = 12;
1716 cells[3].vertices[3] = 14;
1717 cells[3].vertices[4] = 3;
1718 cells[3].vertices[5] = 9;
1719 cells[3].vertices[6] = 6;
1720 cells[3].vertices[7] = 11;
1721 cells[3].material_id = 0;
1722 break;
1723 default:
1725 }
1726 tria.create_triangulation(points, cells, SubCellData());
1727 }
1728
1729
1730
1731 template <int dim, int spacedim>
1732 void
1734 const ReferenceCell &reference_cell)
1735 {
1736 AssertDimension(dim, reference_cell.get_dimension());
1737
1738 if (reference_cell == ReferenceCells::get_hypercube<dim>())
1739 {
1740 GridGenerator::hyper_cube(tria, 0, 1);
1741 }
1742 else
1743 {
1744 // Create an array that contains the vertices of the reference cell.
1745 // We can query these points from ReferenceCell, but then we have
1746 // to embed them into the spacedim-dimensional space.
1747 std::vector<Point<spacedim>> vertices(reference_cell.n_vertices());
1748 for (const unsigned int v : reference_cell.vertex_indices())
1749 {
1750 const Point<dim> this_vertex = reference_cell.vertex<dim>(v);
1751 for (unsigned int d = 0; d < dim; ++d)
1752 vertices[v][d] = this_vertex[d];
1753 // Point<spacedim> initializes everything to zero, so any remaining
1754 // elements are left at zero and we don't have to explicitly pad
1755 // from 'dim' to 'spacedim' here.
1756 }
1757
1758 // Then make one cell out of these vertices. They are ordered correctly
1759 // already, so we just need to enumerate them
1760 std::vector<CellData<dim>> cells(1);
1761 cells[0].vertices.resize(reference_cell.n_vertices());
1762 for (const unsigned int v : reference_cell.vertex_indices())
1763 cells[0].vertices[v] = v;
1764
1765 // Turn all of this into a triangulation
1766 tria.create_triangulation(vertices, cells, {});
1767 }
1768 }
1769
1770 void
1772 const unsigned int n_cells,
1773 const unsigned int n_rotations,
1774 const double R,
1775 const double r)
1776 {
1777 const unsigned int dim = 3;
1778 Assert(n_cells > 4,
1779 ExcMessage(
1780 "More than 4 cells are needed to create a moebius grid."));
1781 Assert(r > 0 && R > 0,
1782 ExcMessage("Outer and inner radius must be positive."));
1783 Assert(R > r,
1784 ExcMessage("Outer radius must be greater than inner radius."));
1785
1786
1787 std::vector<Point<dim>> vertices(4 * n_cells);
1788 double beta_step = n_rotations * numbers::PI / 2.0 / n_cells;
1789 double alpha_step = 2.0 * numbers::PI / n_cells;
1790
1791 for (unsigned int i = 0; i < n_cells; ++i)
1792 for (unsigned int j = 0; j < 4; ++j)
1793 {
1794 vertices[4 * i + j][0] =
1795 R * std::cos(i * alpha_step) +
1796 r * std::cos(i * beta_step + j * numbers::PI / 2.0) *
1797 std::cos(i * alpha_step);
1798 vertices[4 * i + j][1] =
1799 R * std::sin(i * alpha_step) +
1800 r * std::cos(i * beta_step + j * numbers::PI / 2.0) *
1801 std::sin(i * alpha_step);
1802 vertices[4 * i + j][2] =
1803 r * std::sin(i * beta_step + j * numbers::PI / 2.0);
1804 }
1805
1806 unsigned int offset = 0;
1807
1808 // This Triangulation is constructed using a numbering scheme in which
1809 // the front face is first and the back face is second,
1810 // which is more convenient for creating a Moebius loop
1811 static constexpr std::array<unsigned int, 8> local_vertex_numbering{
1812 {0, 1, 5, 4, 2, 3, 7, 6}};
1813 std::vector<CellData<dim>> cells(n_cells);
1814 for (unsigned int i = 0; i < n_cells; ++i)
1815 {
1816 for (unsigned int j = 0; j < 2; ++j)
1817 {
1818 cells[i].vertices[local_vertex_numbering[0 + 4 * j]] =
1819 offset + 0 + 4 * j;
1820 cells[i].vertices[local_vertex_numbering[1 + 4 * j]] =
1821 offset + 3 + 4 * j;
1822 cells[i].vertices[local_vertex_numbering[2 + 4 * j]] =
1823 offset + 2 + 4 * j;
1824 cells[i].vertices[local_vertex_numbering[3 + 4 * j]] =
1825 offset + 1 + 4 * j;
1826 }
1827 offset += 4;
1828 cells[i].material_id = 0;
1829 }
1830
1831 // now correct the last four vertices
1832 cells[n_cells - 1].vertices[local_vertex_numbering[4]] =
1833 (0 + n_rotations) % 4;
1834 cells[n_cells - 1].vertices[local_vertex_numbering[5]] =
1835 (3 + n_rotations) % 4;
1836 cells[n_cells - 1].vertices[local_vertex_numbering[6]] =
1837 (2 + n_rotations) % 4;
1838 cells[n_cells - 1].vertices[local_vertex_numbering[7]] =
1839 (1 + n_rotations) % 4;
1840
1842 tria.create_triangulation(vertices, cells, SubCellData());
1843 }
1844
1845
1846
1847 template <>
1848 void
1850 const double centerline_radius,
1851 const double inner_radius,
1852 const unsigned int,
1853 const double)
1854 {
1855 Assert(centerline_radius > inner_radius,
1856 ExcMessage("The centerline radius must be greater than the "
1857 "inner radius."));
1858 Assert(inner_radius > 0.0,
1859 ExcMessage("The inner radius must be positive."));
1860
1861 const unsigned int dim = 2;
1862 const unsigned int spacedim = 3;
1863 std::vector<Point<spacedim>> vertices(16);
1864
1865 vertices[0] = Point<spacedim>(centerline_radius - inner_radius, 0, 0);
1866 vertices[1] = Point<spacedim>(centerline_radius, -inner_radius, 0);
1867 vertices[2] = Point<spacedim>(centerline_radius + inner_radius, 0, 0);
1868 vertices[3] = Point<spacedim>(centerline_radius, inner_radius, 0);
1869 vertices[4] = Point<spacedim>(0, 0, centerline_radius - inner_radius);
1870 vertices[5] = Point<spacedim>(0, -inner_radius, centerline_radius);
1871 vertices[6] = Point<spacedim>(0, 0, centerline_radius + inner_radius);
1872 vertices[7] = Point<spacedim>(0, inner_radius, centerline_radius);
1873 vertices[8] = Point<spacedim>(-(centerline_radius - inner_radius), 0, 0);
1874 vertices[9] = Point<spacedim>(-centerline_radius, -inner_radius, 0);
1875 vertices[10] = Point<spacedim>(-(centerline_radius + inner_radius), 0, 0);
1876 vertices[11] = Point<spacedim>(-centerline_radius, inner_radius, 0);
1877 vertices[12] = Point<spacedim>(0, 0, -(centerline_radius - inner_radius));
1878 vertices[13] = Point<spacedim>(0, -inner_radius, -centerline_radius);
1879 vertices[14] = Point<spacedim>(0, 0, -(centerline_radius + inner_radius));
1880 vertices[15] = Point<spacedim>(0, inner_radius, -centerline_radius);
1881
1882 std::vector<CellData<dim>> cells(16);
1883 // Right Hand Orientation
1884 cells[0].vertices[0] = 0;
1885 cells[0].vertices[1] = 4;
1886 cells[0].vertices[2] = 3;
1887 cells[0].vertices[3] = 7;
1888 cells[0].material_id = 0;
1889
1890 cells[1].vertices[0] = 1;
1891 cells[1].vertices[1] = 5;
1892 cells[1].vertices[2] = 0;
1893 cells[1].vertices[3] = 4;
1894 cells[1].material_id = 0;
1895
1896 cells[2].vertices[0] = 2;
1897 cells[2].vertices[1] = 6;
1898 cells[2].vertices[2] = 1;
1899 cells[2].vertices[3] = 5;
1900 cells[2].material_id = 0;
1901
1902 cells[3].vertices[0] = 3;
1903 cells[3].vertices[1] = 7;
1904 cells[3].vertices[2] = 2;
1905 cells[3].vertices[3] = 6;
1906 cells[3].material_id = 0;
1907
1908 cells[4].vertices[0] = 4;
1909 cells[4].vertices[1] = 8;
1910 cells[4].vertices[2] = 7;
1911 cells[4].vertices[3] = 11;
1912 cells[4].material_id = 0;
1913
1914 cells[5].vertices[0] = 5;
1915 cells[5].vertices[1] = 9;
1916 cells[5].vertices[2] = 4;
1917 cells[5].vertices[3] = 8;
1918 cells[5].material_id = 0;
1919
1920 cells[6].vertices[0] = 6;
1921 cells[6].vertices[1] = 10;
1922 cells[6].vertices[2] = 5;
1923 cells[6].vertices[3] = 9;
1924 cells[6].material_id = 0;
1925
1926 cells[7].vertices[0] = 7;
1927 cells[7].vertices[1] = 11;
1928 cells[7].vertices[2] = 6;
1929 cells[7].vertices[3] = 10;
1930 cells[7].material_id = 0;
1931
1932 cells[8].vertices[0] = 8;
1933 cells[8].vertices[1] = 12;
1934 cells[8].vertices[2] = 11;
1935 cells[8].vertices[3] = 15;
1936 cells[8].material_id = 0;
1937
1938 cells[9].vertices[0] = 9;
1939 cells[9].vertices[1] = 13;
1940 cells[9].vertices[2] = 8;
1941 cells[9].vertices[3] = 12;
1942 cells[9].material_id = 0;
1943
1944 cells[10].vertices[0] = 10;
1945 cells[10].vertices[1] = 14;
1946 cells[10].vertices[2] = 9;
1947 cells[10].vertices[3] = 13;
1948 cells[10].material_id = 0;
1949
1950 cells[11].vertices[0] = 11;
1951 cells[11].vertices[1] = 15;
1952 cells[11].vertices[2] = 10;
1953 cells[11].vertices[3] = 14;
1954 cells[11].material_id = 0;
1955
1956 cells[12].vertices[0] = 12;
1957 cells[12].vertices[1] = 0;
1958 cells[12].vertices[2] = 15;
1959 cells[12].vertices[3] = 3;
1960 cells[12].material_id = 0;
1961
1962 cells[13].vertices[0] = 13;
1963 cells[13].vertices[1] = 1;
1964 cells[13].vertices[2] = 12;
1965 cells[13].vertices[3] = 0;
1966 cells[13].material_id = 0;
1967
1968 cells[14].vertices[0] = 14;
1969 cells[14].vertices[1] = 2;
1970 cells[14].vertices[2] = 13;
1971 cells[14].vertices[3] = 1;
1972 cells[14].material_id = 0;
1973
1974 cells[15].vertices[0] = 15;
1975 cells[15].vertices[1] = 3;
1976 cells[15].vertices[2] = 14;
1977 cells[15].vertices[3] = 2;
1978 cells[15].material_id = 0;
1979
1981 tria.create_triangulation(vertices, cells, SubCellData());
1982
1983 tria.set_all_manifold_ids(0);
1984 tria.set_manifold(0, TorusManifold<2>(centerline_radius, inner_radius));
1985 }
1986
1987
1988
1989 namespace
1990 {
1991 static constexpr int circle_cell_vertices[5][4] = {{0, 1, 2, 3},
1992 {0, 2, 6, 4},
1993 {2, 3, 4, 5},
1994 {1, 7, 3, 5},
1995 {6, 4, 7, 5}};
1996 }
1997
1998
1999
2000 template <>
2001 void
2003 const double centerline_radius,
2004 const double inner_radius,
2005 const unsigned int n_cells_toroidal,
2006 const double phi)
2007 {
2008 Assert(centerline_radius > inner_radius,
2009 ExcMessage("The centerline radius must be greater than the "
2010 "inner radius."));
2011 Assert(inner_radius > 0.0,
2012 ExcMessage("The inner radius must be positive."));
2013 Assert(n_cells_toroidal > static_cast<unsigned int>(phi / numbers::PI),
2014 ExcMessage("Number of cells in toroidal direction has "
2015 "to be at least 3 for a torus of polar extent 2*pi."));
2016 AssertThrow(phi > 0.0 && phi < 2.0 * numbers::PI + 1.0e-15,
2017 ExcMessage("Invalid angle phi specified."));
2018
2019 // the first 8 vertices are in the x-y-plane
2020 const Point<3> p = Point<3>(centerline_radius, 0.0, 0.0);
2021 const double a = 1. / (1 + std::sqrt(2.0));
2022 // A value of 1 indicates "open" torus with angle < 2*pi, which
2023 // means that we need an additional layer of vertices
2024 const unsigned int additional_layer =
2025 (phi < 2.0 * numbers::PI - 1.0e-15) ?
2026 1 :
2027 0; // torus is closed (angle of 2*pi)
2028 const unsigned int n_point_layers_toroidal =
2030 std::vector<Point<3>> vertices(8 * n_point_layers_toroidal);
2031 vertices[0] = p + Point<3>(-1, -1, 0) * (inner_radius / std::sqrt(2.0)),
2032 vertices[1] = p + Point<3>(+1, -1, 0) * (inner_radius / std::sqrt(2.0)),
2033 vertices[2] = p + Point<3>(-1, -1, 0) * (inner_radius / std::sqrt(2.0) * a),
2034 vertices[3] = p + Point<3>(+1, -1, 0) * (inner_radius / std::sqrt(2.0) * a),
2035 vertices[4] = p + Point<3>(-1, +1, 0) * (inner_radius / std::sqrt(2.0) * a),
2036 vertices[5] = p + Point<3>(+1, +1, 0) * (inner_radius / std::sqrt(2.0) * a),
2037 vertices[6] = p + Point<3>(-1, +1, 0) * (inner_radius / std::sqrt(2.0)),
2038 vertices[7] = p + Point<3>(+1, +1, 0) * (inner_radius / std::sqrt(2.0));
2039
2040 // create remaining vertices by rotating around negative y-axis (the
2041 // direction is to ensure positive cell measures)
2042 const double phi_cell = phi / n_cells_toroidal;
2043 for (unsigned int c = 1; c < n_point_layers_toroidal; ++c)
2044 {
2045 for (unsigned int v = 0; v < 8; ++v)
2046 {
2047 const double inner_radius_2d = vertices[v][0];
2048 vertices[8 * c + v][0] = inner_radius_2d * std::cos(phi_cell * c);
2049 vertices[8 * c + v][1] = vertices[v][1];
2050 vertices[8 * c + v][2] = inner_radius_2d * std::sin(phi_cell * c);
2051 }
2052 }
2053
2054 // cell connectivity
2055 std::vector<CellData<3>> cells(5 * n_cells_toroidal);
2056 for (unsigned int c = 0; c < n_cells_toroidal; ++c)
2057 {
2058 for (unsigned int j = 0; j < 2; ++j)
2059 {
2060 const unsigned int offset =
2061 (8 * (c + j)) % (8 * n_point_layers_toroidal);
2062
2063 // cells in x-y-plane
2064 for (unsigned int c2 = 0; c2 < 5; ++c2)
2065 for (unsigned int i = 0; i < 4; ++i)
2066 cells[5 * c + c2].vertices[i + j * 4] =
2067 offset + circle_cell_vertices[c2][i];
2068 }
2069
2070 cells[5 * c].material_id = 0;
2071 // mark cell on torus centerline
2072 cells[5 * c + 1].material_id = 0;
2073 cells[5 * c + 2].material_id = 1;
2074 cells[5 * c + 3].material_id = 0;
2075 cells[5 * c + 4].material_id = 0;
2076 }
2077
2078 tria.create_triangulation(vertices, cells, SubCellData());
2079
2080 tria.reset_all_manifolds();
2081 tria.set_all_manifold_ids(0);
2082
2083 for (const auto &cell : tria.cell_iterators())
2084 {
2085 // identify faces on torus surface and set manifold to 1
2086 for (const unsigned int f : GeometryInfo<3>::face_indices())
2087 {
2088 // faces 4 and 5 are those with normal vector aligned with torus
2089 // centerline
2090 if (cell->face(f)->at_boundary() && f != 4 && f != 5)
2091 {
2092 cell->face(f)->set_all_manifold_ids(1);
2093 }
2094 }
2095
2096 // set manifold id to 2 for those cells that are on the torus centerline
2097 if (cell->material_id() == 1)
2098 {
2099 cell->set_all_manifold_ids(2);
2100 // reset to 0
2101 cell->set_material_id(0);
2102 }
2103 }
2104
2105 tria.set_manifold(1, TorusManifold<3>(centerline_radius, inner_radius));
2106 tria.set_manifold(2,
2108 Point<3>()));
2109
2110 tria.set_manifold(0, FlatManifold<3>());
2112 transfinite.initialize(tria);
2113 tria.set_manifold(0, transfinite);
2114 }
2115
2116
2117
2118 template <int dim, int spacedim>
2119 void
2121 const std::vector<Point<spacedim>> &vertices,
2122 const bool colorize)
2123 {
2125 ExcMessage("Wrong number of vertices."));
2126
2127 // First create a hyper_rectangle and then deform it.
2128 hyper_cube(tria, 0, 1, colorize);
2129
2131 tria.begin_active();
2132 for (const unsigned int i : GeometryInfo<dim>::vertex_indices())
2133 cell->vertex(i) = vertices[i];
2134
2135 // Check that the order of the vertices makes sense, i.e., the volume of the
2136 // cell is positive.
2138 ExcMessage(
2139 "The volume of the cell is not greater than zero. "
2140 "This could be due to the wrong ordering of the vertices."));
2141 }
2142
2143
2144
2145 template <>
2146 void
2148 const Point<3> (& /*corners*/)[3],
2149 const bool /*colorize*/)
2150 {
2152 }
2153
2154 template <>
2155 void
2157 const Point<1> (& /*corners*/)[1],
2158 const bool /*colorize*/)
2159 {
2161 }
2162
2163 // Implementation for 2d only
2164 template <>
2165 void
2167 const Point<2> (&corners)[2],
2168 const bool colorize)
2169 {
2171 std::array<Tensor<1, 2>, 2> edges;
2172 edges[0] = corners[0];
2173 edges[1] = corners[1];
2174 std::vector<unsigned int> subdivisions;
2177 }
2178
2179
2180
2181 template <int dim>
2182 void
2184 const Point<dim> (&corners)[dim],
2185 const bool colorize)
2186 {
2187 unsigned int n_subdivisions[dim];
2188 for (unsigned int i = 0; i < dim; ++i)
2189 n_subdivisions[i] = 1;
2190
2191 // and call the function below
2192 subdivided_parallelepiped(tria, n_subdivisions, corners, colorize);
2193 }
2194
2195 template <int dim>
2196 void
2198 const unsigned int n_subdivisions,
2199 const Point<dim> (&corners)[dim],
2200 const bool colorize)
2201 {
2202 // Equalize number of subdivisions in each dim-direction, their
2203 // validity will be checked later
2204 unsigned int n_subdivisions_[dim];
2205 for (unsigned int i = 0; i < dim; ++i)
2206 n_subdivisions_[i] = n_subdivisions;
2207
2208 // and call the function below
2210 }
2211
2212 template <int dim>
2213 void
2216 const unsigned int (&n_subdivisions)[dim],
2217# else
2218 const unsigned int *n_subdivisions,
2219# endif
2220 const Point<dim> (&corners)[dim],
2221 const bool colorize)
2222 {
2224 std::vector<unsigned int> subdivisions;
2225 std::array<Tensor<1, dim>, dim> edges;
2226 for (unsigned int i = 0; i < dim; ++i)
2227 {
2228 subdivisions.push_back(n_subdivisions[i]);
2229 edges[i] = corners[i];
2230 }
2231
2234 }
2235
2236 // Parallelepiped implementation in 1d, 2d, and 3d. @note The
2237 // implementation in 1d is similar to hyper_rectangle(), and in 2d is
2238 // similar to parallelogram().
2239 template <int dim, int spacedim>
2240 void
2242 const Point<spacedim> &origin,
2243 const std::array<Tensor<1, spacedim>, dim> &edges,
2244 const std::vector<unsigned int> &subdivisions,
2245 const bool colorize)
2246 {
2247 std::vector<unsigned int> compute_subdivisions = subdivisions;
2248 if (compute_subdivisions.empty())
2249 {
2250 compute_subdivisions.resize(dim, 1);
2251 }
2252
2253 Assert(compute_subdivisions.size() == dim,
2254 ExcMessage("One subdivision must be provided for each dimension."));
2255 // check subdivisions
2256 for (unsigned int i = 0; i < dim; ++i)
2257 {
2259 ExcInvalidRepetitions(subdivisions[i]));
2260 Assert(
2261 edges[i].norm() > 0,
2262 ExcMessage(
2263 "Edges in subdivided_parallelepiped() must not be degenerate."));
2264 }
2265
2266 /*
2267 * Verify that the edge points to the right in 1d, vectors are oriented in
2268 * a counter clockwise direction in 2d, or form a right handed system in
2269 * 3d.
2270 */
2271 bool twisted_data = false;
2272 switch (dim)
2273 {
2274 case 1:
2275 {
2276 twisted_data = (edges[0][0] < 0);
2277 break;
2278 }
2279 case 2:
2280 {
2281 if (spacedim == 2) // this check does not make sense otherwise
2282 {
2283 const double plane_normal =
2284 edges[0][0] * edges[1][1] - edges[0][1] * edges[1][0];
2285 twisted_data = (plane_normal < 0.0);
2286 }
2287 break;
2288 }
2289 case 3:
2290 {
2291 // Check that the first two vectors are not linear combinations to
2292 // avoid zero division later on.
2293 Assert(std::abs(edges[0] * edges[1] /
2294 (edges[0].norm() * edges[1].norm()) -
2295 1.0) > 1.0e-15,
2296 ExcMessage(
2297 "Edges in subdivided_parallelepiped() must point in"
2298 " different directions."));
2301
2302 /*
2303 * Ensure that edges 1, 2, and 3 form a right-handed set of
2304 * vectors. This works by applying the definition of the dot product
2305 *
2306 * cos(theta) = dot(x, y)/(norm(x)*norm(y))
2307 *
2308 * and then, since the normal vector and third edge should both
2309 * point away from the plane formed by the first two edges, the
2310 * angle between them must be between 0 and pi/2; hence we just need
2311 *
2312 * 0 < dot(x, y).
2313 */
2314 twisted_data = (plane_normal * edges[2] < 0.0);
2315 break;
2316 }
2317 default:
2319 }
2320 (void)twisted_data; // make the static analyzer happy
2321 Assert(
2322 !twisted_data,
2323 ExcInvalidInputOrientation(
2324 "The triangulation you are trying to create will consist of cells"
2325 " with negative measures. This is usually the result of input data"
2326 " that does not define a right-handed coordinate system. The usual"
2327 " fix for this is to ensure that in 1d the given point is to the"
2328 " right of the origin (or the given edge tensor is positive), in 2d"
2329 " that the two edges (and their cross product) obey the right-hand"
2330 " rule (which may usually be done by switching the order of the"
2331 " points or edge tensors), or in 3d that the edges form a"
2332 " right-handed coordinate system (which may also be accomplished by"
2333 " switching the order of the first two points or edge tensors)."));
2334
2335 // Check corners do not overlap (unique)
2336 for (unsigned int i = 0; i < dim; ++i)
2337 for (unsigned int j = i + 1; j < dim; ++j)
2338 Assert((edges[i] != edges[j]),
2339 ExcMessage(
2340 "Degenerate edges of subdivided_parallelepiped encountered."));
2341
2342 // Create a list of points
2343 std::vector<Point<spacedim>> points;
2344
2345 switch (dim)
2346 {
2347 case 1:
2348 for (unsigned int x = 0; x <= compute_subdivisions[0]; ++x)
2349 points.push_back(origin + edges[0] / compute_subdivisions[0] * x);
2350 break;
2351
2352 case 2:
2353 for (unsigned int y = 0; y <= compute_subdivisions[1]; ++y)
2354 for (unsigned int x = 0; x <= compute_subdivisions[0]; ++x)
2355 points.push_back(origin + edges[0] / compute_subdivisions[0] * x +
2356 edges[1] / compute_subdivisions[1] * y);
2357 break;
2358
2359 case 3:
2360 for (unsigned int z = 0; z <= compute_subdivisions[2]; ++z)
2361 for (unsigned int y = 0; y <= compute_subdivisions[1]; ++y)
2362 for (unsigned int x = 0; x <= compute_subdivisions[0]; ++x)
2363 points.push_back(origin +
2364 edges[0] / compute_subdivisions[0] * x +
2365 edges[1] / compute_subdivisions[1] * y +
2366 edges[2] / compute_subdivisions[2] * z);
2367 break;
2368
2369 default:
2371 }
2372
2373 // Prepare cell data
2374 unsigned int n_cells = 1;
2375 for (unsigned int i = 0; i < dim; ++i)
2376 n_cells *= compute_subdivisions[i];
2377 std::vector<CellData<dim>> cells(n_cells);
2378
2379 // Create fixed ordering of
2380 switch (dim)
2381 {
2382 case 1:
2383 for (unsigned int x = 0; x < compute_subdivisions[0]; ++x)
2384 {
2385 cells[x].vertices[0] = x;
2386 cells[x].vertices[1] = x + 1;
2387
2388 // wipe material id
2389 cells[x].material_id = 0;
2390 }
2391 break;
2392
2393 case 2:
2394 {
2395 // Shorthand
2396 const unsigned int n_dy = compute_subdivisions[1];
2397 const unsigned int n_dx = compute_subdivisions[0];
2398
2399 for (unsigned int y = 0; y < n_dy; ++y)
2400 for (unsigned int x = 0; x < n_dx; ++x)
2401 {
2402 const unsigned int c = y * n_dx + x;
2403 cells[c].vertices[0] = y * (n_dx + 1) + x;
2404 cells[c].vertices[1] = y * (n_dx + 1) + x + 1;
2405 cells[c].vertices[2] = (y + 1) * (n_dx + 1) + x;
2406 cells[c].vertices[3] = (y + 1) * (n_dx + 1) + x + 1;
2407
2408 // wipe material id
2409 cells[c].material_id = 0;
2410 }
2411 }
2412 break;
2413
2414 case 3:
2415 {
2416 // Shorthand
2417 const unsigned int n_dz = compute_subdivisions[2];
2418 const unsigned int n_dy = compute_subdivisions[1];
2419 const unsigned int n_dx = compute_subdivisions[0];
2420
2421 for (unsigned int z = 0; z < n_dz; ++z)
2422 for (unsigned int y = 0; y < n_dy; ++y)
2423 for (unsigned int x = 0; x < n_dx; ++x)
2424 {
2425 const unsigned int c = z * n_dy * n_dx + y * n_dx + x;
2426
2427 cells[c].vertices[0] =
2428 z * (n_dy + 1) * (n_dx + 1) + y * (n_dx + 1) + x;
2429 cells[c].vertices[1] =
2430 z * (n_dy + 1) * (n_dx + 1) + y * (n_dx + 1) + x + 1;
2431 cells[c].vertices[2] =
2432 z * (n_dy + 1) * (n_dx + 1) + (y + 1) * (n_dx + 1) + x;
2433 cells[c].vertices[3] = z * (n_dy + 1) * (n_dx + 1) +
2434 (y + 1) * (n_dx + 1) + x + 1;
2435 cells[c].vertices[4] =
2436 (z + 1) * (n_dy + 1) * (n_dx + 1) + y * (n_dx + 1) + x;
2437 cells[c].vertices[5] = (z + 1) * (n_dy + 1) * (n_dx + 1) +
2438 y * (n_dx + 1) + x + 1;
2439 cells[c].vertices[6] = (z + 1) * (n_dy + 1) * (n_dx + 1) +
2440 (y + 1) * (n_dx + 1) + x;
2441 cells[c].vertices[7] = (z + 1) * (n_dy + 1) * (n_dx + 1) +
2442 (y + 1) * (n_dx + 1) + x + 1;
2443
2444 // wipe material id
2445 cells[c].material_id = 0;
2446 }
2447 break;
2448 }
2449
2450 default:
2452 }
2453
2454 // Create triangulation
2455 // reorder the cells to ensure that they satisfy the convention for
2456 // edge and face directions
2458 tria.create_triangulation(points, cells, SubCellData());
2459
2460 // Finally assign boundary indicators according to hyper_rectangle
2461 if (colorize)
2462 {
2464 tria.begin_active(),
2465 endc = tria.end();
2466 for (; cell != endc; ++cell)
2467 {
2468 for (const unsigned int face : GeometryInfo<dim>::face_indices())
2469 {
2470 if (cell->face(face)->at_boundary())
2471 cell->face(face)->set_boundary_id(face);
2472 }
2473 }
2474 }
2475 }
2476
2477
2478 template <int dim, int spacedim>
2479 void
2481 const unsigned int repetitions,
2482 const double left,
2483 const double right,
2484 const bool colorize)
2485 {
2486 Assert(repetitions >= 1, ExcInvalidRepetitions(repetitions));
2487 Assert(left < right,
2488 ExcMessage("Invalid left-to-right bounds of hypercube"));
2489
2490 Point<dim> p0, p1;
2491 for (unsigned int i = 0; i < dim; ++i)
2492 {
2493 p0[i] = left;
2494 p1[i] = right;
2495 }
2496
2497 std::vector<unsigned int> reps(dim, repetitions);
2499 }
2500
2501
2502
2503 template <int dim, int spacedim>
2504 void
2506 const std::vector<unsigned int> &repetitions,
2507 const Point<dim> &p_1,
2508 const Point<dim> &p_2,
2509 const bool colorize)
2510 {
2511 Assert(repetitions.size() == dim, ExcInvalidRepetitionsDimension(dim));
2512
2513 // First, extend dimensions from dim to spacedim and
2514 // normalize such that p1 is lower in all coordinate
2515 // directions. Additional entries will be 0.
2517 for (unsigned int i = 0; i < dim; ++i)
2518 {
2519 p1[i] = std::min(p_1[i], p_2[i]);
2520 p2[i] = std::max(p_1[i], p_2[i]);
2521 }
2522
2523 // calculate deltas and validate input
2524 std::array<Point<spacedim>, dim> delta;
2525 for (unsigned int i = 0; i < dim; ++i)
2526 {
2527 Assert(repetitions[i] >= 1, ExcInvalidRepetitions(repetitions[i]));
2528
2529 delta[i][i] = (p2[i] - p1[i]) / repetitions[i];
2530 Assert(
2531 delta[i][i] > 0.0,
2532 ExcMessage(
2533 "The first dim entries of coordinates of p1 and p2 need to be different."));
2534 }
2535
2536 // then generate the points
2537 std::vector<Point<spacedim>> points;
2538 switch (dim)
2539 {
2540 case 1:
2541 for (unsigned int x = 0; x <= repetitions[0]; ++x)
2542 points.push_back(p1 + x * delta[0]);
2543 break;
2544
2545 case 2:
2546 for (unsigned int y = 0; y <= repetitions[1]; ++y)
2547 for (unsigned int x = 0; x <= repetitions[0]; ++x)
2548 points.push_back(p1 + x * delta[0] + y * delta[1]);
2549 break;
2550
2551 case 3:
2552 for (unsigned int z = 0; z <= repetitions[2]; ++z)
2553 for (unsigned int y = 0; y <= repetitions[1]; ++y)
2554 for (unsigned int x = 0; x <= repetitions[0]; ++x)
2555 points.push_back(p1 + x * delta[0] + y * delta[1] +
2556 z * delta[2]);
2557 break;
2558
2559 default:
2561 }
2562
2563 // next create the cells
2564 std::vector<CellData<dim>> cells;
2565 switch (dim)
2566 {
2567 case 1:
2568 {
2569 cells.resize(repetitions[0]);
2570 for (unsigned int x = 0; x < repetitions[0]; ++x)
2571 {
2572 cells[x].vertices[0] = x;
2573 cells[x].vertices[1] = x + 1;
2574 cells[x].material_id = 0;
2575 }
2576 break;
2577 }
2578
2579 case 2:
2580 {
2581 cells.resize(repetitions[1] * repetitions[0]);
2582 for (unsigned int y = 0; y < repetitions[1]; ++y)
2583 for (unsigned int x = 0; x < repetitions[0]; ++x)
2584 {
2585 const unsigned int c = x + y * repetitions[0];
2586 cells[c].vertices[0] = y * (repetitions[0] + 1) + x;
2587 cells[c].vertices[1] = y * (repetitions[0] + 1) + x + 1;
2588 cells[c].vertices[2] = (y + 1) * (repetitions[0] + 1) + x;
2589 cells[c].vertices[3] = (y + 1) * (repetitions[0] + 1) + x + 1;
2590 cells[c].material_id = 0;
2591 }
2592 break;
2593 }
2594
2595 case 3:
2596 {
2597 const unsigned int n_x = (repetitions[0] + 1);
2598 const unsigned int n_xy =
2599 (repetitions[0] + 1) * (repetitions[1] + 1);
2600
2601 cells.resize(repetitions[2] * repetitions[1] * repetitions[0]);
2602 for (unsigned int z = 0; z < repetitions[2]; ++z)
2603 for (unsigned int y = 0; y < repetitions[1]; ++y)
2604 for (unsigned int x = 0; x < repetitions[0]; ++x)
2605 {
2606 const unsigned int c = x + y * repetitions[0] +
2607 z * repetitions[0] * repetitions[1];
2608 cells[c].vertices[0] = z * n_xy + y * n_x + x;
2609 cells[c].vertices[1] = z * n_xy + y * n_x + x + 1;
2610 cells[c].vertices[2] = z * n_xy + (y + 1) * n_x + x;
2611 cells[c].vertices[3] = z * n_xy + (y + 1) * n_x + x + 1;
2612 cells[c].vertices[4] = (z + 1) * n_xy + y * n_x + x;
2613 cells[c].vertices[5] = (z + 1) * n_xy + y * n_x + x + 1;
2614 cells[c].vertices[6] = (z + 1) * n_xy + (y + 1) * n_x + x;
2615 cells[c].vertices[7] =
2616 (z + 1) * n_xy + (y + 1) * n_x + x + 1;
2617 cells[c].material_id = 0;
2618 }
2619 break;
2620 }
2621
2622 default:
2624 }
2625
2626 tria.create_triangulation(points, cells, SubCellData());
2627
2628 if (colorize)
2629 {
2630 // to colorize, run through all
2631 // faces of all cells and set
2632 // boundary indicator to the
2633 // correct value if it was 0.
2634
2635 // use a large epsilon to
2636 // compare numbers to avoid
2637 // roundoff problems.
2638 double epsilon = std::numeric_limits<double>::max();
2639 for (unsigned int i = 0; i < dim; ++i)
2640 epsilon = std::min(epsilon, 0.01 * delta[i][i]);
2641 Assert(epsilon > 0,
2642 ExcMessage(
2643 "The distance between corner points must be positive."));
2644
2645 // actual code is external since
2646 // 1-D is different from 2/3d.
2647 colorize_subdivided_hyper_rectangle(tria, p1, p2, epsilon);
2648 }
2649 }
2650
2651
2652
2653 template <int dim>
2654 void
2656 const std::vector<std::vector<double>> &step_sz,
2657 const Point<dim> &p_1,
2658 const Point<dim> &p_2,
2659 const bool colorize)
2660 {
2661 Assert(step_sz.size() == dim, ExcInvalidRepetitionsDimension(dim));
2662
2663 // First, normalize input such that
2664 // p1 is lower in all coordinate
2665 // directions and check the consistency of
2666 // step sizes, i.e. that they all
2667 // add up to the sizes specified by
2668 // p_1 and p_2
2669 Point<dim> p1(p_1);
2670 Point<dim> p2(p_2);
2671 std::vector<std::vector<double>> step_sizes(step_sz);
2672
2673 for (unsigned int i = 0; i < dim; ++i)
2674 {
2675 if (p1[i] > p2[i])
2676 {
2677 std::swap(p1[i], p2[i]);
2678 std::reverse(step_sizes[i].begin(), step_sizes[i].end());
2679 }
2680
2681# ifdef DEBUG
2682 double x = 0;
2683 for (unsigned int j = 0; j < step_sizes.at(i).size(); ++j)
2684 x += step_sizes[i][j];
2685 Assert(std::fabs(x - (p2[i] - p1[i])) <= 1e-12 * std::fabs(x),
2686 ExcMessage(
2687 "The sequence of step sizes in coordinate direction " +
2689 " must be equal to the distance of the two given "
2690 "points in this coordinate direction."));
2691# endif
2692 }
2693
2694
2695 // then generate the necessary
2696 // points
2697 std::vector<Point<dim>> points;
2698 switch (dim)
2699 {
2700 case 1:
2701 {
2702 double x = 0;
2703 for (unsigned int i = 0;; ++i)
2704 {
2705 points.push_back(Point<dim>(p1[0] + x));
2706
2707 // form partial sums. in
2708 // the last run through
2709 // avoid accessing
2710 // non-existent values
2711 // and exit early instead
2712 if (i == step_sizes[0].size())
2713 break;
2714
2715 x += step_sizes[0][i];
2716 }
2717 break;
2718 }
2719
2720 case 2:
2721 {
2722 double y = 0;
2723 for (unsigned int j = 0;; ++j)
2724 {
2725 double x = 0;
2726 for (unsigned int i = 0;; ++i)
2727 {
2728 points.push_back(Point<dim>(p1[0] + x, p1[1] + y));
2729 if (i == step_sizes[0].size())
2730 break;
2731
2732 x += step_sizes[0][i];
2733 }
2734
2735 if (j == step_sizes[1].size())
2736 break;
2737
2738 y += step_sizes[1][j];
2739 }
2740 break;
2741 }
2742 case 3:
2743 {
2744 double z = 0;
2745 for (unsigned int k = 0;; ++k)
2746 {
2747 double y = 0;
2748 for (unsigned int j = 0;; ++j)
2749 {
2750 double x = 0;
2751 for (unsigned int i = 0;; ++i)
2752 {
2753 points.push_back(
2754 Point<dim>(p1[0] + x, p1[1] + y, p1[2] + z));
2755 if (i == step_sizes[0].size())
2756 break;
2757
2758 x += step_sizes[0][i];
2759 }
2760
2761 if (j == step_sizes[1].size())
2762 break;
2763
2764 y += step_sizes[1][j];
2765 }
2766
2767 if (k == step_sizes[2].size())
2768 break;
2769
2770 z += step_sizes[2][k];
2771 }
2772 break;
2773 }
2774
2775 default:
2777 }
2778
2779 // next create the cells
2780 // Prepare cell data
2781 std::vector<CellData<dim>> cells;
2782 switch (dim)
2783 {
2784 case 1:
2785 {
2786 cells.resize(step_sizes[0].size());
2787 for (unsigned int x = 0; x < step_sizes[0].size(); ++x)
2788 {
2789 cells[x].vertices[0] = x;
2790 cells[x].vertices[1] = x + 1;
2791 cells[x].material_id = 0;
2792 }
2793 break;
2794 }
2795
2796 case 2:
2797 {
2798 cells.resize(step_sizes[1].size() * step_sizes[0].size());
2799 for (unsigned int y = 0; y < step_sizes[1].size(); ++y)
2800 for (unsigned int x = 0; x < step_sizes[0].size(); ++x)
2801 {
2802 const unsigned int c = x + y * step_sizes[0].size();
2803 cells[c].vertices[0] = y * (step_sizes[0].size() + 1) + x;
2804 cells[c].vertices[1] = y * (step_sizes[0].size() + 1) + x + 1;
2805 cells[c].vertices[2] =
2806 (y + 1) * (step_sizes[0].size() + 1) + x;
2807 cells[c].vertices[3] =
2808 (y + 1) * (step_sizes[0].size() + 1) + x + 1;
2809 cells[c].material_id = 0;
2810 }
2811 break;
2812 }
2813
2814 case 3:
2815 {
2816 const unsigned int n_x = (step_sizes[0].size() + 1);
2817 const unsigned int n_xy =
2818 (step_sizes[0].size() + 1) * (step_sizes[1].size() + 1);
2819
2820 cells.resize(step_sizes[2].size() * step_sizes[1].size() *
2821 step_sizes[0].size());
2822 for (unsigned int z = 0; z < step_sizes[2].size(); ++z)
2823 for (unsigned int y = 0; y < step_sizes[1].size(); ++y)
2824 for (unsigned int x = 0; x < step_sizes[0].size(); ++x)
2825 {
2826 const unsigned int c =
2827 x + y * step_sizes[0].size() +
2828 z * step_sizes[0].size() * step_sizes[1].size();
2829 cells[c].vertices[0] = z * n_xy + y * n_x + x;
2830 cells[c].vertices[1] = z * n_xy + y * n_x + x + 1;
2831 cells[c].vertices[2] = z * n_xy + (y + 1) * n_x + x;
2832 cells[c].vertices[3] = z * n_xy + (y + 1) * n_x + x + 1;
2833 cells[c].vertices[4] = (z + 1) * n_xy + y * n_x + x;
2834 cells[c].vertices[5] = (z + 1) * n_xy + y * n_x + x + 1;
2835 cells[c].vertices[6] = (z + 1) * n_xy + (y + 1) * n_x + x;
2836 cells[c].vertices[7] =
2837 (z + 1) * n_xy + (y + 1) * n_x + x + 1;
2838 cells[c].material_id = 0;
2839 }
2840 break;
2841 }
2842
2843 default:
2845 }
2846
2847 tria.create_triangulation(points, cells, SubCellData());
2848
2849 if (colorize)
2850 {
2851 // to colorize, run through all
2852 // faces of all cells and set
2853 // boundary indicator to the
2854 // correct value if it was 0.
2855
2856 // use a large epsilon to
2857 // compare numbers to avoid
2858 // roundoff problems.
2859 double min_size =
2860 *std::min_element(step_sizes[0].begin(), step_sizes[0].end());
2861 for (unsigned int i = 1; i < dim; ++i)
2863 *std::min_element(step_sizes[i].begin(),
2864 step_sizes[i].end()));
2865 const double epsilon = 0.01 * min_size;
2866
2867 // actual code is external since
2868 // 1-D is different from 2/3d.
2869 colorize_subdivided_hyper_rectangle(tria, p1, p2, epsilon);
2870 }
2871 }
2872
2873
2874
2875 template <>
2876 void
2878 const std::vector<std::vector<double>> &spacing,
2879 const Point<1> &p,
2880 const Table<1, types::material_id> &material_id,
2881 const bool colorize)
2882 {
2883 Assert(spacing.size() == 1, ExcInvalidRepetitionsDimension(1));
2884
2885 const unsigned int n_cells = material_id.size(0);
2886
2887 Assert(spacing[0].size() == n_cells, ExcInvalidRepetitionsDimension(1));
2888
2889 double delta = std::numeric_limits<double>::max();
2890 for (unsigned int i = 0; i < n_cells; ++i)
2891 {
2892 Assert(spacing[0][i] >= 0, ExcInvalidRepetitions(-1));
2893 delta = std::min(delta, spacing[0][i]);
2894 }
2895
2896 // generate the necessary points
2897 std::vector<Point<1>> points;
2898 double ax = p[0];
2899 for (unsigned int x = 0; x <= n_cells; ++x)
2900 {
2901 points.emplace_back(ax);
2902 if (x < n_cells)
2903 ax += spacing[0][x];
2904 }
2905 // create the cells
2906 unsigned int n_val_cells = 0;
2907 for (unsigned int i = 0; i < n_cells; ++i)
2908 if (material_id[i] != numbers::invalid_material_id)
2909 ++n_val_cells;
2910
2911 std::vector<CellData<1>> cells(n_val_cells);
2912 unsigned int id = 0;
2913 for (unsigned int x = 0; x < n_cells; ++x)
2914 if (material_id[x] != numbers::invalid_material_id)
2915 {
2916 cells[id].vertices[0] = x;
2917 cells[id].vertices[1] = x + 1;
2918 cells[id].material_id = material_id[x];
2919 ++id;
2920 }
2921 // create triangulation
2922 SubCellData t;
2923 GridTools::delete_unused_vertices(points, cells, t);
2924
2925 tria.create_triangulation(points, cells, t);
2926
2927 // set boundary indicator
2928 if (colorize)
2930 }
2931
2932
2933 template <>
2934 void
2936 const std::vector<std::vector<double>> &spacing,
2937 const Point<2> &p,
2938 const Table<2, types::material_id> &material_id,
2939 const bool colorize)
2940 {
2941 Assert(spacing.size() == 2, ExcInvalidRepetitionsDimension(2));
2942
2943 std::vector<unsigned int> repetitions(2);
2944 double delta = std::numeric_limits<double>::max();
2945 for (unsigned int i = 0; i < 2; ++i)
2946 {
2947 repetitions[i] = spacing[i].size();
2948 for (unsigned int j = 0; j < repetitions[i]; ++j)
2949 {
2950 Assert(spacing[i][j] >= 0, ExcInvalidRepetitions(-1));
2951 delta = std::min(delta, spacing[i][j]);
2952 }
2953 Assert(material_id.size(i) == repetitions[i],
2954 ExcInvalidRepetitionsDimension(i));
2955 }
2956
2957 // generate the necessary points
2958 std::vector<Point<2>> points;
2959 double ay = p[1];
2960 for (unsigned int y = 0; y <= repetitions[1]; ++y)
2961 {
2962 double ax = p[0];
2963 for (unsigned int x = 0; x <= repetitions[0]; ++x)
2964 {
2965 points.emplace_back(ax, ay);
2966 if (x < repetitions[0])
2967 ax += spacing[0][x];
2968 }
2969 if (y < repetitions[1])
2970 ay += spacing[1][y];
2971 }
2972
2973 // create the cells
2974 unsigned int n_val_cells = 0;
2975 for (unsigned int i = 0; i < material_id.size(0); ++i)
2976 for (unsigned int j = 0; j < material_id.size(1); ++j)
2977 if (material_id[i][j] != numbers::invalid_material_id)
2978 ++n_val_cells;
2979
2980 std::vector<CellData<2>> cells(n_val_cells);
2981 unsigned int id = 0;
2982 for (unsigned int y = 0; y < repetitions[1]; ++y)
2983 for (unsigned int x = 0; x < repetitions[0]; ++x)
2984 if (material_id[x][y] != numbers::invalid_material_id)
2985 {
2986 cells[id].vertices[0] = y * (repetitions[0] + 1) + x;
2987 cells[id].vertices[1] = y * (repetitions[0] + 1) + x + 1;
2988 cells[id].vertices[2] = (y + 1) * (repetitions[0] + 1) + x;
2989 cells[id].vertices[3] = (y + 1) * (repetitions[0] + 1) + x + 1;
2990 cells[id].material_id = material_id[x][y];
2991 ++id;
2992 }
2993
2994 // create triangulation
2995 SubCellData t;
2996 GridTools::delete_unused_vertices(points, cells, t);
2997
2998 tria.create_triangulation(points, cells, t);
2999
3000 // set boundary indicator
3001 if (colorize)
3002 {
3003 double eps = 0.01 * delta;
3004 Triangulation<2>::cell_iterator cell = tria.begin(), endc = tria.end();
3005 for (; cell != endc; ++cell)
3006 {
3007 Point<2> cell_center = cell->center();
3008 for (const unsigned int f : GeometryInfo<2>::face_indices())
3009 if (cell->face(f)->boundary_id() == 0)
3010 {
3011 Point<2> face_center = cell->face(f)->center();
3012 for (unsigned int i = 0; i < 2; ++i)
3013 {
3014 if (face_center[i] < cell_center[i] - eps)
3015 cell->face(f)->set_boundary_id(i * 2);
3016 if (face_center[i] > cell_center[i] + eps)
3017 cell->face(f)->set_boundary_id(i * 2 + 1);
3018 }
3019 }
3020 }
3021 }
3022 }
3023
3024
3025 template <>
3026 void
3028 const std::vector<std::vector<double>> &spacing,
3029 const Point<3> &p,
3030 const Table<3, types::material_id> &material_id,
3031 const bool colorize)
3032 {
3033 const unsigned int dim = 3;
3034
3035 Assert(spacing.size() == dim, ExcInvalidRepetitionsDimension(dim));
3036
3037 std::array<unsigned int, dim> repetitions;
3038 double delta = std::numeric_limits<double>::max();
3039 for (unsigned int i = 0; i < dim; ++i)
3040 {
3041 repetitions[i] = spacing[i].size();
3042 for (unsigned int j = 0; j < repetitions[i]; ++j)
3043 {
3044 Assert(spacing[i][j] >= 0, ExcInvalidRepetitions(-1));
3045 delta = std::min(delta, spacing[i][j]);
3046 }
3047 Assert(material_id.size(i) == repetitions[i],
3048 ExcInvalidRepetitionsDimension(i));
3049 }
3050
3051 // generate the necessary points
3052 std::vector<Point<dim>> points;
3053 double az = p[2];
3054 for (unsigned int z = 0; z <= repetitions[2]; ++z)
3055 {
3056 double ay = p[1];
3057 for (unsigned int y = 0; y <= repetitions[1]; ++y)
3058 {
3059 double ax = p[0];
3060 for (unsigned int x = 0; x <= repetitions[0]; ++x)
3061 {
3062 points.emplace_back(ax, ay, az);
3063 if (x < repetitions[0])
3064 ax += spacing[0][x];
3065 }
3066 if (y < repetitions[1])
3067 ay += spacing[1][y];
3068 }
3069 if (z < repetitions[2])
3070 az += spacing[2][z];
3071 }
3072
3073 // create the cells
3074 unsigned int n_val_cells = 0;
3075 for (unsigned int i = 0; i < material_id.size(0); ++i)
3076 for (unsigned int j = 0; j < material_id.size(1); ++j)
3077 for (unsigned int k = 0; k < material_id.size(2); ++k)
3078 if (material_id[i][j][k] != numbers::invalid_material_id)
3079 ++n_val_cells;
3080
3081 std::vector<CellData<dim>> cells(n_val_cells);
3082 unsigned int id = 0;
3083 const unsigned int n_x = (repetitions[0] + 1);
3084 const unsigned int n_xy = (repetitions[0] + 1) * (repetitions[1] + 1);
3085 for (unsigned int z = 0; z < repetitions[2]; ++z)
3086 for (unsigned int y = 0; y < repetitions[1]; ++y)
3087 for (unsigned int x = 0; x < repetitions[0]; ++x)
3088 if (material_id[x][y][z] != numbers::invalid_material_id)
3089 {
3090 cells[id].vertices[0] = z * n_xy + y * n_x + x;
3091 cells[id].vertices[1] = z * n_xy + y * n_x + x + 1;
3092 cells[id].vertices[2] = z * n_xy + (y + 1) * n_x + x;
3093 cells[id].vertices[3] = z * n_xy + (y + 1) * n_x + x + 1;
3094 cells[id].vertices[4] = (z + 1) * n_xy + y * n_x + x;
3095 cells[id].vertices[5] = (z + 1) * n_xy + y * n_x + x + 1;
3096 cells[id].vertices[6] = (z + 1) * n_xy + (y + 1) * n_x + x;
3097 cells[id].vertices[7] = (z + 1) * n_xy + (y + 1) * n_x + x + 1;
3098 cells[id].material_id = material_id[x][y][z];
3099 ++id;
3100 }
3101
3102 // create triangulation
3103 SubCellData t;
3104 GridTools::delete_unused_vertices(points, cells, t);
3105
3106 tria.create_triangulation(points, cells, t);
3107
3108 // set boundary indicator
3109 if (colorize)
3110 {
3111 double eps = 0.01 * delta;
3112 Triangulation<dim>::cell_iterator cell = tria.begin(),
3113 endc = tria.end();
3114 for (; cell != endc; ++cell)
3115 {
3116 Point<dim> cell_center = cell->center();
3117 for (auto f : GeometryInfo<dim>::face_indices())
3118 if (cell->face(f)->boundary_id() == 0)
3119 {
3120 Point<dim> face_center = cell->face(f)->center();
3121 for (unsigned int i = 0; i < dim; ++i)
3122 {
3123 if (face_center[i] < cell_center[i] - eps)
3124 cell->face(f)->set_boundary_id(i * 2);
3125 if (face_center[i] > cell_center[i] + eps)
3126 cell->face(f)->set_boundary_id(i * 2 + 1);
3127 }
3128 }
3129 }
3130 }
3131 }
3132
3133 template <int dim, int spacedim>
3134 void
3136 const std::vector<unsigned int> &holes)
3137 {
3138 AssertDimension(holes.size(), dim);
3139 // The corner points of the first cell. If there is a desire at
3140 // some point to change the geometry of the cells, they can be
3141 // made an argument to the function.
3142
3145 for (unsigned int d = 0; d < dim; ++d)
3146 p2[d] = 1.;
3147
3148 // then check that all repetitions
3149 // are >= 1, and calculate deltas
3150 // convert repetitions from double
3151 // to int by taking the ceiling.
3152 std::array<Point<spacedim>, dim> delta;
3153 std::array<unsigned int, dim> repetitions;
3154 for (unsigned int i = 0; i < dim; ++i)
3155 {
3156 Assert(holes[i] >= 1,
3157 ExcMessage("At least one hole needed in each direction"));
3158 repetitions[i] = 2 * holes[i] + 1;
3159 delta[i][i] = (p2[i] - p1[i]);
3160 }
3161
3162 // then generate the necessary
3163 // points
3164 std::vector<Point<spacedim>> points;
3165 switch (dim)
3166 {
3167 case 1:
3168 for (unsigned int x = 0; x <= repetitions[0]; ++x)
3169 points.push_back(p1 + x * delta[0]);
3170 break;
3171
3172 case 2:
3173 for (unsigned int y = 0; y <= repetitions[1]; ++y)
3174 for (unsigned int x = 0; x <= repetitions[0]; ++x)
3175 points.push_back(p1 + x * delta[0] + y * delta[1]);
3176 break;
3177
3178 case 3:
3179 for (unsigned int z = 0; z <= repetitions[2]; ++z)
3180 for (unsigned int y = 0; y <= repetitions[1]; ++y)
3181 for (unsigned int x = 0; x <= repetitions[0]; ++x)
3182 points.push_back(p1 + x * delta[0] + y * delta[1] +
3183 z * delta[2]);
3184 break;
3185
3186 default:
3188 }
3189
3190 // next create the cells
3191 // Prepare cell data
3192 std::vector<CellData<dim>> cells;
3193 switch (dim)
3194 {
3195 case 2:
3196 {
3197 cells.resize(repetitions[1] * repetitions[0] - holes[1] * holes[0]);
3198 unsigned int c = 0;
3199 for (unsigned int y = 0; y < repetitions[1]; ++y)
3200 for (unsigned int x = 0; x < repetitions[0]; ++x)
3201 {
3202 if ((x % 2 == 1) && (y % 2 == 1))
3203 continue;
3204 Assert(c < cells.size(), ExcInternalError());
3205 cells[c].vertices[0] = y * (repetitions[0] + 1) + x;
3206 cells[c].vertices[1] = y * (repetitions[0] + 1) + x + 1;
3207 cells[c].vertices[2] = (y + 1) * (repetitions[0] + 1) + x;
3208 cells[c].vertices[3] = (y + 1) * (repetitions[0] + 1) + x + 1;
3209 cells[c].material_id = 0;
3210 ++c;
3211 }
3212 break;
3213 }
3214
3215 case 3:
3216 {
3217 const unsigned int n_x = (repetitions[0] + 1);
3218 const unsigned int n_xy =
3219 (repetitions[0] + 1) * (repetitions[1] + 1);
3220
3221 cells.resize(repetitions[2] * repetitions[1] * repetitions[0]);
3222
3223 unsigned int c = 0;
3224 for (unsigned int z = 0; z < repetitions[2]; ++z)
3225 for (unsigned int y = 0; y < repetitions[1]; ++y)
3226 for (unsigned int x = 0; x < repetitions[0]; ++x)
3227 {
3228 Assert(c < cells.size(), ExcInternalError());
3229 cells[c].vertices[0] = z * n_xy + y * n_x + x;
3230 cells[c].vertices[1] = z * n_xy + y * n_x + x + 1;
3231 cells[c].vertices[2] = z * n_xy + (y + 1) * n_x + x;
3232 cells[c].vertices[3] = z * n_xy + (y + 1) * n_x + x + 1;
3233 cells[c].vertices[4] = (z + 1) * n_xy + y * n_x + x;
3234 cells[c].vertices[5] = (z + 1) * n_xy + y * n_x + x + 1;
3235 cells[c].vertices[6] = (z + 1) * n_xy + (y + 1) * n_x + x;
3236 cells[c].vertices[7] =
3237 (z + 1) * n_xy + (y + 1) * n_x + x + 1;
3238 cells[c].material_id = 0;
3239 ++c;
3240 }
3241 break;
3242 }
3243
3244 default:
3246 }
3247
3248 tria.create_triangulation(points, cells, SubCellData());
3249 }
3250
3251
3252
3253 template <>
3254 void
3256 const double /*inner_radius*/,
3257 const double /*outer_radius*/,
3258 const double /*pad_bottom*/,
3259 const double /*pad_top*/,
3260 const double /*pad_left*/,
3261 const double /*pad_right*/,
3262 const Point<1> & /*center*/,
3263 const types::manifold_id /*polar_manifold_id*/,
3264 const types::manifold_id /*tfi_manifold_id*/,
3265 const double /*L*/,
3266 const unsigned int /*n_slices*/,
3267 const bool /*colorize*/)
3268 {
3270 }
3271
3272
3273
3274 template <>
3275 void
3277 const double /*shell_region_width*/,
3278 const unsigned int /*n_shells*/,
3279 const double /*skewness*/,
3280 const bool /*colorize*/)
3281 {
3283 }
3284
3285
3286
3287 namespace internal
3288 {
3289 // helper function to check if point is in 2d box
3290 bool inline point_in_2d_box(const Point<2> &p,
3291 const Point<2> &c,
3292 const double radius)
3293 {
3294 return (std::abs(p[0] - c[0]) < radius) &&
3295 (std::abs(p[1] - c[1]) < radius);
3296 }
3297
3298
3299
3300 // Find the minimal distance between two vertices. This is useful for
3301 // computing a tolerance for merging vertices in
3302 // GridTools::merge_triangulations.
3303 template <int dim, int spacedim>
3304 double
3306 {
3307 double length = std::numeric_limits<double>::max();
3308 for (const auto &cell : triangulation.active_cell_iterators())
3309 for (unsigned int n = 0; n < GeometryInfo<dim>::lines_per_cell; ++n)
3310 length = std::min(length, cell->line(n)->diameter());
3311 return length;
3312 }
3313 } // namespace internal
3314
3315
3316
3317 template <>
3318 void
3320 const double inner_radius,
3321 const double outer_radius,
3322 const double pad_bottom,
3323 const double pad_top,
3324 const double pad_left,
3325 const double pad_right,
3326 const Point<2> &new_center,
3329 const double L,
3330 const unsigned int /*n_slices*/,
3331 const bool colorize)
3332 {
3333 const bool with_padding =
3334 pad_bottom > 0 || pad_top > 0 || pad_left > 0 || pad_right > 0;
3335
3336 Assert(pad_bottom >= 0., ExcMessage("Negative bottom padding."));
3337 Assert(pad_top >= 0., ExcMessage("Negative top padding."));
3338 Assert(pad_left >= 0., ExcMessage("Negative left padding."));
3339 Assert(pad_right >= 0., ExcMessage("Negative right padding."));
3340
3341 const Point<2> center;
3342
3343 auto min_line_length = [](const Triangulation<2> &tria) -> double {
3344 double length = std::numeric_limits<double>::max();
3345 for (const auto &cell : tria.active_cell_iterators())
3346 for (unsigned int n = 0; n < cell->n_lines(); ++n)
3347 length = std::min(length, cell->line(n)->diameter());
3348 return length;
3349 };
3350
3351 // start by setting up the cylinder triangulation
3355 inner_radius,
3357 L,
3358 /*repetitions*/ 1,
3359 colorize);
3360
3361 // we will deal with face manifold ids after we merge triangulations
3362 for (const auto &cell : cylinder_tria.active_cell_iterators())
3363 cell->set_manifold_id(tfi_manifold_id);
3364
3367 if (with_padding)
3368 {
3369 // hyper_cube_with_cylindrical_hole will have 2 cells along
3370 // each face, so the element size is outer_radius
3371
3372 auto add_sizes = [](std::vector<double> &step_sizes,
3373 const double padding,
3374 const double h) -> void {
3375 // use std::round instead of std::ceil to improve aspect ratio
3376 // in case padding is only slightly larger than h.
3377 const auto rounded =
3378 static_cast<unsigned int>(std::round(padding / h));
3379 // in case padding is much smaller than h, make sure we
3380 // have at least 1 element
3381 const unsigned int num = (padding > 0. && rounded == 0) ? 1 : rounded;
3382 for (unsigned int i = 0; i < num; ++i)
3383 step_sizes.push_back(padding / num);
3384 };
3385
3386 std::vector<std::vector<double>> step_sizes(2);
3387 // x-coord
3388 // left:
3390 // center
3391 step_sizes[0].push_back(outer_radius);
3392 step_sizes[0].push_back(outer_radius);
3393 // right
3395 // y-coord
3396 // bottom
3398 // center
3399 step_sizes[1].push_back(outer_radius);
3400 step_sizes[1].push_back(outer_radius);
3401 // top
3403
3404 // now create bulk
3408
3409 // now remove cells reserved from the cylindrical hole
3410 std::set<Triangulation<2>::active_cell_iterator> cells_to_remove;
3411 for (const auto &cell : bulk_tria.active_cell_iterators())
3412 if (internal::point_in_2d_box(cell->center(), center, outer_radius))
3413 cells_to_remove.insert(cell);
3414
3418
3419 const double tolerance =
3422 2.0;
3423
3425 tria_without_cylinder, cylinder_tria, tria, tolerance, true);
3426 }
3427
3428 // now set manifold ids:
3429 for (const auto &cell : tria.active_cell_iterators())
3430 {
3431 // set all non-boundary manifold ids on the cells that came from the
3432 // grid around the cylinder to the new TFI manifold id.
3433 if (cell->manifold_id() == tfi_manifold_id)
3434 {
3435 for (const unsigned int face_n : cell->face_indices())
3436 {
3437 const auto &face = cell->face(face_n);
3438 if (face->at_boundary() &&
3439 internal::point_in_2d_box(face->center(),
3440 center,
3441 outer_radius * (1. - 1e-12)))
3442 face->set_manifold_id(polar_manifold_id);
3443 else
3444 face->set_manifold_id(tfi_manifold_id);
3445 }
3446 }
3447 else
3448 {
3449 // ensure that all other manifold ids (including the faces
3450 // opposite the cylinder) are set to the flat id
3451 cell->set_all_manifold_ids(numbers::flat_manifold_id);
3452 }
3453 }
3454
3455 static constexpr double tol =
3456 std::numeric_limits<double>::epsilon() * 10000;
3457 if (colorize)
3458 for (const auto &cell : tria.active_cell_iterators())
3459 for (const unsigned int face_n : cell->face_indices())
3460 {
3461 const auto face = cell->face(face_n);
3462 if (face->at_boundary())
3463 {
3464 const Point<2> center = face->center();
3465 // left side
3466 if (std::abs(center[0] - bl[0]) < tol * std::abs(bl[0]))
3467 face->set_boundary_id(0);
3468 // right side
3469 else if (std::abs(center[0] - tr[0]) < tol * std::abs(tr[0]))
3470 face->set_boundary_id(1);
3471 // bottom
3472 else if (std::abs(center[1] - bl[1]) < tol * std::abs(bl[1]))
3473 face->set_boundary_id(2);
3474 // top
3475 else if (std::abs(center[1] - tr[1]) < tol * std::abs(tr[1]))
3476 face->set_boundary_id(3);
3477 // cylinder boundary
3478 else
3479 {
3480 Assert(cell->manifold_id() == tfi_manifold_id,
3482 face->set_boundary_id(4);
3483 }
3484 }
3485 }
3486
3487 // move to the new center
3489
3490 PolarManifold<2> polar_manifold(new_center);
3491 tria.set_manifold(polar_manifold_id, polar_manifold);
3492 tria.set_manifold(tfi_manifold_id, FlatManifold<2>());
3494 inner_manifold.initialize(tria);
3495 tria.set_manifold(tfi_manifold_id, inner_manifold);
3496 }
3497
3498
3499
3500 template <>
3501 void
3503 const double inner_radius,
3504 const double outer_radius,
3505 const double pad_bottom,
3506 const double pad_top,
3507 const double pad_left,
3508 const double pad_right,
3509 const Point<3> &new_center,
3512 const double L,
3513 const unsigned int n_slices,
3514 const bool colorize)
3515 {
3518 inner_radius,
3520 pad_bottom,
3521 pad_top,
3522 pad_left,
3523 pad_right,
3527 L,
3528 n_slices,
3529 colorize);
3530
3531 // extrude to 3d
3532 extrude_triangulation(tria_2, n_slices, L, tria, true);
3533
3534 // shift in Z direction to match specified center
3535 GridTools::shift(Point<3>(0, 0, new_center[2] - L / 2.), tria);
3536
3537 // set up the new manifolds
3538 const Tensor<1, 3> direction{{0.0, 0.0, 1.0}};
3540 direction,
3541 /*axial_point*/ new_center);
3542 tria.set_manifold(polar_manifold_id, FlatManifold<3>());
3543 tria.set_manifold(tfi_manifold_id, FlatManifold<3>());
3545 inner_manifold.initialize(tria);
3546
3547 tria.set_manifold(polar_manifold_id, cylindrical_manifold);
3548 tria.set_manifold(tfi_manifold_id, inner_manifold);
3549 }
3550
3551
3552
3553 template <>
3554 void
3556 const double shell_region_width,
3557 const unsigned int n_shells,
3558 const double skewness,
3559 const bool colorize)
3560 {
3562 ExcMessage("The width of the shell region must be less than 0.05 "
3563 "(and preferably close to 0.03)"));
3566
3567 // We begin by setting up a grid that is 4 by 22 cells. While not
3568 // squares, these have pretty good aspect ratios.
3571 {22u, 4u},
3572 Point<2>(0.0, 0.0),
3573 Point<2>(2.2, 0.41));
3574 // bulk_tria now looks like this:
3575 //
3576 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
3577 // | | | | | | | | | | | | | | | | | | | | | | |
3578 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
3579 // | |XX|XX| | | | | | | | | | | | | | | | | | | |
3580 // +--+--O--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
3581 // | |XX|XX| | | | | | | | | | | | | | | | | | | |
3582 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
3583 // | | | | | | | | | | | | | | | | | | | | | | |
3584 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
3585 //
3586 // Note that these cells are not quite squares: they are all 0.1 by
3587 // 0.1025.
3588 //
3589 // The next step is to remove the cells marked with XXs: we will place
3590 // the grid around the cylinder there later. The next loop does two
3591 // things:
3592 // 1. Determines which cells need to be removed from the Triangulation
3593 // (i.e., find the cells marked with XX in the picture).
3594 // 2. Finds the location of the vertex marked with 'O' and uses that to
3595 // calculate the shift vector for aligning cylinder_tria with
3596 // tria_without_cylinder.
3597 std::set<Triangulation<2>::active_cell_iterator> cells_to_remove;
3599 for (const auto &cell : bulk_tria.active_cell_iterators())
3600 {
3601 if ((cell->center() - Point<2>(0.2, 0.2)).norm() < 0.15)
3602 cells_to_remove.insert(cell);
3603
3605 {
3606 for (const unsigned int vertex_n :
3608 if (cell->vertex(vertex_n) == Point<2>())
3609 {
3610 // cylinder_tria is centered at zero, so we need to
3611 // shift it up and to the right by two cells:
3613 2.0 * (cell->vertex(3) - Point<2>());
3614 break;
3615 }
3616 }
3617 }
3621
3622 // set up the cylinder triangulation. Note that this function sets the
3623 // manifold ids of the interior boundary cells to 0
3624 // (polar_manifold_id).
3627 0.05 + shell_region_width,
3628 0.41 / 4.0);
3629 // The bulk cells are not quite squares, so we need to move the left
3630 // and right sides of cylinder_tria inwards so that it fits in
3631 // bulk_tria:
3632 for (const auto &cell : cylinder_tria.active_cell_iterators())
3633 for (const unsigned int vertex_n : GeometryInfo<2>::vertex_indices())
3634 {
3635 if (std::abs(cell->vertex(vertex_n)[0] - -0.41 / 4.0) < 1e-10)
3636 cell->vertex(vertex_n)[0] = -0.1;
3637 else if (std::abs(cell->vertex(vertex_n)[0] - 0.41 / 4.0) < 1e-10)
3638 cell->vertex(vertex_n)[0] = 0.1;
3639 }
3640
3641 // Assign interior manifold ids to be the TFI id.
3642 for (const auto &cell : cylinder_tria.active_cell_iterators())
3643 {
3644 cell->set_manifold_id(tfi_manifold_id);
3645 for (const unsigned int face_n : GeometryInfo<2>::face_indices())
3646 if (!cell->face(face_n)->at_boundary())
3647 cell->face(face_n)->set_manifold_id(tfi_manifold_id);
3648 }
3649 if (0.0 < shell_region_width)
3650 {
3651 Assert(0 < n_shells,
3652 ExcMessage("If the shell region has positive width then "
3653 "there must be at least one shell."));
3656 Point<2>(),
3657 0.05,
3658 0.05 + shell_region_width,
3659 n_shells,
3660 skewness,
3661 8);
3662
3663 // Make the tolerance as large as possible since these cells can
3664 // be quite close together
3665 const double vertex_tolerance =
3666 std::min(internal::minimal_vertex_distance(shell_tria),
3667 internal::minimal_vertex_distance(cylinder_tria)) *
3668 0.5;
3669
3670 shell_tria.set_all_manifold_ids(polar_manifold_id);
3674 cylinder_tria = std::move(temp);
3675 }
3677
3678 // Compute the tolerance again, since the shells may be very close to
3679 // each-other:
3680 const double vertex_tolerance =
3681 std::min(internal::minimal_vertex_distance(tria_without_cylinder),
3682 internal::minimal_vertex_distance(cylinder_tria)) /
3683 10;
3686
3687 // Move the vertices in the middle of the faces of cylinder_tria slightly
3688 // to give a better mesh quality. We have to balance the quality of these
3689 // cells with the quality of the outer cells (initially rectangles). For
3690 // constant radial distance, we would place them at the distance 0.1 *
3691 // sqrt(2.) from the center. In case the shell region width is more than
3692 // 0.1/6., we choose to place them at 0.1 * 4./3. from the center, which
3693 // ensures that the shortest edge of the outer cells is 2./3. of the
3694 // original length. If the shell region width is less, we make the edge
3695 // length of the inner part and outer part (in the shorter x direction)
3696 // the same.
3697 {
3698 const double shift =
3699 std::min(0.125 + shell_region_width * 0.5, 0.1 * 4. / 3.);
3700 for (const auto &cell : tria.active_cell_iterators())
3701 for (const unsigned int v : GeometryInfo<2>::vertex_indices())
3702 if (cell->vertex(v).distance(Point<2>(0.1, 0.205)) < 1e-10)
3703 cell->vertex(v) = Point<2>(0.2 - shift, 0.205);
3704 else if (cell->vertex(v).distance(Point<2>(0.3, 0.205)) < 1e-10)
3705 cell->vertex(v) = Point<2>(0.2 + shift, 0.205);
3706 else if (cell->vertex(v).distance(Point<2>(0.2, 0.1025)) < 1e-10)
3707 cell->vertex(v) = Point<2>(0.2, 0.2 - shift);
3708 else if (cell->vertex(v).distance(Point<2>(0.2, 0.3075)) < 1e-10)
3709 cell->vertex(v) = Point<2>(0.2, 0.2 + shift);
3710 }
3711
3712 // Ensure that all manifold ids on a polar cell really are set to the
3713 // polar manifold id:
3714 for (const auto &cell : tria.active_cell_iterators())
3715 if (cell->manifold_id() == polar_manifold_id)
3716 cell->set_all_manifold_ids(polar_manifold_id);
3717
3718 // Ensure that all other manifold ids (including the interior faces
3719 // opposite the cylinder) are set to the flat manifold id:
3720 for (const auto &cell : tria.active_cell_iterators())
3721 if (cell->manifold_id() != polar_manifold_id &&
3722 cell->manifold_id() != tfi_manifold_id)
3723 cell->set_all_manifold_ids(numbers::flat_manifold_id);
3724
3725 // We need to calculate the current center so that we can move it later:
3726 // to start get a unique list of (points to) vertices on the cylinder
3727 std::vector<Point<2> *> cylinder_pointers;
3728 for (const auto &face : tria.active_face_iterators())
3729 if (face->manifold_id() == polar_manifold_id)
3730 {
3731 cylinder_pointers.push_back(&face->vertex(0));
3732 cylinder_pointers.push_back(&face->vertex(1));
3733 }
3734 // de-duplicate
3735 std::sort(cylinder_pointers.begin(), cylinder_pointers.end());
3736 cylinder_pointers.erase(std::unique(cylinder_pointers.begin(),
3737 cylinder_pointers.end()),
3738 cylinder_pointers.end());
3739
3740 // find the current center...
3741 Point<2> center;
3742 for (const Point<2> *const ptr : cylinder_pointers)
3743 center += *ptr / double(cylinder_pointers.size());
3744
3745 // and recenter at (0.2, 0.2)
3746 for (Point<2> *const ptr : cylinder_pointers)
3747 *ptr += Point<2>(0.2, 0.2) - center;
3748
3749 // attach manifolds
3750 PolarManifold<2> polar_manifold(Point<2>(0.2, 0.2));
3751 tria.set_manifold(polar_manifold_id, polar_manifold);
3752
3753 tria.set_manifold(tfi_manifold_id, FlatManifold<2>());
3755 inner_manifold.initialize(tria);
3756 tria.set_manifold(tfi_manifold_id, inner_manifold);
3757
3758 if (colorize)
3759 for (const auto &face : tria.active_face_iterators())
3760 if (face->at_boundary())
3761 {
3762 const Point<2> center = face->center();
3763 // left side
3764 if (std::abs(center[0] - 0.0) < 1e-10)
3765 face->set_boundary_id(0);
3766 // right side
3767 else if (std::abs(center[0] - 2.2) < 1e-10)
3768 face->set_boundary_id(1);
3769 // cylinder boundary
3770 else if (face->manifold_id() == polar_manifold_id)
3771 face->set_boundary_id(2);
3772 // sides of channel
3773 else
3774 {
3775 Assert(std::abs(center[1] - 0.00) < 1.0e-10 ||
3776 std::abs(center[1] - 0.41) < 1.0e-10,
3778 face->set_boundary_id(3);
3779 }
3780 }
3781 }
3782
3783
3784
3785 template <>
3786 void
3788 const double shell_region_width,
3789 const unsigned int n_shells,
3790 const double skewness,
3791 const bool colorize)
3792 {
3796 extrude_triangulation(tria_2, 5, 0.41, tria, true);
3797
3798 // set up the new 3d manifolds
3801 const PolarManifold<2> *const m_ptr =
3802 dynamic_cast<const PolarManifold<2> *>(
3803 &tria_2.get_manifold(cylindrical_manifold_id));
3804 Assert(m_ptr != nullptr, ExcInternalError());
3805 const Point<3> axial_point(m_ptr->center[0], m_ptr->center[1], 0.0);
3806 const Tensor<1, 3> direction{{0.0, 0.0, 1.0}};
3807
3808 tria.set_manifold(cylindrical_manifold_id, FlatManifold<3>());
3809 tria.set_manifold(tfi_manifold_id, FlatManifold<3>());
3812 inner_manifold.initialize(tria);
3814 tria.set_manifold(tfi_manifold_id, inner_manifold);
3815
3816 // From extrude_triangulation: since the maximum boundary id of tria_2 was
3817 // 3, the bottom boundary id is 4 and the top is 5: both are walls, so set
3818 // them to 3
3819 if (colorize)
3820 for (const auto &face : tria.active_face_iterators())
3821 if (face->boundary_id() == 4 || face->boundary_id() == 5)
3822 face->set_boundary_id(3);
3823 }
3824
3825
3826
3827 template <int dim, int spacedim>
3828 void
3830 const std::vector<unsigned int> &sizes,
3831 const bool colorize)
3832 {
3834 Assert(dim > 1, ExcNotImplemented());
3835 Assert(dim < 4, ExcNotImplemented());
3836
3837 // If there is a desire at some point to change the geometry of
3838 // the cells, this tensor can be made an argument to the function.
3839 Tensor<1, dim> dimensions;
3840 for (unsigned int d = 0; d < dim; ++d)
3841 dimensions[d] = 1.;
3842
3843 std::vector<Point<spacedim>> points;
3844 unsigned int n_cells = 1;
3845 for (const unsigned int i : GeometryInfo<dim>::face_indices())
3846 n_cells += sizes[i];
3847
3848 std::vector<CellData<dim>> cells(n_cells);
3849 // Vertices of the center cell
3850 for (const unsigned int i : GeometryInfo<dim>::vertex_indices())
3851 {
3853 for (unsigned int d = 0; d < dim; ++d)
3854 p[d] = 0.5 * dimensions[d] *
3857 points.push_back(p);
3858 cells[0].vertices[i] = i;
3859 }
3860 cells[0].material_id = 0;
3861
3862 // The index of the first cell of the leg.
3863 unsigned int cell_index = 1;
3864 // The legs of the cross
3865 for (const unsigned int face : GeometryInfo<dim>::face_indices())
3866 {
3867 const unsigned int oface = GeometryInfo<dim>::opposite_face[face];
3868 const unsigned int dir = GeometryInfo<dim>::unit_normal_direction[face];
3869
3870 // We are moving in the direction of face
3871 for (unsigned int j = 0; j < sizes[face]; ++j, ++cell_index)
3872 {
3873 const unsigned int last_cell = (j == 0) ? 0U : (cell_index - 1);
3874
3875 for (unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_face;
3876 ++v)
3877 {
3878 const unsigned int cellv =
3880 const unsigned int ocellv =
3882 // First the vertices which already exist
3883 cells[cell_index].vertices[ocellv] =
3884 cells[last_cell].vertices[cellv];
3885
3886 // Now the new vertices
3887 cells[cell_index].vertices[cellv] = points.size();
3888
3889 Point<spacedim> p = points[cells[cell_index].vertices[ocellv]];
3891 dimensions[dir];
3892 points.push_back(p);
3893 }
3894 cells[cell_index].material_id = (colorize) ? (face + 1U) : 0U;
3895 }
3896 }
3897 tria.create_triangulation(points, cells, SubCellData());
3898 }
3899
3900
3901 template <>
3902 void
3903 hyper_cube_slit(Triangulation<1> &, const double, const double, const bool)
3904 {
3906 }
3907
3908
3909
3910 template <>
3911 void
3913 const double,
3914 const double,
3915 const double,
3916 const bool)
3917 {
3919 }
3920
3921
3922
3923 template <>
3924 void
3925 hyper_L(Triangulation<1> &, const double, const double, const bool)
3926 {
3928 }
3929
3930
3931
3932 template <>
3933 void
3934 hyper_ball_balanced(Triangulation<1> &, const Point<1> &, const double)
3935 {
3937 }
3938
3939
3940
3941 template <>
3942 void
3943 cylinder(Triangulation<1> &, const double, const double)
3944 {
3946 }
3947
3948
3949 template <>
3950 void
3952 const unsigned int,
3953 const double,
3954 const double)
3955 {
3957 }
3958
3959
3960
3961 template <>
3962 void
3963 truncated_cone(Triangulation<1> &, const double, const double, const double)
3964 {
3966 }
3967
3968
3969
3970 template <>
3971 void
3973 const Point<1> &,
3974 const double,
3975 const double,
3976 const unsigned int,
3977 const bool)
3978 {
3980 }
3981
3982 template <>
3983 void
3985 const double,
3986 const double,
3987 const double,
3988 const unsigned int,
3989 const unsigned int,
3990 const bool)
3991 {
3993 }
3994
3995
3996 template <>
3997 void
3998 quarter_hyper_ball(Triangulation<1> &, const Point<1> &, const double)
3999 {
4001 }
4002
4003
4004 template <>
4005 void
4006 half_hyper_ball(Triangulation<1> &, const Point<1> &, const double)
4007 {
4009 }
4010
4011
4012 template <>
4013 void
4015 const Point<1> &,
4016 const double,
4017 const double,
4018 const unsigned int,
4019 const bool)
4020 {
4022 }
4023
4024 template <>
4025 void
4027 const Point<1> &,
4028 const double,
4029 const double,
4030 const unsigned int,
4031 const bool)
4032 {
4034 }
4035
4036 template <>
4037 void
4039 const double left,
4040 const double right,
4041 const double thickness,
4042 const bool colorize)
4043 {
4044 Assert(left < right,
4045 ExcMessage("Invalid left-to-right bounds of enclosed hypercube"));
4046
4047 std::vector<Point<2>> vertices(16);
4048 double coords[4];
4049 coords[0] = left - thickness;
4050 coords[1] = left;
4051 coords[2] = right;
4052 coords[3] = right + thickness;
4053
4054 unsigned int k = 0;
4055 for (const double y : coords)
4056 for (const double x : coords)
4057 vertices[k++] = Point<2>(x, y);
4058
4059 const types::material_id materials[9] = {5, 4, 6, 1, 0, 2, 9, 8, 10};
4060
4061 std::vector<CellData<2>> cells(9);
4062 k = 0;
4063 for (unsigned int i0 = 0; i0 < 3; ++i0)
4064 for (unsigned int i1 = 0; i1 < 3; ++i1)
4065 {
4066 cells[k].vertices[0] = i1 + 4 * i0;
4067 cells[k].vertices[1] = i1 + 4 * i0 + 1;
4068 cells[k].vertices[2] = i1 + 4 * i0 + 4;
4069 cells[k].vertices[3] = i1 + 4 * i0 + 5;
4070 if (colorize)
4071 cells[k].material_id = materials[k];
4072 ++k;
4073 }
4074 tria.create_triangulation(vertices,
4075 cells,
4076 SubCellData()); // no boundary information
4077 }
4078
4079
4080
4081 // Implementation for 2d only
4082 template <>
4083 void
4085 const double left,
4086 const double right,
4087 const bool colorize)
4088 {
4089 const double rl2 = (right + left) / 2;
4090 const Point<2> vertices[10] = {Point<2>(left, left),
4091 Point<2>(rl2, left),
4092 Point<2>(rl2, rl2),
4093 Point<2>(left, rl2),
4094 Point<2>(right, left),
4095 Point<2>(right, rl2),
4096 Point<2>(rl2, right),
4097 Point<2>(left, right),
4098 Point<2>(right, right),
4099 Point<2>(rl2, left)};
4100 const int cell_vertices[4][4] = {{0, 1, 3, 2},
4101 {9, 4, 2, 5},
4102 {3, 2, 7, 6},
4103 {2, 5, 6, 8}};
4104 std::vector<CellData<2>> cells(4, CellData<2>());
4105 for (unsigned int i = 0; i < 4; ++i)
4106 {
4107 for (unsigned int j = 0; j < 4; ++j)
4108 cells[i].vertices[j] = cell_vertices[i][j];
4109 cells[i].material_id = 0;
4110 }
4111 tria.create_triangulation(std::vector<Point<2>>(std::begin(vertices),
4112 std::end(vertices)),
4113 cells,
4114 SubCellData()); // no boundary information
4115
4116 if (colorize)
4117 {
4118 Triangulation<2>::cell_iterator cell = tria.begin();
4119 cell->face(1)->set_boundary_id(1);
4120 ++cell;
4121 cell->face(0)->set_boundary_id(2);
4122 }
4123 }
4124
4125
4126
4127 template <>
4128 void
4130 const double radius_0,
4131 const double radius_1,
4132 const double half_length)
4133 {
4135
4140
4141 const std::vector<Point<2>> vertices(std::begin(vertices_tmp),
4142 std::end(vertices_tmp));
4143 unsigned int cell_vertices[1][GeometryInfo<2>::vertices_per_cell];
4144
4145 for (const unsigned int i : GeometryInfo<2>::vertex_indices())
4146 cell_vertices[0][i] = i;
4147
4148 std::vector<CellData<2>> cells(1, CellData<2>());
4149
4150 for (const unsigned int i : GeometryInfo<2>::vertex_indices())
4151 cells[0].vertices[i] = cell_vertices[0][i];
4152
4153 cells[0].material_id = 0;
4154 triangulation.create_triangulation(vertices, cells, SubCellData());
4155
4157
4158 cell->face(0)->set_boundary_id(1);
4159 cell->face(1)->set_boundary_id(2);
4160
4161 for (unsigned int i = 2; i < 4; ++i)
4162 cell->face(i)->set_boundary_id(0);
4163 }
4164
4165
4166
4167 // Implementation for 2d only
4168 template <>
4169 void
4171 const double a,
4172 const double b,
4173 const bool colorize)
4174 {
4175 const Point<2> vertices[8] = {Point<2>(a, a),
4176 Point<2>((a + b) / 2, a),
4177 Point<2>(b, a),
4178 Point<2>(a, (a + b) / 2),
4179 Point<2>((a + b) / 2, (a + b) / 2),
4180 Point<2>(b, (a + b) / 2),
4181 Point<2>(a, b),
4182 Point<2>((a + b) / 2, b)};
4183 const int cell_vertices[3][4] = {{0, 1, 3, 4}, {1, 2, 4, 5}, {3, 4, 6, 7}};
4184
4185 std::vector<CellData<2>> cells(3, CellData<2>());
4186
4187 for (unsigned int i = 0; i < 3; ++i)
4188 {
4189 for (unsigned int j = 0; j < 4; ++j)
4190 cells[i].vertices[j] = cell_vertices[i][j];
4191 cells[i].material_id = 0;
4192 }
4193
4194 tria.create_triangulation(std::vector<Point<2>>(std::begin(vertices),
4195 std::end(vertices)),
4196 cells,
4197 SubCellData());
4198
4199 if (colorize)
4200 {
4201 Triangulation<2>::cell_iterator cell = tria.begin();
4202
4203 cell->face(0)->set_boundary_id(0);
4204 cell->face(2)->set_boundary_id(1);
4205 ++cell;
4206
4207 cell->face(1)->set_boundary_id(2);
4208 cell->face(2)->set_boundary_id(1);
4209 cell->face(3)->set_boundary_id(3);
4210 ++cell;
4211
4212 cell->face(0)->set_boundary_id(0);
4213 cell->face(1)->set_boundary_id(4);
4214 cell->face(3)->set_boundary_id(5);
4215 }
4216 }
4217
4218
4219
4220 template <int dim, int spacedim>
4221 void
4223 const std::vector<unsigned int> &repetitions,
4224 const Point<dim> &bottom_left,
4225 const Point<dim> &top_right,
4226 const std::vector<int> &n_cells_to_remove)
4227 {
4228 Assert(dim > 1, ExcNotImplemented());
4229 // Check the consistency of the dimensions provided.
4230 AssertDimension(repetitions.size(), dim);
4232 for (unsigned int d = 0; d < dim; ++d)
4233 {
4234 Assert(std::fabs(n_cells_to_remove[d]) <= repetitions[d],
4235 ExcMessage("Attempting to cut away too many cells."));
4236 }
4237 // Create the domain to be cut
4242 top_right);
4243 // compute the vertex of the cut step, we will cut according to the
4244 // location of the cartesian coordinates of the cell centers
4245 std::array<double, dim> h;
4247 for (unsigned int d = 0; d < dim; ++d)
4248 {
4249 // mesh spacing in each direction in cartesian coordinates
4250 h[d] = (top_right[d] - bottom_left[d]) / repetitions[d];
4251 // left to right, bottom to top, front to back
4252 if (n_cells_to_remove[d] >= 0)
4253 {
4254 // cartesian coordinates of vertex location
4255 cut_step[d] =
4256 h[d] * std::fabs(n_cells_to_remove[d]) + bottom_left[d];
4257 }
4258 // right to left, top to bottom, back to front
4259 else
4260 {
4261 cut_step[d] = top_right[d] - h[d] * std::fabs(n_cells_to_remove[d]);
4262 }
4263 }
4264
4265
4266 // compute cells to remove
4267 std::set<typename Triangulation<dim, spacedim>::active_cell_iterator>
4269 for (const auto &cell : rectangle.active_cell_iterators())
4270 {
4271 bool remove_cell = true;
4272 for (unsigned int d = 0; d < dim && remove_cell; ++d)
4273 if ((n_cells_to_remove[d] > 0 && cell->center()[d] >= cut_step[d]) ||
4274 (n_cells_to_remove[d] < 0 && cell->center()[d] <= cut_step[d]))
4275 remove_cell = false;
4276 if (remove_cell)
4277 cells_to_remove.insert(cell);
4278 }
4279
4282 tria);
4283 }
4284
4285
4286
4287 template <int dim, int spacedim>
4288 void
4290 const Point<spacedim> &p,
4291 const double radius,
4292 const bool internal_manifolds)
4293 {
4294 if constexpr (dim == 2)
4295 {
4296 const auto embed_point = [](const double x,
4297 const double y) -> Point<spacedim> {
4298 if constexpr (spacedim == 2)
4299 return Point<spacedim>(x, y);
4300 else if constexpr (spacedim == 3)
4301 return Point<spacedim>(x, y, 0);
4302 else
4304 };
4305
4306
4307 // Equilibrate cell sizes at transition from the inner part
4308 // to the radial cells
4309 const double a = 1. / (1 + std::sqrt(2.0));
4310 const Point<spacedim> vertices[8] = {
4311 p + embed_point(-1., -1.) * (radius / std::sqrt(2.0)),
4312 p + embed_point(+1., -1.) * (radius / std::sqrt(2.0)),
4313 p + embed_point(-1., -1.) * (radius / std::sqrt(2.0) * a),
4314 p + embed_point(+1., -1.) * (radius / std::sqrt(2.0) * a),
4315 p + embed_point(-1., +1.) * (radius / std::sqrt(2.0) * a),
4316 p + embed_point(+1., +1.) * (radius / std::sqrt(2.0) * a),
4317 p + embed_point(-1., +1.) * (radius / std::sqrt(2.0)),
4318 p + embed_point(+1., +1.) * (radius / std::sqrt(2.0))};
4319
4320 std::vector<CellData<2>> cells(5, CellData<2>());
4321
4322 for (unsigned int i = 0; i < 5; ++i)
4323 {
4324 for (unsigned int j = 0; j < 4; ++j)
4325 cells[i].vertices[j] = circle_cell_vertices[i][j];
4326 cells[i].material_id = 0;
4327 cells[i].manifold_id = (i == 2 ? numbers::flat_manifold_id : 1);
4328 }
4329
4330 tria.create_triangulation(std::vector<Point<spacedim>>(
4331 std::begin(vertices), std::end(vertices)),
4332 cells,
4333 SubCellData()); // no boundary information
4334 tria.set_all_manifold_ids_on_boundary(0);
4335 tria.set_manifold(0, SphericalManifold<dim, spacedim>(p));
4337 tria.set_manifold(1, SphericalManifold<dim, spacedim>(p));
4338 else
4339 tria.set_manifold(1, FlatManifold<dim, spacedim>());
4340 }
4341 else if constexpr (dim == 3)
4342 {
4343 const double a =
4344 1. / (1 + std::sqrt(3.0)); // equilibrate cell sizes at transition
4345 // from the inner part to the radial
4346 // cells
4347 const unsigned int n_vertices = 16;
4348 const Point<3> vertices[n_vertices] = {
4349 // first the vertices of the inner
4350 // cell
4351 p + Point<3>(-1, -1, -1) * (radius / std::sqrt(3.0) * a),
4352 p + Point<3>(+1, -1, -1) * (radius / std::sqrt(3.0) * a),
4353 p + Point<3>(+1, -1, +1) * (radius / std::sqrt(3.0) * a),
4354 p + Point<3>(-1, -1, +1) * (radius / std::sqrt(3.0) * a),
4355 p + Point<3>(-1, +1, -1) * (radius / std::sqrt(3.0) * a),
4356 p + Point<3>(+1, +1, -1) * (radius / std::sqrt(3.0) * a),
4357 p + Point<3>(+1, +1, +1) * (radius / std::sqrt(3.0) * a),
4358 p + Point<3>(-1, +1, +1) * (radius / std::sqrt(3.0) * a),
4359 // now the eight vertices at
4360 // the outer sphere
4361 p + Point<3>(-1, -1, -1) * (radius / std::sqrt(3.0)),
4362 p + Point<3>(+1, -1, -1) * (radius / std::sqrt(3.0)),
4363 p + Point<3>(+1, -1, +1) * (radius / std::sqrt(3.0)),
4364 p + Point<3>(-1, -1, +1) * (radius / std::sqrt(3.0)),
4365 p + Point<3>(-1, +1, -1) * (radius / std::sqrt(3.0)),
4366 p + Point<3>(+1, +1, -1) * (radius / std::sqrt(3.0)),
4367 p + Point<3>(+1, +1, +1) * (radius / std::sqrt(3.0)),
4368 p + Point<3>(-1, +1, +1) * (radius / std::sqrt(3.0)),
4369 };
4370
4371 // one needs to draw the seven cubes to
4372 // understand what's going on here
4373 const unsigned int n_cells = 7;
4374 const int cell_vertices[n_cells][8] = {
4375 {0, 1, 4, 5, 3, 2, 7, 6}, // center
4376 {8, 9, 12, 13, 0, 1, 4, 5}, // bottom
4377 {9, 13, 1, 5, 10, 14, 2, 6}, // right
4378 {11, 10, 3, 2, 15, 14, 7, 6}, // top
4379 {8, 0, 12, 4, 11, 3, 15, 7}, // left
4380 {8, 9, 0, 1, 11, 10, 3, 2}, // front
4381 {12, 4, 13, 5, 15, 7, 14, 6}}; // back
4382
4383 std::vector<CellData<3>> cells(n_cells, CellData<3>());
4384
4385 for (unsigned int i = 0; i < n_cells; ++i)
4386 {
4387 for (const unsigned int j : GeometryInfo<3>::vertex_indices())
4388 cells[i].vertices[j] = cell_vertices[i][j];
4389 cells[i].material_id = 0;
4390 cells[i].manifold_id = i == 0 ? numbers::flat_manifold_id : 1;
4391 }
4392
4393 tria.create_triangulation(std::vector<Point<3>>(std::begin(vertices),
4394 std::end(vertices)),
4395 cells,
4396 SubCellData()); // no boundary information
4397 tria.set_all_manifold_ids_on_boundary(0);
4398 tria.set_manifold(0, SphericalManifold<3>(p));
4400 tria.set_manifold(1, SphericalManifold<3>(p));
4401 else
4402 tria.set_manifold(1, FlatManifold<3>());
4403 }
4404 else
4406 }
4407
4408
4409
4410 template <int spacedim>
4411 void
4413 const Point<spacedim> &center,
4414 const double inner_radius,
4415 const double outer_radius,
4416 const unsigned int n_cells,
4417 const bool colorize)
4418 {
4419 Assert((inner_radius > 0) && (inner_radius < outer_radius),
4420 ExcInvalidRadii());
4421
4422 const double pi = numbers::PI;
4423
4424 // determine the number of cells
4425 // for the grid. if not provided by
4426 // the user determine it such that
4427 // the length of each cell on the
4428 // median (in the middle between
4429 // the two circles) is equal to its
4430 // radial extent (which is the
4431 // difference between the two
4432 // radii)
4433 const unsigned int N =
4434 (n_cells == 0 ? static_cast<unsigned int>(
4435 std::ceil((2 * pi * (outer_radius + inner_radius) / 2) /
4436 (outer_radius - inner_radius))) :
4437 n_cells);
4438
4439 // set up N vertices on the
4440 // outer and N vertices on
4441 // the inner circle. the
4442 // first N ones are on the
4443 // outer one, and all are
4444 // numbered counter-clockwise
4445 std::vector<Point<spacedim>> vertices(2 * N);
4446 for (unsigned int i = 0; i < N; ++i)
4447 {
4449 point[0] = std::cos(2 * pi * i / N);
4450 point[1] = std::sin(2 * pi * i / N);
4451
4452 vertices[i] = point * outer_radius;
4453 vertices[i + N] = vertices[i] * (inner_radius / outer_radius);
4454
4455 vertices[i] += center;
4456 vertices[i + N] += center;
4457 }
4458
4459 std::vector<CellData<2>> cells(N, CellData<2>());
4460
4461 for (unsigned int i = 0; i < N; ++i)
4462 {
4463 cells[i].vertices[0] = i;
4464 cells[i].vertices[1] = (i + 1) % N;
4465 cells[i].vertices[2] = N + i;
4466 cells[i].vertices[3] = N + ((i + 1) % N);
4467
4468 cells[i].material_id = 0;
4469 }
4470
4471 tria.create_triangulation(vertices, cells, SubCellData());
4472
4473 if (colorize)
4474 colorize_hyper_shell(tria, center, inner_radius, outer_radius);
4475
4476 tria.set_all_manifold_ids(0);
4477 tria.set_manifold(0, SphericalManifold<2, spacedim>(center));
4478 }
4479
4480
4481
4482 template <>
4483 void
4485 const Point<2> &center,
4486 const double inner_radius,
4487 const double outer_radius,
4488 const unsigned int n_cells,
4489 const bool colorize)
4490 {
4491 hyper_shell_2D(tria, center, inner_radius, outer_radius, n_cells, colorize);
4492 }
4493
4494
4495
4496 template <>
4497 void
4499 const Point<3> &center,
4500 const double inner_radius,
4501 const double outer_radius,
4502 const unsigned int n_cells,
4503 const bool colorize)
4504 {
4505 hyper_shell_2D(tria, center, inner_radius, outer_radius, n_cells, colorize);
4506 }
4507
4508
4509
4510 template <int dim>
4511 void
4513 const Point<dim> &inner_center,
4514 const Point<dim> &outer_center,
4515 const double inner_radius,
4516 const double outer_radius,
4517 const unsigned int n_cells)
4518 {
4520 tria, outer_center, inner_radius, outer_radius, n_cells, true);
4521
4522 // check the consistency of the dimensions provided
4523 Assert(
4524 outer_radius - inner_radius > outer_center.distance(inner_center),
4526 "The inner radius is greater than or equal to the outer radius plus eccentricity."));
4527
4528 // shift nodes along the inner boundary according to the position of
4529 // inner_circle
4530 std::set<Point<dim> *> vertices_to_move;
4531
4532 for (const auto &face : tria.active_face_iterators())
4533 if (face->boundary_id() == 0)
4534 for (unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_face; ++v)
4535 vertices_to_move.insert(&face->vertex(v));
4536
4537 const auto shift = inner_center - outer_center;
4538 for (const auto &p : vertices_to_move)
4539 (*p) += shift;
4540
4541 // the original hyper_shell function assigns the same manifold id
4542 // to all cells and faces. Set all manifolds ids to a different
4543 // value (2), then use boundary ids to assign different manifolds to
4544 // the inner (0) and outer manifolds (1). Use a transfinite manifold
4545 // for all faces and cells aside from the boundaries.
4546 tria.set_all_manifold_ids(2);
4548
4551
4552 tria.set_manifold(0, FlatManifold<dim>());
4553 tria.set_manifold(1, FlatManifold<dim>());
4554 tria.set_manifold(2, FlatManifold<dim>());
4556 transfinite.initialize(tria);
4557
4558 tria.set_manifold(0, inner_manifold);
4559 tria.set_manifold(1, outer_manifold);
4560 tria.set_manifold(2, transfinite);
4561 }
4562
4563
4564
4565 // Implementation for 2d only
4566 template <>
4567 void
4569 const double radius,
4570 const double half_length)
4571 {
4572 Point<2> p1(-half_length, -radius);
4573 Point<2> p2(half_length, radius);
4574
4575 hyper_rectangle(tria, p1, p2, true);
4576
4577 Triangulation<2>::face_iterator f = tria.begin_face();
4578 Triangulation<2>::face_iterator end = tria.end_face();
4579 while (f != end)
4580 {
4581 switch (f->boundary_id())
4582 {
4583 case 0:
4584 f->set_boundary_id(1);
4585 break;
4586 case 1:
4587 f->set_boundary_id(2);
4588 break;
4589 default:
4590 f->set_boundary_id(0);
4591 break;
4592 }
4593 ++f;
4594 }
4595 }
4596
4597 template <>
4598 void
4600 const unsigned int,
4601 const double,
4602 const double)
4603 {
4605 }
4606
4607
4608
4609 // Implementation for 2d only
4610 template <>
4611 void
4613 const double,
4614 const double,
4615 const double,
4616 const unsigned int,
4617 const unsigned int,
4618 const bool)
4619 {
4621 }
4622
4623
4624 template <>
4625 void
4627 const Point<2> &p,
4628 const double radius)
4629 {
4630 const unsigned int dim = 2;
4631
4632 // the numbers 0.55647 and 0.42883 have been found by a search for the
4633 // best aspect ratio (defined as the maximal between the minimal singular
4634 // value of the Jacobian)
4635 const Point<dim> vertices[7] = {p + Point<dim>(0, 0) * radius,
4636 p + Point<dim>(+1, 0) * radius,
4637 p + Point<dim>(+1, 0) * (radius * 0.55647),
4638 p + Point<dim>(0, +1) * (radius * 0.55647),
4639 p + Point<dim>(+1, +1) * (radius * 0.42883),
4640 p + Point<dim>(0, +1) * radius,
4641 p + Point<dim>(+1, +1) *
4642 (radius / std::sqrt(2.0))};
4643
4644 const int cell_vertices[3][4] = {{0, 2, 3, 4}, {1, 6, 2, 4}, {5, 3, 6, 4}};
4645
4646 std::vector<CellData<dim>> cells(3, CellData<dim>());
4647
4648 for (unsigned int i = 0; i < 3; ++i)
4649 {
4650 for (unsigned int j = 0; j < 4; ++j)
4651 cells[i].vertices[j] = cell_vertices[i][j];
4652 cells[i].material_id = 0;
4653 }
4654
4655 tria.create_triangulation(std::vector<Point<dim>>(std::begin(vertices),
4656 std::end(vertices)),
4657 cells,
4658 SubCellData()); // no boundary information
4659
4660 Triangulation<dim>::cell_iterator cell = tria.begin();
4662
4663 tria.set_all_manifold_ids_on_boundary(0);
4664
4665 while (cell != end)
4666 {
4667 for (const unsigned int i : GeometryInfo<dim>::face_indices())
4668 {
4669 if (cell->face(i)->boundary_id() ==
4671 continue;
4672
4673 // If one the components is the same as the respective
4674 // component of the center, then this is part of the plane
4675 if (cell->face(i)->center()[0] < p[0] + 1.e-5 * radius ||
4676 cell->face(i)->center()[1] < p[1] + 1.e-5 * radius)
4677 {
4678 cell->face(i)->set_boundary_id(1);
4679 cell->face(i)->set_manifold_id(numbers::flat_manifold_id);
4680 }
4681 }
4682 ++cell;
4683 }
4684 tria.set_manifold(0, SphericalManifold<2>(p));
4685 }
4686
4687
4688 template <>
4689 void
4691 const Point<2> &p,
4692 const double radius)
4693 {
4694 // equilibrate cell sizes at
4695 // transition from the inner part
4696 // to the radial cells
4697 const double a = 1. / (1 + std::sqrt(2.0));
4698 const Point<2> vertices[8] = {
4699 p + Point<2>(0, -1) * radius,
4700 p + Point<2>(+1, -1) * (radius / std::sqrt(2.0)),
4701 p + Point<2>(0, -1) * (radius / std::sqrt(2.0) * a),
4702 p + Point<2>(+1, -1) * (radius / std::sqrt(2.0) * a),
4703 p + Point<2>(0, +1) * (radius / std::sqrt(2.0) * a),
4704 p + Point<2>(+1, +1) * (radius / std::sqrt(2.0) * a),
4705 p + Point<2>(0, +1) * radius,
4706 p + Point<2>(+1, +1) * (radius / std::sqrt(2.0))};
4707
4708 const int cell_vertices[5][4] = {{0, 1, 2, 3},
4709 {2, 3, 4, 5},
4710 {1, 7, 3, 5},
4711 {6, 4, 7, 5}};
4712
4713 std::vector<CellData<2>> cells(4, CellData<2>());
4714
4715 for (unsigned int i = 0; i < 4; ++i)
4716 {
4717 for (unsigned int j = 0; j < 4; ++j)
4718 cells[i].vertices[j] = cell_vertices[i][j];
4719 cells[i].material_id = 0;
4720 }
4721
4722 tria.create_triangulation(std::vector<Point<2>>(std::begin(vertices),
4723 std::end(vertices)),
4724 cells,
4725 SubCellData()); // no boundary information
4726
4727 Triangulation<2>::cell_iterator cell = tria.begin();
4729
4730 tria.set_all_manifold_ids_on_boundary(0);
4731
4732 while (cell != end)
4733 {
4734 for (const unsigned int i : GeometryInfo<2>::face_indices())
4735 {
4736 if (cell->face(i)->boundary_id() ==
4738 continue;
4739
4740 // If x is zero, then this is part of the plane
4741 if (cell->face(i)->center()[0] < p[0] + 1.e-5 * radius)
4742 {
4743 cell->face(i)->set_boundary_id(1);
4744 cell->face(i)->set_manifold_id(numbers::flat_manifold_id);
4745 }
4746 }
4747 ++cell;
4748 }
4749 tria.set_manifold(0, SphericalManifold<2>(p));
4750 }
4751
4752
4753
4754 // Implementation for 2d only
4755 template <>
4756 void
4758 const Point<2> &center,
4759 const double inner_radius,
4760 const double outer_radius,
4761 const unsigned int n_cells,
4762 const bool colorize)
4763 {
4764 Assert((inner_radius > 0) && (inner_radius < outer_radius),
4765 ExcInvalidRadii());
4766
4767 const double pi = numbers::PI;
4768 // determine the number of cells
4769 // for the grid. if not provided by
4770 // the user determine it such that
4771 // the length of each cell on the
4772 // median (in the middle between
4773 // the two circles) is equal to its
4774 // radial extent (which is the
4775 // difference between the two
4776 // radii)
4777 const unsigned int N =
4778 (n_cells == 0 ? static_cast<unsigned int>(
4779 std::ceil((pi * (outer_radius + inner_radius) / 2) /
4780 (outer_radius - inner_radius))) :
4781 n_cells);
4782
4783 // set up N+1 vertices on the
4784 // outer and N+1 vertices on
4785 // the inner circle. the
4786 // first N+1 ones are on the
4787 // outer one, and all are
4788 // numbered counter-clockwise
4789 std::vector<Point<2>> vertices(2 * (N + 1));
4790 for (unsigned int i = 0; i <= N; ++i)
4791 {
4792 // enforce that the x-coordinates
4793 // of the first and last point of
4794 // each half-circle are exactly
4795 // zero (contrary to what we may
4796 // compute using the imprecise
4797 // value of pi)
4798 vertices[i] =
4799 Point<2>(((i == 0) || (i == N) ? 0 : std::cos(pi * i / N - pi / 2)),
4800 std::sin(pi * i / N - pi / 2)) *
4802 vertices[i + N + 1] = vertices[i] * (inner_radius / outer_radius);
4803
4804 vertices[i] += center;
4805 vertices[i + N + 1] += center;
4806 }
4807
4808
4809 std::vector<CellData<2>> cells(N, CellData<2>());
4810
4811 for (unsigned int i = 0; i < N; ++i)
4812 {
4813 cells[i].vertices[0] = i;
4814 cells[i].vertices[1] = (i + 1) % (N + 1);
4815 cells[i].vertices[2] = N + 1 + i;
4816 cells[i].vertices[3] = N + 1 + ((i + 1) % (N + 1));
4817
4818 cells[i].material_id = 0;
4819 }
4820
4821 tria.create_triangulation(vertices, cells, SubCellData());
4822
4823 if (colorize)
4824 {
4825 Triangulation<2>::cell_iterator cell = tria.begin();
4826 for (; cell != tria.end(); ++cell)
4827 {
4828 cell->face(2)->set_boundary_id(1);
4829 }
4830 tria.begin()->face(0)->set_boundary_id(3);
4831
4832 tria.last()->face(1)->set_boundary_id(2);
4833 }
4834 tria.set_all_manifold_ids(0);
4835 tria.set_manifold(0, SphericalManifold<2>(center));
4836 }
4837
4838
4839 template <>
4840 void
4842 const Point<2> &center,
4843 const double inner_radius,
4844 const double outer_radius,
4845 const unsigned int n_cells,
4846 const bool colorize)
4847 {
4848 Assert((inner_radius > 0) && (inner_radius < outer_radius),
4849 ExcInvalidRadii());
4850
4851 const double pi = numbers::PI;
4852 // determine the number of cells
4853 // for the grid. if not provided by
4854 // the user determine it such that
4855 // the length of each cell on the
4856 // median (in the middle between
4857 // the two circles) is equal to its
4858 // radial extent (which is the
4859 // difference between the two
4860 // radii)
4861 const unsigned int N =
4862 (n_cells == 0 ? static_cast<unsigned int>(
4863 std::ceil((pi * (outer_radius + inner_radius) / 4) /
4864 (outer_radius - inner_radius))) :
4865 n_cells);
4866
4867 // set up N+1 vertices on the
4868 // outer and N+1 vertices on
4869 // the inner circle. the
4870 // first N+1 ones are on the
4871 // outer one, and all are
4872 // numbered counter-clockwise
4873 std::vector<Point<2>> vertices(2 * (N + 1));
4874 for (unsigned int i = 0; i <= N; ++i)
4875 {
4876 // enforce that the x-coordinates
4877 // of the last point is exactly
4878 // zero (contrary to what we may
4879 // compute using the imprecise
4880 // value of pi)
4881 vertices[i] = Point<2>(((i == N) ? 0 : std::cos(pi * i / N / 2)),
4882 std::sin(pi * i / N / 2)) *
4884 vertices[i + N + 1] = vertices[i] * (inner_radius / outer_radius);
4885
4886 vertices[i] += center;
4887 vertices[i + N + 1] += center;
4888 }
4889
4890
4891 std::vector<CellData<2>> cells(N, CellData<2>());
4892
4893 for (unsigned int i = 0; i < N; ++i)
4894 {
4895 cells[i].vertices[0] = i;
4896 cells[i].vertices[1] = (i + 1) % (N + 1);
4897 cells[i].vertices[2] = N + 1 + i;
4898 cells[i].vertices[3] = N + 1 + ((i + 1) % (N + 1));
4899
4900 cells[i].material_id = 0;
4901 }
4902
4903 tria.create_triangulation(vertices, cells, SubCellData());
4904
4905 if (colorize)
4906 {
4907 Triangulation<2>::cell_iterator cell = tria.begin();
4908 for (; cell != tria.end(); ++cell)
4909 {
4910 cell->face(2)->set_boundary_id(1);
4911 }
4912 tria.begin()->face(0)->set_boundary_id(3);
4913
4914 tria.last()->face(1)->set_boundary_id(2);
4915 }
4916
4917 tria.set_all_manifold_ids(0);
4918 tria.set_manifold(0, SphericalManifold<2>(center));
4919 }
4920
4921
4922
4923 // Implementation for 3d only
4924 template <>
4925 void
4927 const double left,
4928 const double right,
4929 const bool colorize)
4930 {
4931 const double rl2 = (right + left) / 2;
4932 const double len = (right - left) / 2.;
4933
4934 const Point<3> vertices[20] = {
4935 Point<3>(left, left, -len / 2.), Point<3>(rl2, left, -len / 2.),
4936 Point<3>(rl2, rl2, -len / 2.), Point<3>(left, rl2, -len / 2.),
4937 Point<3>(right, left, -len / 2.), Point<3>(right, rl2, -len / 2.),
4938 Point<3>(rl2, right, -len / 2.), Point<3>(left, right, -len / 2.),
4939 Point<3>(right, right, -len / 2.), Point<3>(rl2, left, -len / 2.),
4940 Point<3>(left, left, len / 2.), Point<3>(rl2, left, len / 2.),
4941 Point<3>(rl2, rl2, len / 2.), Point<3>(left, rl2, len / 2.),
4942 Point<3>(right, left, len / 2.), Point<3>(right, rl2, len / 2.),
4943 Point<3>(rl2, right, len / 2.), Point<3>(left, right, len / 2.),
4944 Point<3>(right, right, len / 2.), Point<3>(rl2, left, len / 2.)};
4945 const int cell_vertices[4][8] = {{0, 1, 3, 2, 10, 11, 13, 12},
4946 {9, 4, 2, 5, 19, 14, 12, 15},
4947 {3, 2, 7, 6, 13, 12, 17, 16},
4948 {2, 5, 6, 8, 12, 15, 16, 18}};
4949 std::vector<CellData<3>> cells(4, CellData<3>());
4950 for (unsigned int i = 0; i < 4; ++i)
4951 {
4952 for (unsigned int j = 0; j < 8; ++j)
4953 cells[i].vertices[j] = cell_vertices[i][j];
4954 cells[i].material_id = 0;
4955 }
4956 tria.create_triangulation(std::vector<Point<3>>(std::begin(vertices),
4957 std::end(vertices)),
4958 cells,
4959 SubCellData()); // no boundary information
4960
4961 if (colorize)
4962 {
4963 Triangulation<3>::cell_iterator cell = tria.begin();
4964 cell->face(1)->set_boundary_id(1);
4965 ++cell;
4966 cell->face(0)->set_boundary_id(2);
4967 }
4968 }
4969
4970
4971
4972 // Implementation for 3d only
4973 template <>
4974 void
4976 const double left,
4977 const double right,
4978 const double thickness,
4979 const bool colorize)
4980 {
4981 Assert(left < right,
4982 ExcMessage("Invalid left-to-right bounds of enclosed hypercube"));
4983
4984 std::vector<Point<3>> vertices(64);
4985 double coords[4];
4986 coords[0] = left - thickness;
4987 coords[1] = left;
4988 coords[2] = right;
4989 coords[3] = right + thickness;
4990
4991 unsigned int k = 0;
4992 for (const double z : coords)
4993 for (const double y : coords)
4994 for (const double x : coords)
4995 vertices[k++] = Point<3>(x, y, z);
4996
4997 const types::material_id materials[27] = {21, 20, 22, 17, 16, 18, 25,
4998 24, 26, 5, 4, 6, 1, 0,
4999 2, 9, 8, 10, 37, 36, 38,
5000 33, 32, 34, 41, 40, 42};
5001
5002 std::vector<CellData<3>> cells(27);
5003 k = 0;
5004 for (unsigned int z = 0; z < 3; ++z)
5005 for (unsigned int y = 0; y < 3; ++y)
5006 for (unsigned int x = 0; x < 3; ++x)
5007 {
5008 cells[k].vertices[0] = x + 4 * y + 16 * z;
5009 cells[k].vertices[1] = x + 4 * y + 16 * z + 1;
5010 cells[k].vertices[2] = x + 4 * y + 16 * z + 4;
5011 cells[k].vertices[3] = x + 4 * y + 16 * z + 5;
5012 cells[k].vertices[4] = x + 4 * y + 16 * z + 16;
5013 cells[k].vertices[5] = x + 4 * y + 16 * z + 17;
5014 cells[k].vertices[6] = x + 4 * y + 16 * z + 20;
5015 cells[k].vertices[7] = x + 4 * y + 16 * z + 21;
5016 if (colorize)
5017 cells[k].material_id = materials[k];
5018 ++k;
5019 }
5020 tria.create_triangulation(vertices,
5021 cells,
5022 SubCellData()); // no boundary information
5023 }
5024
5025
5026
5027 template <>
5028 void
5030 const double radius_0,
5031 const double radius_1,
5032 const double half_length)
5033 {
5034 Assert(triangulation.n_cells() == 0,
5035 ExcMessage("The output triangulation object needs to be empty."));
5036 Assert(0 < radius_0, ExcMessage("The radii must be positive."));
5037 Assert(0 < radius_1, ExcMessage("The radii must be positive."));
5038 Assert(0 < half_length, ExcMessage("The half length must be positive."));
5039
5040 const auto n_slices = 1 + static_cast<unsigned int>(std::ceil(
5042
5046 n_slices,
5047 2 * half_length,
5051 // At this point we have a cylinder. Multiply the y and z coordinates by a
5052 // factor that scales (with x) linearly between radius_0 and radius_1 to fix
5053 // the circle radii and interior points:
5054 auto shift_radii = [=](const Point<3> &p) {
5055 const double slope = (radius_1 / radius_0 - 1.0) / (2.0 * half_length);
5056 const double factor = slope * (p[0] - -half_length) + 1.0;
5057 return Point<3>(p[0], factor * p[1], factor * p[2]);
5058 };
5060
5061 // Set boundary ids at -half_length to 1 and at half_length to 2. Set the
5062 // manifold id on hull faces (i.e., faces not on either end) to 0.
5063 for (const auto &face : triangulation.active_face_iterators())
5064 if (face->at_boundary())
5065 {
5066 if (std::abs(face->center()[0] - -half_length) < 1e-8 * half_length)
5067 face->set_boundary_id(1);
5068 else if (std::abs(face->center()[0] - half_length) <
5069 1e-8 * half_length)
5070 face->set_boundary_id(2);
5071 else
5072 face->set_all_manifold_ids(0);
5073 }
5074
5075 triangulation.set_manifold(0, CylindricalManifold<3>());
5076 }
5077
5078
5079 // Implementation for 3d only
5080 template <>
5081 void
5083 const double a,
5084 const double b,
5085 const bool colorize)
5086 {
5087 // we slice out the top back right
5088 // part of the cube
5089 const Point<3> vertices[26] = {
5090 // front face of the big cube
5091 Point<3>(a, a, a),
5092 Point<3>((a + b) / 2, a, a),
5093 Point<3>(b, a, a),
5094 Point<3>(a, a, (a + b) / 2),
5095 Point<3>((a + b) / 2, a, (a + b) / 2),
5096 Point<3>(b, a, (a + b) / 2),
5097 Point<3>(a, a, b),
5098 Point<3>((a + b) / 2, a, b),
5099 Point<3>(b, a, b),
5100 // middle face of the big cube
5101 Point<3>(a, (a + b) / 2, a),
5102 Point<3>((a + b) / 2, (a + b) / 2, a),
5103 Point<3>(b, (a + b) / 2, a),
5104 Point<3>(a, (a + b) / 2, (a + b) / 2),
5105 Point<3>((a + b) / 2, (a + b) / 2, (a + b) / 2),
5106 Point<3>(b, (a + b) / 2, (a + b) / 2),
5107 Point<3>(a, (a + b) / 2, b),
5108 Point<3>((a + b) / 2, (a + b) / 2, b),
5109 Point<3>(b, (a + b) / 2, b),
5110 // back face of the big cube
5111 // last (top right) point is missing
5112 Point<3>(a, b, a),
5113 Point<3>((a + b) / 2, b, a),
5114 Point<3>(b, b, a),
5115 Point<3>(a, b, (a + b) / 2),
5116 Point<3>((a + b) / 2, b, (a + b) / 2),
5117 Point<3>(b, b, (a + b) / 2),
5118 Point<3>(a, b, b),
5119 Point<3>((a + b) / 2, b, b)};
5120 const int cell_vertices[7][8] = {{0, 1, 9, 10, 3, 4, 12, 13},
5121 {1, 2, 10, 11, 4, 5, 13, 14},
5122 {3, 4, 12, 13, 6, 7, 15, 16},
5123 {4, 5, 13, 14, 7, 8, 16, 17},
5124 {9, 10, 18, 19, 12, 13, 21, 22},
5125 {10, 11, 19, 20, 13, 14, 22, 23},
5126 {12, 13, 21, 22, 15, 16, 24, 25}};
5127
5128 std::vector<CellData<3>> cells(7, CellData<3>());
5129
5130 for (unsigned int i = 0; i < 7; ++i)
5131 {
5132 for (unsigned int j = 0; j < 8; ++j)
5133 cells[i].vertices[j] = cell_vertices[i][j];
5134 cells[i].material_id = 0;
5135 }
5136
5137 tria.create_triangulation(std::vector<Point<3>>(std::begin(vertices),
5138 std::end(vertices)),
5139 cells,
5140 SubCellData()); // no boundary information
5141
5142 if (colorize)
5143 {
5145 }
5146 }
5147
5148
5149
5150 void
5152 const unsigned int n_rotate_middle_square)
5153 {
5155 ExcMessage("The number of rotation by pi/2 of the right square "
5156 "must be in the half-open range [0,4)."));
5157
5158 constexpr unsigned int dim = 2;
5159
5160 const unsigned int n_cells = 5;
5161 std::vector<CellData<dim>> cells(n_cells);
5162
5163 // Corner points of the cube [0,1]^2
5164 const std::vector<Point<dim>> vertices = {Point<dim>(0, 0), // 0
5165 Point<dim>(1, 0), // 1
5166 Point<dim>(0, 1), // 2
5167 Point<dim>(1, 1), // 3
5168 Point<dim>(2, 0), // 4
5169 Point<dim>(2, 1), // 5
5170 Point<dim>(3, 0), // 6
5171 Point<dim>(3, 1), // 7
5172 Point<dim>(1, -1), // 8
5173 Point<dim>(2, -1), // 9
5174 Point<dim>(1, 2), // 10
5175 Point<dim>(2, 2)}; // 11
5176
5177
5178 // consistent orientation
5179 unsigned int cell_vertices[n_cells][4] = {{0, 1, 2, 3},
5180 {1, 4, 3, 5}, // rotating cube
5181 {8, 9, 1, 4},
5182 {4, 6, 5, 7},
5183 {3, 5, 10, 11}};
5184
5185 switch (n_rotate_middle_square)
5186 {
5187 case /* rotate right square */ 1:
5188 {
5189 cell_vertices[1][0] = 4;
5190 cell_vertices[1][1] = 5;
5191 cell_vertices[1][2] = 1;
5192 cell_vertices[1][3] = 3;
5193 break;
5194 }
5195
5196 case /* rotate right square */ 2:
5197 {
5198 cell_vertices[1][0] = 5;
5199 cell_vertices[1][1] = 3;
5200 cell_vertices[1][2] = 4;
5201 cell_vertices[1][3] = 1;
5202 break;
5203 }
5204
5205 case /* rotate right square */ 3:
5206 {
5207 cell_vertices[1][0] = 3;
5208 cell_vertices[1][1] = 1;
5209 cell_vertices[1][2] = 5;
5210 cell_vertices[1][3] = 4;
5211 break;
5212 }
5213
5214 default /* 0 */:
5215 break;
5216 } // switch
5217
5218 cells.resize(n_cells, CellData<dim>());
5219
5220 for (unsigned int cell_index = 0; cell_index < n_cells; ++cell_index)
5221 {
5222 for (const unsigned int vertex_index :
5224 {
5225 cells[cell_index].vertices[vertex_index] =
5226 cell_vertices[cell_index][vertex_index];
5227 cells[cell_index].material_id = 0;
5228 }
5229 }
5230
5231 tria.create_triangulation(vertices, cells, SubCellData());
5232 }
5233
5234
5235 void
5237 const bool face_orientation,
5238 const bool face_flip,
5239 const bool face_rotation,
5240 const bool manipulate_left_cube)
5241 {
5242 constexpr unsigned int dim = 3;
5243
5244 const unsigned int n_cells = 2;
5245 std::vector<CellData<dim>> cells(n_cells);
5246
5247 // Corner points of the cube [0,1]^3
5248 const std::vector<Point<dim>> vertices = {Point<dim>(0, 0, 0), // 0
5249 Point<dim>(1, 0, 0), // 1
5250 Point<dim>(0, 1, 0), // 2
5251 Point<dim>(1, 1, 0), // 3
5252 Point<dim>(0, 0, 1), // 4
5253 Point<dim>(1, 0, 1), // 5
5254 Point<dim>(0, 1, 1), // 6
5255 Point<dim>(1, 1, 1), // 7
5256 Point<dim>(2, 0, 0), // 8
5257 Point<dim>(2, 1, 0), // 9
5258 Point<dim>(2, 0, 1), // 10
5259 Point<dim>(2, 1, 1)}; // 11
5260
5261 unsigned int cell_vertices[n_cells][8] = {
5262 {0, 1, 2, 3, 4, 5, 6, 7}, // unit cube
5263 {1, 8, 3, 9, 5, 10, 7, 11}}; // shifted cube
5264
5265 // binary to case number
5266 const unsigned int this_case = 4 * static_cast<int>(face_orientation) +
5267 2 * static_cast<int>(face_flip) +
5268 static_cast<int>(face_rotation);
5269
5271 {
5272 switch (this_case)
5273 {
5274 case 0:
5275 {
5276 cell_vertices[0][0] = 1;
5277 cell_vertices[0][1] = 0;
5278 cell_vertices[0][2] = 5;
5279 cell_vertices[0][3] = 4;
5280 cell_vertices[0][4] = 3;
5281 cell_vertices[0][5] = 2;
5282 cell_vertices[0][6] = 7;
5283 cell_vertices[0][7] = 6;
5284 break;
5285 }
5286
5287 case 1:
5288 {
5289 cell_vertices[0][0] = 5;
5290 cell_vertices[0][1] = 4;
5291 cell_vertices[0][2] = 7;
5292 cell_vertices[0][3] = 6;
5293 cell_vertices[0][4] = 1;
5294 cell_vertices[0][5] = 0;
5295 cell_vertices[0][6] = 3;
5296 cell_vertices[0][7] = 2;
5297 break;
5298 }
5299
5300 case 2:
5301 {
5302 cell_vertices[0][0] = 7;
5303 cell_vertices[0][1] = 6;
5304 cell_vertices[0][2] = 3;
5305 cell_vertices[0][3] = 2;
5306 cell_vertices[0][4] = 5;
5307 cell_vertices[0][5] = 4;
5308 cell_vertices[0][6] = 1;
5309 cell_vertices[0][7] = 0;
5310 break;
5311 }
5312 case 3:
5313 {
5314 cell_vertices[0][0] = 3;
5315 cell_vertices[0][1] = 2;
5316 cell_vertices[0][2] = 1;
5317 cell_vertices[0][3] = 0;
5318 cell_vertices[0][4] = 7;
5319 cell_vertices[0][5] = 6;
5320 cell_vertices[0][6] = 5;
5321 cell_vertices[0][7] = 4;
5322 break;
5323 }
5324
5325 case 4:
5326 {
5327 cell_vertices[0][0] = 0;
5328 cell_vertices[0][1] = 1;
5329 cell_vertices[0][2] = 2;
5330 cell_vertices[0][3] = 3;
5331 cell_vertices[0][4] = 4;
5332 cell_vertices[0][5] = 5;
5333 cell_vertices[0][6] = 6;
5334 cell_vertices[0][7] = 7;
5335 break;
5336 }
5337
5338 case 5:
5339 {
5340 cell_vertices[0][0] = 2;
5341 cell_vertices[0][1] = 3;
5342 cell_vertices[0][2] = 6;
5343 cell_vertices[0][3] = 7;
5344 cell_vertices[0][4] = 0;
5345 cell_vertices[0][5] = 1;
5346 cell_vertices[0][6] = 4;
5347 cell_vertices[0][7] = 5;
5348 break;
5349 }
5350
5351 case 6:
5352 {
5353 cell_vertices[0][0] = 6;
5354 cell_vertices[0][1] = 7;
5355 cell_vertices[0][2] = 4;
5356 cell_vertices[0][3] = 5;
5357 cell_vertices[0][4] = 2;
5358 cell_vertices[0][5] = 3;
5359 cell_vertices[0][6] = 0;
5360 cell_vertices[0][7] = 1;
5361 break;
5362 }
5363
5364 case 7:
5365 {
5366 cell_vertices[0][0] = 4;
5367 cell_vertices[0][1] = 5;
5368 cell_vertices[0][2] = 0;
5369 cell_vertices[0][3] = 1;
5370 cell_vertices[0][4] = 6;
5371 cell_vertices[0][5] = 7;
5372 cell_vertices[0][6] = 2;
5373 cell_vertices[0][7] = 3;
5374 break;
5375 }
5376 } // switch
5377 }
5378 else
5379 {
5380 switch (this_case)
5381 {
5382 case 0:
5383 {
5384 cell_vertices[1][0] = 8;
5385 cell_vertices[1][1] = 1;
5386 cell_vertices[1][2] = 10;
5387 cell_vertices[1][3] = 5;
5388 cell_vertices[1][4] = 9;
5389 cell_vertices[1][5] = 3;
5390 cell_vertices[1][6] = 11;
5391 cell_vertices[1][7] = 7;
5392 break;
5393 }
5394
5395 case 1:
5396 {
5397 cell_vertices[1][0] = 10;
5398 cell_vertices[1][1] = 5;
5399 cell_vertices[1][2] = 11;
5400 cell_vertices[1][3] = 7;
5401 cell_vertices[1][4] = 8;
5402 cell_vertices[1][5] = 1;
5403 cell_vertices[1][6] = 9;
5404 cell_vertices[1][7] = 3;
5405 break;
5406 }
5407
5408 case 2:
5409 {
5410 cell_vertices[1][0] = 11;
5411 cell_vertices[1][1] = 7;
5412 cell_vertices[1][2] = 9;
5413 cell_vertices[1][3] = 3;
5414 cell_vertices[1][4] = 10;
5415 cell_vertices[1][5] = 5;
5416 cell_vertices[1][6] = 8;
5417 cell_vertices[1][7] = 1;
5418 break;
5419 }
5420
5421 case 3:
5422 {
5423 cell_vertices[1][0] = 9;
5424 cell_vertices[1][1] = 3;
5425 cell_vertices[1][2] = 8;
5426 cell_vertices[1][3] = 1;
5427 cell_vertices[1][4] = 11;
5428 cell_vertices[1][5] = 7;
5429 cell_vertices[1][6] = 10;
5430 cell_vertices[1][7] = 5;
5431 break;
5432 }
5433
5434 case 4:
5435 {
5436 cell_vertices[1][0] = 1;
5437 cell_vertices[1][1] = 8;
5438 cell_vertices[1][2] = 3;
5439 cell_vertices[1][3] = 9;
5440 cell_vertices[1][4] = 5;
5441 cell_vertices[1][5] = 10;
5442 cell_vertices[1][6] = 7;
5443 cell_vertices[1][7] = 11;
5444 break;
5445 }
5446
5447 case 5:
5448 {
5449 cell_vertices[1][0] = 5;
5450 cell_vertices[1][1] = 10;
5451 cell_vertices[1][2] = 1;
5452 cell_vertices[1][3] = 8;
5453 cell_vertices[1][4] = 7;
5454 cell_vertices[1][5] = 11;
5455 cell_vertices[1][6] = 3;
5456 cell_vertices[1][7] = 9;
5457 break;
5458 }
5459
5460 case 6:
5461 {
5462 cell_vertices[1][0] = 7;
5463 cell_vertices[1][1] = 11;
5464 cell_vertices[1][2] = 5;
5465 cell_vertices[1][3] = 10;
5466 cell_vertices[1][4] = 3;
5467 cell_vertices[1][5] = 9;
5468 cell_vertices[1][6] = 1;
5469 cell_vertices[1][7] = 8;
5470 break;
5471 }
5472
5473 case 7:
5474 {
5475 cell_vertices[1][0] = 3;
5476 cell_vertices[1][1] = 9;
5477 cell_vertices[1][2] = 7;
5478 cell_vertices[1][3] = 11;
5479 cell_vertices[1][4] = 1;
5480 cell_vertices[1][5] = 8;
5481 cell_vertices[1][6] = 5;
5482 cell_vertices[1][7] = 10;
5483 break;
5484 }
5485 } // switch
5486 }
5487
5488 cells.resize(n_cells, CellData<dim>());
5489
5490 for (unsigned int cell_index = 0; cell_index < n_cells; ++cell_index)
5491 {
5492 for (const unsigned int vertex_index :
5494 {
5495 cells[cell_index].vertices[vertex_index] =
5496 cell_vertices[cell_index][vertex_index];
5497 cells[cell_index].material_id = 0;
5498 }
5499 }
5500
5501 tria.create_triangulation(vertices, cells, SubCellData());
5502 }
5503
5504
5505
5506 template <int spacedim>
5507 void
5509 const Point<spacedim> &p,
5510 const double radius)
5511 {
5514 const std::set<types::boundary_id> boundary_ids = {0};
5516 tria.set_all_manifold_ids(0);
5517 tria.set_manifold(0, SphericalManifold<spacedim - 1, spacedim>(p));
5518 }
5519
5520
5521
5522 // Implementation for 3d only
5523 template <>
5524 void
5526 const unsigned int x_subdivisions,
5527 const double radius,
5528 const double half_length)
5529 {
5530 // Copy the base from hyper_ball<3>
5531 // and transform it to yz
5532 const double d = radius / std::sqrt(2.0);
5533 const double a = d / (1 + std::sqrt(2.0));
5534
5535 std::vector<Point<3>> vertices;
5536 const double initial_height = -half_length;
5537 const double height_increment = 2. * half_length / x_subdivisions;
5538
5539 for (unsigned int rep = 0; rep < (x_subdivisions + 1); ++rep)
5540 {
5541 const double height = initial_height + height_increment * rep;
5542
5543 vertices.emplace_back(-d, height, -d);
5544 vertices.emplace_back(d, height, -d);
5545 vertices.emplace_back(-a, height, -a);
5546 vertices.emplace_back(a, height, -a);
5547 vertices.emplace_back(-a, height, a);
5548 vertices.emplace_back(a, height, a);
5549 vertices.emplace_back(-d, height, d);
5550 vertices.emplace_back(d, height, d);
5551 }
5552
5553 // Turn cylinder such that y->x
5554 for (auto &vertex : vertices)
5555 {
5556 const double h = vertex[1];
5557 vertex[1] = -vertex[0];
5558 vertex[0] = h;
5559 }
5560
5561 std::vector<std::vector<int>> cell_vertices;
5562 cell_vertices.push_back({0, 1, 8, 9, 2, 3, 10, 11});
5563 cell_vertices.push_back({0, 2, 8, 10, 6, 4, 14, 12});
5564 cell_vertices.push_back({2, 3, 10, 11, 4, 5, 12, 13});
5565 cell_vertices.push_back({1, 7, 9, 15, 3, 5, 11, 13});
5566 cell_vertices.push_back({6, 4, 14, 12, 7, 5, 15, 13});
5567
5568 for (unsigned int rep = 1; rep < x_subdivisions; ++rep)
5569 {
5570 for (unsigned int i = 0; i < 5; ++i)
5571 {
5572 std::vector<int> new_cell_vertices(8);
5573 for (unsigned int j = 0; j < 8; ++j)
5574 new_cell_vertices[j] = cell_vertices[i][j] + 8 * rep;
5575 cell_vertices.push_back(new_cell_vertices);
5576 }
5577 }
5578
5579 unsigned int n_cells = x_subdivisions * 5;
5580
5581 std::vector<CellData<3>> cells(n_cells, CellData<3>());
5582
5583 for (unsigned int i = 0; i < n_cells; ++i)
5584 {
5585 for (unsigned int j = 0; j < 8; ++j)
5586 cells[i].vertices[j] = cell_vertices[i][j];
5587 cells[i].material_id = 0;
5588 }
5589
5590 tria.create_triangulation(std::vector<Point<3>>(std::begin(vertices),
5591 std::end(vertices)),
5592 cells,
5593 SubCellData()); // no boundary information
5594
5595 // set boundary indicators for the
5596 // faces at the ends to 1 and 2,
5597 // respectively. note that we also
5598 // have to deal with those lines
5599 // that are purely in the interior
5600 // of the ends. we determine whether
5601 // an edge is purely in the
5602 // interior if one of its vertices
5603 // is at coordinates '+-a' as set
5604 // above
5605 tria.set_all_manifold_ids_on_boundary(0);
5606
5607 // Tolerance is calculated using the minimal length defining
5608 // the cylinder
5609 const double tolerance = 1e-5 * std::min(radius, half_length);
5610
5611 for (const auto &cell : tria.cell_iterators())
5612 for (const unsigned int i : GeometryInfo<3>::face_indices())
5613 if (cell->at_boundary(i))
5614 {
5615 if (cell->face(i)->center()[0] > half_length - tolerance)
5616 {
5617 cell->face(i)->set_boundary_id(2);
5618 cell->face(i)->set_manifold_id(numbers::flat_manifold_id);
5619
5620 for (unsigned int e = 0; e < GeometryInfo<3>::lines_per_face;
5621 ++e)
5622 if ((std::fabs(cell->face(i)->line(e)->vertex(0)[1]) == a) ||
5623 (std::fabs(cell->face(i)->line(e)->vertex(0)[2]) == a) ||
5624 (std::fabs(cell->face(i)->line(e)->vertex(1)[1]) == a) ||
5625 (std::fabs(cell->face(i)->line(e)->vertex(1)[2]) == a))
5626 {
5627 cell->face(i)->line(e)->set_boundary_id(2);
5628 cell->face(i)->line(e)->set_manifold_id(
5630 }
5631 }
5632 else if (cell->face(i)->center()[0] < -half_length + tolerance)
5633 {
5634 cell->face(i)->set_boundary_id(1);
5635 cell->face(i)->set_manifold_id(numbers::flat_manifold_id);
5636
5637 for (unsigned int e = 0; e < GeometryInfo<3>::lines_per_face;
5638 ++e)
5639 if ((std::fabs(cell->face(i)->line(e)->vertex(0)[1]) == a) ||
5640 (std::fabs(cell->face(i)->line(e)->vertex(0)[2]) == a) ||
5641 (std::fabs(cell->face(i)->line(e)->vertex(1)[1]) == a) ||
5642 (std::fabs(cell->face(i)->line(e)->vertex(1)[2]) == a))
5643 {
5644 cell->face(i)->line(e)->set_boundary_id(1);
5645 cell->face(i)->line(e)->set_manifold_id(
5647 }
5648 }
5649 }
5650 tria.set_manifold(0, CylindricalManifold<3>());
5651 }
5652
5653 // Implementation for 3d only
5654 template <>
5655 void
5657 const double radius,
5658 const double half_length)
5659 {
5660 subdivided_cylinder(tria, 2, radius, half_length);
5661 }
5662
5663 template <>
5664 void
5666 const Point<3> &center,
5667 const double radius)
5668 {
5669 const unsigned int dim = 3;
5670
5671 // the parameters a (intersection on the octant lines from center), b
5672 // (intersection within the octant faces) and c (position inside the
5673 // octant) have been derived by equilibrating the minimal singular value
5674 // of the Jacobian of the four cells around the center point c and, as a
5675 // secondary measure, to minimize the aspect ratios defined as the maximal
5676 // divided by the minimal singular values throughout cells
5677 const double a = 0.528;
5678 const double b = 0.4533;
5679 const double c = 0.3752;
5680 const Point<dim> vertices[15] = {
5681 center + Point<dim>(0, 0, 0) * radius,
5682 center + Point<dim>(+1, 0, 0) * radius,
5683 center + Point<dim>(+1, 0, 0) * (radius * a),
5684 center + Point<dim>(0, +1, 0) * (radius * a),
5685 center + Point<dim>(+1, +1, 0) * (radius * b),
5686 center + Point<dim>(0, +1, 0) * radius,
5687 center + Point<dim>(+1, +1, 0) * radius / std::sqrt(2.0),
5688 center + Point<dim>(0, 0, 1) * radius * a,
5689 center + Point<dim>(+1, 0, 1) * radius / std::sqrt(2.0),
5690 center + Point<dim>(+1, 0, 1) * (radius * b),
5691 center + Point<dim>(0, +1, 1) * (radius * b),
5692 center + Point<dim>(+1, +1, 1) * (radius * c),
5693 center + Point<dim>(0, +1, 1) * radius / std::sqrt(2.0),
5694 center + Point<dim>(+1, +1, 1) * (radius / (std::sqrt(3.0))),
5695 center + Point<dim>(0, 0, 1) * radius};
5696 const int cell_vertices[4][8] = {{0, 2, 3, 4, 7, 9, 10, 11},
5697 {1, 6, 2, 4, 8, 13, 9, 11},
5698 {5, 3, 6, 4, 12, 10, 13, 11},
5699 {7, 9, 10, 11, 14, 8, 12, 13}};
5700
5701 std::vector<CellData<dim>> cells(4, CellData<dim>());
5702
5703 for (unsigned int i = 0; i < 4; ++i)
5704 {
5705 for (unsigned int j = 0; j < 8; ++j)
5706 cells[i].vertices[j] = cell_vertices[i][j];
5707 cells[i].material_id = 0;
5708 }
5709
5710 tria.create_triangulation(std::vector<Point<dim>>(std::begin(vertices),
5711 std::end(vertices)),
5712 cells,
5713 SubCellData()); // no boundary information
5714
5715 Triangulation<dim>::cell_iterator cell = tria.begin();
5717
5718 tria.set_all_manifold_ids_on_boundary(0);
5719 while (cell != end)
5720 {
5721 for (const unsigned int i : GeometryInfo<dim>::face_indices())
5722 {
5723 if (cell->face(i)->boundary_id() ==
5725 continue;
5726
5727 // If x,y or z is zero, then this is part of the plane
5728 if (cell->face(i)->center()[0] < center[0] + 1.e-5 * radius ||
5729 cell->face(i)->center()[1] < center[1] + 1.e-5 * radius ||
5730 cell->face(i)->center()[2] < center[2] + 1.e-5 * radius)
5731 {
5732 cell->face(i)->set_boundary_id(1);
5733 cell->face(i)->set_manifold_id(numbers::flat_manifold_id);
5734 // also set the boundary indicators of the bounding lines,
5735 // unless both vertices are on the perimeter
5736 for (unsigned int j = 0; j < GeometryInfo<3>::lines_per_face;
5737 ++j)
5738 {
5739 const Point<3> line_vertices[2] = {
5740 cell->face(i)->line(j)->vertex(0),
5741 cell->face(i)->line(j)->vertex(1)};
5742 if ((std::fabs(line_vertices[0].distance(center) - radius) >
5743 1e-5 * radius) ||
5744 (std::fabs(line_vertices[1].distance(center) - radius) >
5745 1e-5 * radius))
5746 {
5747 cell->face(i)->line(j)->set_boundary_id(1);
5748 cell->face(i)->line(j)->set_manifold_id(
5750 }
5751 }
5752 }
5753 }
5754 ++cell;
5755 }
5756 tria.set_manifold(0, SphericalManifold<3>(center));
5757 }
5758
5759
5760
5761 // Implementation for 3d only
5762 template <>
5763 void
5765 const Point<3> &center,
5766 const double radius)
5767 {
5768 // These are for the two lower squares
5769 const double d = radius / std::sqrt(2.0);
5770 const double a = d / (1 + std::sqrt(2.0));
5771 // These are for the two upper square
5772 const double b = a / 2.0;
5773 const double c = d / 2.0;
5774 // And so are these
5775 const double hb = radius * std::sqrt(3.0) / 4.0;
5776 const double hc = radius * std::sqrt(3.0) / 2.0;
5777
5778 Point<3> vertices[16] = {
5779 center + Point<3>(0, d, -d),
5780 center + Point<3>(0, -d, -d),
5781 center + Point<3>(0, a, -a),
5782 center + Point<3>(0, -a, -a),
5783 center + Point<3>(0, a, a),
5784 center + Point<3>(0, -a, a),
5785 center + Point<3>(0, d, d),
5786 center + Point<3>(0, -d, d),
5787
5788 center + Point<3>(hc, c, -c),
5789 center + Point<3>(hc, -c, -c),
5790 center + Point<3>(hb, b, -b),
5791 center + Point<3>(hb, -b, -b),
5792 center + Point<3>(hb, b, b),
5793 center + Point<3>(hb, -b, b),
5794 center + Point<3>(hc, c, c),
5795 center + Point<3>(hc, -c, c),
5796 };
5797
5798 int cell_vertices[6][8] = {{0, 1, 8, 9, 2, 3, 10, 11},
5799 {0, 2, 8, 10, 6, 4, 14, 12},
5800 {2, 3, 10, 11, 4, 5, 12, 13},
5801 {1, 7, 9, 15, 3, 5, 11, 13},
5802 {6, 4, 14, 12, 7, 5, 15, 13},
5803 {8, 10, 9, 11, 14, 12, 15, 13}};
5804
5805 std::vector<CellData<3>> cells(6, CellData<3>());
5806
5807 for (unsigned int i = 0; i < 6; ++i)
5808 {
5809 for (unsigned int j = 0; j < 8; ++j)
5810 cells[i].vertices[j] = cell_vertices[i][j];
5811 cells[i].material_id = 0;
5812 }
5813
5814 tria.create_triangulation(std::vector<Point<3>>(std::begin(vertices),
5815 std::end(vertices)),
5816 cells,
5817 SubCellData()); // no boundary information
5818
5819 Triangulation<3>::cell_iterator cell = tria.begin();
5821
5822 tria.set_all_manifold_ids_on_boundary(0);
5823
5824 // go over all faces. for the ones on the flat face, set boundary
5825 // indicator for face and edges to one; the rest will remain at
5826 // zero but we have to pay attention to those edges that are
5827 // at the perimeter of the flat face since they should not be
5828 // set to one
5829 while (cell != end)
5830 {
5831 for (const unsigned int i : GeometryInfo<3>::face_indices())
5832 {
5833 if (!cell->at_boundary(i))
5834 continue;
5835
5836 // If the center is on the plane x=0, this is a planar element. set
5837 // its boundary indicator. also set the boundary indicators of the
5838 // bounding faces unless both vertices are on the perimeter
5839 if (cell->face(i)->center()[0] < center[0] + 1.e-5 * radius)
5840 {
5841 cell->face(i)->set_boundary_id(1);
5842 cell->face(i)->set_manifold_id(numbers::flat_manifold_id);
5843 for (unsigned int j = 0; j < GeometryInfo<3>::lines_per_face;
5844 ++j)
5845 {
5846 const Point<3> line_vertices[2] = {
5847 cell->face(i)->line(j)->vertex(0),
5848 cell->face(i)->line(j)->vertex(1)};
5849 if ((std::fabs(line_vertices[0].distance(center) - radius) >
5850 1e-5 * radius) ||
5851 (std::fabs(line_vertices[1].distance(center) - radius) >
5852 1e-5 * radius))
5853 {
5854 cell->face(i)->line(j)->set_boundary_id(1);
5855 cell->face(i)->line(j)->set_manifold_id(
5857 }
5858 }
5859 }
5860 }
5861 ++cell;
5862 }
5863 tria.set_manifold(0, SphericalManifold<3>(center));
5864 }
5865
5866
5867
5868 template <int dim>
5869 void
5871 const Point<dim> &p,
5872 const double radius)
5873 {
5874 // We create the ball by duplicating the information in each dimension at
5875 // a time by appropriate rotations, starting from the quarter ball. The
5876 // rotations make sure we do not generate inverted cells that would appear
5877 // if we tried the slightly simpler approach to simply mirror the cells.
5878 //
5879 // Make the rotations easy by centering at the origin now and shifting by p
5880 // later.
5881
5884
5885 for (unsigned int round = 0; round < dim; ++round)
5886 {
5888 tria_copy.copy_triangulation(tria_piece);
5889 tria_piece.clear();
5890 std::vector<Point<dim>> new_points(tria_copy.n_vertices());
5891 if (round == 0)
5892 for (unsigned int v = 0; v < tria_copy.n_vertices(); ++v)
5893 {
5894 // rotate by 90 degrees counterclockwise
5895 new_points[v][0] = -tria_copy.get_vertices()[v][1];
5896 new_points[v][1] = tria_copy.get_vertices()[v][0];
5897 if (dim == 3)
5898 new_points[v][2] = tria_copy.get_vertices()[v][2];
5899 }
5900 else if (round == 1)
5901 {
5902 for (unsigned int v = 0; v < tria_copy.n_vertices(); ++v)
5903 {
5904 // rotate by 180 degrees along the xy plane
5905 new_points[v][0] = -tria_copy.get_vertices()[v][0];
5906 new_points[v][1] = -tria_copy.get_vertices()[v][1];
5907 if (dim == 3)
5908 new_points[v][2] = tria_copy.get_vertices()[v][2];
5909 }
5910 }
5911 else if (round == 2)
5912 for (unsigned int v = 0; v < tria_copy.n_vertices(); ++v)
5913 {
5914 // rotate by 180 degrees along the xz plane
5915 Assert(dim == 3, ExcInternalError());
5916 new_points[v][0] = -tria_copy.get_vertices()[v][0];
5917 new_points[v][1] = tria_copy.get_vertices()[v][1];
5918 new_points[v][2] = -tria_copy.get_vertices()[v][2];
5919 }
5920 else
5922
5923
5924 // the cell data is exactly the same as before
5925 std::vector<CellData<dim>> cells;
5926 cells.reserve(tria_copy.n_cells());
5927 for (const auto &cell : tria_copy.cell_iterators())
5928 {
5930 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
5931 data.vertices[v] = cell->vertex_index(v);
5932 data.material_id = cell->material_id();
5933 data.manifold_id = cell->manifold_id();
5934 cells.push_back(data);
5935 }
5936
5938 rotated_tria.create_triangulation(new_points, cells, SubCellData());
5939
5940 // merge the triangulations - this will make sure that the duplicate
5941 // vertices in the interior are absorbed
5942 if (round == dim - 1)
5943 merge_triangulations(tria_copy, rotated_tria, tria, 1e-12 * radius);
5944 else
5947 tria_piece,
5948 1e-12 * radius);
5949 }
5950
5951 for (const auto &cell : tria.cell_iterators())
5952 if (cell->center().norm_square() > 0.4 * radius)
5953 cell->set_manifold_id(1);
5954 else
5955 cell->set_all_manifold_ids(numbers::flat_manifold_id);
5956 GridTools::shift(p, tria);
5957
5958 tria.set_manifold(1, FlatManifold<dim>());
5959
5960 tria.set_all_manifold_ids_on_boundary(0);
5961 tria.set_manifold(0, SphericalManifold<dim>(p));
5962 }
5963
5964 // To work around an internal clang-13 error we need to split up the
5965 // individual hyper shell functions. This has the added bonus of making the
5966 // control flow easier to follow - some hyper shell functions call others.
5967 namespace internal
5968 {
5969 namespace
5970 {
5971 void
5973 const Point<3> &p,
5974 const double inner_radius,
5975 const double outer_radius)
5976 {
5977 std::vector<Point<3>> vertices;
5978 std::vector<CellData<3>> cells;
5979
5980 const double irad = inner_radius / std::sqrt(3.0);
5981 const double orad = outer_radius / std::sqrt(3.0);
5982
5983 // Corner points of the cube [-1,1]^3
5984 static const std::array<Point<3>, 8> hexahedron = {{{-1, -1, -1}, //
5985 {+1, -1, -1}, //
5986 {-1, +1, -1}, //
5987 {+1, +1, -1}, //
5988 {-1, -1, +1}, //
5989 {+1, -1, +1}, //
5990 {-1, +1, +1}, //
5991 {+1, +1, +1}}};
5992
5993 // Start with the shell bounded by two nested cubes
5994 for (unsigned int i = 0; i < 8; ++i)
5995 vertices.push_back(p + hexahedron[i] * irad);
5996 for (unsigned int i = 0; i < 8; ++i)
5997 vertices.push_back(p + hexahedron[i] * orad);
5998
5999 const unsigned int n_cells = 6;
6000 const int cell_vertices[n_cells][8] = {
6001 {8, 9, 10, 11, 0, 1, 2, 3}, // bottom
6002 {9, 11, 1, 3, 13, 15, 5, 7}, // right
6003 {12, 13, 4, 5, 14, 15, 6, 7}, // top
6004 {8, 0, 10, 2, 12, 4, 14, 6}, // left
6005 {8, 9, 0, 1, 12, 13, 4, 5}, // front
6006 {10, 2, 11, 3, 14, 6, 15, 7}}; // back
6007
6008 cells.resize(n_cells, CellData<3>());
6009
6010 for (unsigned int i = 0; i < n_cells; ++i)
6011 {
6012 for (const unsigned int j : GeometryInfo<3>::vertex_indices())
6013 cells[i].vertices[j] = cell_vertices[i][j];
6014 cells[i].material_id = 0;
6015 }
6016
6017 tria.create_triangulation(vertices, cells, SubCellData());
6018 tria.set_all_manifold_ids(0);
6019 tria.set_manifold(0, SphericalManifold<3>(p));
6020 }
6021
6022 void
6024 const Point<3> &p,
6025 const double inner_radius,
6026 const double outer_radius)
6027 {
6028 std::vector<Point<3>> vertices;
6029 std::vector<CellData<3>> cells;
6030
6031 const double irad = inner_radius / std::sqrt(3.0);
6032 const double orad = outer_radius / std::sqrt(3.0);
6033
6034 // A more regular subdivision can be obtained by two nested rhombic
6035 // dodecahedra
6036 //
6037 // Octahedron inscribed in the cube [-1,1]^3
6038 static const std::array<Point<3>, 6> octahedron = {{{-1, 0, 0}, //
6039 {1, 0, 0}, //
6040 {0, -1, 0}, //
6041 {0, 1, 0}, //
6042 {0, 0, -1}, //
6043 {0, 0, 1}}};
6044
6045 // Corner points of the cube [-1,1]^3
6046 static const std::array<Point<3>, 8> hexahedron = {{{-1, -1, -1}, //
6047 {+1, -1, -1}, //
6048 {-1, +1, -1}, //
6049 {+1, +1, -1}, //
6050 {-1, -1, +1}, //
6051 {+1, -1, +1}, //
6052 {-1, +1, +1}, //
6053 {+1, +1, +1}}};
6054
6055 for (unsigned int i = 0; i < 8; ++i)
6056 vertices.push_back(p + hexahedron[i] * irad);
6057 for (unsigned int i = 0; i < 6; ++i)
6058 vertices.push_back(p + octahedron[i] * inner_radius);
6059 for (unsigned int i = 0; i < 8; ++i)
6060 vertices.push_back(p + hexahedron[i] * orad);
6061 for (unsigned int i = 0; i < 6; ++i)
6062 vertices.push_back(p + octahedron[i] * outer_radius);
6063
6064 const unsigned int n_cells = 12;
6065 const unsigned int rhombi[n_cells][4] = {{10, 4, 0, 8},
6066 {4, 13, 8, 6},
6067 {10, 5, 4, 13},
6068 {1, 9, 10, 5},
6069 {9, 7, 5, 13},
6070 {7, 11, 13, 6},
6071 {9, 3, 7, 11},
6072 {1, 12, 9, 3},
6073 {12, 2, 3, 11},
6074 {2, 8, 11, 6},
6075 {12, 0, 2, 8},
6076 {1, 10, 12, 0}};
6077
6078 cells.resize(n_cells, CellData<3>());
6079
6080 for (unsigned int i = 0; i < n_cells; ++i)
6081 {
6082 for (unsigned int j = 0; j < 4; ++j)
6083 {
6084 cells[i].vertices[j] = rhombi[i][j];
6085 cells[i].vertices[j + 4] = rhombi[i][j] + 14;
6086 }
6087 cells[i].material_id = 0;
6088 }
6089
6090 tria.create_triangulation(vertices, cells, SubCellData());
6091 tria.set_all_manifold_ids(0);
6092 tria.set_manifold(0, SphericalManifold<3>(p));
6093 }
6094
6095 void
6097 const unsigned int n,
6098 const unsigned int n_refinement_steps,
6099 const Point<3> &p,
6100 const double inner_radius,
6101 const double outer_radius)
6102 {
6103 // These two meshes are created by first creating a mesh of the
6104 // 6-cell/12-cell version, refining globally, and removing the outer
6105 // half of the cells. For 192 and more cells, we do this iteratively
6106 // several times, always refining and removing the outer half. Thus, the
6107 // outer radius for the start is larger and set as 2^n_refinement_steps
6108 // such that it exactly gives the desired radius in the end. It would
6109 // have been slightly less code to treat refinement steps recursively
6110 // for 192 cells or beyond, but unfortunately we could end up with the
6111 // 96 cell case which is not what we want. Thus, we need to implement a
6112 // loop manually here.
6113 Triangulation<3> tmp;
6114 const unsigned int outer_radius_factor = 1 << n_refinement_steps;
6115 if (n == 24)
6116 hyper_shell_6(tmp,
6117 p,
6118 inner_radius,
6120 (outer_radius_factor - 1) * inner_radius);
6121 else if (n == 48)
6122 hyper_shell_12(tmp,
6123 p,
6124 inner_radius,
6126 (outer_radius_factor - 1) * inner_radius);
6127 else
6128 Assert(n == 24 || n == 48, ExcInternalError());
6129 for (unsigned int r = 0; r < n_refinement_steps; ++r)
6130 {
6131 tmp.refine_global(1);
6132 std::set<Triangulation<3>::active_cell_iterator> cells_to_remove;
6133
6134 // We remove all cells which do not have exactly four vertices
6135 // at the inner radius (plus some tolerance).
6136 for (const auto &cell : tmp.active_cell_iterators())
6137 {
6138 unsigned int n_vertices_inside = 0;
6139 for (const auto v : GeometryInfo<3>::vertex_indices())
6140 if ((cell->vertex(v) - p).norm_square() <
6141 inner_radius * inner_radius * (1 + 1e-12))
6143 if (n_vertices_inside < 4)
6144 cells_to_remove.insert(cell);
6145 }
6146
6147 AssertDimension(cells_to_remove.size(), tmp.n_active_cells() / 2);
6148 if (r == n_refinement_steps - 1)
6151 tria);
6152 else
6153 {
6157 copy);
6158 tmp = std::move(copy);
6159 tmp.set_all_manifold_ids(0);
6160 tmp.set_manifold(0, SphericalManifold<3>(p));
6161 }
6162 }
6163 tria.set_all_manifold_ids(0);
6164 tria.set_manifold(0, SphericalManifold<3>(p));
6165 }
6166
6167 } // namespace
6168 } // namespace internal
6169
6170
6171
6172 template <>
6173 void
6175 const Point<3> &p,
6176 const double inner_radius,
6177 const double outer_radius,
6178 const unsigned int n_cells,
6179 const bool colorize)
6180 {
6181 Assert((inner_radius > 0) && (inner_radius < outer_radius),
6182 ExcInvalidRadii());
6183
6184 unsigned int n_refinement_steps = 0;
6185 unsigned int n_cells_coarsened = n_cells;
6186 if (n_cells != 96 && n_cells > 12)
6187 while (n_cells_coarsened > 12 && n_cells_coarsened % 4 == 0)
6188 {
6189 ++n_refinement_steps;
6190 n_cells_coarsened /= 4;
6191 }
6192 Assert(n_cells == 0 || n_cells == 6 || n_cells == 12 || n_cells == 96 ||
6193 (n_refinement_steps > 0 &&
6194 (n_cells_coarsened == 6 || n_cells_coarsened == 12)),
6195 ExcMessage("Invalid number of coarse mesh cells"));
6196
6197 const unsigned int n = n_refinement_steps > 0 ?
6198 4 * n_cells_coarsened :
6199 ((n_cells == 0) ? 6 : n_cells);
6200
6201 switch (n)
6202 {
6203 case 6:
6204 internal::hyper_shell_6(tria, p, inner_radius, outer_radius);
6205 break;
6206 case 12:
6207 internal::hyper_shell_12(tria, p, inner_radius, outer_radius);
6208 break;
6209 case 24:
6210 case 48:
6211 internal::hyper_shell_24_48(
6212 tria, n, n_refinement_steps, p, inner_radius, outer_radius);
6213 break;
6214 case 96:
6215 {
6216 // create a triangulation based on the 12-cell version. This
6217 // function was needed before SphericalManifold was written: it
6218 // manually adjusted the interior vertices to lie along concentric
6219 // spheres. Nowadays we can just refine globally:
6220 Triangulation<3> tmp;
6221 internal::hyper_shell_12(tmp, p, inner_radius, outer_radius);
6222 tmp.refine_global(1);
6223 flatten_triangulation(tmp, tria);
6224 tria.set_all_manifold_ids(0);
6225 tria.set_manifold(0, SphericalManifold<3>(p));
6226 break;
6227 }
6228 default:
6229 {
6230 Assert(false, ExcMessage("Invalid number of coarse mesh cells."));
6231 }
6232 }
6233
6234 if (n_cells > 0)
6235 AssertDimension(tria.n_global_active_cells(), n_cells);
6236
6237 if (colorize)
6238 colorize_hyper_shell(tria, p, inner_radius, outer_radius);
6239 }
6240
6241
6242
6243 // Implementation for 3d only
6244 template <>
6245 void
6247 const Point<3> &center,
6248 const double inner_radius,
6249 const double outer_radius,
6250 const unsigned int /*n_cells*/,
6251 const bool colorize)
6252 {
6253 Assert((inner_radius > 0) && (inner_radius < outer_radius),
6254 ExcInvalidRadii());
6255
6256 // These are for the two lower squares
6257 const double d = outer_radius / std::sqrt(2.0);
6258 const double a = inner_radius / std::sqrt(2.0);
6259 // These are for the two upper square
6260 const double b = a / 2.0;
6261 const double c = d / 2.0;
6262 // And so are these
6263 const double hb = inner_radius * std::sqrt(3.0) / 2.0;
6264 const double hc = outer_radius * std::sqrt(3.0) / 2.0;
6265
6266 Point<3> vertices[16] = {
6267 center + Point<3>(0, d, -d),
6268 center + Point<3>(0, -d, -d),
6269 center + Point<3>(0, a, -a),
6270 center + Point<3>(0, -a, -a),
6271 center + Point<3>(0, a, a),
6272 center + Point<3>(0, -a, a),
6273 center + Point<3>(0, d, d),
6274 center + Point<3>(0, -d, d),
6275
6276 center + Point<3>(hc, c, -c),
6277 center + Point<3>(hc, -c, -c),
6278 center + Point<3>(hb, b, -b),
6279 center + Point<3>(hb, -b, -b),
6280 center + Point<3>(hb, b, b),
6281 center + Point<3>(hb, -b, b),
6282 center + Point<3>(hc, c, c),
6283 center + Point<3>(hc, -c, c),
6284 };
6285
6286 int cell_vertices[5][8] = {{0, 1, 8, 9, 2, 3, 10, 11},
6287 {0, 2, 8, 10, 6, 4, 14, 12},
6288 {1, 7, 9, 15, 3, 5, 11, 13},
6289 {6, 4, 14, 12, 7, 5, 15, 13},
6290 {8, 10, 9, 11, 14, 12, 15, 13}};
6291
6292 std::vector<CellData<3>> cells(5, CellData<3>());
6293
6294 for (unsigned int i = 0; i < 5; ++i)
6295 {
6296 for (unsigned int j = 0; j < 8; ++j)
6297 cells[i].vertices[j] = cell_vertices[i][j];
6298 cells[i].material_id = 0;
6299 }
6300
6301 tria.create_triangulation(std::vector<Point<3>>(std::begin(vertices),
6302 std::end(vertices)),
6303 cells,
6304 SubCellData()); // no boundary information
6305
6306 if (colorize)
6307 {
6308 // We want to use a standard boundary description where
6309 // the boundary is not curved. Hence set boundary id 2 to
6310 // to all faces in a first step.
6311 Triangulation<3>::cell_iterator cell = tria.begin();
6312 for (; cell != tria.end(); ++cell)
6313 for (const unsigned int i : GeometryInfo<3>::face_indices())
6314 if (cell->at_boundary(i))
6315 cell->face(i)->set_all_boundary_ids(2);
6316
6317 // Next look for the curved boundaries. If the x value of the
6318 // center of the face is not equal to center(0), we're on a curved
6319 // boundary. Then decide whether the center is nearer to the inner
6320 // or outer boundary to set the correct boundary id.
6321 for (cell = tria.begin(); cell != tria.end(); ++cell)
6322 for (const unsigned int i : GeometryInfo<3>::face_indices())
6323 if (cell->at_boundary(i))
6324 {
6325 const Triangulation<3>::face_iterator face = cell->face(i);
6326
6327 const Point<3> face_center(face->center());
6328 if (std::abs(face_center[0] - center[0]) >
6329 1.e-6 * face_center.norm())
6330 {
6331 if (std::abs((face_center - center).norm() - inner_radius) <
6332 std::abs((face_center - center).norm() - outer_radius))
6333 face->set_all_boundary_ids(0);
6334 else
6335 face->set_all_boundary_ids(1);
6336 }
6337 }
6338 }
6339 tria.set_all_manifold_ids(0);
6340 tria.set_manifold(0, SphericalManifold<3>(center));
6341 }
6342
6343
6344 // Implementation for 3d only
6345 template <>
6346 void
6348 const Point<3> &center,
6349 const double inner_radius,
6350 const double outer_radius,
6351 const unsigned int n,
6352 const bool colorize)
6353 {
6354 Assert((inner_radius > 0) && (inner_radius < outer_radius),
6355 ExcInvalidRadii());
6356 if (n == 0 || n == 3)
6357 {
6358 const double a = inner_radius * std::sqrt(2.0) / 2e0;
6359 const double b = outer_radius * std::sqrt(2.0) / 2e0;
6360 const double c = a * std::sqrt(3.0) / 2e0;
6361 const double d = b * std::sqrt(3.0) / 2e0;
6362 const double e = outer_radius / 2e0;
6363 const double h = inner_radius / 2e0;
6364
6365 std::vector<Point<3>> vertices;
6366
6367 vertices.push_back(center + Point<3>(0, inner_radius, 0)); // 0
6368 vertices.push_back(center + Point<3>(a, a, 0)); // 1
6369 vertices.push_back(center + Point<3>(b, b, 0)); // 2
6370 vertices.push_back(center + Point<3>(0, outer_radius, 0)); // 3
6371 vertices.push_back(center + Point<3>(0, a, a)); // 4
6372 vertices.push_back(center + Point<3>(c, c, h)); // 5
6373 vertices.push_back(center + Point<3>(d, d, e)); // 6
6374 vertices.push_back(center + Point<3>(0, b, b)); // 7
6375 vertices.push_back(center + Point<3>(inner_radius, 0, 0)); // 8
6376 vertices.push_back(center + Point<3>(outer_radius, 0, 0)); // 9
6377 vertices.push_back(center + Point<3>(a, 0, a)); // 10
6378 vertices.push_back(center + Point<3>(b, 0, b)); // 11
6379 vertices.push_back(center + Point<3>(0, 0, inner_radius)); // 12
6380 vertices.push_back(center + Point<3>(0, 0, outer_radius)); // 13
6381
6382 const int cell_vertices[3][8] = {
6383 {0, 1, 3, 2, 4, 5, 7, 6},
6384 {1, 8, 2, 9, 5, 10, 6, 11},
6385 {4, 5, 7, 6, 12, 10, 13, 11},
6386 };
6387 std::vector<CellData<3>> cells(3);
6388
6389 for (unsigned int i = 0; i < 3; ++i)
6390 {
6391 for (unsigned int j = 0; j < 8; ++j)
6392 cells[i].vertices[j] = cell_vertices[i][j];
6393 cells[i].material_id = 0;
6394 }
6395
6396 tria.create_triangulation(vertices,
6397 cells,
6398 SubCellData()); // no boundary information
6399 }
6400 else
6401 {
6403 }
6404
6405 if (colorize)
6406 colorize_quarter_hyper_shell(tria, center, inner_radius, outer_radius);
6407
6408 tria.set_all_manifold_ids(0);
6409 tria.set_manifold(0, SphericalManifold<3>(center));
6410 }
6411
6412
6413 // Implementation for 3d only
6414 template <>
6415 void
6417 const double length,
6418 const double inner_radius,
6419 const double outer_radius,
6420 const unsigned int n_radial_cells,
6421 const unsigned int n_axial_cells,
6422 const bool colorize)
6423 {
6424 Assert((inner_radius > 0) && (inner_radius < outer_radius),
6425 ExcInvalidRadii());
6426
6427 const double pi = numbers::PI;
6428
6429 // determine the number of cells
6430 // for the grid. if not provided by
6431 // the user determine it such that
6432 // the length of each cell on the
6433 // median (in the middle between
6434 // the two circles) is equal to its
6435 // radial extent (which is the
6436 // difference between the two
6437 // radii)
6438 const unsigned int N_r =
6439 (n_radial_cells == 0 ? static_cast<unsigned int>(std::ceil(
6440 (2 * pi * (outer_radius + inner_radius) / 2) /
6441 (outer_radius - inner_radius))) :
6443 const unsigned int N_z =
6444 (n_axial_cells == 0 ?
6445 static_cast<unsigned int>(std::ceil(
6446 length / (2 * pi * (outer_radius + inner_radius) / 2 / N_r))) :
6448
6449 // set up N vertices on the
6450 // outer and N vertices on
6451 // the inner circle. the
6452 // first N ones are on the
6453 // outer one, and all are
6454 // numbered counter-clockwise
6455 std::vector<Point<2>> vertices_2d(2 * N_r);
6456 for (unsigned int i = 0; i < N_r; ++i)
6457 {
6458 vertices_2d[i] =
6459 Point<2>(std::cos(2 * pi * i / N_r), std::sin(2 * pi * i / N_r)) *
6461 vertices_2d[i + N_r] = vertices_2d[i] * (inner_radius / outer_radius);
6462 }
6463
6464 std::vector<Point<3>> vertices_3d;
6465 vertices_3d.reserve(2 * N_r * (N_z + 1));
6466 for (unsigned int j = 0; j <= N_z; ++j)
6467 for (unsigned int i = 0; i < 2 * N_r; ++i)
6468 {
6469 const Point<3> v(vertices_2d[i][0],
6470 vertices_2d[i][1],
6471 j * length / N_z);
6472 vertices_3d.push_back(v);
6473 }
6474
6475 std::vector<CellData<3>> cells(N_r * N_z, CellData<3>());
6476
6477 for (unsigned int j = 0; j < N_z; ++j)
6478 for (unsigned int i = 0; i < N_r; ++i)
6479 {
6480 cells[i + j * N_r].vertices[0] = i + (j + 1) * 2 * N_r;
6481 cells[i + j * N_r].vertices[1] = (i + 1) % N_r + (j + 1) * 2 * N_r;
6482 cells[i + j * N_r].vertices[2] = i + j * 2 * N_r;
6483 cells[i + j * N_r].vertices[3] = (i + 1) % N_r + j * 2 * N_r;
6484
6485 cells[i + j * N_r].vertices[4] = N_r + i + (j + 1) * 2 * N_r;
6486 cells[i + j * N_r].vertices[5] =
6487 N_r + ((i + 1) % N_r) + (j + 1) * 2 * N_r;
6488 cells[i + j * N_r].vertices[6] = N_r + i + j * 2 * N_r;
6489 cells[i + j * N_r].vertices[7] = N_r + ((i + 1) % N_r) + j * 2 * N_r;
6490
6491 cells[i + j * N_r].material_id = 0;
6492 }
6493
6494 tria.create_triangulation(vertices_3d, cells, SubCellData());
6495 tria.set_all_manifold_ids(0);
6496 tria.set_manifold(0, CylindricalManifold<3>(2));
6497
6498 if (!colorize)
6499 return;
6500
6501 // If colorize, set boundary id on the triangualtion.
6502 // Inner cylinder has boundary id 0
6503 // Outer cylinder has boundary id 1
6504 // Bottom (Z-) part of the cylinder has boundary id 2
6505 // Top (Z+) part of the cylinder has boundary id 3
6506
6507 // Define tolerance to help detect boundary conditions
6508 // First we define the tolerance along the z axis to identify
6509 // bottom and top cells.
6510 double eps_z = 1e-6 * length;
6511
6512 // Gather the inner radius from the faces instead of the argument, this is
6513 // more robust for some aspect ratios. First initialize the outer to 0 and
6514 // the inner to a large value
6515 double face_inner_radius = std::numeric_limits<double>::max();
6516 double face_outer_radius = 0.;
6517
6518 // Loop over the cells once to acquire the min and max radius at the face
6519 // centers. Otherwise, for some cell ratio, the center of the faces can be
6520 // at a radius which is significantly different from the one prescribed.
6521 for (const auto &cell : tria.active_cell_iterators())
6522 for (const unsigned int f : GeometryInfo<3>::face_indices())
6523 {
6524 if (!cell->face(f)->at_boundary())
6525 continue;
6526
6527 const auto face_center = cell->face(f)->center();
6528 const double z = face_center[2];
6529
6530 if ((std::fabs(z) > eps_z) &&
6531 (std::fabs(z - length) > eps_z)) // Not a zmin or zmax boundary
6532 {
6533 const double radius = std::sqrt(face_center[0] * face_center[0] +
6534 face_center[1] * face_center[1]);
6537 }
6538 }
6539
6541
6542 for (const auto &cell : tria.active_cell_iterators())
6543 for (const unsigned int f : GeometryInfo<3>::face_indices())
6544 {
6545 if (cell->face(f)->at_boundary())
6546 {
6547 const auto face_center = cell->face(f)->center();
6548
6549 const double radius = std::sqrt(face_center[0] * face_center[0] +
6550 face_center[1] * face_center[1]);
6551
6552 const double z = face_center[2];
6553
6554 if (std::fabs(z) < eps_z) // z = 0 set boundary 2
6555 {
6556 cell->face(f)->set_boundary_id(2);
6557 }
6558 else if (std::fabs(z - length) <
6559 eps_z) // z = length set boundary 3
6560 {
6561 cell->face(f)->set_boundary_id(3);
6562 }
6563 else if (std::fabs(radius - face_inner_radius) >
6564 mid_radial_distance) // r = outer_radius set boundary 1
6565 {
6566 cell->face(f)->set_boundary_id(1);
6567 }
6568 else if (std::fabs(radius - face_inner_radius) <
6569 mid_radial_distance) // r = inner_radius set boundary 0
6570 {
6571 cell->face(f)->set_boundary_id(0);
6572 }
6573 else
6575 }
6576 }
6577 }
6578
6579
6580 template <int dim, int spacedim>
6581 void
6583 const std::vector<const Triangulation<dim, spacedim> *> &triangulations,
6585 const double duplicated_vertex_tolerance,
6586 const bool copy_manifold_ids,
6587 const bool copy_boundary_ids)
6588 {
6589 std::vector<Point<spacedim>> vertices;
6590 std::vector<CellData<dim>> cells;
6592
6593 unsigned int n_accumulated_vertices = 0;
6594 for (const auto triangulation : triangulations)
6595 {
6596 Assert(triangulation->n_levels() == 1,
6597 ExcMessage("The input triangulations must be non-empty "
6598 "and must not be refined."));
6599
6602 Assert(tria_vertices.size() == triangulation->n_vertices(),
6604 Assert(tria_cells.size() == triangulation->n_cells(),
6606
6607 // Copy the vertices of the current triangulation into the merged list,
6608 // and then let the vertex indices of the cells refer to those in
6609 // the merged list:
6610 vertices.insert(vertices.end(),
6611 tria_vertices.begin(),
6612 tria_vertices.end());
6613 for (CellData<dim> &cell_data : tria_cells)
6614 {
6615 for (unsigned int &vertex_n : cell_data.vertices)
6617 cells.push_back(cell_data);
6618 }
6619
6620 // Skip copying lines with no manifold information.
6622 {
6623 for (CellData<1> &line_data : tria_subcell_data.boundary_lines)
6624 {
6625 if (line_data.manifold_id == numbers::flat_manifold_id)
6626 continue;
6627 for (unsigned int &vertex_n : line_data.vertices)
6629 line_data.boundary_id =
6631 subcell_data.boundary_lines.push_back(line_data);
6632 }
6633
6634 for (CellData<2> &quad_data : tria_subcell_data.boundary_quads)
6635 {
6636 if (quad_data.manifold_id == numbers::flat_manifold_id)
6637 continue;
6638 for (unsigned int &vertex_n : quad_data.vertices)
6640 quad_data.boundary_id =
6642 subcell_data.boundary_quads.push_back(quad_data);
6643 }
6644 }
6645
6646 n_accumulated_vertices += triangulation->n_vertices();
6647 }
6648
6649 // throw out duplicated vertices
6650 std::vector<unsigned int> considered_vertices;
6652 cells,
6656
6657 // reorder the cells to ensure that they satisfy the convention for
6658 // edge and face directions
6659 if (std::all_of(cells.begin(), cells.end(), [](const auto &cell) {
6660 return cell.vertices.size() ==
6661 ReferenceCells::get_hypercube<dim>().n_vertices();
6662 }))
6664 result.clear();
6665 result.create_triangulation(vertices, cells, subcell_data);
6666
6667 if (!copy_manifold_ids)
6668 result.set_all_manifold_ids(numbers::flat_manifold_id);
6669
6671 {
6672 auto result_cell = result.begin();
6673 for (const auto &tria : triangulations)
6674 {
6675 for (const auto &cell : tria->cell_iterators())
6676 {
6677 for (const auto &f : cell->face_indices())
6678 if (result_cell->face(f)->at_boundary())
6679 result_cell->face(f)->set_boundary_id(
6680 cell->face(f)->boundary_id());
6681 ++result_cell;
6682 }
6683 }
6684 }
6685
6687 n_accumulated_vertices == result.n_vertices(),
6689 }
6690
6691
6692
6693 template <int dim, int spacedim>
6694 void
6698 const double duplicated_vertex_tolerance,
6699 const bool copy_manifold_ids,
6700 const bool copy_boundary_ids)
6701 {
6702 // if either Triangulation is empty then merging is just a copy.
6703 if (triangulation_1.n_cells() == 0)
6704 {
6705 if (&result != &triangulation_2)
6706 result.copy_triangulation(triangulation_2);
6707 }
6708 else if (triangulation_2.n_cells() == 0)
6709 {
6710 if (&result != &triangulation_1)
6711 result.copy_triangulation(triangulation_1);
6712 }
6713 else
6715 result,
6719 }
6720
6721
6722
6723 namespace
6724 {
6746 template <int structdim>
6747 void
6749 {
6750 static_assert(structdim == 1 || structdim == 2,
6751 "This function is only implemented for lines and "
6752 "quadrilaterals.");
6753 // start by making sure that all objects representing the same vertices
6754 // are numbered in the same way by canonicalizing the numberings. This
6755 // makes it possible to detect duplicates.
6756 for (CellData<structdim> &cell_data : subcell_data)
6757 {
6758 if (structdim == 1)
6759 std::sort(std::begin(cell_data.vertices),
6760 std::end(cell_data.vertices));
6761 else if (structdim == 2)
6762 {
6763 // rotate the vertex numbers so that the lowest one is first
6764 std::array<unsigned int, 4> renumbering{};
6765 std::copy(std::begin(cell_data.vertices),
6766 std::end(cell_data.vertices),
6767 renumbering.begin());
6768
6769 // convert to old style vertex numbering. This makes the
6770 // permutations easy since the valid configurations are
6771 //
6772 // 3 2 2 1 1 0 0 3
6773 // 0 1 3 0 2 3 1 2
6774 // (0123) (3012) (2310) (1230)
6775 //
6776 // rather than the lexical ordering which is harder to permute
6777 // by rotation.
6778 std::swap(renumbering[2], renumbering[3]);
6779 std::rotate(renumbering.begin(),
6780 std::min_element(renumbering.begin(),
6781 renumbering.end()),
6782 renumbering.end());
6783 // convert to new style
6784 std::swap(renumbering[2], renumbering[3]);
6785 // deal with cases where we might have
6786 //
6787 // 3 2 1 2
6788 // 0 1 0 3
6789 //
6790 // by forcing the second vertex (in lexical ordering) to be
6791 // smaller than the third
6792 if (renumbering[1] > renumbering[2])
6793 std::swap(renumbering[1], renumbering[2]);
6794 std::copy(renumbering.begin(),
6795 renumbering.end(),
6796 std::begin(cell_data.vertices));
6797 }
6798 }
6799
6800 // Now that all cell objects have been canonicalized they can be sorted:
6801 auto compare = [](const CellData<structdim> &a,
6802 const CellData<structdim> &b) {
6803 return std::lexicographical_compare(std::begin(a.vertices),
6804 std::end(a.vertices),
6805 std::begin(b.vertices),
6806 std::end(b.vertices));
6807 };
6808 std::sort(subcell_data.begin(), subcell_data.end(), compare);
6809
6810 // Finally, determine which objects are duplicates. Duplicates are
6811 // assumed to be interior objects, so delete all but one and change the
6812 // boundary id:
6813 auto left = subcell_data.begin();
6814 while (left != subcell_data.end())
6815 {
6816 const auto right =
6817 std::upper_bound(left, subcell_data.end(), *left, compare);
6818 // if the range has more than one item, then there are duplicates -
6819 // set all boundary ids in the range to the internal boundary id
6820 if (left + 1 != right)
6821 for (auto it = left; it != right; ++it)
6822 {
6824 Assert(it->manifold_id == left->manifold_id,
6825 ExcMessage(
6826 "In the process of grid generation a single "
6827 "line or quadrilateral has been assigned two "
6828 "different manifold ids. This can happen when "
6829 "a Triangulation is copied, e.g., via "
6830 "GridGenerator::replicate_triangulation() and "
6831 "not all external boundary faces have the same "
6832 "manifold id. Double check that all faces "
6833 "which you expect to be merged together have "
6834 "the same manifold id."));
6835 }
6836 left = right;
6837 }
6838
6839 subcell_data.erase(std::unique(subcell_data.begin(), subcell_data.end()),
6840 subcell_data.end());
6841 }
6842 } // namespace
6843
6844
6845
6846 template <int dim, int spacedim>
6847 void
6849 const std::vector<unsigned int> &extents,
6851 {
6852 AssertDimension(dim, extents.size());
6853# ifdef DEBUG
6854 for (const auto &extent : extents)
6855 Assert(0 < extent,
6856 ExcMessage("The Triangulation must be copied at least one time in "
6857 "each coordinate dimension."));
6858# endif
6859 const BoundingBox<spacedim> bbox(input.get_vertices());
6860 const auto &min = bbox.get_boundary_points().first;
6861 const auto &max = bbox.get_boundary_points().second;
6862
6863 std::array<Tensor<1, spacedim>, dim> offsets;
6864 for (unsigned int d = 0; d < dim; ++d)
6865 offsets[d][d] = max[d] - min[d];
6866
6868 tria_to_replicate.copy_triangulation(input);
6869 for (unsigned int d = 0; d < dim; ++d)
6870 {
6873
6874 std::vector<Point<spacedim>> output_vertices = input_vertices;
6875 std::vector<CellData<dim>> output_cell_data = input_cell_data;
6877
6878 for (unsigned int k = 1; k < extents[d]; ++k)
6879 {
6880 const std::size_t vertex_offset = k * input_vertices.size();
6881 // vertices
6882 for (const Point<spacedim> &point : input_vertices)
6883 output_vertices.push_back(point + double(k) * offsets[d]);
6884 // cell data
6885 for (const CellData<dim> &cell_data : input_cell_data)
6886 {
6887 output_cell_data.push_back(cell_data);
6888 for (unsigned int &vertex : output_cell_data.back().vertices)
6889 vertex += vertex_offset;
6890 }
6891 // subcell data
6892 for (const CellData<1> &boundary_line :
6893 input_subcell_data.boundary_lines)
6894 {
6895 output_subcell_data.boundary_lines.push_back(boundary_line);
6896 for (unsigned int &vertex :
6897 output_subcell_data.boundary_lines.back().vertices)
6898 vertex += vertex_offset;
6899 }
6900 for (const CellData<2> &boundary_quad :
6901 input_subcell_data.boundary_quads)
6902 {
6903 output_subcell_data.boundary_quads.push_back(boundary_quad);
6904 for (unsigned int &vertex :
6905 output_subcell_data.boundary_quads.back().vertices)
6906 vertex += vertex_offset;
6907 }
6908 }
6909 // check all vertices: since the grid is coarse, most will be on the
6910 // boundary anyway
6911 std::vector<unsigned int> boundary_vertices;
6917 1e-6 * input.begin_active()->diameter());
6918 // delete_duplicated_vertices also deletes any unused vertices
6919 // deal with any reordering issues created by delete_duplicated_vertices
6921 // clean up the boundary ids of the boundary objects: note that we
6922 // have to do this after delete_duplicated_vertices so that boundary
6923 // objects are actually duplicated at this point
6924 if (dim == 2)
6926 else if (dim == 3)
6927 {
6930 output_subcell_data.boundary_lines)
6931 // set boundary lines to the default value - let
6932 // create_triangulation figure out the rest.
6934 }
6935
6937 tria_to_replicate.create_triangulation(output_vertices,
6940 }
6941
6942 result.copy_triangulation(tria_to_replicate);
6943 }
6944
6945
6946
6947 template <int dim, int spacedim>
6948 void
6953 {
6955 ExcMessage("The two input triangulations are not derived from "
6956 "the same coarse mesh as required."));
6957 Assert((dynamic_cast<
6959 &triangulation_1) == nullptr) &&
6960 (dynamic_cast<
6962 &triangulation_2) == nullptr),
6963 ExcMessage("The source triangulations for this function must both "
6964 "be available entirely locally, and not be distributed "
6965 "triangulations."));
6966
6967 // first copy triangulation_1, and
6968 // then do as many iterations as
6969 // there are levels in
6970 // triangulation_2 to refine
6971 // additional cells. since this is
6972 // the maximum number of
6973 // refinements to get from the
6974 // coarse grid to triangulation_2,
6975 // it is clear that this is also
6976 // the maximum number of
6977 // refinements to get from any cell
6978 // on triangulation_1 to
6979 // triangulation_2
6980 result.clear();
6981 result.copy_triangulation(triangulation_1);
6982 for (unsigned int iteration = 0; iteration < triangulation_2.n_levels();
6983 ++iteration)
6984 {
6986 intergrid_map.make_mapping(result, triangulation_2);
6987
6988 bool any_cell_flagged = false;
6989 for (const auto &result_cell : result.active_cell_iterators())
6990 if (intergrid_map[result_cell]->has_children())
6991 {
6992 any_cell_flagged = true;
6993 result_cell->set_refine_flag();
6994 }
6995
6996 if (any_cell_flagged == false)
6997 break;
6998 else
6999 result.execute_coarsening_and_refinement();
7000 }
7001 }
7002
7003
7004
7005 template <int dim, int spacedim>
7006 void
7012 {
7013 // simply copy the vertices; we will later strip those
7014 // that turn out to be unused
7015 std::vector<Point<spacedim>> vertices = input_triangulation.get_vertices();
7016
7017 // the loop through the cells and copy stuff, excluding
7018 // the ones we are to remove
7019 std::vector<CellData<dim>> cells;
7020 for (const auto &cell : input_triangulation.active_cell_iterators())
7021 if (cells_to_remove.find(cell) == cells_to_remove.end())
7022 {
7023 Assert(static_cast<unsigned int>(cell->level()) ==
7024 input_triangulation.n_levels() - 1,
7025 ExcMessage(
7026 "Your input triangulation appears to have "
7027 "adaptively refined cells. This is not allowed. You can "
7028 "only call this function on a triangulation in which "
7029 "all cells are on the same refinement level."));
7030
7032 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
7033 this_cell.vertices[v] = cell->vertex_index(v);
7034 this_cell.material_id = cell->material_id();
7035 cells.push_back(this_cell);
7036 }
7037
7038 // throw out duplicated vertices from the two meshes, reorder vertices as
7039 // necessary and create the triangulation
7041 std::vector<unsigned int> considered_vertices;
7043 cells,
7046
7047 // then clear the old triangulation and create the new one
7048 result.clear();
7049 result.create_triangulation(vertices, cells, subcell_data);
7050 }
7051
7052
7053
7054 void
7056 const Triangulation<2, 2> &input,
7057 const unsigned int n_slices,
7058 const double height,
7060 const bool copy_manifold_ids,
7061 const std::vector<types::manifold_id> &manifold_priorities)
7062 {
7063 Assert(input.n_levels() == 1,
7064 ExcMessage(
7065 "The input triangulation must be a coarse mesh, i.e., it must "
7066 "not have been refined."));
7067 Assert(result.n_cells() == 0,
7068 ExcMessage("The output triangulation object needs to be empty."));
7069 Assert(height > 0,
7070 ExcMessage("The given height for extrusion must be positive."));
7071 Assert(n_slices >= 2,
7072 ExcMessage(
7073 "The number of slices for extrusion must be at least 2."));
7074
7075 const double delta_h = height / (n_slices - 1);
7076 std::vector<double> slices_z_values;
7077 for (unsigned int i = 0; i < n_slices; ++i)
7078 slices_z_values.push_back(i * delta_h);
7081 }
7082
7083
7084
7085 void
7087 const Triangulation<2, 2> &input,
7088 const unsigned int n_slices,
7089 const double height,
7091 const bool copy_manifold_ids,
7092 const std::vector<types::manifold_id> &manifold_priorities)
7093 {
7094 (void)input;
7095 (void)n_slices;
7096 (void)height;
7097 (void)result;
7100
7101 AssertThrow(false,
7102 ExcMessage(
7103 "GridTools::extrude_triangulation() is only available "
7104 "for Triangulation<3, 3> as output triangulation."));
7105 }
7106
7107
7108
7109 void
7111 const Triangulation<2, 2> &input,
7112 const std::vector<double> &slice_coordinates,
7114 const bool copy_manifold_ids,
7115 const std::vector<types::manifold_id> &manifold_priorities)
7116 {
7117 Assert(input.n_levels() == 1,
7118 ExcMessage(
7119 "The input triangulation must be a coarse mesh, i.e., it must "
7120 "not have been refined."));
7121 Assert(result.n_cells() == 0,
7122 ExcMessage("The output triangulation object needs to be empty."));
7123 Assert(slice_coordinates.size() >= 2,
7124 ExcMessage(
7125 "The number of slices for extrusion must be at least 2."));
7126 Assert(std::is_sorted(slice_coordinates.begin(), slice_coordinates.end()),
7127 ExcMessage("Slice z-coordinates should be in ascending order"));
7128 Assert(input.all_reference_cells_are_hyper_cube(),
7129 ExcMessage(
7130 "This function is only implemented for quadrilateral meshes."));
7131
7132 const auto priorities = [&]() -> std::vector<types::manifold_id> {
7133 // if a non-empty (i.e., not the default) vector is given for
7134 // manifold_priorities then use it (but check its validity in debug
7135 // mode)
7136 if (0 < manifold_priorities.size())
7137 {
7138# ifdef DEBUG
7139 // check that the provided manifold_priorities is valid
7140 std::vector<types::manifold_id> sorted_manifold_priorities =
7142 std::sort(sorted_manifold_priorities.begin(),
7144 Assert(std::unique(sorted_manifold_priorities.begin(),
7147 ExcMessage(
7148 "The given vector of manifold ids may not contain any "
7149 "duplicated entries."));
7150 std::vector<types::manifold_id> sorted_manifold_ids =
7151 input.get_manifold_ids();
7152 std::sort(sorted_manifold_ids.begin(), sorted_manifold_ids.end());
7154 {
7155 std::ostringstream message;
7156 message << "The given triangulation has manifold ids {";
7157 for (const types::manifold_id manifold_id : sorted_manifold_ids)
7159 message << manifold_id << ", ";
7160 message << sorted_manifold_ids.back() << "}, but \n"
7161 << " the given vector of manifold ids is {";
7162 for (const types::manifold_id manifold_id : manifold_priorities)
7164 message << manifold_id << ", ";
7165 message
7166 << manifold_priorities.back() << "}.\n"
7167 << " These vectors should contain the same elements.\n";
7168 const std::string m = message.str();
7169 Assert(false, ExcMessage(m));
7170 }
7171# endif
7172 return manifold_priorities;
7173 }
7174 // otherwise use the default ranking: ascending order, but TFI manifolds
7175 // are at the end.
7176 std::vector<types::manifold_id> default_priorities =
7177 input.get_manifold_ids();
7178 const auto first_tfi_it = std::partition(
7179 default_priorities.begin(),
7180 default_priorities.end(),
7181 [&input](const types::manifold_id &id) {
7182 return dynamic_cast<const TransfiniteInterpolationManifold<2, 2> *>(
7183 &input.get_manifold(id)) == nullptr;
7184 });
7185 std::sort(default_priorities.begin(), first_tfi_it);
7186 std::sort(first_tfi_it, default_priorities.end());
7187
7188 return default_priorities;
7189 }();
7190
7191 const std::size_t n_slices = slice_coordinates.size();
7192 std::vector<Point<3>> points(n_slices * input.n_vertices());
7193 std::vector<CellData<3>> cells;
7194 cells.reserve((n_slices - 1) * input.n_active_cells());
7195
7196 // copy the array of points as many times as there will be slices,
7197 // one slice at a time. The z-axis value are defined in slices_coordinates
7198 for (std::size_t slice_n = 0; slice_n < n_slices; ++slice_n)
7199 {
7200 for (std::size_t vertex_n = 0; vertex_n < input.n_vertices();
7201 ++vertex_n)
7202 {
7203 const Point<2> vertex = input.get_vertices()[vertex_n];
7204 points[slice_n * input.n_vertices() + vertex_n] =
7205 Point<3>(vertex[0], vertex[1], slice_coordinates[slice_n]);
7206 }
7207 }
7208
7209 // then create the cells of each of the slices, one stack at a
7210 // time
7211 for (const auto &cell : input.active_cell_iterators())
7212 {
7213 for (std::size_t slice_n = 0; slice_n < n_slices - 1; ++slice_n)
7214 {
7216 for (const unsigned int vertex_n :
7218 {
7219 this_cell.vertices[vertex_n] =
7220 cell->vertex_index(vertex_n) + slice_n * input.n_vertices();
7221 this_cell
7223 cell->vertex_index(vertex_n) +
7224 (slice_n + 1) * input.n_vertices();
7225 }
7226
7227 this_cell.material_id = cell->material_id();
7229 this_cell.manifold_id = cell->manifold_id();
7230 cells.push_back(this_cell);
7231 }
7232 }
7233
7234 // Next, create face data for all faces that are orthogonal to the x-y
7235 // plane
7237 std::vector<CellData<2>> &quads = subcell_data.boundary_quads;
7239 quads.reserve(input.n_active_lines() * (n_slices - 1) +
7240 input.n_active_cells() * 2);
7241 for (const auto &face : input.active_face_iterators())
7242 {
7243 CellData<2> quad;
7244 quad.boundary_id = face->boundary_id();
7245 if (face->at_boundary())
7246 max_boundary_id = std::max(max_boundary_id, quad.boundary_id);
7248 quad.manifold_id = face->manifold_id();
7249 for (std::size_t slice_n = 0; slice_n < n_slices - 1; ++slice_n)
7250 {
7251 quad.vertices[0] =
7252 face->vertex_index(0) + slice_n * input.n_vertices();
7253 quad.vertices[1] =
7254 face->vertex_index(1) + slice_n * input.n_vertices();
7255 quad.vertices[2] =
7256 face->vertex_index(0) + (slice_n + 1) * input.n_vertices();
7257 quad.vertices[3] =
7258 face->vertex_index(1) + (slice_n + 1) * input.n_vertices();
7259 quads.push_back(quad);
7260 }
7261 }
7262
7263 // if necessary, create face data for faces parallel to the x-y
7264 // plane. This is only necessary if we need to set manifolds.
7266 for (const auto &cell : input.active_cell_iterators())
7267 {
7268 CellData<2> quad;
7269 quad.boundary_id = numbers::internal_face_boundary_id;
7270 quad.manifold_id = cell->manifold_id(); // check is outside loop
7271 for (std::size_t slice_n = 1; slice_n < n_slices - 1; ++slice_n)
7272 {
7273 quad.vertices[0] =
7274 cell->vertex_index(0) + slice_n * input.n_vertices();
7275 quad.vertices[1] =
7276 cell->vertex_index(1) + slice_n * input.n_vertices();
7277 quad.vertices[2] =
7278 cell->vertex_index(2) + slice_n * input.n_vertices();
7279 quad.vertices[3] =
7280 cell->vertex_index(3) + slice_n * input.n_vertices();
7281 quads.push_back(quad);
7282 }
7283 }
7284
7285 // then mark the bottom and top boundaries of the extruded mesh
7286 // with max_boundary_id+1 and max_boundary_id+2. check that this
7287 // remains valid
7291 ExcMessage(
7292 "The input triangulation to this function is using boundary "
7293 "indicators in a range that do not allow using "
7294 "max_boundary_id+1 and max_boundary_id+2 as boundary "
7295 "indicators for the bottom and top faces of the "
7296 "extruded triangulation."));
7299 for (const auto &cell : input.active_cell_iterators())
7300 {
7301 CellData<2> quad;
7302 quad.boundary_id = bottom_boundary_id;
7303 quad.vertices[0] = cell->vertex_index(0);
7304 quad.vertices[1] = cell->vertex_index(1);
7305 quad.vertices[2] = cell->vertex_index(2);
7306 quad.vertices[3] = cell->vertex_index(3);
7308 quad.manifold_id = cell->manifold_id();
7309 quads.push_back(quad);
7310
7311 quad.boundary_id = top_boundary_id;
7312 for (unsigned int &vertex : quad.vertices)
7313 vertex += (n_slices - 1) * input.n_vertices();
7315 quad.manifold_id = cell->manifold_id();
7316 quads.push_back(quad);
7317 }
7318
7319 // use all of this to finally create the extruded 3d
7320 // triangulation. it is not necessary to call
7321 // GridTools::consistently_order_cells() because the cells we have
7322 // constructed above are automatically correctly oriented. this is
7323 // because the 2d base mesh is always correctly oriented, and
7324 // extruding it automatically yields a correctly oriented 3d mesh,
7325 // as discussed in the edge orientation paper mentioned in the
7326 // introduction to the @ref reordering "reordering module".
7327 result.create_triangulation(points, cells, subcell_data);
7328
7329 for (auto manifold_id_it = priorities.rbegin();
7330 manifold_id_it != priorities.rend();
7332 for (const auto &face : result.active_face_iterators())
7333 if (face->manifold_id() == *manifold_id_it)
7334 for (unsigned int line_n = 0;
7336 ++line_n)
7337 face->line(line_n)->set_manifold_id(*manifold_id_it);
7338 }
7339
7340
7341
7342 void
7344 const Triangulation<2, 2> &input,
7345 const std::vector<double> &slice_coordinates,
7347 const bool copy_manifold_ids,
7348 const std::vector<types::manifold_id> &manifold_priorities)
7349 {
7350 (void)input;
7352 (void)result;
7355
7356 AssertThrow(false,
7357 ExcMessage(
7358 "GridTools::extrude_triangulation() is only available "
7359 "for Triangulation<3, 3> as output triangulation."));
7360 }
7361
7362
7363
7364 template <>
7365 void
7367 const double,
7368 const double,
7369 const double,
7370 const unsigned int,
7371 const bool)
7372 {
7374 }
7375
7376
7377
7378 template <int spacedim>
7379 void
7381 const double inner_radius,
7382 const double outer_radius,
7383 const double, // width,
7384 const unsigned int, // width_repetition,
7385 const bool colorize)
7386 {
7387 const int dim = 2;
7388
7389 Assert(inner_radius < outer_radius,
7390 ExcMessage("outer_radius has to be bigger than inner_radius."));
7391
7392 const Point<spacedim> center;
7393
7394 // We create a hyper_shell (i.e., an annulus) in two dimensions, and then we
7395 // modify it by pulling the vertices on the diagonals out to where the
7396 // corners of a square would be:
7397 hyper_shell(triangulation, center, inner_radius, outer_radius, 8);
7398 triangulation.set_all_manifold_ids(numbers::flat_manifold_id);
7399 std::vector<bool> treated_vertices(triangulation.n_vertices(), false);
7400 for (const auto &cell : triangulation.active_cell_iterators())
7401 {
7402 for (auto f : GeometryInfo<dim>::face_indices())
7403 if (cell->face(f)->at_boundary())
7404 for (const unsigned int v : cell->face(f)->vertex_indices())
7405 if (/* is the vertex on the outer ring? */
7406 (std::fabs(cell->face(f)->vertex(v).norm() - outer_radius) <
7407 1e-12 * outer_radius)
7408 /* and */
7409 &&
7410 /* is the vertex on one of the two diagonals? */
7411 (std::fabs(std::fabs(cell->face(f)->vertex(v)[0]) -
7412 std::fabs(cell->face(f)->vertex(v)[1])) <
7413 1e-12 * outer_radius))
7414 cell->face(f)->vertex(v) *= std::sqrt(2.);
7415 }
7416 const double eps = 1e-3 * outer_radius;
7417 for (const auto &cell : triangulation.active_cell_iterators())
7418 {
7419 for (const unsigned int f : cell->face_indices())
7420 if (cell->face(f)->at_boundary())
7421 {
7422 const double dx = cell->face(f)->center()[0] - center[0];
7423 const double dy = cell->face(f)->center()[1] - center[1];
7424 if (colorize)
7425 {
7426 if (std::abs(dx + outer_radius) < eps)
7427 cell->face(f)->set_boundary_id(0);
7428 else if (std::abs(dx - outer_radius) < eps)
7429 cell->face(f)->set_boundary_id(1);
7430 else if (std::abs(dy + outer_radius) < eps)
7431 cell->face(f)->set_boundary_id(2);
7432 else if (std::abs(dy - outer_radius) < eps)
7433 cell->face(f)->set_boundary_id(3);
7434 else
7435 {
7436 cell->face(f)->set_boundary_id(4);
7437 cell->face(f)->set_manifold_id(0);
7438 }
7439 }
7440 else
7441 {
7442 const double d = (cell->face(f)->center() - center).norm();
7443 if (d - inner_radius < 0)
7444 {
7445 cell->face(f)->set_boundary_id(1);
7446 cell->face(f)->set_manifold_id(0);
7447 }
7448 else
7449 cell->face(f)->set_boundary_id(0);
7450 }
7451 }
7452 }
7453 triangulation.set_manifold(0, PolarManifold<2, spacedim>(center));
7454 }
7455
7456
7457
7458 template <>
7459 void
7461 const double inner_radius,
7462 const double outer_radius,
7463 const double width,
7464 const unsigned int width_repetition,
7465 const bool colorize)
7466 {
7468 inner_radius,
7470 width,
7472 colorize);
7473 }
7474
7475
7476
7477 template <>
7478 void
7480 const double inner_radius,
7481 const double outer_radius,
7482 const double width,
7483 const unsigned int width_repetition,
7484 const bool colorize)
7485 {
7487 inner_radius,
7489 width,
7491 colorize);
7492 }
7493
7494
7495
7496 template <int dim>
7497 void
7499 const Point<dim> &center,
7500 const double inner_radius,
7501 const double outer_radius,
7502 const unsigned int n_shells,
7503 const double skewness,
7504 const unsigned int n_cells,
7505 const bool colorize)
7506 {
7507 Assert(dim == 2 || dim == 3, ExcNotImplemented());
7508 (void)colorize;
7509 (void)n_cells;
7510 Assert(inner_radius < outer_radius,
7511 ExcMessage("outer_radius has to be bigger than inner_radius."));
7512 if (n_shells == 0)
7513 return; // empty Triangulation
7514
7515 std::vector<double> radii;
7516 radii.push_back(inner_radius);
7517 for (unsigned int shell_n = 1; shell_n < n_shells; ++shell_n)
7518 if (skewness == 0.0)
7519 // same as below, but works in the limiting case of zero skewness
7520 radii.push_back(inner_radius +
7521 (outer_radius - inner_radius) *
7522 (1.0 - (1.0 - double(shell_n) / n_shells)));
7523 else
7524 radii.push_back(
7525 inner_radius +
7526 (outer_radius - inner_radius) *
7527 (1.0 - std::tanh(skewness * (1.0 - double(shell_n) / n_shells)) /
7529 radii.push_back(outer_radius);
7530
7531 double grid_vertex_tolerance = 0.0;
7532 for (unsigned int shell_n = 0; shell_n < radii.size() - 1; ++shell_n)
7533 {
7536 center,
7537 radii[shell_n],
7538 radii[shell_n + 1],
7539 n_cells == 0 ? (dim == 2 ? 8 : 12) :
7540 n_cells);
7541
7542 // The innermost shell has the smallest cells: use that to set the
7543 // vertex merging tolerance
7544 if (grid_vertex_tolerance == 0.0)
7546 0.5 * internal::minimal_vertex_distance(current_shell);
7547
7551 temp,
7554 }
7555
7557 triangulation.set_all_manifold_ids(manifold_id);
7558 if (dim == 2)
7559 triangulation.set_manifold(manifold_id, PolarManifold<dim>(center));
7560 else if (dim == 3)
7561 triangulation.set_manifold(manifold_id, SphericalManifold<dim>(center));
7562
7563 // We use boundary vertex positions to see if things are on the inner or
7564 // outer boundary.
7565 constexpr double radial_vertex_tolerance =
7566 100.0 * std::numeric_limits<double>::epsilon();
7568 [center, radial_vertex_tolerance](
7569 const TriaIterator<TriaAccessor<dim - 1, dim, dim>> face,
7570 const double radius) {
7571 (void)center;
7573 (void)face;
7574 (void)radius;
7575 for (unsigned int vertex_n = 0;
7577 ++vertex_n)
7578 {
7579 Assert(std::abs((face->vertex(vertex_n) - center).norm() - radius) <
7580 (center.norm() + radius) * radial_vertex_tolerance,
7582 }
7583 };
7584 if (colorize)
7585 for (const auto &cell : triangulation.active_cell_iterators())
7586 for (const unsigned int face_n : GeometryInfo<dim>::face_indices())
7587 {
7588 auto face = cell->face(face_n);
7589 if (face->at_boundary())
7590 {
7591 if (((face->vertex(0) - center).norm() - inner_radius) <
7592 (center.norm() + inner_radius) * radial_vertex_tolerance)
7593 {
7594 // we must be at an inner face, but check
7595 assert_vertex_distance_within_tolerance(face, inner_radius);
7596 face->set_all_boundary_ids(0);
7597 }
7598 else
7599 {
7600 // we must be at an outer face, but check
7602 face->set_all_boundary_ids(1);
7603 }
7604 }
7605 }
7606 }
7607
7608
7609
7610 template <>
7611 void
7613 const double inner_radius,
7614 const double outer_radius,
7615 const double L,
7616 const unsigned int Nz,
7617 const bool colorize)
7618 {
7619 const int dim = 3;
7620
7621 Assert(inner_radius < outer_radius,
7622 ExcMessage("outer_radius has to be bigger than inner_radius."));
7623 Assert(L > 0, ExcMessage("Must give positive extension L"));
7624 Assert(Nz >= 1, ExcLowerRange(1, Nz));
7625
7626 // Start with a cylinder shell with the correct inner and outer radius
7627 // and as many layers as requested
7628 cylinder_shell(triangulation, L, inner_radius, outer_radius, 8, Nz, false);
7629 triangulation.set_all_manifold_ids(numbers::flat_manifold_id);
7630
7631 // Then loop over all vertices that are at the boundary (by looping
7632 // over all cells, their faces, and if the face is at the boundary,
7633 // their vertices. If we haven't touched that vertex yet, see if
7634 // we need to move it from its cylinder mantle position to the
7635 // outer boundary of the box.
7636 std::vector<bool> treated_vertices(triangulation.n_vertices(), false);
7637 for (const auto &cell : triangulation.active_cell_iterators())
7638 {
7639 for (const auto f : cell->face_indices())
7640 if (cell->face(f)->at_boundary())
7641 {
7642 for (const unsigned int v : cell->face(f)->vertex_indices())
7643 {
7644 const unsigned int vv = cell->face(f)->vertex_index(v);
7645 if (treated_vertices[vv] == false)
7646 {
7647 treated_vertices[vv] = true;
7648
7649 // The vertices we have to treat are the ones that
7650 // have x=y or x=-y and are at the outer ring -- that is,
7651 // they are on the diagonal in the x-y plane and radius
7652 // equal to outer_radius. These need to be pulled out to
7653 // the corner point of the square, i.e., their x and y
7654 // coordinates need to be multiplied by sqrt(2),
7655 // whereas the z coordinate remains unchanged:
7657 cell->face(f)->vertex(v);
7658 if ((std::fabs(std::fabs(vertex_location[0]) -
7659 std::fabs(vertex_location[1])) <
7660 1e-12 * outer_radius) &&
7661 (std::fabs(vertex_location[0] * vertex_location[0] +
7664 1e-12 * outer_radius))
7665 cell->face(f)->vertex(v) =
7667 vertex_location[1] * std::sqrt(2.0),
7668 vertex_location[2]);
7669 }
7670 }
7671 }
7672 }
7673 double eps = 1e-3 * outer_radius;
7674 for (const auto &cell : triangulation.active_cell_iterators())
7675 {
7676 for (const unsigned int f : cell->face_indices())
7677 if (cell->face(f)->at_boundary())
7678 {
7679 const double dx = cell->face(f)->center()[0];
7680 const double dy = cell->face(f)->center()[1];
7681 const double dz = cell->face(f)->center()[2];
7682
7683 if (colorize)
7684 {
7685 if (std::abs(dx + outer_radius) < eps)
7686 cell->face(f)->set_boundary_id(0);
7687
7688 else if (std::abs(dx - outer_radius) < eps)
7689 cell->face(f)->set_boundary_id(1);
7690
7691 else if (std::abs(dy + outer_radius) < eps)
7692 cell->face(f)->set_boundary_id(2);
7693
7694 else if (std::abs(dy - outer_radius) < eps)
7695 cell->face(f)->set_boundary_id(3);
7696
7697 else if (std::abs(dz) < eps)
7698 cell->face(f)->set_boundary_id(4);
7699
7700 else if (std::abs(dz - L) < eps)
7701 cell->face(f)->set_boundary_id(5);
7702
7703 else
7704 {
7705 cell->face(f)->set_all_boundary_ids(6);
7706 cell->face(f)->set_all_manifold_ids(0);
7707 }
7708 }
7709 else
7710 {
7711 Point<dim> c = cell->face(f)->center();
7712 c[2] = 0;
7713 const double d = c.norm();
7714 if (d - inner_radius < 0)
7715 {
7716 cell->face(f)->set_all_boundary_ids(1);
7717 cell->face(f)->set_all_manifold_ids(0);
7718 }
7719 else
7720 cell->face(f)->set_boundary_id(0);
7721 }
7722 }
7723 }
7724 triangulation.set_manifold(0, CylindricalManifold<3>(2));
7725 }
7726
7727
7728
7729 template <int dim, int spacedim1, int spacedim2>
7730 void
7733 {
7734 Assert((dynamic_cast<
7736 &in_tria) == nullptr),
7737 ExcMessage(
7738 "This function cannot be used on "
7739 "parallel::distributed::Triangulation objects as inputs."));
7740 Assert(in_tria.has_hanging_nodes() == false,
7741 ExcMessage("This function does not work for meshes that have "
7742 "hanging nodes."));
7743
7744
7745 const unsigned int spacedim = std::min(spacedim1, spacedim2);
7746 const std::vector<Point<spacedim1>> &in_vertices = in_tria.get_vertices();
7747
7748 // Create an array of vertices, with components either truncated
7749 // or extended by zeroes.
7750 std::vector<Point<spacedim2>> v(in_vertices.size());
7751 for (unsigned int i = 0; i < in_vertices.size(); ++i)
7752 for (unsigned int d = 0; d < spacedim; ++d)
7753 v[i][d] = in_vertices[i][d];
7754
7755 std::vector<CellData<dim>> cells(in_tria.n_active_cells());
7756 for (const auto &cell : in_tria.active_cell_iterators())
7757 {
7758 const unsigned int id = cell->active_cell_index();
7759
7760 cells[id].vertices.resize(cell->n_vertices());
7761 for (const auto i : cell->vertex_indices())
7762 cells[id].vertices[i] = cell->vertex_index(i);
7763 cells[id].material_id = cell->material_id();
7764 cells[id].manifold_id = cell->manifold_id();
7765 }
7766
7768 switch (dim)
7769 {
7770 case 1:
7771 {
7772 // Nothing to do in 1d
7773 break;
7774 }
7775
7776 case 2:
7777 {
7778 std::vector<bool> user_flags_line;
7779 in_tria.save_user_flags_line(user_flags_line);
7781 .clear_user_flags_line();
7782
7783 // Loop over all the faces of the triangulation and create
7784 // objects that describe their boundary and manifold ids.
7785 for (const auto &face : in_tria.active_face_iterators())
7786 {
7787 if (face->at_boundary())
7788 {
7790
7791 boundary_line.vertices.resize(face->n_vertices());
7792 for (const auto i : face->vertex_indices())
7793 boundary_line.vertices[i] = face->vertex_index(i);
7794 boundary_line.boundary_id = face->boundary_id();
7795 boundary_line.manifold_id = face->manifold_id();
7796
7797 subcelldata.boundary_lines.emplace_back(
7798 std::move(boundary_line));
7799 }
7800 else
7801 // The face is not at the boundary. We won't have to set
7802 // boundary_ids (that is not possible for interior faces), but
7803 // we need to do something if the manifold-id is not the
7804 // default.
7805 //
7806 // We keep track via the user flags whether we have already
7807 // dealt with a face or not. (We need to do that here because
7808 // we will return to interior faces twice, once for each
7809 // neighbor, whereas we only touch each of the boundary faces
7810 // above once.)
7811 if ((face->user_flag_set() == false) &&
7812 (face->manifold_id() != numbers::flat_manifold_id))
7813 {
7815
7816 boundary_line.vertices.resize(face->n_vertices());
7817 for (const auto i : face->vertex_indices())
7818 boundary_line.vertices[i] = face->vertex_index(i);
7819 boundary_line.boundary_id =
7821 boundary_line.manifold_id = face->manifold_id();
7822
7823 subcelldata.boundary_lines.emplace_back(
7824 std::move(boundary_line));
7825
7826 face->set_user_flag();
7827 }
7828 }
7829
7830 // Reset the user flags to their previous values:
7832 .load_user_flags_line(user_flags_line);
7833
7834 break;
7835 }
7836
7837 case 3:
7838 {
7839 std::vector<bool> user_flags_line;
7840 in_tria.save_user_flags_line(user_flags_line);
7842 .clear_user_flags_line();
7843
7844 std::vector<bool> user_flags_quad;
7845 in_tria.save_user_flags_quad(user_flags_quad);
7847 .clear_user_flags_quad();
7848
7849 // Loop over all the faces of the triangulation and create
7850 // objects that describe their boundary and manifold ids.
7851 for (const auto &face : in_tria.active_face_iterators())
7852 {
7853 if (face->at_boundary())
7854 {
7856
7857 boundary_face.vertices.resize(face->n_vertices());
7858 for (const auto i : face->vertex_indices())
7859 boundary_face.vertices[i] = face->vertex_index(i);
7860 boundary_face.boundary_id = face->boundary_id();
7861 boundary_face.manifold_id = face->manifold_id();
7862
7863 subcelldata.boundary_quads.emplace_back(
7864 std::move(boundary_face));
7865
7866 // Then also loop over the edges and do the same. We would
7867 // accidentally create duplicates for edges that are part of
7868 // two boundary faces. To avoid this, use the user_flag on
7869 // edges to mark those that we have already visited. (Note
7870 // how we save and restore those above and below.)
7871 for (unsigned int e = 0; e < face->n_lines(); ++e)
7872 if (face->line(e)->user_flag_set() == false)
7873 {
7874 const typename Triangulation<dim,
7875 spacedim1>::line_iterator
7876 edge = face->line(e);
7878
7879 boundary_edge.vertices.resize(edge->n_vertices());
7880 for (const auto i : edge->vertex_indices())
7881 boundary_edge.vertices[i] = edge->vertex_index(i);
7882 boundary_edge.boundary_id = edge->boundary_id();
7883 boundary_edge.manifold_id = edge->manifold_id();
7884
7885 subcelldata.boundary_lines.emplace_back(
7886 std::move(boundary_edge));
7887
7888 edge->set_user_flag();
7889 }
7890 }
7891 else
7892 // The face is not at the boundary. We won't have to set
7893 // boundary_ids (that is not possible for interior faces), but
7894 // we need to do something if the manifold-id is not the
7895 // default.
7896 //
7897 // We keep track via the user flags whether we have already
7898 // dealt with a face or not. (We need to do that here because
7899 // we will return to interior faces twice, once for each
7900 // neighbor, whereas we only touch each of the boundary faces
7901 // above once.)
7902 //
7903 // Note that if we have already dealt with a face, then we
7904 // have also already dealt with the edges and don't have
7905 // to worry about that any more separately.
7906 if (face->user_flag_set() == false)
7907 {
7908 if (face->manifold_id() != numbers::flat_manifold_id)
7909 {
7911
7912 boundary_face.vertices.resize(face->n_vertices());
7913 for (const auto i : face->vertex_indices())
7914 boundary_face.vertices[i] = face->vertex_index(i);
7915 boundary_face.boundary_id =
7917 boundary_face.manifold_id = face->manifold_id();
7918
7919 subcelldata.boundary_quads.emplace_back(
7920 std::move(boundary_face));
7921
7922 face->set_user_flag();
7923 }
7924
7925 // Then also loop over the edges of this face. Because
7926 // every boundary edge must also be a part of a boundary
7927 // face, we can ignore these. But it is possible that we
7928 // have already encountered an interior edge through a
7929 // previous face, and in that case we have to just ignore
7930 // it
7931 for (unsigned int e = 0; e < face->n_lines(); ++e)
7932 if (face->line(e)->at_boundary() == false)
7933 if (face->line(e)->user_flag_set() == false)
7934 {
7935 const typename Triangulation<dim, spacedim1>::
7936 line_iterator edge = face->line(e);
7938
7939 boundary_edge.vertices.resize(edge->n_vertices());
7940 for (const auto i : edge->vertex_indices())
7941 boundary_edge.vertices[i] =
7942 edge->vertex_index(i);
7943 boundary_edge.boundary_id =
7945 boundary_edge.manifold_id = edge->manifold_id();
7946
7947 subcelldata.boundary_lines.emplace_back(
7948 std::move(boundary_edge));
7949
7950 edge->set_user_flag();
7951 }
7952 }
7953 }
7954
7955 // Reset the user flags to their previous values:
7957 .load_user_flags_line(user_flags_line);
7959 .load_user_flags_quad(user_flags_quad);
7960
7961 break;
7962 }
7963 default:
7965 }
7966
7967 out_tria.create_triangulation(v, cells, subcelldata);
7968
7969 for (const auto i : out_tria.get_manifold_ids())
7971 out_tria.set_manifold(i, FlatManifold<dim, spacedim2>());
7972 }
7973
7974
7975
7976 template <int dim, int spacedim>
7977 void
7980 {
7981 Assert(dim > 1, ExcNotImplemented());
7983 in_tria.all_reference_cells_are_hyper_cube(),
7984 ExcMessage(
7985 "GridGenerator::convert_hypercube_to_simplex_mesh() expects a mesh that consists only of quads/hexes."));
7986
7988 if (in_tria.n_global_levels() > 1)
7989 {
7990 AssertThrow(!in_tria.has_hanging_nodes(), ExcNotImplemented());
7992 }
7994 in_tria.n_global_levels() > 1 ? temp_tria : in_tria;
7995
7996 // static tables with the definitions of cells, faces and edges by its
7997 // vertices for 2d and 3d. For the inheritance of the manifold_id,
7998 // definitions of inner-faces and boundary-faces are required. In case of
7999 // 3d, also inner-edges and boundary-edges need to be defined.
8000
8001 // Cell definition 2d:
8002 // A quadrilateral element is converted to 8 simplices elements. Each
8003 // triangle is defined by 3 vertices.
8004 static const ndarray<unsigned int, 8, 3> table_2D_cell = {{{{0, 6, 4}},
8005 {{8, 4, 6}},
8006 {{8, 6, 5}},
8007 {{1, 5, 6}},
8008 {{2, 4, 7}},
8009 {{8, 7, 4}},
8010 {{8, 5, 7}},
8011 {{3, 7, 5}}}};
8012
8013 // Cell definition 3d:
8014 // A hexahedron element is converted to 24 tetrahedron elements. Each
8015 // tetrahedron is defined by 4 vertices.
8017 {{{0, 1, 12, 10}}, {{2, 3, 11, 12}}, {{7, 6, 11, 13}},
8018 {{5, 4, 13, 10}}, {{0, 2, 8, 12}}, {{4, 6, 13, 8}},
8019 {{5, 13, 7, 9}}, {{1, 9, 3, 12}}, {{0, 8, 4, 10}},
8020 {{1, 5, 9, 10}}, {{3, 7, 11, 9}}, {{2, 6, 8, 11}},
8021 {{12, 13, 10, 9}}, {{12, 13, 9, 11}}, {{12, 13, 11, 8}},
8022 {{12, 13, 8, 10}}, {{13, 8, 10, 4}}, {{13, 10, 9, 5}},
8023 {{13, 9, 11, 7}}, {{13, 11, 8, 6}}, {{10, 12, 9, 1}},
8024 {{9, 12, 11, 3}}, {{11, 12, 8, 2}}, {{8, 12, 10, 0}}}};
8025
8026 // Boundary-faces 2d:
8027 // After converting, each of the 4 quadrilateral faces is defined by faces
8028 // of 2 different triangles, i.e., lines. Note that lines are defined by 2
8029 // vertices.
8031 vertex_ids_for_boundary_faces_2d = {{{{{{0, 4}}, {{4, 2}}}},
8032 {{{{1, 5}}, {{5, 3}}}},
8033 {{{{0, 6}}, {{6, 1}}}},
8034 {{{{2, 7}}, {{7, 3}}}}}};
8035
8036 // Boundary-faces 3d:
8037 // After converting, each of the 6 hexahedron faces corresponds to faces of
8038 // 4 different tetrahedron faces, i.e., triangles. Note that a triangle is
8039 // defined by 3 vertices.
8042 {{{{{0, 4, 8}}, {{4, 8, 6}}, {{8, 6, 2}}, {{0, 2, 8}}}},
8043 {{{{1, 3, 9}}, {{3, 9, 7}}, {{9, 7, 5}}, {{1, 9, 5}}}},
8044 {{{{0, 1, 10}}, {{1, 10, 5}}, {{10, 5, 4}}, {{0, 10, 4}}}},
8045 {{{{2, 3, 11}}, {{3, 11, 7}}, {{11, 7, 6}}, {{2, 11, 6}}}},
8046 {{{{0, 1, 12}}, {{1, 12, 3}}, {{12, 3, 2}}, {{0, 12, 2}}}},
8047 {{{{4, 5, 13}}, {{5, 13, 7}}, {{13, 7, 6}}, {{4, 13, 6}}}}}};
8048
8049 // Inner-faces 2d:
8050 // The converted triangulation based on simplices has 8 faces that do not
8051 // form the boundary, i.e. inner-faces, each defined by 2 vertices.
8053 {{{6, 4}},
8054 {{6, 8}},
8055 {{6, 5}},
8056 {{4, 8}},
8057 {{8, 5}},
8058 {{7, 4}},
8059 {{7, 8}},
8060 {{7, 5}}}};
8061
8062 // Inner-faces 3d:
8063 // The converted triangulation based on simplices has 72 faces that do not
8064 // form the boundary, i.e. inner-faces, each defined by 3 vertices.
8066 {{{0, 12, 10}}, {{12, 1, 10}}, {{12, 1, 9}}, {{12, 3, 9}},
8067 {{12, 2, 11}}, {{12, 3, 11}}, {{12, 0, 8}}, {{12, 2, 8}},
8068 {{9, 13, 5}}, {{13, 7, 9}}, {{11, 7, 13}}, {{11, 6, 13}},
8069 {{4, 8, 13}}, {{6, 8, 13}}, {{4, 13, 10}}, {{13, 5, 10}},
8070 {{10, 9, 5}}, {{10, 9, 1}}, {{11, 9, 7}}, {{11, 9, 3}},
8071 {{8, 11, 2}}, {{8, 11, 6}}, {{8, 10, 0}}, {{8, 10, 4}},
8072 {{12, 3, 9}}, {{12, 9, 11}}, {{12, 3, 11}}, {{3, 9, 11}},
8073 {{2, 12, 8}}, {{2, 12, 11}}, {{2, 11, 8}}, {{8, 12, 11}},
8074 {{0, 12, 10}}, {{0, 12, 8}}, {{0, 8, 10}}, {{8, 10, 12}},
8075 {{12, 1, 10}}, {{12, 1, 9}}, {{1, 10, 9}}, {{10, 9, 12}},
8076 {{10, 8, 4}}, {{10, 8, 13}}, {{4, 13, 8}}, {{4, 13, 10}},
8077 {{10, 9, 13}}, {{10, 9, 5}}, {{13, 5, 10}}, {{13, 5, 9}},
8078 {{13, 7, 9}}, {{13, 7, 11}}, {{9, 11, 13}}, {{9, 11, 7}},
8079 {{8, 11, 13}}, {{8, 11, 6}}, {{6, 13, 8}}, {{6, 13, 11}},
8080 {{12, 13, 10}}, {{12, 13, 8}}, {{8, 10, 13}}, {{8, 10, 12}},
8081 {{12, 13, 10}}, {{12, 13, 9}}, {{10, 9, 13}}, {{10, 9, 12}},
8082 {{12, 13, 9}}, {{12, 13, 11}}, {{9, 11, 13}}, {{9, 11, 12}},
8083 {{12, 13, 11}}, {{12, 13, 8}}, {{8, 11, 13}}, {{8, 11, 12}}}};
8084
8085 // Inner-edges 3d:
8086 // The converted triangulation based on simplices has 60 edges that do not
8087 // coincide with the boundary, i.e. inner-edges, each defined by 2 vertices.
8089 {{{12, 10}}, {{12, 9}}, {{12, 11}}, {{12, 8}}, {{9, 13}}, {{11, 13}},
8090 {{8, 13}}, {{10, 13}}, {{10, 9}}, {{9, 11}}, {{11, 8}}, {{8, 10}},
8091 {{12, 9}}, {{12, 11}}, {{11, 9}}, {{12, 8}}, {{12, 11}}, {{11, 8}},
8092 {{12, 8}}, {{12, 10}}, {{10, 8}}, {{12, 10}}, {{12, 9}}, {{9, 10}},
8093 {{13, 10}}, {{13, 8}}, {{8, 10}}, {{13, 10}}, {{13, 9}}, {{9, 10}},
8094 {{13, 11}}, {{13, 9}}, {{11, 9}}, {{13, 11}}, {{13, 8}}, {{11, 8}},
8095 {{12, 13}}, {{8, 10}}, {{8, 13}}, {{10, 13}}, {{8, 12}}, {{10, 12}},
8096 {{12, 13}}, {{10, 9}}, {{10, 13}}, {{9, 13}}, {{10, 12}}, {{9, 12}},
8097 {{12, 13}}, {{9, 11}}, {{9, 13}}, {{11, 13}}, {{9, 12}}, {{11, 12}},
8098 {{12, 13}}, {{11, 8}}, {{11, 13}}, {{8, 13}}, {{11, 12}}, {{8, 12}}}};
8099
8100 // Boundary-edges 3d:
8101 // For each of the 6 boundary-faces of the hexahedron, there are 8 edges (of
8102 // different tetrahedrons) that coincide with the boundary, i.e.
8103 // boundary-edges. Each boundary-edge is defined by 2 vertices. 4 of these
8104 // edges are new (they are placed in the middle of a presently existing
8105 // face); the other 4 coincide with edges present in the hexahedral
8106 // triangulation. The new 4 edges inherit the manifold id of the relevant
8107 // face, but the other 4 need to be copied from the input and thus do not
8108 // require a lookup table.
8111 {{{{{4, 8}}, {{6, 8}}, {{0, 8}}, {{2, 8}}}},
8112 {{{{5, 9}}, {{7, 9}}, {{1, 9}}, {{3, 9}}}},
8113 {{{{4, 10}}, {{5, 10}}, {{0, 10}}, {{1, 10}}}},
8114 {{{{6, 11}}, {{7, 11}}, {{2, 11}}, {{3, 11}}}},
8115 {{{{2, 12}}, {{3, 12}}, {{0, 12}}, {{1, 12}}}},
8116 {{{{6, 13}}, {{7, 13}}, {{4, 13}}, {{5, 13}}}}}};
8117
8118 std::vector<Point<spacedim>> vertices;
8119 std::vector<CellData<dim>> cells;
8121
8122 // store for each vertex and face the assigned index so that we only
8123 // assign them a value once
8124 std::vector<unsigned int> old_to_new_vertex_indices(
8126 std::vector<unsigned int> face_to_new_vertex_indices(
8128
8129 // We first have to create all of the new vertices. To do this, we loop over
8130 // all cells and on each cell
8131 // (i) copy the existing vertex locations (and record their new indices in
8132 // the 'old_to_new_vertex_indices' vector),
8133 // (ii) create new midpoint vertex locations for each face (and record their
8134 // new indices in the 'face_to_new_vertex_indices' vector),
8135 // (iii) create new midpoint vertex locations for each cell (dim = 2 only)
8136 for (const auto &cell : ref_tria.cell_iterators())
8137 {
8138 // temporary array storing the global indices of each cell entity in the
8139 // sequence: vertices, edges/faces, cell
8140 std::array<unsigned int, dim == 2 ? 9 : 14> local_vertex_indices;
8141
8142 // (i) copy the existing vertex locations
8143 for (const auto v : cell->vertex_indices())
8144 {
8145 const auto v_global = cell->vertex_index(v);
8146
8149 {
8150 old_to_new_vertex_indices[v_global] = vertices.size();
8151 vertices.push_back(cell->vertex(v));
8152 }
8153
8156 }
8157
8158 // (ii) create new midpoint vertex locations for each face
8159 for (const auto f : cell->face_indices())
8160 {
8161 const auto f_global = cell->face_index(f);
8162
8165 {
8166 face_to_new_vertex_indices[f_global] = vertices.size();
8167 vertices.push_back(
8168 cell->face(f)->center(/*respect_manifold*/ true));
8169 }
8170
8171 AssertIndexRange(cell->n_vertices() + f,
8172 local_vertex_indices.size());
8173 local_vertex_indices[cell->n_vertices() + f] =
8175 }
8176
8177 // (iii) create new midpoint vertex locations for each cell
8178 if (dim == 2)
8179 {
8180 AssertIndexRange(cell->n_vertices() + cell->n_faces(),
8181 local_vertex_indices.size());
8182 local_vertex_indices[cell->n_vertices() + cell->n_faces()] =
8183 vertices.size();
8184 vertices.push_back(cell->center(/*respect_manifold*/ true));
8185 }
8186
8187 // helper function for creating cells and subcells
8188 const auto add_cell = [&](const unsigned int struct_dim,
8189 const auto &index_vertices,
8190 const unsigned int material_or_boundary_id,
8191 const unsigned int manifold_id = 0) {
8192 // sub-cell data only has to be stored if the information differs
8193 // from the default
8194 if (struct_dim < dim &&
8196 manifold_id == numbers::flat_manifold_id))
8197 return;
8198
8199 if (struct_dim == dim) // cells
8200 {
8201 AssertDimension(index_vertices.size(), dim + 1);
8202
8203 CellData<dim> cell_data(index_vertices.size());
8204 cell_data.material_id =
8205 material_or_boundary_id; // inherit material id
8206 cell_data.manifold_id = manifold_id; // inherit cell-manifold id
8207 for (unsigned int i = 0; i < index_vertices.size(); ++i)
8208 {
8210 local_vertex_indices.size());
8211 cell_data.vertices[i] =
8213 }
8214 cells.push_back(cell_data);
8215 }
8216 else if (dim == 2 && struct_dim == 1) // an edge of a simplex
8217 {
8218 Assert(index_vertices.size() == 2, ExcInternalError());
8221 boundary_line.manifold_id = manifold_id;
8222 for (unsigned int i = 0; i < index_vertices.size(); ++i)
8223 {
8225 local_vertex_indices.size());
8226 boundary_line.vertices[i] =
8228 }
8229 subcell_data.boundary_lines.push_back(boundary_line);
8230 }
8231 else if (dim == 3 && struct_dim == 2) // a face of a tetrahedron
8232 {
8233 Assert(index_vertices.size() == 3, ExcInternalError());
8236 boundary_quad.manifold_id = manifold_id;
8237 for (unsigned int i = 0; i < index_vertices.size(); ++i)
8238 {
8240 local_vertex_indices.size());
8241 boundary_quad.vertices[i] =
8243 }
8244 subcell_data.boundary_quads.push_back(boundary_quad);
8245 }
8246 else if (dim == 3 && struct_dim == 1) // an edge of a tetrahedron
8247 {
8248 Assert(index_vertices.size() == 2, ExcInternalError());
8251 boundary_line.manifold_id = manifold_id;
8252 for (unsigned int i = 0; i < index_vertices.size(); ++i)
8253 {
8255 local_vertex_indices.size());
8256 boundary_line.vertices[i] =
8258 }
8259 subcell_data.boundary_lines.push_back(boundary_line);
8260 }
8261 else
8262 {
8264 }
8265 };
8266
8267 const auto material_id_cell = cell->material_id();
8268
8269 // create cells one by one
8270 if (dim == 2)
8271 {
8272 // get cell-manifold id from current quad cell
8273 const auto manifold_id_cell = cell->manifold_id();
8274 // inherit cell manifold
8275 for (const auto &cell_vertices : table_2D_cell)
8276 add_cell(dim, cell_vertices, material_id_cell, manifold_id_cell);
8277
8278 // inherit inner manifold (faces)
8280 // set inner tri-faces according to cell-manifold of quad
8281 // element, set invalid b_id, since we do not want to modify
8282 // b_id inside
8283 add_cell(1,
8287 }
8288 else if (dim == 3)
8289 {
8290 // get cell-manifold id from current quad cell
8291 const auto manifold_id_cell = cell->manifold_id();
8292 // inherit cell manifold
8293 for (const auto &cell_vertices : vertex_ids_for_cells_3d)
8294 add_cell(dim, cell_vertices, material_id_cell, manifold_id_cell);
8295
8296 // set manifold of inner FACES of tets according to
8297 // hex-cell-manifold
8299 add_cell(2,
8303
8304 // set manifold of inner EDGES of tets according to
8305 // hex-cell-manifold
8307 add_cell(1,
8311 }
8312 else
8314
8315 // Set up sub-cell data.
8316 for (const auto f : cell->face_indices())
8317 {
8318 const auto bid = cell->face(f)->boundary_id();
8319 const auto mid = cell->face(f)->manifold_id();
8320
8321 // process boundary-faces: set boundary and manifold ids
8322 if (dim == 2) // 2d boundary-faces
8323 {
8324 for (const auto &face_vertices :
8327 }
8328 else if (dim == 3) // 3d boundary-faces
8329 {
8330 // set manifold ids of tet-boundary-faces according to
8331 // hex-boundary-faces
8332 for (const auto &face_vertices :
8335 // set manifold ids of new tet-boundary-edges according to
8336 // hex-boundary-faces
8337 for (const auto &edge_vertices :
8340 }
8341 else
8343 }
8344
8345 // set manifold ids of edges that were already present in the
8346 // triangulation.
8347 if (dim == 3)
8348 {
8349 for (const auto e : cell->line_indices())
8350 {
8351 auto edge = cell->line(e);
8352 // Rather than use add_cell(), which does additional index
8353 // translation, just add edges directly into subcell_data since
8354 // we already know the correct global vertex indices.
8356 edge_data.vertices[0] =
8357 old_to_new_vertex_indices[edge->vertex_index(0)];
8358 edge_data.vertices[1] =
8359 old_to_new_vertex_indices[edge->vertex_index(1)];
8360 edge_data.boundary_id = edge->boundary_id();
8361 edge_data.manifold_id = edge->manifold_id();
8362
8363 subcell_data.boundary_lines.push_back(std::move(edge_data));
8364 }
8365 }
8366 }
8367
8368 out_tria.clear();
8369 out_tria.create_triangulation(vertices, cells, subcell_data);
8370
8371 for (const auto i : out_tria.get_manifold_ids())
8373 out_tria.set_manifold(i, FlatManifold<dim, spacedim>());
8374 }
8375
8376
8377
8378 template <int spacedim>
8379 void
8382 {
8383 out_tria.copy_triangulation(in_tria);
8384 return;
8385 }
8386
8387
8388
8389 template <int dim, int spacedim>
8390 void
8393 {
8395 if (in_tria.n_global_levels() > 1)
8396 {
8397 AssertThrow(!in_tria.has_hanging_nodes(), ExcNotImplemented());
8399 }
8401 in_tria.n_global_levels() > 1 ? temp_tria : in_tria;
8402
8403 // Three triangles connecting to barycenter with vertex index 3:
8405 {{{0, 1, 3}}, {{1, 2, 3}}, {{2, 0, 3}}}};
8406
8407 // Boundary-faces 2d:
8408 // Each face of the original simplex is defined by the following vertices:
8411 {{{{{0, 1}}}}, {{{{1, 2}}}}, {{{{2, 0}}}}}};
8412
8413 // Three tetrahedra connecting to barycenter with vertex index 4:
8415 {{{0, 1, 2, 4}}, {{1, 0, 3, 4}}, {{0, 2, 3, 4}}, {{2, 1, 3, 4}}}};
8416
8417 // Boundary-faces 3d:
8418 // Each face of the original simplex is defined by the following vertices:
8421 {{{{{0, 1, 2}}}}, {{{{1, 0, 3}}}}, {{{{0, 2, 3}}}}, {{{{2, 1, 3}}}}}};
8422
8423 // Boundary-lines 3d:
8424 // Each line/edge of the original simplex is defined by the following
8425 // vertices:
8427 vertex_ids_for_boundary_lines_3d = {{{{{{0, 1}}}},
8428 {{{{1, 2}}}},
8429 {{{{2, 0}}}},
8430 {{{{0, 3}}}},
8431 {{{{1, 3}}}},
8432 {{{{2, 3}}}}}};
8433
8434 std::vector<Point<spacedim>> vertices;
8435 std::vector<CellData<dim>> cells;
8437
8438 // for each vertex we store the assigned index so that we only
8439 // assign them a value once
8440 std::vector<unsigned int> old_to_new_vertex_indices(
8442
8443 // We first have to create all of the new vertices. To do this, we loop over
8444 // all cells and on each cell
8445 // (i) copy the existing vertex locations (and record their new indices in
8446 // the 'old_to_new_vertex_indices' vector),
8447 // (ii) create new barycenter vertex location
8448 for (const auto &cell : ref_tria.cell_iterators())
8449 {
8451 cell->reference_cell().is_simplex(),
8452 ExcMessage(
8453 "Cell with invalid ReferenceCell encountered. GridGenerator::alfeld_split_of_simplex_mesh() "
8454 "only supports simplex meshes as input."));
8455
8456 // temporary array storing the global indices of each cell entity in the
8457 // sequence: vertices, edges/faces, cell
8458 std::array<unsigned int, (dim == 3) ? 5 : 4> local_vertex_indices;
8459
8460 // (i) copy the existing vertex locations
8461 Point<spacedim> barycenter;
8462 for (const auto v : cell->vertex_indices())
8463 {
8464 const auto v_global = cell->vertex_index(v);
8465
8468 {
8469 old_to_new_vertex_indices[v_global] = vertices.size();
8470 vertices.push_back(cell->vertex(v));
8471 }
8472
8475
8476 barycenter += vertices[local_vertex_indices[v]] - Point<spacedim>();
8477 }
8478
8479 // (ii) barycenter:
8480 local_vertex_indices[local_vertex_indices.size() - 1] = vertices.size();
8481 vertices.push_back(barycenter / static_cast<double>(dim + 1));
8482
8483 // helper function for creating cells and subcells
8484 const auto add_cell = [&](const unsigned int struct_dim,
8485 const auto &index_vertices,
8486 const unsigned int material_or_boundary_id,
8487 const unsigned int manifold_id = 0) {
8488 // sub-cell data only has to be stored if the information differs
8489 // from the default
8490 if (struct_dim < dim &&
8492 manifold_id == numbers::flat_manifold_id))
8493 return;
8494
8495 if (struct_dim == dim) // cells
8496 {
8497 AssertDimension(index_vertices.size(), dim + 1);
8498
8499 CellData<dim> cell_data(index_vertices.size());
8500 for (unsigned int i = 0; i < index_vertices.size(); ++i)
8501 {
8503 local_vertex_indices.size());
8504 cell_data.vertices[i] =
8506 }
8507 cell_data.material_id =
8508 material_or_boundary_id; // inherit material id
8509 cell_data.manifold_id = manifold_id; // inherit cell-manifold id
8510 cells.push_back(cell_data);
8511 }
8512 else if (dim == 2 && struct_dim == 1) // an edge of a simplex
8513 {
8514 Assert(index_vertices.size() == 2, ExcInternalError());
8517 boundary_line.manifold_id = manifold_id;
8518 for (unsigned int i = 0; i < index_vertices.size(); ++i)
8519 {
8521 local_vertex_indices.size());
8522 boundary_line.vertices[i] =
8524 }
8525 subcell_data.boundary_lines.push_back(boundary_line);
8526 }
8527 else if (dim == 3 && struct_dim == 2) // a face of a tetrahedron
8528 {
8529 Assert(index_vertices.size() == 3, ExcInternalError());
8532 boundary_quad.manifold_id = manifold_id;
8533 for (unsigned int i = 0; i < index_vertices.size(); ++i)
8534 {
8536 local_vertex_indices.size());
8537 boundary_quad.vertices[i] =
8539 }
8540 subcell_data.boundary_quads.push_back(boundary_quad);
8541 }
8542 else if (dim == 3 && struct_dim == 1) // an edge of a tetrahedron
8543 {
8544 Assert(index_vertices.size() == 2, ExcInternalError());
8547 boundary_line.manifold_id = manifold_id;
8548 for (unsigned int i = 0; i < index_vertices.size(); ++i)
8549 {
8551 local_vertex_indices.size());
8552 boundary_line.vertices[i] =
8554 }
8555 subcell_data.boundary_lines.push_back(boundary_line);
8556 }
8557 else
8558 {
8560 }
8561 };
8562
8563 const auto material_id_cell = cell->material_id();
8564 const auto manifold_id_cell = cell->manifold_id();
8565
8566 // create cells one by one
8567 if (dim == 2)
8568 {
8569 for (const auto &cell_vertices : table_2D_cell)
8570 add_cell(dim, cell_vertices, material_id_cell, manifold_id_cell);
8571 }
8572 else if (dim == 3)
8573 {
8574 for (const auto &cell_vertices : table_3D_cell)
8575 add_cell(dim, cell_vertices, material_id_cell, manifold_id_cell);
8576 }
8577 else
8579
8580 // Set up sub-cell data.
8581 for (const auto f : cell->face_indices())
8582 {
8583 const auto bid = cell->face(f)->boundary_id();
8584 const auto mid = cell->face(f)->manifold_id();
8585
8586 // process boundary-faces: set boundary and manifold ids
8587 if (dim == 2) // 2d boundary-faces
8588 {
8589 for (const auto &face_vertices :
8592 }
8593 else if (dim == 3)
8594 {
8595 for (const auto &face_vertices :
8598 }
8599 else
8601 }
8602
8603 // In 3D we need to treat boundary lines separately.
8604 if (dim == 3)
8605 {
8606 for (const auto l : cell->line_indices())
8607 {
8608 const auto bid = cell->line(l)->boundary_id();
8609 const auto mid = cell->line(l)->manifold_id();
8610
8611 for (const auto &line_vertices :
8613 add_cell(1, line_vertices, bid, mid);
8614 }
8615 }
8616 }
8617
8618 out_tria.clear();
8619 out_tria.create_triangulation(vertices, cells, subcell_data);
8620
8621 for (const auto i : out_tria.get_manifold_ids())
8623 out_tria.set_manifold(i, FlatManifold<dim, spacedim>());
8624 }
8625
8626
8627
8628 template <template <int, int> class MeshType, int dim, int spacedim>
8631# ifndef _MSC_VER
8632 std::map<typename MeshType<dim - 1, spacedim>::cell_iterator,
8634# else
8636# endif
8639 const std::set<types::boundary_id> &boundary_ids)
8640 {
8641 Assert((dynamic_cast<
8643 &volume_mesh.get_triangulation()) == nullptr),
8645
8646 // This function works using the following assumption:
8647 // Triangulation::create_triangulation(...) will create cells that
8648 // preserve the order of cells passed in using the CellData argument;
8649 // also, that it will not reorder the vertices.
8650
8651 // dimension of the boundary mesh
8652 const unsigned int boundary_dim = dim - 1;
8653
8654 // temporary map for level==0
8655 // iterator to face is stored along with face number
8656 // (this is required by the algorithm to adjust the normals of the
8657 // cells of the boundary mesh)
8658 std::vector<
8659 std::pair<typename MeshType<dim, spacedim>::face_iterator, unsigned int>>
8661
8662 // vector indicating whether a vertex of the volume mesh has
8663 // already been visited (necessary to avoid duplicate vertices in
8664 // boundary mesh)
8665 std::vector<bool> touched(volume_mesh.get_triangulation().n_vertices(),
8666 false);
8667
8668 // data structures required for creation of boundary mesh
8669 std::vector<CellData<boundary_dim>> cells;
8671 std::vector<Point<spacedim>> vertices;
8672
8673 // volume vertex indices to surf ones
8674 std::map<unsigned int, unsigned int> map_vert_index;
8675
8676 // define swapping of vertices to get proper normal orientation of boundary
8677 // mesh;
8678 // the entry (i,j) of swap_matrix stores the index of the vertex of
8679 // the boundary cell corresponding to the j-th vertex on the i-th face
8680 // of the underlying volume cell
8681 // if e.g. face 3 of a volume cell is considered and vertices 1 and 2 of the
8682 // corresponding boundary cell are swapped to get
8683 // proper normal orientation, swap_matrix[3]=( 0, 2, 1, 3 )
8687 for (unsigned int i1 = 0; i1 < GeometryInfo<spacedim>::faces_per_cell; ++i1)
8688 {
8689 for (unsigned int i2 = 0; i2 < GeometryInfo<dim - 1>::vertices_per_cell;
8690 i2++)
8691 swap_matrix[i1][i2] = i2;
8692 }
8693 // vertex swapping such that normals on the surface mesh point out of the
8694 // underlying volume
8695 if (dim == 3)
8696 {
8697 std::swap(swap_matrix[0][1], swap_matrix[0][2]);
8698 std::swap(swap_matrix[2][1], swap_matrix[2][2]);
8699 std::swap(swap_matrix[4][1], swap_matrix[4][2]);
8700 }
8701 else if (dim == 2)
8702 {
8703 std::swap(swap_matrix[1][0], swap_matrix[1][1]);
8704 std::swap(swap_matrix[2][0], swap_matrix[2][1]);
8705 }
8706
8707 // Create boundary mesh and mapping
8708 // from only level(0) cells of volume_mesh
8709 for (typename MeshType<dim, spacedim>::cell_iterator cell =
8710 volume_mesh.begin(0);
8711 cell != volume_mesh.end(0);
8712 ++cell)
8713 for (const unsigned int i : GeometryInfo<dim>::face_indices())
8714 {
8715 const typename MeshType<dim, spacedim>::face_iterator face =
8716 cell->face(i);
8717
8718 if (face->at_boundary() &&
8719 (boundary_ids.empty() ||
8720 (boundary_ids.find(face->boundary_id()) != boundary_ids.end())))
8721 {
8723
8724 for (const unsigned int j :
8726 {
8727 const unsigned int v_index = face->vertex_index(j);
8728
8729 if (!touched[v_index])
8730 {
8731 vertices.push_back(face->vertex(j));
8732 map_vert_index[v_index] = vertices.size() - 1;
8733 touched[v_index] = true;
8734 }
8735
8736 c_data.vertices[swap_matrix[i][j]] = map_vert_index[v_index];
8737 }
8738 c_data.material_id =
8739 static_cast<types::material_id>(face->boundary_id());
8740 c_data.manifold_id = face->manifold_id();
8741
8742
8743 // in 3d, we need to make sure we copy the manifold
8744 // indicators from the edges of the volume mesh to the
8745 // edges of the surface mesh
8746 //
8747 // we set default boundary ids for boundary lines
8748 // and numbers::internal_face_boundary_id for internal lines
8749 if (dim == 3)
8750 for (unsigned int e = 0; e < 4; ++e)
8751 {
8752 // see if we already saw this edge from a
8753 // neighboring face, either in this or the reverse
8754 // orientation. if so, skip it.
8755 {
8756 bool edge_found = false;
8757 for (auto &boundary_line : subcell_data.boundary_lines)
8758 if (((boundary_line.vertices[0] ==
8759 map_vert_index[face->line(e)->vertex_index(0)]) &&
8760 (boundary_line.vertices[1] ==
8761 map_vert_index[face->line(e)->vertex_index(
8762 1)])) ||
8763 ((boundary_line.vertices[0] ==
8764 map_vert_index[face->line(e)->vertex_index(1)]) &&
8765 (boundary_line.vertices[1] ==
8766 map_vert_index[face->line(e)->vertex_index(0)])))
8767 {
8768 boundary_line.boundary_id =
8770 edge_found = true;
8771 break;
8772 }
8773 if (edge_found == true)
8774 // try next edge of current face
8775 continue;
8776 }
8777
8779 edge.vertices[0] =
8780 map_vert_index[face->line(e)->vertex_index(0)];
8781 edge.vertices[1] =
8782 map_vert_index[face->line(e)->vertex_index(1)];
8783 edge.boundary_id = 0;
8784 edge.manifold_id = face->line(e)->manifold_id();
8785
8786 subcell_data.boundary_lines.push_back(edge);
8787 }
8788
8789 cells.push_back(c_data);
8790 temporary_mapping_level0.push_back(std::make_pair(face, i));
8791 }
8792 }
8793
8794 // create level 0 surface triangulation
8795 Assert(cells.size() > 0, ExcMessage("No boundary faces selected"));
8796 const_cast<Triangulation<dim - 1, spacedim> &>(
8797 surface_mesh.get_triangulation())
8798 .create_triangulation(vertices, cells, subcell_data);
8799
8800 // in 2d: set default boundary ids for "boundary vertices"
8801 if (dim == 2)
8802 {
8803 for (const auto &cell : surface_mesh.active_cell_iterators())
8804 for (unsigned int vertex = 0; vertex < 2; ++vertex)
8805 if (cell->face(vertex)->at_boundary())
8806 cell->face(vertex)->set_boundary_id(0);
8807 }
8808
8809 // Make mapping for level 0
8810
8811 // temporary map between cells on the boundary and corresponding faces of
8812 // domain mesh (each face is characterized by an iterator to the face and
8813 // the face number within the underlying cell)
8814 std::vector<std::pair<
8815 const typename MeshType<dim - 1, spacedim>::cell_iterator,
8816 std::pair<typename MeshType<dim, spacedim>::face_iterator, unsigned int>>>
8818 for (const auto &cell : surface_mesh.active_cell_iterators())
8820 std::make_pair(cell, temporary_mapping_level0.at(cell->index())));
8821
8822
8823 // refine the boundary mesh according to the refinement of the underlying
8824 // volume mesh,
8825 // algorithm:
8826 // (1) check which cells on refinement level i need to be refined
8827 // (2) do refinement (yields cells on level i+1)
8828 // (3) repeat for the next level (i+1->i) until refinement is completed
8829
8830 // stores the index into temporary_map_boundary_cell_face at which
8831 // presently deepest refinement level of boundary mesh begins
8832 unsigned int index_cells_deepest_level = 0;
8833 do
8834 {
8835 bool changed = false;
8836
8837 // vector storing cells which have been marked for
8838 // refinement
8839 std::vector<unsigned int> cells_refined;
8840
8841 // loop over cells of presently deepest level of boundary triangulation
8842 for (unsigned int cell_n = index_cells_deepest_level;
8844 cell_n++)
8845 {
8846 // mark boundary cell for refinement if underlying volume face has
8847 // children
8849 .second.first->has_children())
8850 {
8851 // algorithm only works for
8852 // isotropic refinement!
8854 .second.first->refinement_case() ==
8858 .first->set_refine_flag();
8859 cells_refined.push_back(cell_n);
8860 changed = true;
8861 }
8862 }
8863
8864 // if cells have been marked for refinement (i.e., presently deepest
8865 // level is not the deepest level of the volume mesh)
8866 if (changed)
8867 {
8868 // do actual refinement
8869 const_cast<Triangulation<dim - 1, spacedim> &>(
8870 surface_mesh.get_triangulation())
8871 .execute_coarsening_and_refinement();
8872
8873 // add new level of cells to temporary_map_boundary_cell_face
8875 for (const auto &refined_cell_n : cells_refined)
8876 {
8877 const typename MeshType<dim - 1, spacedim>::cell_iterator
8878 refined_cell =
8880 const typename MeshType<dim,
8881 spacedim>::face_iterator refined_face =
8883 const unsigned int refined_face_number =
8885 .second.second;
8886 for (unsigned int child_n = 0;
8887 child_n < refined_cell->n_children();
8888 ++child_n)
8889 // at this point, the swapping of vertices done earlier must
8890 // be taken into account to get the right association between
8891 // volume faces and boundary cells!
8893 std::make_pair(refined_cell->child(
8895 std::make_pair(refined_face->child(child_n),
8897 }
8898 }
8899 // we are at the deepest level of refinement of the volume mesh
8900 else
8901 break;
8902 }
8903 while (true);
8904
8905 // generate the final mapping from the temporary mapping
8906 std::map<typename MeshType<dim - 1, spacedim>::cell_iterator,
8909 for (unsigned int i = 0; i < temporary_map_boundary_cell_face.size(); ++i)
8912
8913 // TODO: we attach flat manifolds here; one should attach submanifolds here
8914 const auto attached_mids =
8915 surface_mesh.get_triangulation().get_manifold_ids();
8916 for (const auto i : volume_mesh.get_triangulation().get_manifold_ids())
8917 if (i != numbers::flat_manifold_id &&
8918 std::find(attached_mids.begin(), attached_mids.end(), i) ==
8920 const_cast<Triangulation<dim - 1, spacedim> &>(
8921 surface_mesh.get_triangulation())
8922 .set_manifold(i, FlatManifold<dim - 1, spacedim>());
8923
8925 }
8926
8927
8928
8929 template <int dim, int spacedim>
8930 void
8933 const std::vector<unsigned int> &repetitions,
8934 const Point<dim> &p1,
8935 const Point<dim> &p2,
8936 const bool colorize)
8937 {
8938 AssertDimension(dim, spacedim);
8939
8940 std::vector<Point<spacedim>> vertices;
8941 std::vector<CellData<dim>> cells;
8942
8943 if (dim == 2)
8944 {
8945 // determine cell sizes
8946 const Point<dim> dx((p2[0] - p1[0]) / repetitions[0],
8947 (p2[1] - p1[1]) / repetitions[1]);
8948
8949 // create vertices
8950 for (unsigned int j = 0; j <= repetitions[1]; ++j)
8951 for (unsigned int i = 0; i <= repetitions[0]; ++i)
8952 vertices.push_back(
8953 Point<spacedim>(p1[0] + dx[0] * i, p1[1] + dx[1] * j));
8954
8955 // create cells
8956 for (unsigned int j = 0; j < repetitions[1]; ++j)
8957 for (unsigned int i = 0; i < repetitions[0]; ++i)
8958 {
8959 // create reference QUAD cell
8960 std::array<unsigned int, 4> quad{{
8961 (j + 0) * (repetitions[0] + 1) + i + 0, //
8962 (j + 0) * (repetitions[0] + 1) + i + 1, //
8963 (j + 1) * (repetitions[0] + 1) + i + 0, //
8964 (j + 1) * (repetitions[0] + 1) + i + 1 //
8965 }}; //
8966
8967 // TRI cell 0
8968 {
8970 tri.vertices = {quad[0], quad[1], quad[2]};
8971 cells.push_back(tri);
8972 }
8973
8974 // TRI cell 1
8975 {
8977 tri.vertices = {quad[3], quad[2], quad[1]};
8978 cells.push_back(tri);
8979 }
8980 }
8981 }
8982 else if (dim == 3)
8983 {
8984 // determine cell sizes
8985 const Point<dim> dx((p2[0] - p1[0]) / repetitions[0],
8986 (p2[1] - p1[1]) / repetitions[1],
8987 (p2[2] - p1[2]) / repetitions[2]);
8988
8989 // create vertices
8990 for (unsigned int k = 0; k <= repetitions[2]; ++k)
8991 for (unsigned int j = 0; j <= repetitions[1]; ++j)
8992 for (unsigned int i = 0; i <= repetitions[0]; ++i)
8993 vertices.push_back(Point<spacedim>(p1[0] + dx[0] * i,
8994 p1[1] + dx[1] * j,
8995 p1[2] + dx[2] * k));
8996
8997 // create cells
8998 for (unsigned int k = 0; k < repetitions[2]; ++k)
8999 for (unsigned int j = 0; j < repetitions[1]; ++j)
9000 for (unsigned int i = 0; i < repetitions[0]; ++i)
9001 {
9002 // create reference HEX cell
9003 std::array<unsigned int, 8> quad{
9004 {(k + 0) * (repetitions[0] + 1) * (repetitions[1] + 1) +
9005 (j + 0) * (repetitions[0] + 1) + i + 0,
9006 (k + 0) * (repetitions[0] + 1) * (repetitions[1] + 1) +
9007 (j + 0) * (repetitions[0] + 1) + i + 1,
9008 (k + 0) * (repetitions[0] + 1) * (repetitions[1] + 1) +
9009 (j + 1) * (repetitions[0] + 1) + i + 0,
9010 (k + 0) * (repetitions[0] + 1) * (repetitions[1] + 1) +
9011 (j + 1) * (repetitions[0] + 1) + i + 1,
9012 (k + 1) * (repetitions[0] + 1) * (repetitions[1] + 1) +
9013 (j + 0) * (repetitions[0] + 1) + i + 0,
9014 (k + 1) * (repetitions[0] + 1) * (repetitions[1] + 1) +
9015 (j + 0) * (repetitions[0] + 1) + i + 1,
9016 (k + 1) * (repetitions[0] + 1) * (repetitions[1] + 1) +
9017 (j + 1) * (repetitions[0] + 1) + i + 0,
9018 (k + 1) * (repetitions[0] + 1) * (repetitions[1] + 1) +
9019 (j + 1) * (repetitions[0] + 1) + i + 1}};
9020
9021 // TET cell 0
9022 {
9023 CellData<dim> cell;
9024 if (((i % 2) + (j % 2) + (k % 2)) % 2 == 0)
9025 cell.vertices = {{quad[0], quad[1], quad[2], quad[4]}};
9026 else
9027 cell.vertices = {{quad[0], quad[1], quad[3], quad[5]}};
9028
9029 cells.push_back(cell);
9030 }
9031
9032 // TET cell 1
9033 {
9034 CellData<dim> cell;
9035 if (((i % 2) + (j % 2) + (k % 2)) % 2 == 0)
9036 cell.vertices = {{quad[2], quad[1], quad[3], quad[7]}};
9037 else
9038 cell.vertices = {{quad[0], quad[3], quad[2], quad[6]}};
9039 cells.push_back(cell);
9040 }
9041
9042 // TET cell 2
9043 {
9044 CellData<dim> cell;
9045 if (((i % 2) + (j % 2) + (k % 2)) % 2 == 0)
9046 cell.vertices = {{quad[1], quad[4], quad[5], quad[7]}};
9047 else
9048 cell.vertices = {{quad[0], quad[4], quad[5], quad[6]}};
9049 cells.push_back(cell);
9050 }
9051
9052 // TET cell 3
9053 {
9054 CellData<dim> cell;
9055 if (((i % 2) + (j % 2) + (k % 2)) % 2 == 0)
9056 cell.vertices = {{quad[2], quad[4], quad[7], quad[6]}};
9057 else
9058 cell.vertices = {{quad[3], quad[5], quad[7], quad[6]}};
9059 cells.push_back(cell);
9060 }
9061
9062 // TET cell 4
9063 {
9064 CellData<dim> cell;
9065 if (((i % 2) + (j % 2) + (k % 2)) % 2 == 0)
9066 cell.vertices = {{quad[1], quad[2], quad[4], quad[7]}};
9067 else
9068 cell.vertices = {{quad[0], quad[3], quad[6], quad[5]}};
9069 cells.push_back(cell);
9070 }
9071 }
9072 }
9073 else
9074 {
9076 }
9077
9078 // actually create triangulation
9079 tria.create_triangulation(vertices, cells, SubCellData());
9080
9081 if (colorize)
9082 {
9083 // to colorize, run through all
9084 // faces of all cells and set
9085 // boundary indicator to the
9086 // correct value if it was 0.
9087
9088 // use a large epsilon to
9089 // compare numbers to avoid
9090 // roundoff problems.
9091 double epsilon = std::numeric_limits<double>::max();
9092 for (unsigned int i = 0; i < dim; ++i)
9093 epsilon = std::min(epsilon,
9094 0.01 * (std::abs(p2[i] - p1[i]) / repetitions[i]));
9095 Assert(epsilon > 0,
9096 ExcMessage(
9097 "The distance between corner points must be positive."));
9098
9099 // actual code is external since
9100 // 1-D is different from 2/3d.
9101 colorize_subdivided_hyper_rectangle(tria, p1, p2, epsilon);
9102 }
9103 }
9104
9105
9106
9107 template <int dim, int spacedim>
9108 void
9110 const unsigned int repetitions,
9111 const double p1,
9112 const double p2,
9113 const bool colorize)
9114 {
9115 if (dim == 2)
9116 {
9118 tria, {{repetitions, repetitions}}, {p1, p1}, {p2, p2}, colorize);
9119 }
9120 else if (dim == 3)
9121 {
9123 tria,
9125 {p1, p1, p1},
9126 {p2, p2, p2},
9127 colorize);
9128 }
9129 else
9130 {
9132 }
9133 }
9134} // namespace GridGenerator
9135
9136// explicit instantiations
9137# include "grid/grid_generator.inst"
9138
9139#endif // DOXYGEN
9140
void add_parameter(const std::string &entry, ParameterType &parameter, const std::string &documentation="", const Patterns::PatternBase &pattern= *Patterns::Tools::Convert< ParameterType >::to_pattern(), const bool has_to_be_set=false)
void enter_subsection(const std::string &subsection, const bool create_path_if_needed=true)
Definition point.h:113
numbers::NumberTraits< Number >::real_type norm() const
constexpr void clear()
friend class Tensor
Definition tensor.h:865
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:518
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:190
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:519
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
Point< 2 > second
Definition grid_out.cc:4630
bool colorize
Definition grid_out.cc:4631
Point< 2 > first
Definition grid_out.cc:4629
unsigned int vertex_indices[2]
unsigned int cell_index
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcLowerRange(int arg1, int arg2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
void copy_boundary_to_manifold_id(Triangulation< dim, spacedim > &tria, const bool reset_boundary_ids=false)
void consistently_order_cells(std::vector< CellData< dim > > &cells)
#define DEAL_II_ASSERT_UNREACHABLE()
#define DEAL_II_NOT_IMPLEMENTED()
const Mapping< dim, spacedim > & get_default_linear_mapping(const Triangulation< dim, spacedim > &triangulation)
Definition mapping.cc:316
std::vector< index_type > data
Definition mpi.cc:740
std::size_t size
Definition mpi.cc:739
CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt K
Expression fabs(const Expression &x)
void interpolate(const DoFHandler< dim, spacedim > &dof1, const InVector &u1, const DoFHandler< dim, spacedim > &dof2, OutVector &u2)
void create_triangulation(Triangulation< dim, dim > &tria, const AdditionalData &additional_data=AdditionalData())
void subdivided_hyper_cube_with_simplices(Triangulation< dim, spacedim > &tria, const unsigned int repetitions, const double p1=0.0, const double p2=1.0, const bool colorize=false)
void parallelepiped(Triangulation< dim > &tria, const Point< dim >(&corners)[dim], const bool colorize=false)
void hyper_cross(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &sizes, const bool colorize_cells=false)
A center cell with stacks of cell protruding from each surface.
void hyper_cube_with_cylindrical_hole(Triangulation< dim, spacedim > &triangulation, const double inner_radius=.25, const double outer_radius=.5, const double L=.5, const unsigned int repetitions=1, const bool colorize=false)
void hyper_ball_balanced(Triangulation< dim > &tria, const Point< dim > &center=Point< dim >(), const double radius=1.)
void plate_with_a_hole(Triangulation< dim > &tria, const double inner_radius=0.4, const double outer_radius=1., const double pad_bottom=2., const double pad_top=2., const double pad_left=1., const double pad_right=1., const Point< dim > &center=Point< dim >(), const types::manifold_id polar_manifold_id=0, const types::manifold_id tfi_manifold_id=1, const double L=1., const unsigned int n_slices=2, const bool colorize=false)
Rectangular plate with an (offset) cylindrical hole.
void enclosed_hyper_cube(Triangulation< dim > &tria, const double left=0., const double right=1., const double thickness=1., const bool colorize=false)
void replicate_triangulation(const Triangulation< dim, spacedim > &input, const std::vector< unsigned int > &extents, Triangulation< dim, spacedim > &result)
Replicate a given triangulation in multiple coordinate axes.
void parallelogram(Triangulation< dim > &tria, const Point< dim >(&corners)[dim], const bool colorize=false)
void general_cell(Triangulation< dim, spacedim > &tria, const std::vector< Point< spacedim > > &vertices, const bool colorize=false)
void subdivided_hyper_cube(Triangulation< dim, spacedim > &tria, const unsigned int repetitions, const double left=0., const double right=1., const bool colorize=false)
void hyper_shell(Triangulation< dim, spacedim > &tria, const Point< spacedim > &center, const double inner_radius, const double outer_radius, const unsigned int n_cells=0, bool colorize=false)
void hyper_L(Triangulation< dim > &tria, const double left=-1., const double right=1., const bool colorize=false)
void hyper_cube_slit(Triangulation< dim > &tria, const double left=0., const double right=1., const bool colorize=false)
void eccentric_hyper_shell(Triangulation< dim > &triangulation, const Point< dim > &inner_center, const Point< dim > &outer_center, const double inner_radius, const double outer_radius, const unsigned int n_cells)
void hyper_rectangle(Triangulation< dim, spacedim > &tria, const Point< dim > &p1, const Point< dim > &p2, const bool colorize=false)
void cylinder(Triangulation< dim > &tria, const double radius=1., const double half_length=1.)
void moebius(Triangulation< 3, 3 > &tria, const unsigned int n_cells, const unsigned int n_rotations, const double R, const double r)
void extrude_triangulation(const Triangulation< 2, 2 > &input, const unsigned int n_slices, const double height, Triangulation< 3, 3 > &result, const bool copy_manifold_ids=false, const std::vector< types::manifold_id > &manifold_priorities={})
void half_hyper_shell(Triangulation< dim > &tria, const Point< dim > &center, const double inner_radius, const double outer_radius, const unsigned int n_cells=0, const bool colorize=false)
void quarter_hyper_ball(Triangulation< dim > &tria, const Point< dim > &center=Point< dim >(), const double radius=1.)
void cheese(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &holes)
Rectangular domain with rectangular pattern of holes.
void create_union_triangulation(const Triangulation< dim, spacedim > &triangulation_1, const Triangulation< dim, spacedim > &triangulation_2, Triangulation< dim, spacedim > &result)
void hyper_ball(Triangulation< dim, spacedim > &tria, const Point< spacedim > &center={}, const double radius=1., const bool attach_spherical_manifold_on_boundary_cells=false)
void subdivided_hyper_rectangle_with_simplices(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &repetitions, const Point< dim > &p1, const Point< dim > &p2, const bool colorize=false)
void non_standard_orientation_mesh(Triangulation< 2 > &tria, const unsigned int n_rotate_middle_square)
return_type extract_boundary_mesh(const MeshType< dim, spacedim > &volume_mesh, MeshType< dim - 1, spacedim > &surface_mesh, const std::set< types::boundary_id > &boundary_ids=std::set< types::boundary_id >())
void alfeld_split_of_simplex_mesh(const Triangulation< dim, spacedim > &in_tria, Triangulation< dim, spacedim > &out_tria)
void subdivided_parallelepiped(Triangulation< dim > &tria, const unsigned int n_subdivisions, const Point< dim >(&corners)[dim], const bool colorize=false)
void subdivided_cylinder(Triangulation< dim > &tria, const unsigned int x_subdivisions, const double radius=1., const double half_length=1.)
void channel_with_cylinder(Triangulation< dim > &tria, const double shell_region_width=0.03, const unsigned int n_shells=2, const double skewness=2.0, const bool colorize=false)
void subdivided_hyper_L(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &repetitions, const Point< dim > &bottom_left, const Point< dim > &top_right, const std::vector< int > &n_cells_to_remove)
void hyper_sphere(Triangulation< spacedim - 1, spacedim > &tria, const Point< spacedim > &center=Point< spacedim >(), const double radius=1.)
void concentric_hyper_shells(Triangulation< dim > &triangulation, const Point< dim > &center, const double inner_radius=0.125, const double outer_radius=0.25, const unsigned int n_shells=1, const double skewness=0.1, const unsigned int n_cells_per_shell=0, const bool colorize=false)
void convert_hypercube_to_simplex_mesh(const Triangulation< dim, spacedim > &in_tria, Triangulation< dim, spacedim > &out_tria)
void subdivided_hyper_rectangle(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &repetitions, const Point< dim > &p1, const Point< dim > &p2, const bool colorize=false)
void quarter_hyper_shell(Triangulation< dim > &tria, const Point< dim > &center, const double inner_radius, const double outer_radius, const unsigned int n_cells=0, const bool colorize=false)
void hyper_cube(Triangulation< dim, spacedim > &tria, const double left=0., const double right=1., const bool colorize=false)
void create_triangulation_with_removed_cells(const Triangulation< dim, spacedim > &input_triangulation, const std::set< typename Triangulation< dim, spacedim >::active_cell_iterator > &cells_to_remove, Triangulation< dim, spacedim > &result)
void simplex(Triangulation< dim, dim > &tria, const std::vector< Point< dim > > &vertices)
void truncated_cone(Triangulation< dim > &tria, const double radius_0=1.0, const double radius_1=0.5, const double half_length=1.0)
void merge_triangulations(const Triangulation< dim, spacedim > &triangulation_1, const Triangulation< dim, spacedim > &triangulation_2, Triangulation< dim, spacedim > &result, const double duplicated_vertex_tolerance=1.0e-12, const bool copy_manifold_ids=false, const bool copy_boundary_ids=false)
void reference_cell(Triangulation< dim, spacedim > &tria, const ReferenceCell &reference_cell)
void half_hyper_ball(Triangulation< dim > &tria, const Point< dim > &center=Point< dim >(), const double radius=1.)
void cylinder_shell(Triangulation< dim > &tria, const double length, const double inner_radius, const double outer_radius, const unsigned int n_radial_cells=0, const unsigned int n_axial_cells=0, const bool colorize=false)
void flatten_triangulation(const Triangulation< dim, spacedim1 > &in_tria, Triangulation< dim, spacedim2 > &out_tria)
void delete_unused_vertices(std::vector< Point< spacedim > > &vertices, std::vector< CellData< dim > > &cells, SubCellData &subcelldata)
void scale(const double scaling_factor, Triangulation< dim, spacedim > &triangulation)
void rotate(const double angle, Triangulation< dim, spacedim > &triangulation)
void transform(const Transformation &transformation, Triangulation< dim, spacedim > &triangulation)
void shift(const Tensor< 1, spacedim > &shift_vector, Triangulation< dim, spacedim > &triangulation)
void collect_periodic_faces(const MeshType &mesh, const types::boundary_id b_id1, const types::boundary_id b_id2, const unsigned int direction, std::vector< PeriodicFacePair< typename MeshType::cell_iterator > > &matched_pairs, const Tensor< 1, MeshType::space_dimension > &offset=::Tensor< 1, MeshType::space_dimension >(), const FullMatrix< double > &matrix=FullMatrix< double >())
void delete_duplicated_vertices(std::vector< Point< spacedim > > &all_vertices, std::vector< CellData< dim > > &cells, SubCellData &subcelldata, std::vector< unsigned int > &considered_vertices, const double tol=1e-12)
bool have_same_coarse_mesh(const Triangulation< dim, spacedim > &mesh_1, const Triangulation< dim, spacedim > &mesh_2)
double volume(const Triangulation< dim, spacedim > &tria)
void invert_all_negative_measure_cells(const std::vector< Point< spacedim > > &all_vertices, std::vector< CellData< dim > > &cells)
std::tuple< std::vector< Point< spacedim > >, std::vector< CellData< dim > >, SubCellData > get_coarse_mesh_description(const Triangulation< dim, spacedim > &tria)
constexpr char L
constexpr char N
constexpr char U
constexpr char A
double norm(const FEValuesBase< dim > &fe, const ArrayView< const std::vector< Tensor< 1, dim > > > &Du)
Definition divergence.h:471
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition utilities.cc:193
SymmetricTensor< 2, dim, Number > C(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > epsilon(const Tensor< 2, dim, Number > &Grad_u)
Tensor< 2, dim, Number > F(const Tensor< 2, dim, Number > &Grad_u)
Tensor< 2, 2, Number > rotation_matrix_2d(const Number &angle)
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
constexpr T fixed_power(const T t)
Definition utilities.h:943
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
Definition utilities.cc:474
long double gamma(const unsigned int n)
unsigned int n_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
Definition tria.cc:14889
void copy(const T *begin, const T *end, U *dest)
constexpr double PI_2
Definition numbers.h:246
constexpr double E
Definition numbers.h:216
constexpr double PI
Definition numbers.h:241
constexpr unsigned int invalid_unsigned_int
Definition types.h:232
constexpr types::boundary_id internal_face_boundary_id
Definition types.h:323
constexpr types::boundary_id invalid_boundary_id
Definition types.h:303
constexpr types::manifold_id flat_manifold_id
Definition types.h:336
constexpr types::material_id invalid_material_id
Definition types.h:288
STL namespace.
::VectorizedArray< Number, width > tan(const ::VectorizedArray< Number, width > &)
inline ::VectorizedArray< Number, width > tanh(const ::VectorizedArray< Number, width > &x)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > cos(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sin(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)
inline ::VectorizedArray< Number, width > atan(const ::VectorizedArray< Number, width > &x)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
unsigned int manifold_id
Definition types.h:165
unsigned int material_id
Definition types.h:176
unsigned int boundary_id
Definition types.h:153
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
static unsigned int face_to_cell_vertices(const unsigned int face, const unsigned int vertex, const bool face_orientation=true, const bool face_flip=false, const bool face_rotation=false)
DEAL_II_HOST constexpr Number determinant(const SymmetricTensor< 2, dim, Number > &)