https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ConcentricCircleMeshGenerator.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
11#include "CastUniquePointer.h"
12#include "libmesh/replicated_mesh.h"
13#include "libmesh/face_quad4.h"
14#include "libmesh/mesh_modification.h"
15#include "libmesh/serial_mesh.h"
16#include "libmesh/boundary_info.h"
17#include "libmesh/utility.h"
18#include "libmesh/mesh_smoother_laplace.h"
19
20// C++ includes
21#include <cmath> // provides round, not std::round (see http://www.cplusplus.com/reference/cmath/round/)
22
24
27{
29 params.addParam<std::vector<SubdomainName>>(
30 "subdomain_name",
31 "Name(s) of the subdomain(s) assigned to elements in each ring (and outer square)");
32 MooseEnum portion(
33 "full top_right top_left bottom_left bottom_right right_half left_half top_half bottom_half",
34 "full");
35 params.addRequiredParam<unsigned int>("num_sectors",
36 "num_sectors % 2 = 0, num_sectors > 0"
37 "Number of azimuthal sectors in each quadrant"
38 "'num_sectors' must be an even number.");
39 params.addRequiredParam<std::vector<Real>>("radii", "Radii of major concentric circles");
40 params.addRequiredParam<std::vector<unsigned int>>(
41 "rings", "Number of rings in each circle or in the enclosing square");
42 params.addRequiredParam<bool>(
43 "has_outer_square",
44 "It determines if meshes for a outer square are added to concentric circle meshes.");
45 params.addRangeCheckedParam<Real>(
46 "pitch",
47 0.0,
48 "pitch>=0.0",
49 "The enclosing square can be added to the completed concentric circle mesh."
50 "Elements are quad meshes.");
51 params.addParam<MooseEnum>("portion", portion, "Control of which part of mesh is created");
52 params.addRequiredParam<bool>(
53 "preserve_volumes", "Volume of concentric circles can be preserved using this function.");
54 params.addParam<std::string>("boundary_name_prefix", "", "Prefix to prepend to boundary names");
55 params.addParam<unsigned int>("smoothing_max_it", 1, "Number of Laplacian smoothing iterations");
57 "This ConcentricCircleMeshGenerator source code is to generate concentric "
58 "circle meshes.");
59
60 return params;
61}
62
64 : MeshGenerator(parameters),
65 _num_sectors(getParam<unsigned int>("num_sectors")),
66 _radii(getParam<std::vector<Real>>("radii")),
67 _rings(getParam<std::vector<unsigned int>>("rings")),
68 _has_outer_square(getParam<bool>("has_outer_square")),
69 _pitch(getParam<Real>("pitch")),
70 _preserve_volumes(getParam<bool>("preserve_volumes")),
71 _smoothing_max_it(getParam<unsigned int>("smoothing_max_it")),
72 _portion(getParam<MooseEnum>("portion")),
73 _boundary_name_prefix(getParam<std::string>("boundary_name_prefix"))
74{
75 declareMeshProperty("use_distributed_mesh", false);
76
77 if (_num_sectors % 2 != 0)
78 paramError("num_sectors", "must be an even number.");
79
80 // radii data check
81 for (unsigned i = 0; i < _radii.size() - 1; ++i)
82 {
83 if (_radii[i] == 0.0)
84 paramError("radii", "must be positive numbers.");
85 if (_radii[i] > _radii[i + 1])
86 paramError("radii",
87 "must be provided in order by starting with the smallest radius providing the "
88 "following gradual radii.");
89 }
90
91 // size of 'rings' check
93 {
94 if (_rings.size() != _radii.size() + 1)
95 paramError("rings", "The size of 'rings' must be equal to the size of 'radii' plus 1.");
96 }
97 else
98 {
99 if (_rings.size() != _radii.size())
100 paramError("rings", "The size of 'rings' must be equal to the size of 'radii'.");
101 }
102 // pitch / 2 must be bigger than any raddi.
104 for (unsigned i = 0; i < _radii.size(); ++i)
105 if (_pitch / 2 < _radii[i])
106 paramError("pitch", "The pitch / 2 must be larger than any radii.");
107}
108
109std::unique_ptr<MeshBase>
111{
112 auto mesh = buildReplicatedMesh(2);
113 BoundaryInfo & boundary_info = mesh->get_boundary_info();
114
115 // Creating real mesh concentric circles
116 // i: index for _rings, j: index for _radii
117 std::vector<Real> radii_all_circles;
118 std::vector<Real> cum_num_rings(_radii.size());
119 unsigned int j = 0;
120 while (j < _radii.size())
121 {
122 // Keep track of number of rings
123 cum_num_rings[j] = ((j > 0) ? cum_num_rings[j - 1] : 0) + _rings[j];
124
125 unsigned int i = 0;
126 if (j == 0)
127 while (i < _rings[j])
128 {
129 radii_all_circles.push_back(_radii[j] / (_num_sectors / 2 + _rings[j]) *
130 (i + _num_sectors / 2 + 1));
131 ++i;
132 }
133 else
134 while (i < _rings[j])
135 {
136 radii_all_circles.push_back(_radii[j - 1] +
137 (_radii[j] - _radii[j - 1]) / _rings[j] * (i + 1));
138 ++i;
139 }
140 ++j;
141 }
142
143 // volume preserving function is used to conserve volume.
144 const Real d_angle = M_PI / 2 / _num_sectors;
145
147 {
148 Real original_radius = 0.0;
149 for (unsigned i = 0; i < radii_all_circles.size(); ++i)
150 {
151 // volume preserving function for the center circle
152 if (i == 0)
153 {
154 const Real target_area = M_PI * Utility::pow<2>(radii_all_circles[i]);
155 Real modified_radius = std::sqrt(2 * target_area / std::sin(d_angle) / _num_sectors / 4);
156 original_radius = radii_all_circles[i];
157 radii_all_circles[i] = modified_radius;
158 }
159 else
160 {
161 // volume preserving functions for outer circles
162 const Real target_area =
163 M_PI * (Utility::pow<2>(radii_all_circles[i]) - Utility::pow<2>(original_radius));
164 Real modified_radius = std::sqrt(target_area / std::sin(d_angle) / _num_sectors / 2 +
165 Utility::pow<2>(radii_all_circles[i - 1]));
166 original_radius = radii_all_circles[i];
167 radii_all_circles[i] = modified_radius;
168 }
169 }
170 }
171
172 // number of total nodes
173 unsigned num_total_nodes = 0;
174
176 num_total_nodes = Utility::pow<2>(_num_sectors / 2 + 1) +
177 (_num_sectors + 1) * radii_all_circles.size() +
178 Utility::pow<2>(_rings.back() + 2) + _num_sectors * (_rings.back() + 1) - 1;
179 else
180 num_total_nodes =
181 Utility::pow<2>(_num_sectors / 2 + 1) + (_num_sectors + 1) * radii_all_circles.size();
182
183 std::vector<Node *> nodes(num_total_nodes);
184
185 unsigned node_id = 0;
186
187 // for adding nodes for the square at the center of the circle
188 Real xx = radii_all_circles[0] / (_num_sectors / 2 + 1) * _num_sectors / 2;
189 Point p1 = Point(xx, 0, 0);
190 Point p2 = Point(0, xx, 0);
191 Point p3 = Point(xx * std::sqrt(2.0) / 2, xx * std::sqrt(2.0) / 2, 0);
192 for (unsigned i = 0; i <= _num_sectors / 2; ++i)
193 {
194 Real fx = i / (_num_sectors / 2.0);
195 for (unsigned j = 0; j <= _num_sectors / 2; ++j)
196 {
197 Real fy = j / (_num_sectors / 2.0);
198 Point p = p1 * fx * (1 - fy) + p2 * fy * (1 - fx) + p3 * fx * fy;
199 nodes[node_id] = mesh->add_point(p, node_id);
200 ++node_id;
201 }
202 }
203
204 // for adding the outer layers of the square
205 Real current_radius = radii_all_circles[0];
206
207 // for adding the outer circles of the square.
208 for (unsigned layers = 0; layers < radii_all_circles.size(); ++layers)
209 {
210 current_radius = radii_all_circles[layers];
211 for (unsigned num_outer_nodes = 0; num_outer_nodes <= _num_sectors; ++num_outer_nodes)
212 {
213 const Real x = current_radius * std::cos(num_outer_nodes * d_angle);
214 const Real y = current_radius * std::sin(num_outer_nodes * d_angle);
215 nodes[node_id] = mesh->add_point(Point(x, y, 0.0), node_id);
216 ++node_id;
217 }
218 }
219
220 // adding nodes for the enclosing square.
221 // adding nodes for the left edge of the square.
222 // applying the method for partitioning the line segments.
223
225 {
226 // putting nodes for the left side of the enclosing square.
227 for (unsigned i = 0; i <= _num_sectors / 2; ++i)
228 {
229 const Real a1 = (_pitch / 2) * i / (_num_sectors / 2 + _rings.back() + 1);
230 const Real b1 = _pitch / 2;
231
232 const Real a2 = radii_all_circles.back() * std::cos(M_PI / 2 - i * d_angle);
233 const Real b2 = radii_all_circles.back() * std::sin(M_PI / 2 - i * d_angle);
234
235 for (unsigned j = 0; j <= _rings.back(); ++j)
236 {
237 Real x = ((_rings.back() + 1 - j) * a1 + j * a2) / (_rings.back() + 1);
238 Real y = ((_rings.back() + 1 - j) * b1 + j * b2) / (_rings.back() + 1);
239 nodes[node_id] = mesh->add_point(Point(x, y, 0.0), node_id);
240 ++node_id;
241 }
242 }
243 // putting nodes for the center part of the enclosing square.
244 unsigned k = 1;
245 for (unsigned i = 1; i <= _rings.back() + 1; ++i)
246 {
247 const Real a1 =
248 (_pitch / 2) * (i + _num_sectors / 2) / (_num_sectors / 2 + _rings.back() + 1);
249 const Real b1 = _pitch / 2;
250
251 const Real a2 = _pitch / 2;
252 const Real b2 = (_pitch / 2) * (_num_sectors / 2) / (_num_sectors / 2 + _rings.back() + 1);
253
254 const Real a3 = radii_all_circles.back() * std::cos(M_PI / 4);
255 const Real b3 = radii_all_circles.back() * std::sin(M_PI / 4);
256
257 const Real a4 = ((_rings.back() + 1 - k) * a3 + k * a2) / (_rings.back() + 1);
258 const Real b4 = ((_rings.back() + 1 - k) * b3 + k * b2) / (_rings.back() + 1);
259
260 for (unsigned j = 0; j <= _rings.back() + 1; ++j)
261 {
262 Real x = ((_rings.back() + 1 - j) * a1 + j * a4) / (_rings.back() + 1);
263 Real y = ((_rings.back() + 1 - j) * b1 + j * b4) / (_rings.back() + 1);
264 nodes[node_id] = mesh->add_point(Point(x, y, 0.0), node_id);
265 ++node_id;
266 }
267 ++k;
268 }
269
270 // putting nodes for the right part of the enclosing square.
271 for (unsigned i = 1; i <= _num_sectors / 2; ++i)
272 {
273 const Real a1 = _pitch / 2;
274 const Real b1 =
275 (_pitch / 2) * (_num_sectors / 2 - i) / (_num_sectors / 2 + _rings.back() + 1);
276
277 const Real a2 = radii_all_circles.back() * std::cos(M_PI / 4 - i * d_angle);
278 const Real b2 = radii_all_circles.back() * std::sin(M_PI / 4 - i * d_angle);
279
280 for (unsigned j = 0; j <= _rings.back(); ++j)
281 {
282 Real x = ((_rings.back() + 1 - j) * a1 + j * a2) / (_rings.back() + 1);
283 Real y = ((_rings.back() + 1 - j) * b1 + j * b2) / (_rings.back() + 1);
284 nodes[node_id] = mesh->add_point(Point(x, y, 0.0), node_id);
285 ++node_id;
286 }
287 }
288 }
289
290 // Currently, index, limit, counter variables use the int type because of the 'modulo' function.
291 // adding elements
292 int index = 0;
293 int limit = 0;
294 int standard = static_cast<int>(_num_sectors);
295
296 // This is to set the limit for the index
297 if (standard > 4)
298 {
299 int additional_term = 0;
300 int counter = standard;
301 while (counter > 4)
302 {
303 counter = counter - 2;
304 additional_term = additional_term + counter;
305 }
306 limit = standard + additional_term;
307 }
308 else if (standard == 4)
309 limit = standard;
310
311 // SubdomainIDs set up
312 std::vector<unsigned int> subdomainIDs;
313
314 // Assign subdomains per circle (multiple rings per circle). IDs start at 1 for backwards
315 // compatibility
316 for (unsigned int i = 0; i < _rings.size() - _has_outer_square; ++i)
317 subdomainIDs.push_back(i + 1);
318 // Assign outer square
320 subdomainIDs.push_back(subdomainIDs.back() + 1);
321
322 // adding elements in the square
323 while (index <= limit)
324 {
325 // inner circle area (polygonal core)
326 Elem * elem = mesh->add_elem(std::make_unique<Quad4>());
327 elem->set_node(0, nodes[index]);
328 elem->set_node(1, nodes[index + _num_sectors / 2 + 1]);
329 elem->set_node(2, nodes[index + _num_sectors / 2 + 2]);
330 elem->set_node(3, nodes[index + 1]);
331 elem->subdomain_id() = subdomainIDs[0];
332
333 if (index < standard / 2)
334 boundary_info.add_side(elem, 3, 1);
335 if (index % (standard / 2 + 1) == 0)
336 boundary_info.add_side(elem, 0, 2);
337
338 ++index;
339
340 // increment by 2 indices is necessary depending on where the index points to.
341 if ((index - standard / 2) % (standard / 2 + 1) == 0)
342 ++index;
343 }
344
345 index = (_num_sectors / 2 + 1) * (_num_sectors / 2);
346 limit = (_num_sectors / 2) * (_num_sectors / 2 + 2);
347
348 // adding elements in one outer layer of the square (right side)
349 while (index < limit)
350 {
351 // inner circle elements touching B
352 Elem * elem = mesh->add_elem(std::make_unique<Quad4>());
353 elem->set_node(0, nodes[index]);
354 elem->set_node(1, nodes[index + _num_sectors / 2 + 1]);
355 elem->set_node(2, nodes[index + _num_sectors / 2 + 2]);
356 elem->set_node(3, nodes[index + 1]);
357 elem->subdomain_id() = subdomainIDs[0];
358
359 if (index == (standard / 2 + 1) * (standard / 2))
360 boundary_info.add_side(elem, 0, 2);
361
362 ++index;
363 }
364
365 // adding elements in one outer layer of the square (left side)
366 int counter = 0;
367 while (index != standard / 2)
368 {
369 // inner circle elements touching C
370 Elem * elem = mesh->add_elem(std::make_unique<Quad4>());
371 elem->set_node(0, nodes[index]);
372 elem->set_node(1, nodes[index + (_num_sectors / 2 + 1) + counter * (_num_sectors / 2 + 2)]);
373 elem->set_node(2, nodes[index + (_num_sectors / 2 + 1) + counter * (_num_sectors / 2 + 2) + 1]);
374 elem->set_node(3, nodes[index - _num_sectors / 2 - 1]);
375 elem->subdomain_id() = subdomainIDs[0];
376
377 if (index == standard + 1)
378 boundary_info.add_side(elem, 2, 1);
379
380 index = index - _num_sectors / 2 - 1;
381 ++counter;
382 }
383
384 counter = 0;
385 // adding elements for other concentric circles
386 index = Utility::pow<2>(standard / 2 + 1);
387 limit = Utility::pow<2>(standard / 2 + 1) + (_num_sectors + 1) * (radii_all_circles.size() - 1);
388
389 int num_nodes_boundary = Utility::pow<2>(standard / 2 + 1) + standard + 1;
390
391 while (index < limit)
392 {
393 Elem * elem = mesh->add_elem(std::make_unique<Quad4>());
394 elem->set_node(0, nodes[index]);
395 elem->set_node(1, nodes[index + standard + 1]);
396 elem->set_node(2, nodes[index + standard + 2]);
397 elem->set_node(3, nodes[index + 1]);
398
399 // find ring subdomain ID from circle counter. The first ring was built with the inner square
400 const auto ring = counter + 1;
401 for (const auto i : make_range(subdomainIDs.size() - _has_outer_square))
402 {
403 if (i > 0 && ring >= cum_num_rings[i - 1] && ring < cum_num_rings[i])
404 elem->subdomain_id() = subdomainIDs[i];
405 else if (i == 0 && ring < cum_num_rings[0])
406 elem->subdomain_id() = subdomainIDs[0];
407 }
408
409 const int initial = Utility::pow<2>(standard / 2 + 1);
410 const int final = Utility::pow<2>(standard / 2 + 1) + standard - 1;
411
412 if ((index - initial) % (standard + 1) == 0)
413 boundary_info.add_side(elem, 0, 2);
414 if ((index - final) % (standard + 1) == 0)
415 boundary_info.add_side(elem, 2, 1);
417 if (index >= limit - (standard + 1))
418 boundary_info.add_side(elem, 1, 3);
419
420 // index increment is for adding nodes for a next element.
421 ++index;
422
423 // increment by 2 indices may be necessary depending on where the index points to.
424 // this varies based on the algorithms provided for the specific element and node placement.
425 if (index == (num_nodes_boundary + counter * (standard + 1)) - 1)
426 {
427 ++index;
428 ++counter;
429 }
430 }
431
432 // Enclosing square sections
433 // ABCA
434 // C B
435 // B C
436 // ACBA
437
438 // adding elements for the enclosing square. (top left)
439 int initial = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size();
440
441 int initial2 = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size();
442
444 {
445 if (_rings.back() != 0) // this must be condition up front.
446 {
447 index = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size();
448 limit = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
449 (_rings.back() + 1) * (standard / 2) + Utility::pow<2>(_rings.back() + 2) - 3 -
450 _rings.back() * (_rings.back() + 2) - (_rings.back() + 1);
451 while (index <= limit)
452 {
453 // outer square sector C
454 Elem * elem = mesh->add_elem(std::make_unique<Quad4>());
455 elem->set_node(0, nodes[index]);
456 elem->set_node(1, nodes[index + 1]);
457 elem->set_node(2, nodes[index + 1 + _rings.back() + 1]);
458 elem->set_node(3, nodes[index + 1 + _rings.back()]);
459 elem->subdomain_id() = subdomainIDs.back();
460
461 if (index < (initial2 + static_cast<int>(_rings.back())))
462 boundary_info.add_side(elem, 0, 1);
463
464 if (index == initial)
465 boundary_info.add_side(elem, 3, 4);
466
467 ++index;
468
469 // As mentioned before, increment by 2 indices may be required depending on where the index
470 // points to.
471 if ((index - initial) % static_cast<int>(_rings.back()) == 0)
472 {
473 ++index;
474 initial = initial + (static_cast<int>(_rings.back()) + 1);
475 }
476 }
477
478 // adding elements for the enclosing square. (top right)
479 initial = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
480 (_rings.back() + 1) * (standard / 2 + 1);
481
482 limit = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
483 (_rings.back() + 1) * (standard / 2) + Utility::pow<2>(_rings.back() + 2) - 3 -
484 (_rings.back() + 2);
485
486 while (index <= limit)
487 {
488 // outer square sector A
489 Elem * elem = mesh->add_elem(std::make_unique<Quad4>());
490 elem->set_node(3, nodes[index]);
491 elem->set_node(2, nodes[index + _rings.back() + 2]);
492 elem->set_node(1, nodes[index + _rings.back() + 3]);
493 elem->set_node(0, nodes[index + 1]);
494 elem->subdomain_id() = subdomainIDs.back();
495
496 if (index >= static_cast<int>(limit - (_rings.back() + 1)))
497 boundary_info.add_side(elem, 1, 3);
498
499 if ((index - initial) % static_cast<int>(_rings.back() + 2) == 0)
500 boundary_info.add_side(elem, 2, 4);
501
502 ++index;
503
504 if ((index - initial) % static_cast<int>(_rings.back() + 1) == 0)
505 {
506 ++index;
507 initial = initial + (static_cast<int>(_rings.back()) + 2);
508 }
509 }
510
511 // adding elements for the enclosing square. (one center quad)
512 int index1 = Utility::pow<2>(standard / 2 + 1) +
513 (standard + 1) * (radii_all_circles.size() - 1) + standard / 2;
514
515 int index2 = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
516 (_rings.back() + 1) * (standard / 2) + Utility::pow<2>(_rings.back() + 2) - 3 -
517 _rings.back() * (_rings.back() + 2) - (_rings.back() + 1);
518
519 // pointy tips of the A sectors, touching the inner circle
520 Elem * elem = mesh->add_elem(std::make_unique<Quad4>());
521 elem->set_node(3, nodes[index1]);
522 elem->set_node(2, nodes[index2]);
523 elem->set_node(1, nodes[index2 + _rings.back() + 1]);
524 elem->set_node(0, nodes[index2 + _rings.back() + 2]);
525 elem->subdomain_id() = subdomainIDs.back();
526
527 // adding elements for the left mid part.
528 index = Utility::pow<2>(standard / 2 + 1) + standard / 2 +
529 (standard + 1) * (radii_all_circles.size() - 1);
530 limit = index + standard / 2 - 1;
531
532 while (index <= limit)
533 {
534 // outer square elements in sector C touching the inner circle
535 Elem * elem = mesh->add_elem(std::make_unique<Quad4>());
536 elem->set_node(3, nodes[index]);
537 elem->set_node(2, nodes[index + 1]);
538 elem->set_node(1, nodes[index2 - _rings.back() - 1]);
539 elem->set_node(0, nodes[index2]);
540 elem->subdomain_id() = subdomainIDs.back();
541
542 if (index == limit)
543 boundary_info.add_side(elem, 1, 1);
544
545 ++index;
546
547 // two different indices are used to add nodes for an element.
548 index2 = index2 - _rings.back() - 1;
549 }
550
551 // adding elements for the right mid part.
552 index1 = Utility::pow<2>(standard / 2 + 1) + standard / 2 +
553 (standard + 1) * (radii_all_circles.size() - 1);
554 index2 = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
555 (_rings.back() + 1) * (standard / 2) + Utility::pow<2>(_rings.back() + 2) - 2 +
556 (_rings.back() + 1);
557 int index3 = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
558 (_rings.back() + 1) * (standard / 2) - 1 + (_rings.back() + 1) +
559 (_rings.back() + 2);
560
561 // elements clockwise from the A sector tips
562 elem = mesh->add_elem(std::make_unique<Quad4>());
563 elem->set_node(0, nodes[index1]);
564 elem->set_node(1, nodes[index1 - 1]);
565 elem->set_node(2, nodes[index2]);
566 elem->set_node(3, nodes[index3]);
567 elem->subdomain_id() = subdomainIDs.back();
568
569 if (standard == 2)
570 boundary_info.add_side(elem, 1, 2);
571
572 // adding elements for the right mid bottom part.
573
574 index = Utility::pow<2>(standard / 2 + 1) + standard / 2 +
575 (standard + 1) * (radii_all_circles.size() - 1) - 2;
576 index1 = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
577 (_rings.back() + 1) * (standard / 2) + Utility::pow<2>(_rings.back() + 2) - 2 +
578 (_rings.back() + 1) * 2;
579
580 limit = Utility::pow<2>(standard / 2 + 1) + standard / 2 +
581 (standard + 1) * (radii_all_circles.size() - 1) - standard / 2;
582
583 if (standard != 2)
584 {
585 while (index >= limit)
586 {
587 // outer square elements in sector B touching the inner circle
588 Elem * elem = mesh->add_elem(std::make_unique<Quad4>());
589 elem->set_node(0, nodes[index]);
590 elem->set_node(1, nodes[index1]);
591 elem->set_node(2, nodes[index1 - (_rings.back() + 1)]);
592 elem->set_node(3, nodes[index + 1]);
593 elem->subdomain_id() = subdomainIDs.back();
594
595 if (index == limit)
596 boundary_info.add_side(elem, 0, 2);
597 --index;
598 index1 = index1 + (_rings.back() + 1);
599 }
600 }
601
602 // adding elements for the right low part.
603 index = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
604 (_rings.back() + 1) * (standard / 2) + Utility::pow<2>(_rings.back() + 2) - 2;
605
606 index1 = index - (_rings.back() + 2);
607 // dummy condition for elem definition
608 if (standard >= 2)
609 {
610 // single elements between A and B on the outside of the square
611 Elem * elem = mesh->add_elem(std::make_unique<Quad4>());
612 elem->set_node(3, nodes[index]);
613 elem->set_node(2, nodes[index + 1]);
614 elem->set_node(1, nodes[index + 2]);
615 elem->set_node(0, nodes[index1]);
616 elem->subdomain_id() = subdomainIDs.back();
617
618 boundary_info.add_side(elem, 2, 3);
619
620 if (standard == 2)
621 boundary_info.add_side(elem, 1, 2);
622 }
623
624 index = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
625 (_rings.back() + 1) * (standard / 2) + Utility::pow<2>(_rings.back() + 2) - 2 -
626 (_rings.back() + 2);
627
628 limit = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
629 (_rings.back() + 1) * (standard / 2) + (_rings.back() + 2) * 2 - 2;
630
631 int k = 1;
632 while (index > limit)
633 {
634 Elem * elem = mesh->add_elem(std::make_unique<Quad4>());
635 elem->set_node(3, nodes[index]);
636 elem->set_node(2, nodes[index + (_rings.back() + 2) * k + k + 1]);
637 elem->set_node(1, nodes[index + (_rings.back() + 2) * k + k + 2]);
638 elem->set_node(0, nodes[index - _rings.back() - 2]);
639 elem->subdomain_id() = subdomainIDs.back();
640 index = index - (_rings.back() + 2);
641 ++k;
642
643 if (standard == 2)
644 boundary_info.add_side(elem, 1, 2);
645 }
646
647 index = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
648 (_rings.back() + 1) * (standard / 2) + Utility::pow<2>(_rings.back() + 2) - 1;
649 initial = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
650 (_rings.back() + 1) * (standard / 2) + Utility::pow<2>(_rings.back() + 2) - 1;
651 limit = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
652 (_rings.back() + 1) * (standard / 2) * 2 + Utility::pow<2>(_rings.back() + 2) - 2 -
653 _rings.back() - 1;
654
655 initial2 = Utility::pow<2>(standard / 2 + 1) + (standard + 1) * radii_all_circles.size() +
656 (_rings.back() + 1) * (standard / 2) * 2 + Utility::pow<2>(_rings.back() + 2) - 2 -
657 (_rings.back() + 1) * 2;
658
659 if (standard > 2)
660 {
661 while (index < limit)
662 {
663 Elem * elem = mesh->add_elem(std::make_unique<Quad4>());
664 elem->set_node(0, nodes[index]);
665 elem->set_node(1, nodes[index + 1]);
666 elem->set_node(2, nodes[index + 1 + _rings.back() + 1]);
667 elem->set_node(3, nodes[index + 1 + _rings.back()]);
668 elem->subdomain_id() = subdomainIDs.back();
669
670 if (index > initial2)
671 boundary_info.add_side(elem, 2, 2);
672
673 if ((index - initial) == 0)
674 boundary_info.add_side(elem, 3, 3);
675
676 ++index;
677
678 if ((index - initial) % static_cast<int>(_rings.back()) == 0)
679 {
680 ++index;
681 initial = initial + (static_cast<int>(_rings.back()) + 1);
682 }
683 }
684 }
685 }
686 }
687
688 // This is to set boundary names.
689 boundary_info.sideset_name(1) = _boundary_name_prefix + "left";
690 boundary_info.sideset_name(2) = _boundary_name_prefix + "bottom";
691
693 boundary_info.sideset_name(3) = _boundary_name_prefix + "outer";
694 else
695 {
696 boundary_info.sideset_name(3) = _boundary_name_prefix + "right";
697 boundary_info.sideset_name(4) = _boundary_name_prefix + "top";
698 }
699
700 if (_portion == "top_left")
701 {
702 MeshTools::Modification::rotate(*mesh, 90, 0, 0);
703 boundary_info.sideset_name(1) = _boundary_name_prefix + "bottom";
704 boundary_info.sideset_name(2) = _boundary_name_prefix + "right";
705
707 boundary_info.sideset_name(3) = _boundary_name_prefix + "outer";
708 else
709 {
710 boundary_info.sideset_name(3) = _boundary_name_prefix + "top";
711 boundary_info.sideset_name(4) = _boundary_name_prefix + "left";
712 }
713 }
714 else if (_portion == "bottom_left")
715 {
716 MeshTools::Modification::rotate(*mesh, 180, 0, 0);
717 boundary_info.sideset_name(1) = _boundary_name_prefix + "right";
718 boundary_info.sideset_name(2) = _boundary_name_prefix + "top";
719
721 boundary_info.sideset_name(3) = _boundary_name_prefix + "outer";
722 else
723 {
724 boundary_info.sideset_name(3) = _boundary_name_prefix + "left";
725 boundary_info.sideset_name(4) = _boundary_name_prefix + "bottom";
726 }
727 }
728 else if (_portion == "bottom_right")
729 {
730 MeshTools::Modification::rotate(*mesh, 270, 0, 0);
731 boundary_info.sideset_name(1) = _boundary_name_prefix + "top";
732 boundary_info.sideset_name(2) = _boundary_name_prefix + "left";
733
735 boundary_info.sideset_name(3) = _boundary_name_prefix + "outer";
736 else
737 {
738 boundary_info.sideset_name(3) = _boundary_name_prefix + "bottom";
739 boundary_info.sideset_name(4) = _boundary_name_prefix + "right";
740 }
741 }
742
743 else if (_portion == "top_half")
744 {
745 ReplicatedMesh other_mesh(*mesh);
746 // This is to rotate the mesh and also to reset boundary IDs.
747 MeshTools::Modification::rotate(other_mesh, 90, 0, 0);
749 {
750 MeshTools::Modification::change_boundary_id(other_mesh, 1, 5);
751 MeshTools::Modification::change_boundary_id(other_mesh, 2, 6);
752 MeshTools::Modification::change_boundary_id(other_mesh, 3, 7);
753 MeshTools::Modification::change_boundary_id(other_mesh, 4, 1);
754 MeshTools::Modification::change_boundary_id(other_mesh, 5, 2);
755 MeshTools::Modification::change_boundary_id(other_mesh, 6, 3);
756 MeshTools::Modification::change_boundary_id(other_mesh, 7, 4);
757 mesh->prepare_for_use();
758 other_mesh.prepare_for_use();
759 mesh->stitch_meshes(other_mesh, 1, 3, TOLERANCE, true, /*verbose=*/false);
760 mesh->get_boundary_info().sideset_name(1) = _boundary_name_prefix + "left";
761 mesh->get_boundary_info().sideset_name(2) = _boundary_name_prefix + "bottom";
762 mesh->get_boundary_info().sideset_name(3) = _boundary_name_prefix + "right";
763 mesh->get_boundary_info().sideset_name(4) = _boundary_name_prefix + "top";
764 }
765 else
766 {
767 MeshTools::Modification::change_boundary_id(other_mesh, 1, 5);
768 MeshTools::Modification::change_boundary_id(other_mesh, 2, 1);
769 MeshTools::Modification::change_boundary_id(other_mesh, 5, 2);
770 mesh->prepare_for_use();
771 other_mesh.prepare_for_use();
772 mesh->stitch_meshes(other_mesh, 1, 1, TOLERANCE, true, /*verbose=*/false);
773
774 MeshTools::Modification::change_boundary_id(*mesh, 2, 1);
775 MeshTools::Modification::change_boundary_id(*mesh, 3, 2);
776 mesh->get_boundary_info().sideset_name(1) = _boundary_name_prefix + "bottom";
777 mesh->get_boundary_info().sideset_name(2) = _boundary_name_prefix + "outer";
778 }
779 other_mesh.clear();
780 }
781
782 else if (_portion == "right_half")
783 {
784 ReplicatedMesh other_mesh(*mesh);
785 // This is to rotate the mesh and also to reset boundary IDs.
786 MeshTools::Modification::rotate(other_mesh, 270, 0, 0);
788 {
789 MeshTools::Modification::change_boundary_id(other_mesh, 1, 5);
790 MeshTools::Modification::change_boundary_id(other_mesh, 2, 6);
791 MeshTools::Modification::change_boundary_id(other_mesh, 3, 7);
792 MeshTools::Modification::change_boundary_id(other_mesh, 4, 3);
793 MeshTools::Modification::change_boundary_id(other_mesh, 5, 4);
794 MeshTools::Modification::change_boundary_id(other_mesh, 6, 1);
795 MeshTools::Modification::change_boundary_id(other_mesh, 7, 2);
796 mesh->prepare_for_use();
797 other_mesh.prepare_for_use();
798 mesh->stitch_meshes(other_mesh, 2, 4, TOLERANCE, true, /*verbose=*/false);
799 mesh->get_boundary_info().sideset_name(1) = _boundary_name_prefix + "left";
800 mesh->get_boundary_info().sideset_name(2) = _boundary_name_prefix + "bottom";
801 mesh->get_boundary_info().sideset_name(3) = _boundary_name_prefix + "right";
802 mesh->get_boundary_info().sideset_name(4) = _boundary_name_prefix + "top";
803 }
804 else
805 {
806 MeshTools::Modification::change_boundary_id(other_mesh, 1, 5);
807 MeshTools::Modification::change_boundary_id(other_mesh, 2, 1);
808 MeshTools::Modification::change_boundary_id(other_mesh, 5, 2);
809 mesh->prepare_for_use();
810 other_mesh.prepare_for_use();
811 mesh->stitch_meshes(other_mesh, 2, 2, TOLERANCE, true, /*verbose=*/false);
812
813 MeshTools::Modification::change_boundary_id(*mesh, 3, 2);
814 mesh->get_boundary_info().sideset_name(1) = _boundary_name_prefix + "left";
815 mesh->get_boundary_info().sideset_name(2) = _boundary_name_prefix + "outer";
816 }
817 other_mesh.clear();
818 }
819 else if (_portion == "left_half")
820 {
821 ReplicatedMesh other_mesh(*mesh);
822
823 // This is to rotate the mesh and to reset boundary IDs.
824 MeshTools::Modification::rotate(other_mesh, 90, 0, 0);
825 MeshTools::Modification::rotate(*mesh, 180, 0, 0);
827 {
828 // The other mesh is created by rotating the original mesh about 90 degrees.
829 MeshTools::Modification::change_boundary_id(other_mesh, 1, 5);
830 MeshTools::Modification::change_boundary_id(other_mesh, 2, 6);
831 MeshTools::Modification::change_boundary_id(other_mesh, 3, 7);
832 MeshTools::Modification::change_boundary_id(other_mesh, 4, 1);
833 MeshTools::Modification::change_boundary_id(other_mesh, 5, 2);
834 MeshTools::Modification::change_boundary_id(other_mesh, 6, 3);
835 MeshTools::Modification::change_boundary_id(other_mesh, 7, 4);
836 // The original mesh is then rotated about 180 degrees.
837 MeshTools::Modification::change_boundary_id(*mesh, 1, 5);
838 MeshTools::Modification::change_boundary_id(*mesh, 2, 6);
839 MeshTools::Modification::change_boundary_id(*mesh, 3, 7);
840 MeshTools::Modification::change_boundary_id(*mesh, 4, 2);
841 MeshTools::Modification::change_boundary_id(*mesh, 5, 3);
842 MeshTools::Modification::change_boundary_id(*mesh, 6, 4);
843 MeshTools::Modification::change_boundary_id(*mesh, 7, 1);
844 mesh->prepare_for_use();
845 other_mesh.prepare_for_use();
846 mesh->stitch_meshes(other_mesh, 4, 2, TOLERANCE, true, /*verbose=*/false);
847 mesh->get_boundary_info().sideset_name(1) = _boundary_name_prefix + "left";
848 mesh->get_boundary_info().sideset_name(2) = _boundary_name_prefix + "bottom";
849 mesh->get_boundary_info().sideset_name(3) = _boundary_name_prefix + "right";
850 mesh->get_boundary_info().sideset_name(4) = _boundary_name_prefix + "top";
851 }
852 else
853 {
854 MeshTools::Modification::change_boundary_id(*mesh, 1, 5);
855 MeshTools::Modification::change_boundary_id(*mesh, 2, 1);
856 MeshTools::Modification::change_boundary_id(*mesh, 5, 2);
857 mesh->prepare_for_use();
858 other_mesh.prepare_for_use();
859 mesh->stitch_meshes(other_mesh, 1, 1, TOLERANCE, true, /*verbose=*/false);
860
861 MeshTools::Modification::change_boundary_id(*mesh, 2, 1);
862 MeshTools::Modification::change_boundary_id(*mesh, 3, 2);
863 mesh->get_boundary_info().sideset_name(1) = _boundary_name_prefix + "right";
864 mesh->get_boundary_info().sideset_name(2) = _boundary_name_prefix + "outer";
865 }
866 other_mesh.clear();
867 }
868 else if (_portion == "bottom_half")
869 {
870 ReplicatedMesh other_mesh(*mesh);
871 // This is to rotate the mesh and also to reset boundary IDs.
872 MeshTools::Modification::rotate(other_mesh, 180, 0, 0);
873 MeshTools::Modification::rotate(*mesh, 270, 0, 0);
875 {
876 // The other mesh is created by rotating the original mesh about 180 degrees.
877 MeshTools::Modification::change_boundary_id(other_mesh, 1, 5);
878 MeshTools::Modification::change_boundary_id(other_mesh, 2, 6);
879 MeshTools::Modification::change_boundary_id(other_mesh, 3, 7);
880 MeshTools::Modification::change_boundary_id(other_mesh, 4, 2);
881 MeshTools::Modification::change_boundary_id(other_mesh, 5, 3);
882 MeshTools::Modification::change_boundary_id(other_mesh, 6, 4);
883 MeshTools::Modification::change_boundary_id(other_mesh, 7, 1);
884 // The original mesh is rotated about 270 degrees.
885 MeshTools::Modification::change_boundary_id(*mesh, 1, 5);
886 MeshTools::Modification::change_boundary_id(*mesh, 2, 6);
887 MeshTools::Modification::change_boundary_id(*mesh, 3, 7);
888 MeshTools::Modification::change_boundary_id(*mesh, 4, 3);
889 MeshTools::Modification::change_boundary_id(*mesh, 5, 4);
890 MeshTools::Modification::change_boundary_id(*mesh, 6, 1);
891 MeshTools::Modification::change_boundary_id(*mesh, 7, 2);
892 mesh->prepare_for_use();
893 other_mesh.prepare_for_use();
894 mesh->stitch_meshes(other_mesh, 1, 3, TOLERANCE, true, /*verbose=*/false);
895 mesh->get_boundary_info().sideset_name(1) = _boundary_name_prefix + "left";
896 mesh->get_boundary_info().sideset_name(2) = _boundary_name_prefix + "bottom";
897 mesh->get_boundary_info().sideset_name(3) = _boundary_name_prefix + "right";
898 mesh->get_boundary_info().sideset_name(4) = _boundary_name_prefix + "top";
899 }
900 else
901 {
902 MeshTools::Modification::change_boundary_id(*mesh, 1, 5);
903 MeshTools::Modification::change_boundary_id(*mesh, 2, 1);
904 MeshTools::Modification::change_boundary_id(*mesh, 5, 2);
905 mesh->prepare_for_use();
906 other_mesh.prepare_for_use();
907 mesh->stitch_meshes(other_mesh, 1, 1, TOLERANCE, true, /*verbose=*/false);
908
909 MeshTools::Modification::change_boundary_id(*mesh, 2, 1);
910 MeshTools::Modification::change_boundary_id(*mesh, 3, 2);
911 mesh->get_boundary_info().sideset_name(1) = _boundary_name_prefix + "top";
912 mesh->get_boundary_info().sideset_name(2) = _boundary_name_prefix + "outer";
913 }
914 other_mesh.clear();
915 }
916 else if (_portion == "full")
917 {
918 ReplicatedMesh portion_two(*mesh);
919
920 // This is to rotate the mesh and also to reset boundary IDs.
921 MeshTools::Modification::rotate(portion_two, 90, 0, 0);
922
924 {
925 // Portion 2: 2nd quadrant
926 MeshTools::Modification::change_boundary_id(portion_two, 1, 5);
927 MeshTools::Modification::change_boundary_id(portion_two, 2, 6);
928 MeshTools::Modification::change_boundary_id(portion_two, 3, 7);
929 MeshTools::Modification::change_boundary_id(portion_two, 4, 1);
930 MeshTools::Modification::change_boundary_id(portion_two, 5, 2);
931 MeshTools::Modification::change_boundary_id(portion_two, 6, 3);
932 MeshTools::Modification::change_boundary_id(portion_two, 7, 4);
933 mesh->prepare_for_use();
934 portion_two.prepare_for_use();
935 // 'top_half'
936 mesh->stitch_meshes(portion_two, 1, 3, TOLERANCE, true, /*verbose=*/false);
937
938 // 'bottom_half'
939 ReplicatedMesh portion_bottom(*mesh);
940 MeshTools::Modification::rotate(portion_bottom, 180, 0, 0);
941 MeshTools::Modification::change_boundary_id(portion_bottom, 1, 5);
942 MeshTools::Modification::change_boundary_id(portion_bottom, 2, 6);
943 MeshTools::Modification::change_boundary_id(portion_bottom, 3, 7);
944 MeshTools::Modification::change_boundary_id(portion_bottom, 4, 2);
945 MeshTools::Modification::change_boundary_id(portion_bottom, 5, 3);
946 MeshTools::Modification::change_boundary_id(portion_bottom, 6, 4);
947 MeshTools::Modification::change_boundary_id(portion_bottom, 7, 1);
948 mesh->prepare_for_use();
949 portion_bottom.prepare_for_use();
950 // 'full'
951 mesh->stitch_meshes(portion_bottom, 2, 4, TOLERANCE, true, /*verbose=*/false);
952
953 mesh->get_boundary_info().sideset_name(1) = _boundary_name_prefix + "left";
954 mesh->get_boundary_info().sideset_name(2) = _boundary_name_prefix + "bottom";
955 mesh->get_boundary_info().sideset_name(3) = _boundary_name_prefix + "right";
956 mesh->get_boundary_info().sideset_name(4) = _boundary_name_prefix + "top";
957 portion_bottom.clear();
958 }
959 else
960 {
961 MeshTools::Modification::change_boundary_id(portion_two, 1, 5);
962 MeshTools::Modification::change_boundary_id(portion_two, 2, 1);
963 MeshTools::Modification::change_boundary_id(portion_two, 5, 2);
964 // 'top half'
965 mesh->prepare_for_use();
966 portion_two.prepare_for_use();
967 mesh->stitch_meshes(portion_two, 1, 1, TOLERANCE, true, /*verbose=*/false);
968 // 'bottom half'
969 ReplicatedMesh portion_bottom(*mesh);
970 MeshTools::Modification::rotate(portion_bottom, 180, 0, 0);
971 // 'full'
972 mesh->prepare_for_use();
973 portion_bottom.prepare_for_use();
974 mesh->stitch_meshes(portion_bottom, 2, 2, TOLERANCE, true, /*verbose=*/false);
975 MeshTools::Modification::change_boundary_id(*mesh, 3, 1);
976 mesh->get_boundary_info().sideset_name(1) = _boundary_name_prefix + "outer";
977 portion_bottom.clear();
978 }
979 portion_two.clear();
980 }
981
982 if (_portion != "top_half" && _portion != "right_half" && _portion != "left_half" &&
983 _portion != "bottom_half" && _portion != "full")
984 mesh->prepare_for_use();
985
986 // Laplace smoothing
988 lms.smooth();
989
990 // Add subdomain name
991 if (isParamValid("subdomain_name"))
992 {
993 const auto & subdomain_names = getParam<std::vector<SubdomainName>>("subdomain_name");
994 if (subdomain_names.size() == subdomainIDs.size())
995 for (const auto i : index_range(subdomain_names))
996 mesh->set_subdomain_name(subdomainIDs[i], subdomain_names[i], true);
997 else
998 paramError("subdomain_name",
999 "Parameter (size: " + std::to_string(subdomain_names.size()) +
1000 ") must be the same size as the number of rings (= " +
1001 std::to_string(subdomainIDs.size() - _has_outer_square) + ")" +
1002 (_has_outer_square ? " +1 if the outer square is created" : ""));
1003 }
1004
1005 mesh->prepare_for_use();
1006 return dynamic_pointer_cast<MeshBase>(mesh);
1007}
registerMooseObject("MooseApp", ConcentricCircleMeshGenerator)
void ErrorVector unsigned int
Generates a mesh based on concentric circles, given all the parameters.
MooseEnum _portion
Control of which portion of mesh will be developed.
const std::string & _boundary_name_prefix
Prefix to prepend to boundary names declared by this generator.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
ConcentricCircleMeshGenerator(const InputParameters &parameters)
std::vector< unsigned int > _rings
Number of rings in each circle or in the enclosing square.
bool _has_outer_square
Adding the enclosing square is optional.
std::vector< Real > _radii
Radii of concentric circles.
bool _preserve_volumes
Volume preserving function is optional.
unsigned int _num_sectors
Number of sectors in one quadrant.
unsigned int _smoothing_max_it
Iteration number for Laplace smoothing.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
MeshGenerators are objects that can modify or add to an existing mesh.
std::unique_ptr< ReplicatedMesh > buildReplicatedMesh(unsigned int dim=libMesh::invalid_uint)
Build a replicated mesh.
static InputParameters validParams()
T & declareMeshProperty(const std::string &data_name, Args &&... args)
Methods for writing out attributes to the mesh meta-data store, which can be retrieved from most othe...
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
virtual void smooth() override
MeshBase & mesh