29 const std::vector<
const std::vector<double>*>& vec_xyz_coords,
32 auto const shift_coordinates =
33 [](
auto const& in,
auto& out,
auto const& shift)
35 std::transform(in.begin(), in.end(), std::back_inserter(out),
36 [&shift](
auto const& v) { return v + shift; });
38 std::array<std::vector<double>, 3> coords;
39 for (std::size_t i = 0; i < 3; ++i)
41 coords[i].reserve(vec_xyz_coords[i]->size());
42 shift_coordinates(*vec_xyz_coords[i], coords[i], origin[i]);
45 std::vector<MeshLib::Node*> nodes;
46 nodes.reserve(coords[0].size() * coords[1].size() * coords[2].size());
48 for (
auto const z : coords[2])
50 for (
auto const y : coords[1])
52 std::transform(coords[0].begin(), coords[0].end(),
53 std::back_inserter(nodes),
54 [&y, &z](
double const& x)
64 std::vector<const std::vector<double>*> vec_xyz_coords;
65 vec_xyz_coords.push_back(&vec_x_coords);
66 std::vector<double> dummy(1, 0.0);
67 for (
unsigned i = vec_xyz_coords.size() - 1; i < 3u; i++)
69 vec_xyz_coords.push_back(&dummy);
75 std::vector<double>& vec_x_coords,
76 std::vector<double>& vec_y_coords,
79 std::vector<const std::vector<double>*> vec_xyz_coords;
80 vec_xyz_coords.push_back(&vec_x_coords);
81 vec_xyz_coords.push_back(&vec_y_coords);
82 std::vector<double> dummy(1, 0.0);
83 for (
unsigned i = vec_xyz_coords.size() - 1; i < 3u; i++)
85 vec_xyz_coords.push_back(&dummy);
91 std::vector<double>& vec_x_coords,
92 std::vector<double>& vec_y_coords,
93 std::vector<double>& vec_z_coords,
96 std::vector<const std::vector<double>*> vec_xyz_coords;
97 vec_xyz_coords.push_back(&vec_x_coords);
98 vec_xyz_coords.push_back(&vec_y_coords);
99 vec_xyz_coords.push_back(&vec_z_coords);
104 const std::array<unsigned, 3>& n_cells,
105 const std::array<double, 3>& cell_size,
108 std::vector<MeshLib::Node*> nodes;
109 nodes.reserve((n_cells[0] + 1) * (n_cells[1] + 1) * (n_cells[2] + 1));
111 for (std::size_t i = 0; i < n_cells[2] + 1; i++)
113 const double z(origin[2] + cell_size[2] * i);
114 for (std::size_t j = 0; j < n_cells[1] + 1; j++)
116 const double y(origin[1] + cell_size[1] * j);
117 for (std::size_t k = 0; k < n_cells[0] + 1; k++)
127namespace MeshGenerator
130 std::vector<double>
const& x_coords,
131 std::vector<double>
const& y_coords,
132 std::vector<double>
const& z_coords,
135 std::vector<MeshLib::Node*> nodes;
136 nodes.reserve((x_coords.size() - 1) * (y_coords.size() - 1) *
137 (z_coords.size() - 1));
139 auto const n_x_coords = x_coords.size() - 1;
140 auto const n_y_coords = y_coords.size() - 1;
141 auto const n_z_coords = z_coords.size() - 1;
143 for (std::size_t i = 0; i < n_z_coords; i++)
145 const double z((z_coords[i] + z_coords[i + 1]) / 2 + origin[2]);
146 for (std::size_t j = 0; j < n_y_coords; j++)
148 const double y((y_coords[j] + y_coords[j + 1]) / 2 + origin[1]);
149 for (std::size_t k = 0; k < n_x_coords; k++)
151 const double x((x_coords[k] + x_coords[k + 1]) / 2 + origin[0]);
161 const std::size_t subdivision,
163 std::string
const& mesh_name)
170 const double cell_size,
172 std::string
const& mesh_name)
181 std::string
const& mesh_name)
183 const std::vector<double> vec_x(div());
187 const std::size_t n_cells = nodes.size() - 1;
188 std::vector<MeshLib::Element*> elements;
189 elements.reserve(n_cells);
191 for (std::size_t i = 0; i < n_cells; i++)
193 elements.push_back(
new MeshLib::Line({nodes[i], nodes[i + 1]}));
201 const std::size_t subdivision,
203 std::string
const& mesh_name)
206 length / subdivision, length / subdivision,
211 const double x_length,
212 const double y_length,
213 const std::size_t x_subdivision,
214 const std::size_t y_subdivision,
216 std::string
const& mesh_name)
219 x_length / x_subdivision,
220 y_length / y_subdivision, origin, mesh_name);
224 const unsigned n_x_cells,
225 const unsigned n_y_cells,
226 const double cell_size,
228 std::string
const& mesh_name)
235 const unsigned n_x_cells,
236 const unsigned n_y_cells,
237 const double cell_size_x,
238 const double cell_size_y,
240 std::string
const& mesh_name)
252 std::string
const& mesh_name)
254 std::vector<double> vec_x(div_x());
255 std::vector<double> vec_y(div_y());
256 std::vector<MeshLib::Node*> nodes(
258 const unsigned n_x_nodes(vec_x.size());
261 std::vector<MeshLib::Element*> elements;
262 const unsigned n_x_cells(vec_x.size() - 1);
263 const unsigned n_y_cells(vec_y.size() - 1);
264 elements.reserve(n_x_cells * n_y_cells);
266 for (std::size_t j = 0; j < n_y_cells; j++)
268 const std::size_t offset_y1 = j * n_x_nodes;
269 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
270 for (std::size_t k = 0; k < n_x_cells; k++)
273 {nodes[offset_y1 + k], nodes[offset_y1 + k + 1],
274 nodes[offset_y2 + k + 1], nodes[offset_y2 + k]}));
283 const std::size_t subdivision,
285 std::string
const& mesh_name)
288 subdivision, subdivision, subdivision, length / subdivision, origin,
293 const double x_length,
294 const double y_length,
295 const double z_length,
296 const std::size_t x_subdivision,
297 const std::size_t y_subdivision,
298 const std::size_t z_subdivision,
300 std::string
const& mesh_name)
303 x_subdivision, y_subdivision, z_subdivision, x_length / x_subdivision,
304 y_length / y_subdivision, z_length / z_subdivision, origin, mesh_name);
308 const unsigned n_x_cells,
309 const unsigned n_y_cells,
310 const unsigned n_z_cells,
311 const double cell_size,
313 std::string
const& mesh_name)
316 n_x_cells, n_y_cells, n_z_cells, cell_size, cell_size, cell_size,
321 const unsigned n_x_cells,
322 const unsigned n_y_cells,
323 const unsigned n_z_cells,
324 const double cell_size_x,
325 const double cell_size_y,
326 const double cell_size_z,
328 std::string
const& mesh_name)
342 std::string
const& mesh_name)
344 std::vector<double> vec_x(div_x());
345 std::vector<double> vec_y(div_y());
346 std::vector<double> vec_z(div_z());
347 std::vector<MeshLib::Node*> nodes(
350 const unsigned n_x_nodes(vec_x.size());
351 const unsigned n_y_nodes(vec_y.size());
352 const unsigned n_x_cells(vec_x.size() - 1);
353 const unsigned n_y_cells(vec_y.size() - 1);
354 const unsigned n_z_cells(vec_z.size() - 1);
357 std::vector<MeshLib::Element*> elements;
358 elements.reserve(n_x_cells * n_y_cells * n_z_cells);
360 for (std::size_t i = 0; i < n_z_cells; i++)
362 const std::size_t offset_z1 = i * n_x_nodes * n_y_nodes;
363 const std::size_t offset_z2 = (i + 1) * n_x_nodes * n_y_nodes;
364 for (std::size_t j = 0; j < n_y_cells; j++)
366 const std::size_t offset_y1 = j * n_x_nodes;
367 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
368 for (std::size_t k = 0; k < n_x_cells; k++)
372 nodes[offset_z1 + offset_y1 + k],
373 nodes[offset_z1 + offset_y1 + k + 1],
374 nodes[offset_z1 + offset_y2 + k + 1],
375 nodes[offset_z1 + offset_y2 + k],
377 nodes[offset_z2 + offset_y1 + k],
378 nodes[offset_z2 + offset_y1 + k + 1],
379 nodes[offset_z2 + offset_y2 + k + 1],
380 nodes[offset_z2 + offset_y2 + k]}));
393 std::string
const& mesh_name)
395 std::vector<double> vec_x(div_x());
396 std::vector<double> vec_y(div_y());
397 std::vector<double> vec_z(div_z());
398 std::vector<MeshLib::Node*> nodes(
400 std::vector<MeshLib::Node*>
const top_nodes(
403 nodes.insert(nodes.end(), top_nodes.begin(), top_nodes.end());
405 const unsigned n_x_nodes(vec_x.size());
406 const unsigned n_y_nodes(vec_y.size());
407 const unsigned n_z_nodes(vec_z.size());
408 const unsigned n_x_cells(vec_x.size() - 1);
409 const unsigned n_y_cells(vec_y.size() - 1);
410 const unsigned n_z_cells(vec_z.size() - 1);
413 std::vector<MeshLib::Element*> elements;
414 auto const top_node_offset(n_x_nodes * n_y_nodes * n_z_nodes);
415 elements.reserve(n_x_cells * n_y_cells * n_z_cells);
417 for (std::size_t i = 0; i < n_z_cells; i++)
419 const std::size_t offset_z1 = i * n_x_nodes * n_y_nodes;
420 const std::size_t offset_z2 = (i + 1) * n_x_nodes * n_y_nodes;
421 for (std::size_t j = 0; j < n_y_cells; j++)
423 const std::size_t offset_y1 = j * n_x_nodes;
424 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
425 for (std::size_t k = 0; k < n_x_cells; k++)
428 int const pyramid_top_index(i * n_x_cells * n_y_cells +
433 nodes[offset_z1 + offset_y1 + k],
434 nodes[offset_z1 + offset_y1 + k + 1],
435 nodes[offset_z1 + offset_y2 + k + 1],
436 nodes[offset_z1 + offset_y2 + k],
438 nodes[pyramid_top_index]}});
441 nodes[offset_z2 + offset_y1 + k + 1],
442 nodes[offset_z2 + offset_y1 + k],
443 nodes[offset_z2 + offset_y2 + k],
444 nodes[offset_z2 + offset_y2 + k + 1],
446 nodes[pyramid_top_index]}});
449 nodes[offset_z1 + offset_y1 + k + 1],
450 nodes[offset_z2 + offset_y1 + k + 1],
451 nodes[offset_z2 + offset_y2 + k + 1],
452 nodes[offset_z1 + offset_y2 + k + 1],
454 nodes[pyramid_top_index]}});
457 nodes[offset_z2 + offset_y1 + k],
458 nodes[offset_z1 + offset_y1 + k],
459 nodes[offset_z1 + offset_y2 + k],
460 nodes[offset_z2 + offset_y2 + k],
462 nodes[pyramid_top_index]}});
465 nodes[offset_z2 + offset_y1 + k],
466 nodes[offset_z2 + offset_y1 + k + 1],
467 nodes[offset_z1 + offset_y1 + k + 1],
468 nodes[offset_z1 + offset_y1 + k],
470 nodes[pyramid_top_index]}});
473 nodes[offset_z1 + offset_y2 + k],
474 nodes[offset_z1 + offset_y2 + k + 1],
475 nodes[offset_z2 + offset_y2 + k + 1],
476 nodes[offset_z2 + offset_y2 + k],
478 nodes[pyramid_top_index]}});
487 const std::size_t subdivision,
489 std::string
const& mesh_name)
492 length / subdivision, origin, mesh_name);
496 const double x_length,
497 const double y_length,
498 const std::size_t x_subdivision,
499 const std::size_t y_subdivision,
501 std::string
const& mesh_name)
504 x_length / x_subdivision,
505 y_length / y_subdivision, origin, mesh_name);
509 const unsigned n_x_cells,
510 const unsigned n_y_cells,
511 const double cell_size,
513 std::string
const& mesh_name)
520 const unsigned n_x_cells,
521 const unsigned n_y_cells,
522 const double cell_size_x,
523 const double cell_size_y,
525 std::string
const& mesh_name)
537 std::string
const& mesh_name)
539 std::vector<double> vec_x(div_x());
540 std::vector<double> vec_y(div_y());
541 std::vector<MeshLib::Node*> nodes(
543 const unsigned n_x_nodes(vec_x.size());
544 const unsigned n_x_cells(vec_x.size() - 1);
545 const unsigned n_y_cells(vec_y.size() - 1);
548 std::vector<MeshLib::Element*> elements;
549 elements.reserve(n_x_cells * n_y_cells * 2);
551 for (std::size_t j = 0; j < n_y_cells; j++)
553 const std::size_t offset_y1 = j * n_x_nodes;
554 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
555 for (std::size_t k = 0; k < n_x_cells; k++)
557 elements.push_back(
new MeshLib::Tri({nodes[offset_y1 + k],
558 nodes[offset_y2 + k + 1],
559 nodes[offset_y2 + k]}));
561 elements.push_back(
new MeshLib::Tri({nodes[offset_y1 + k],
562 nodes[offset_y1 + k + 1],
563 nodes[offset_y2 + k + 1]}));
571 const double x_length,
572 const double y_length,
573 const double z_length,
574 const std::size_t x_subdivision,
575 const std::size_t y_subdivision,
576 const std::size_t z_subdivision,
578 std::string
const& mesh_name)
581 x_subdivision, y_subdivision, z_subdivision, x_length / x_subdivision,
582 y_length / y_subdivision, z_length / z_subdivision, origin, mesh_name);
586 const unsigned n_x_cells,
587 const unsigned n_y_cells,
588 const unsigned n_z_cells,
589 const double cell_size,
591 std::string
const& mesh_name)
594 cell_size, cell_size, origin, mesh_name);
598 const unsigned n_x_cells,
599 const unsigned n_y_cells,
600 const unsigned n_z_cells,
601 const double cell_size_x,
602 const double cell_size_y,
603 const double cell_size_z,
605 std::string
const& mesh_name)
608 n_x_cells, n_y_cells, cell_size_x, cell_size_y, origin, mesh_name));
609 std::size_t
const n_tris(mesh->getNumberOfElements());
610 bool const copy_material_ids =
false;
611 for (std::size_t i = 0; i < n_z_cells; ++i)
614 true, copy_material_ids));
616 std::vector<std::size_t> elem_ids(n_tris);
617 std::iota(elem_ids.begin(), elem_ids.end(), 0);
622 const double x_length,
623 const double y_length,
624 const double z_length,
625 const std::size_t x_subdivision,
626 const std::size_t y_subdivision,
627 const std::size_t z_subdivision,
629 std::string
const& mesh_name)
632 x_subdivision, y_subdivision, z_subdivision, x_length / x_subdivision,
633 y_length / y_subdivision, z_length / z_subdivision, origin, mesh_name);
637 const unsigned n_x_cells,
638 const unsigned n_y_cells,
639 const unsigned n_z_cells,
640 const double cell_size_x,
641 const double cell_size_y,
642 const double cell_size_z,
644 std::string
const& mesh_name)
658 std::string
const& mesh_name)
660 std::vector<double> vec_x(div_x());
661 std::vector<double> vec_y(div_y());
662 std::vector<double> vec_z(div_z());
663 std::vector<MeshLib::Node*> nodes(
666 const unsigned n_x_nodes(vec_x.size());
667 const unsigned n_y_nodes(vec_y.size());
668 const unsigned n_x_cells(vec_x.size() - 1);
669 const unsigned n_y_cells(vec_y.size() - 1);
670 const unsigned n_z_cells(vec_z.size() - 1);
673 std::vector<MeshLib::Element*> elements;
674 elements.reserve(n_x_cells * n_y_cells * n_z_cells * 6);
676 for (std::size_t i = 0; i < n_z_cells; i++)
678 const std::size_t offset_z1 = i * n_x_nodes * n_y_nodes;
679 const std::size_t offset_z2 = (i + 1) * n_x_nodes * n_y_nodes;
680 for (std::size_t j = 0; j < n_y_cells; j++)
682 const std::size_t offset_y1 = j * n_x_nodes;
683 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
684 for (std::size_t k = 0; k < n_x_cells; k++)
689 nodes[offset_z1 + offset_y1 + k],
690 nodes[offset_z1 + offset_y2 + k + 1],
691 nodes[offset_z1 + offset_y2 + k],
693 nodes[offset_z2 + offset_y1 + k]}));
697 nodes[offset_z1 + offset_y2 + k + 1],
698 nodes[offset_z1 + offset_y2 + k],
700 nodes[offset_z2 + offset_y1 + k],
701 nodes[offset_z2 + offset_y2 + k + 1]}));
705 nodes[offset_z1 + offset_y2 + k],
707 nodes[offset_z2 + offset_y1 + k],
708 nodes[offset_z2 + offset_y2 + k + 1],
709 nodes[offset_z2 + offset_y2 + k]}));
713 nodes[offset_z1 + offset_y1 + k],
714 nodes[offset_z1 + offset_y1 + k + 1],
715 nodes[offset_z1 + offset_y2 + k + 1],
717 nodes[offset_z2 + offset_y1 + k + 1]}));
721 nodes[offset_z1 + offset_y1 + k],
722 nodes[offset_z1 + offset_y2 + k + 1],
724 nodes[offset_z2 + offset_y1 + k],
725 nodes[offset_z2 + offset_y1 + k + 1]}));
729 nodes[offset_z1 + offset_y2 + k + 1],
731 nodes[offset_z2 + offset_y1 + k],
732 nodes[offset_z2 + offset_y1 + k + 1],
733 nodes[offset_z2 + offset_y2 + k + 1]}));
744 const std::function<
double(
double,
double)>& f)
746 std::array<double, 2>
const step_size{{(ur[0] - ll[0]) / (n_steps[0] - 1),
747 (ur[1] - ll[1]) / (n_steps[1] - 1)}};
749 std::vector<MeshLib::Node*> nodes;
750 for (std::size_t j(0); j < n_steps[1]; ++j)
752 for (std::size_t i(0); i < n_steps[0]; ++i)
754 std::size_t
const id = i + j * n_steps[1];
755 double const x = ll[0] + i * step_size[0];
756 double const y = ll[1] + j * step_size[1];
762 std::vector<MeshLib::Element*> sfc_eles;
763 for (std::size_t j(0); j < n_steps[1] - 1; ++j)
765 for (std::size_t i(0); i < n_steps[0] - 1; ++i)
767 std::size_t id_ll(i + j * n_steps[0]);
768 std::size_t id_lr(i + 1 + j * n_steps[0]);
769 std::size_t id_ul(i + (j + 1) * n_steps[0]);
770 std::size_t id_ur(i + 1 + (j + 1) * n_steps[0]);
772 new MeshLib::Tri({nodes[id_ll], nodes[id_lr], nodes[id_ur]}));
774 new MeshLib::Tri({nodes[id_ll], nodes[id_ur], nodes[id_ul]}));
Definition of AddLayerToMesh class.
Definition of the Hex class.
Definition of the Line class.
Definition of the Node class.
Definition of the Pyramid class.
Definition of the Quad class.
Definition of the Tet class.
Definition of the Tri class.