ryujin 2.1.1 revision 0348cbb53a3e4b1da2a4c037e81f88f2d21ce219
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 : cell->vertex_indices()) {
104 auto &vertex = cell->vertex(v);
105 if (vertex[0] <= -cylinder_diameter + 1.e-6)
106 vertex[0] = -cylinder_position;
107 }
108
109 /*
110 * Set boundary ids:
111 */
112
113 for (auto cell : triangulation.active_cell_iterators()) {
114 for (auto f : cell->face_indices()) {
115 const auto face = cell->face(f);
116
117 if (!face->at_boundary())
118 continue;
119
120 /*
121 * We want slip boundary conditions (i.e. indicator 1) at top and
122 * bottom of the channel, as well as on the obstacle. On the left
123 * side we set inflow conditions (indicator 2) and on the right
124 * side we set indicator 0, i.e. do nothing.
125 */
126
127 const auto center = face->center();
128
129 if (center[0] > length - cylinder_position - 1.e-6) {
130 face->set_boundary_id(Boundary::do_nothing);
131 continue;
132 }
133
134 if (center[0] < -cylinder_position + 1.e-6) {
135 face->set_boundary_id(Boundary::dirichlet);
136 continue;
137 }
138
139 // the rest:
140 face->set_boundary_id(Boundary::slip);
141 }
142 }
143 }
144
145
146 template <template <int, int> class Triangulation>
147 void cylinder(Triangulation<3, 3> &triangulation,
148 const double length,
149 const double height,
150 const double cylinder_position,
151 const double cylinder_diameter)
152 {
153 using namespace dealii;
154
155 dealii::Triangulation<2, 2> tria1;
156
157 cylinder(tria1, length, height, cylinder_position, cylinder_diameter);
158
159 dealii::Triangulation<3, 3> tria2;
160 tria2.set_mesh_smoothing(triangulation.get_mesh_smoothing());
161
162 GridGenerator::extrude_triangulation(tria1, 4, height, tria2, true);
163 GridTools::transform(
164 [height](auto point) {
165 return point - dealii::Tensor<1, 3>{{0, 0, height / 2.}};
166 },
167 tria2);
168
169 triangulation.copy_triangulation(tria2);
170
171 /*
172 * Reattach an appropriate manifold ID:
173 */
174
175 triangulation.set_manifold(
176 0, CylindricalManifold<3>(Tensor<1, 3>{{0., 0., 1.}}, Point<3>()));
177
178 /*
179 * Set boundary ids:
180 */
181
182 for (auto cell : triangulation.active_cell_iterators()) {
183 for (auto f : cell->face_indices()) {
184 const auto face = cell->face(f);
185
186 if (!face->at_boundary())
187 continue;
188
189 /*
190 * We want slip boundary conditions (i.e. indicator 1) almost
191 * everywhere except on the faces with normal in x-direction.
192 * There, on the left side we set inflow conditions (indicator 2)
193 * and on the right side we set indicator 0, i.e. do nothing.
194 */
195
196 const auto center = face->center();
197
198 if (center[0] > length - cylinder_position - 1.e-6) {
199 face->set_boundary_id(Boundary::do_nothing);
200 continue;
201 }
202
203 if (center[0] < -cylinder_position + 1.e-6) {
204 face->set_boundary_id(Boundary::dirichlet);
205 continue;
206 }
207
208 // the rest:
209 face->set_boundary_id(Boundary::slip);
210 }
211 }
212 }
213#endif
214 } /* namespace GridGenerator */
215
216
217 namespace Geometries
218 {
225 template <int dim>
226 class Cylinder : public Geometry<dim>
227 {
228 public:
229 Cylinder(const std::string subsection)
230 : Geometry<dim>("cylinder", subsection)
231 {
232 length_ = 4.;
233 this->add_parameter(
234 "length", length_, "length of computational domain");
235
236 height_ = 2.;
237 this->add_parameter(
238 "height", height_, "height of computational domain");
239
240 object_position_ = 0.6;
241 this->add_parameter("object position",
242 object_position_,
243 "x position of immersed cylinder center point");
244
245 object_diameter_ = 0.5;
246 this->add_parameter("object diameter",
247 object_diameter_,
248 "diameter of immersed cylinder");
249 }
250
252 typename Geometry<dim>::Triangulation &triangulation) final
253 {
254 GridGenerator::cylinder(triangulation,
255 length_,
256 height_,
257 object_position_,
258 object_diameter_);
259 }
260
261 private:
262 double length_;
263 double height_;
264 double object_position_;
265 double object_diameter_;
266 };
267 } /* namespace Geometries */
268} /* 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)