12 namespace GridGenerator
22 template <
int dim,
int spacedim,
template <
int,
int>
class Triangulation>
23 void annulus(Triangulation<dim, spacedim> &,
29 AssertThrow(
false, dealii::ExcNotImplemented());
35 template <
template <
int,
int>
class Triangulation>
36 void annulus(Triangulation<2, 2> &triangulation,
38 const double inner_radius,
39 const double outer_radius,
42 constexpr int dim = 2;
43 constexpr double eps = 1.0e-10;
45 using namespace dealii;
52 const auto assign_manifolds = [&](
auto &tria) {
53 for (
const auto &cell : tria.cell_iterators()) {
58 bool cell_on_annulus =
true;
59 for (
unsigned int v : cell->vertex_indices()) {
60 const auto vertex = cell->vertex(v);
61 const auto distance = vertex.norm();
62 if (!(inner_radius - eps <= distance && distance <= outer_radius)) {
63 cell_on_annulus =
false;
68 cell->set_all_manifold_ids(1);
73 for (
const unsigned int f : cell->face_indices()) {
74 const auto face = cell->face(f);
76 bool face_on_annulus =
true;
77 for (
unsigned int v : face->vertex_indices()) {
78 const auto vertex = face->vertex(v);
79 const auto distance = vertex.norm();
80 if (!(inner_radius - eps <= distance &&
81 distance <= outer_radius)) {
82 face_on_annulus =
false;
87 face->set_all_manifold_ids(1);
91 tria.set_manifold(1, SphericalManifold<dim>());
92 dealii::TransfiniteInterpolationManifold<dim> transfinite_manifold;
93 transfinite_manifold.initialize(tria);
94 tria.set_manifold(0, transfinite_manifold);
98 dealii::Triangulation<dim> tria_inner;
100 dealii::Triangulation<dim> temp;
101 GridGenerator::hyper_ball_balanced(
102 temp, dealii::Point<dim>(), inner_radius);
103 temp.refine_global(2);
104 GridGenerator::flatten_triangulation(temp, tria_inner);
108 dealii::Triangulation<dim>
annulus;
109 GridGenerator::hyper_shell(
110 annulus, dealii::Point<dim>(), inner_radius, outer_radius, 32);
113 dealii::Triangulation<dim> tria_outer;
115 dealii::Triangulation<dim> temp;
116 GridGenerator::hyper_shell(temp,
117 dealii::Point<dim>(),
119 length / 2. * std::sqrt(2),
122 for (
const auto &cell : temp.cell_iterators()) {
123 static_assert(dim == 2,
"not implemented");
124 for (
unsigned int i = 0; i < 4; ++i) {
125 auto &vertex = cell->vertex(i);
126 if (std::abs(vertex[0]) < eps && std::abs(vertex[1]) > length / 2.)
127 vertex[1] = std::copysign(length / 2., vertex[1]);
128 if (std::abs(vertex[1]) < eps && std::abs(vertex[0]) > length / 2.)
129 vertex[0] = std::copysign(length / 2., vertex[0]);
132 assign_manifolds(temp);
133 temp.refine_global(2);
134 GridGenerator::flatten_triangulation(temp, tria_outer);
138 dealii::Triangulation<dim, dim> coarse_triangulation;
139 coarse_triangulation.set_mesh_smoothing(
140 triangulation.get_mesh_smoothing());
141 GridGenerator::merge_triangulations(
142 {&tria_inner, &
annulus, &tria_outer}, coarse_triangulation, 1.e-12);
148 coarse_triangulation.reset_all_manifolds();
149 coarse_triangulation.set_all_manifold_ids(0);
151 assign_manifolds(coarse_triangulation);
152 coarse_triangulation.refine_global(2);
156 std::set<typename dealii::Triangulation<dim>::active_cell_iterator>
159 for (
const auto &cell : coarse_triangulation.active_cell_iterators()) {
160 for (
auto f : cell->face_indices()) {
161 auto face = cell->face(f);
162 const auto position = face->center();
163 const auto radius = position.norm();
164 const auto inner_value = inner_radius;
165 const auto outer_value = outer_radius;
168 radius - inner_value > 1.e-8 && outer_value - radius > 1.e-3;
170 bool partial_annulus =
171 std::abs(position[1]) -
172 std::abs(position[0]) *
173 std::tan(dealii::numbers::PI / 180. * angle) <
176 if (in_anulus && partial_annulus) {
177 cells_to_remove.insert(cell);
182 GridGenerator::create_triangulation_with_removed_cells(
183 coarse_triangulation, cells_to_remove, coarse_triangulation);
188 dealii::Triangulation<dim> flattened_triangulation;
189 flattened_triangulation.set_mesh_smoothing(
190 triangulation.get_mesh_smoothing());
191 GridGenerator::flatten_triangulation(coarse_triangulation,
192 flattened_triangulation);
193 triangulation.copy_triangulation(flattened_triangulation);
194 assign_manifolds(triangulation);
201 for (
auto cell : triangulation.active_cell_iterators()) {
202 for (
auto f : cell->face_indices()) {
203 const auto face = cell->face(f);
205 if (!face->at_boundary())
217 template <
template <
int,
int>
class Triangulation>
218 void annulus(Triangulation<3, 3> & ,
224 using namespace dealii;
225 AssertThrow(
false, dealii::ExcNotImplemented());
245 :
Geometry<dim>(
"annulus", subsection)
249 "length", length_,
"length of computational domain [-L/2,L/2]^d");
253 "inner radius", inner_radius_,
"inner radius of partial annulus");
257 "outer radius", outer_radius_,
"outer radius of partial annulus");
260 this->add_parameter(
"coverage angle",
262 "angle coverage of partial annulus above y-axis");
269 triangulation, length_, inner_radius_, outer_radius_, angle_);
274 double inner_radius_;
275 double outer_radius_;
Annulus(const std::string subsection)
void create_triangulation(typename Geometry< dim >::Triangulation &triangulation) final
typename Discretization< dim >::Triangulation Triangulation
void annulus(Triangulation< dim, spacedim > &, const double, const double, const double, const double)