ryujin 2.1.1 revision feb53359f0c9a08baf43c3dfe847d8a9f7d6893a
geometry_cylinder.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2022 - 2023 by the ryujin authors
4//
5
6#pragma once
7
9
10namespace ryujin
11{
12 namespace GridGenerator
13 {
28 template <int dim, int spacedim, template <int, int> class Triangulation>
29 void cylinder(Triangulation<dim, spacedim> &,
30 const double /*length*/,
31 const double /*height*/,
32 const double /*cylinder_position*/,
33 const double /*cylinder_height*/)
34 {
35 AssertThrow(false, dealii::ExcNotImplemented());
36 __builtin_trap();
37 }
38
39
40#ifndef DOXYGEN
41 template <template <int, int> class Triangulation>
42 void cylinder(Triangulation<2, 2> &triangulation,
43 const double length,
44 const double height,
45 const double cylinder_position,
46 const double cylinder_diameter)
47 {
48 constexpr int dim = 2;
49
50 using namespace dealii;
51
52 dealii::Triangulation<dim, dim> tria1, tria2, tria3, tria4, tria5, tria6,
53 tria7;
54
55 GridGenerator::hyper_cube_with_cylindrical_hole(
56 tria1, cylinder_diameter / 2., cylinder_diameter, 0.5, 1, false);
57
58 GridGenerator::subdivided_hyper_rectangle(
59 tria2,
60 {2, 1},
61 Point<2>(-cylinder_diameter, -cylinder_diameter),
62 Point<2>(cylinder_diameter, -height / 2.));
63
64 GridGenerator::subdivided_hyper_rectangle(
65 tria3,
66 {2, 1},
67 Point<2>(-cylinder_diameter, cylinder_diameter),
68 Point<2>(cylinder_diameter, height / 2.));
69
70 GridGenerator::subdivided_hyper_rectangle(
71 tria4,
72 {6, 2},
73 Point<2>(cylinder_diameter, -cylinder_diameter),
74 Point<2>(length - cylinder_position, cylinder_diameter));
75
76 GridGenerator::subdivided_hyper_rectangle(
77 tria5,
78 {6, 1},
79 Point<2>(cylinder_diameter, cylinder_diameter),
80 Point<2>(length - cylinder_position, height / 2.));
81
82 GridGenerator::subdivided_hyper_rectangle(
83 tria6,
84 {6, 1},
85 Point<2>(cylinder_diameter, -height / 2.),
86 Point<2>(length - cylinder_position, -cylinder_diameter));
87
88 tria7.set_mesh_smoothing(triangulation.get_mesh_smoothing());
89 GridGenerator::merge_triangulations(
90 {&tria1, &tria2, &tria3, &tria4, &tria5, &tria6},
91 tria7,
92 1.e-12,
93 true);
94 triangulation.copy_triangulation(tria7);
95
96 /* Restore polar manifold for disc: */
97
98 triangulation.set_manifold(0, PolarManifold<2>(Point<2>()));
99
100 /* Fix up position of left boundary: */
101
102 for (auto cell : triangulation.active_cell_iterators())
103 for (unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell;
104 ++v) {
105 auto &vertex = cell->vertex(v);
106 if (vertex[0] <= -cylinder_diameter + 1.e-6)
107 vertex[0] = -cylinder_position;
108 }
109
110 /*
111 * Set boundary ids:
112 */
113
114 for (auto cell : triangulation.active_cell_iterators()) {
115 for (auto f : GeometryInfo<2>::face_indices()) {
116 const auto face = cell->face(f);
117
118 if (!face->at_boundary())
119 continue;
120
121 /*
122 * We want slip boundary conditions (i.e. indicator 1) at top and
123 * bottom of the channel, as well as on the obstacle. On the left
124 * side we set inflow conditions (indicator 2) and on the right
125 * side we set indicator 0, i.e. do nothing.
126 */
127
128 const auto center = face->center();
129
130 if (center[0] > length - cylinder_position - 1.e-6) {
131 face->set_boundary_id(Boundary::do_nothing);
132 continue;
133 }
134
135 if (center[0] < -cylinder_position + 1.e-6) {
136 face->set_boundary_id(Boundary::dirichlet);
137 continue;
138 }
139
140 // the rest:
141 face->set_boundary_id(Boundary::slip);
142 }
143 }
144 }
145
146
147 template <template <int, int> class Triangulation>
148 void cylinder(Triangulation<3, 3> &triangulation,
149 const double length,
150 const double height,
151 const double cylinder_position,
152 const double cylinder_diameter)
153 {
154 using namespace dealii;
155
156 dealii::Triangulation<2, 2> tria1;
157
158 cylinder(tria1, length, height, cylinder_position, cylinder_diameter);
159
160 dealii::Triangulation<3, 3> tria2;
161 tria2.set_mesh_smoothing(triangulation.get_mesh_smoothing());
162
163 GridGenerator::extrude_triangulation(tria1, 4, height, tria2, true);
164 GridTools::transform(
165 [height](auto point) {
166 return point - dealii::Tensor<1, 3>{{0, 0, height / 2.}};
167 },
168 tria2);
169
170 triangulation.copy_triangulation(tria2);
171
172 /*
173 * Reattach an appropriate manifold ID:
174 */
175
176 triangulation.set_manifold(
177 0, CylindricalManifold<3>(Tensor<1, 3>{{0., 0., 1.}}, Point<3>()));
178
179 /*
180 * Set boundary ids:
181 */
182
183 for (auto cell : triangulation.active_cell_iterators()) {
184 for (auto f : GeometryInfo<3>::face_indices()) {
185 const auto face = cell->face(f);
186
187 if (!face->at_boundary())
188 continue;
189
190 /*
191 * We want slip boundary conditions (i.e. indicator 1) almost
192 * everywhere except on the faces with normal in x-direction.
193 * There, on the left side we set inflow conditions (indicator 2)
194 * and on the right side we set indicator 0, i.e. do nothing.
195 */
196
197 const auto center = face->center();
198
199 if (center[0] > length - cylinder_position - 1.e-6) {
200 face->set_boundary_id(Boundary::do_nothing);
201 continue;
202 }
203
204 if (center[0] < -cylinder_position + 1.e-6) {
205 face->set_boundary_id(Boundary::dirichlet);
206 continue;
207 }
208
209 // the rest:
210 face->set_boundary_id(Boundary::slip);
211 }
212 }
213 }
214#endif
215 } /* namespace GridGenerator */
216
217
218 namespace Geometries
219 {
226 template <int dim>
227 class Cylinder : public Geometry<dim>
228 {
229 public:
230 Cylinder(const std::string subsection)
231 : Geometry<dim>("cylinder", subsection)
232 {
233 length_ = 4.;
234 this->add_parameter(
235 "length", length_, "length of computational domain");
236
237 height_ = 2.;
238 this->add_parameter(
239 "height", height_, "height of computational domain");
240
241 object_position_ = 0.6;
242 this->add_parameter("object position",
243 object_position_,
244 "x position of immersed cylinder center point");
245
246 object_diameter_ = 0.5;
247 this->add_parameter("object diameter",
248 object_diameter_,
249 "diameter of immersed cylinder");
250 }
251
253 typename Geometry<dim>::Triangulation &triangulation) final
254 {
255 GridGenerator::cylinder(triangulation,
256 length_,
257 height_,
258 object_position_,
259 object_diameter_);
260 }
261
262 private:
263 double length_;
264 double height_;
265 double object_position_;
266 double object_diameter_;
267 };
268 } /* namespace Geometries */
269} /* namespace ryujin */
Cylinder(const std::string subsection)
void create_triangulation(typename Geometry< dim >::Triangulation &triangulation) final
typename Discretization< dim >::Triangulation Triangulation
Definition: geometry.h:38
void cylinder(Triangulation< dim, spacedim > &, const double, const double, const double, const double)