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<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])
53 coords[0].begin(), coords[0].end(), std::back_inserter(nodes),
54 [&y, &z](
double const& x) {
return new Node(x, y, z); });
63 std::vector<const std::vector<double>*> vec_xyz_coords;
64 vec_xyz_coords.push_back(&vec_x_coords);
65 std::vector<double> dummy(1, 0.0);
66 for (
unsigned i = vec_xyz_coords.size() - 1; i < 3u; i++)
68 vec_xyz_coords.push_back(&dummy);
74 std::vector<double>& vec_x_coords,
75 std::vector<double>& vec_y_coords,
78 std::vector<const std::vector<double>*> vec_xyz_coords;
79 vec_xyz_coords.push_back(&vec_x_coords);
80 vec_xyz_coords.push_back(&vec_y_coords);
81 std::vector<double> dummy(1, 0.0);
82 for (
unsigned i = vec_xyz_coords.size() - 1; i < 3u; i++)
84 vec_xyz_coords.push_back(&dummy);
90 std::vector<double>& vec_x_coords,
91 std::vector<double>& vec_y_coords,
92 std::vector<double>& vec_z_coords,
95 std::vector<const std::vector<double>*> vec_xyz_coords;
96 vec_xyz_coords.push_back(&vec_x_coords);
97 vec_xyz_coords.push_back(&vec_y_coords);
98 vec_xyz_coords.push_back(&vec_z_coords);
103 const std::array<unsigned, 3>& n_cells,
104 const std::array<double, 3>& cell_size,
107 std::vector<Node*> nodes;
108 nodes.reserve((n_cells[0] + 1) * (n_cells[1] + 1) * (n_cells[2] + 1));
110 for (std::size_t i = 0; i < n_cells[2] + 1; i++)
112 const double z(origin[2] + cell_size[2] * i);
113 for (std::size_t j = 0; j < n_cells[1] + 1; j++)
115 const double y(origin[1] + cell_size[1] * j);
116 for (std::size_t k = 0; k < n_cells[0] + 1; k++)
118 nodes.push_back(
new Node(origin[0] + cell_size[0] * k, y, z));
125 namespace MeshGenerator
128 std::vector<double>
const& x_coords,
129 std::vector<double>
const& y_coords,
130 std::vector<double>
const& z_coords,
133 std::vector<Node*> nodes;
134 nodes.reserve((x_coords.size() - 1) * (y_coords.size() - 1) *
135 (z_coords.size() - 1));
137 auto const n_x_coords = x_coords.size() - 1;
138 auto const n_y_coords = y_coords.size() - 1;
139 auto const n_z_coords = z_coords.size() - 1;
141 for (std::size_t i = 0; i < n_z_coords; i++)
143 const double z((z_coords[i] + z_coords[i + 1]) / 2 + origin[2]);
144 for (std::size_t j = 0; j < n_y_coords; j++)
146 const double y((y_coords[j] + y_coords[j + 1]) / 2 + origin[1]);
147 for (std::size_t k = 0; k < n_x_coords; k++)
149 const double x((x_coords[k] + x_coords[k + 1]) / 2 + origin[0]);
150 nodes.push_back(
new Node(x, y, z));
159 const std::size_t subdivision,
161 std::string
const& mesh_name)
168 const double cell_size,
170 std::string
const& mesh_name)
179 std::string
const& mesh_name)
181 const std::vector<double> vec_x(div());
185 const std::size_t n_cells = nodes.size() - 1;
186 std::vector<Element*> elements;
187 elements.reserve(n_cells);
189 for (std::size_t i = 0; i < n_cells; i++)
191 elements.push_back(
new Line({nodes[i], nodes[i + 1]}));
194 return new Mesh(mesh_name, nodes, elements);
198 const std::size_t subdivision,
200 std::string
const& mesh_name)
203 length / subdivision, length / subdivision,
208 const double y_length,
209 const std::size_t x_subdivision,
210 const std::size_t y_subdivision,
212 std::string
const& mesh_name)
215 x_length / x_subdivision,
216 y_length / y_subdivision, origin, mesh_name);
220 const unsigned n_y_cells,
221 const double cell_size,
223 std::string
const& mesh_name)
230 const unsigned n_y_cells,
231 const double cell_size_x,
232 const double cell_size_y,
234 std::string
const& mesh_name)
245 std::string
const& mesh_name)
247 std::vector<double> vec_x(div_x());
248 std::vector<double> vec_y(div_y());
250 const unsigned n_x_nodes(vec_x.size());
253 std::vector<Element*> elements;
254 const unsigned n_x_cells(vec_x.size() - 1);
255 const unsigned n_y_cells(vec_y.size() - 1);
256 elements.reserve(n_x_cells * n_y_cells);
258 for (std::size_t j = 0; j < n_y_cells; j++)
260 const std::size_t offset_y1 = j * n_x_nodes;
261 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
262 for (std::size_t k = 0; k < n_x_cells; k++)
265 new Quad({nodes[offset_y1 + k], nodes[offset_y1 + k + 1],
266 nodes[offset_y2 + k + 1], nodes[offset_y2 + k]}));
270 return new Mesh(mesh_name, nodes, elements);
274 const std::size_t subdivision,
276 std::string
const& mesh_name)
279 subdivision, subdivision, subdivision, length / subdivision, origin,
284 const double y_length,
285 const double z_length,
286 const std::size_t x_subdivision,
287 const std::size_t y_subdivision,
288 const std::size_t z_subdivision,
290 std::string
const& mesh_name)
293 x_subdivision, y_subdivision, z_subdivision, x_length / x_subdivision,
294 y_length / y_subdivision, z_length / z_subdivision, origin, mesh_name);
298 const unsigned n_y_cells,
299 const unsigned n_z_cells,
300 const double cell_size,
302 std::string
const& mesh_name)
305 n_x_cells, n_y_cells, n_z_cells, cell_size, cell_size, cell_size,
310 const unsigned n_y_cells,
311 const unsigned n_z_cells,
312 const double cell_size_x,
313 const double cell_size_y,
314 const double cell_size_z,
316 std::string
const& mesh_name)
329 std::string
const& mesh_name)
331 std::vector<double> vec_x(div_x());
332 std::vector<double> vec_y(div_y());
333 std::vector<double> vec_z(div_z());
336 const unsigned n_x_nodes(vec_x.size());
337 const unsigned n_y_nodes(vec_y.size());
338 const unsigned n_x_cells(vec_x.size() - 1);
339 const unsigned n_y_cells(vec_y.size() - 1);
340 const unsigned n_z_cells(vec_z.size() - 1);
343 std::vector<Element*> elements;
344 elements.reserve(n_x_cells * n_y_cells * n_z_cells);
346 for (std::size_t i = 0; i < n_z_cells; i++)
348 const std::size_t offset_z1 = i * n_x_nodes * n_y_nodes;
349 const std::size_t offset_z2 = (i + 1) * n_x_nodes * n_y_nodes;
350 for (std::size_t j = 0; j < n_y_cells; j++)
352 const std::size_t offset_y1 = j * n_x_nodes;
353 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
354 for (std::size_t k = 0; k < n_x_cells; k++)
358 nodes[offset_z1 + offset_y1 + k],
359 nodes[offset_z1 + offset_y1 + k + 1],
360 nodes[offset_z1 + offset_y2 + k + 1],
361 nodes[offset_z1 + offset_y2 + k],
363 nodes[offset_z2 + offset_y1 + k],
364 nodes[offset_z2 + offset_y1 + k + 1],
365 nodes[offset_z2 + offset_y2 + k + 1],
366 nodes[offset_z2 + offset_y2 + k]}));
371 return new Mesh(mesh_name, nodes, elements);
379 std::string
const& mesh_name)
381 std::vector<double> vec_x(div_x());
382 std::vector<double> vec_y(div_y());
383 std::vector<double> vec_z(div_z());
385 std::vector<Node*>
const top_nodes(
388 nodes.insert(nodes.end(), top_nodes.begin(), top_nodes.end());
390 const unsigned n_x_nodes(vec_x.size());
391 const unsigned n_y_nodes(vec_y.size());
392 const unsigned n_z_nodes(vec_z.size());
393 const unsigned n_x_cells(vec_x.size() - 1);
394 const unsigned n_y_cells(vec_y.size() - 1);
395 const unsigned n_z_cells(vec_z.size() - 1);
398 std::vector<Element*> elements;
399 auto const top_node_offset(n_x_nodes * n_y_nodes * n_z_nodes);
400 elements.reserve(n_x_cells * n_y_cells * n_z_cells);
402 for (std::size_t i = 0; i < n_z_cells; i++)
404 const std::size_t offset_z1 = i * n_x_nodes * n_y_nodes;
405 const std::size_t offset_z2 = (i + 1) * n_x_nodes * n_y_nodes;
406 for (std::size_t j = 0; j < n_y_cells; j++)
408 const std::size_t offset_y1 = j * n_x_nodes;
409 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
410 for (std::size_t k = 0; k < n_x_cells; k++)
413 int const pyramid_top_index(i * n_x_cells * n_y_cells +
418 nodes[offset_z1 + offset_y1 + k],
419 nodes[offset_z1 + offset_y1 + k + 1],
420 nodes[offset_z1 + offset_y2 + k + 1],
421 nodes[offset_z1 + offset_y2 + k],
423 nodes[pyramid_top_index]}});
426 nodes[offset_z2 + offset_y1 + k + 1],
427 nodes[offset_z2 + offset_y1 + k],
428 nodes[offset_z2 + offset_y2 + k],
429 nodes[offset_z2 + offset_y2 + k + 1],
431 nodes[pyramid_top_index]}});
434 nodes[offset_z1 + offset_y1 + k + 1],
435 nodes[offset_z2 + offset_y1 + k + 1],
436 nodes[offset_z2 + offset_y2 + k + 1],
437 nodes[offset_z1 + offset_y2 + k + 1],
439 nodes[pyramid_top_index]}});
442 nodes[offset_z2 + offset_y1 + k],
443 nodes[offset_z1 + offset_y1 + k],
444 nodes[offset_z1 + offset_y2 + k],
445 nodes[offset_z2 + offset_y2 + k],
447 nodes[pyramid_top_index]}});
450 nodes[offset_z2 + offset_y1 + k],
451 nodes[offset_z2 + offset_y1 + k + 1],
452 nodes[offset_z1 + offset_y1 + k + 1],
453 nodes[offset_z1 + offset_y1 + k],
455 nodes[pyramid_top_index]}});
458 nodes[offset_z1 + offset_y2 + k],
459 nodes[offset_z1 + offset_y2 + k + 1],
460 nodes[offset_z2 + offset_y2 + k + 1],
461 nodes[offset_z2 + offset_y2 + k],
463 nodes[pyramid_top_index]}});
467 return new Mesh(mesh_name, nodes, elements);
471 const std::size_t subdivision,
473 std::string
const& mesh_name)
476 length / subdivision, origin, mesh_name);
480 const double y_length,
481 const std::size_t x_subdivision,
482 const std::size_t y_subdivision,
484 std::string
const& mesh_name)
487 x_length / x_subdivision,
488 y_length / y_subdivision, origin, mesh_name);
492 const unsigned n_y_cells,
493 const double cell_size,
495 std::string
const& mesh_name)
502 const unsigned n_y_cells,
503 const double cell_size_x,
504 const double cell_size_y,
506 std::string
const& mesh_name)
517 std::string
const& mesh_name)
519 std::vector<double> vec_x(div_x());
520 std::vector<double> vec_y(div_y());
522 const unsigned n_x_nodes(vec_x.size());
523 const unsigned n_x_cells(vec_x.size() - 1);
524 const unsigned n_y_cells(vec_y.size() - 1);
527 std::vector<Element*> elements;
528 elements.reserve(n_x_cells * n_y_cells * 2);
530 for (std::size_t j = 0; j < n_y_cells; j++)
532 const std::size_t offset_y1 = j * n_x_nodes;
533 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
534 for (std::size_t k = 0; k < n_x_cells; k++)
537 new Tri({nodes[offset_y1 + k], nodes[offset_y2 + k + 1],
538 nodes[offset_y2 + k]}));
541 new Tri({nodes[offset_y1 + k], nodes[offset_y1 + k + 1],
542 nodes[offset_y2 + k + 1]}));
546 return new Mesh(mesh_name, nodes, elements);
550 const double y_length,
551 const double z_length,
552 const std::size_t x_subdivision,
553 const std::size_t y_subdivision,
554 const std::size_t z_subdivision,
556 std::string
const& mesh_name)
559 x_subdivision, y_subdivision, z_subdivision, x_length / x_subdivision,
560 y_length / y_subdivision, z_length / z_subdivision, origin, mesh_name);
564 const unsigned n_y_cells,
565 const unsigned n_z_cells,
566 const double cell_size,
568 std::string
const& mesh_name)
571 cell_size, cell_size, origin, mesh_name);
575 const unsigned n_y_cells,
576 const unsigned n_z_cells,
577 const double cell_size_x,
578 const double cell_size_y,
579 const double cell_size_z,
581 std::string
const& mesh_name)
584 n_x_cells, n_y_cells, cell_size_x, cell_size_y, origin, mesh_name));
585 std::size_t
const n_tris(mesh->getNumberOfElements());
586 bool const copy_material_ids =
false;
587 for (std::size_t i = 0; i < n_z_cells; ++i)
592 std::vector<std::size_t> elem_ids(n_tris);
593 std::iota(elem_ids.begin(), elem_ids.end(), 0);
598 const double y_length,
599 const double z_length,
600 const std::size_t x_subdivision,
601 const std::size_t y_subdivision,
602 const std::size_t z_subdivision,
604 std::string
const& mesh_name)
607 x_subdivision, y_subdivision, z_subdivision, x_length / x_subdivision,
608 y_length / y_subdivision, z_length / z_subdivision, origin, mesh_name);
612 const unsigned n_y_cells,
613 const unsigned n_z_cells,
614 const double cell_size_x,
615 const double cell_size_y,
616 const double cell_size_z,
618 std::string
const& mesh_name)
631 std::string
const& mesh_name)
633 std::vector<double> vec_x(div_x());
634 std::vector<double> vec_y(div_y());
635 std::vector<double> vec_z(div_z());
638 const unsigned n_x_nodes(vec_x.size());
639 const unsigned n_y_nodes(vec_y.size());
640 const unsigned n_x_cells(vec_x.size() - 1);
641 const unsigned n_y_cells(vec_y.size() - 1);
642 const unsigned n_z_cells(vec_z.size() - 1);
645 std::vector<Element*> elements;
646 elements.reserve(n_x_cells * n_y_cells * n_z_cells * 6);
648 for (std::size_t i = 0; i < n_z_cells; i++)
650 const std::size_t offset_z1 = i * n_x_nodes * n_y_nodes;
651 const std::size_t offset_z2 = (i + 1) * n_x_nodes * n_y_nodes;
652 for (std::size_t j = 0; j < n_y_cells; j++)
654 const std::size_t offset_y1 = j * n_x_nodes;
655 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
656 for (std::size_t k = 0; k < n_x_cells; k++)
661 nodes[offset_z1 + offset_y1 + k],
662 nodes[offset_z1 + offset_y2 + k + 1],
663 nodes[offset_z1 + offset_y2 + k],
665 nodes[offset_z2 + offset_y1 + k]}));
669 nodes[offset_z1 + offset_y2 + k + 1],
670 nodes[offset_z1 + offset_y2 + k],
672 nodes[offset_z2 + offset_y1 + k],
673 nodes[offset_z2 + offset_y2 + k + 1]}));
677 nodes[offset_z1 + offset_y2 + k],
679 nodes[offset_z2 + offset_y1 + k],
680 nodes[offset_z2 + offset_y2 + k + 1],
681 nodes[offset_z2 + offset_y2 + k]}));
685 nodes[offset_z1 + offset_y1 + k],
686 nodes[offset_z1 + offset_y1 + k + 1],
687 nodes[offset_z1 + offset_y2 + k + 1],
689 nodes[offset_z2 + offset_y1 + k + 1]}));
693 nodes[offset_z1 + offset_y1 + k],
694 nodes[offset_z1 + offset_y2 + k + 1],
696 nodes[offset_z2 + offset_y1 + k],
697 nodes[offset_z2 + offset_y1 + k + 1]}));
701 nodes[offset_z1 + offset_y2 + k + 1],
703 nodes[offset_z2 + offset_y1 + k],
704 nodes[offset_z2 + offset_y1 + k + 1],
705 nodes[offset_z2 + offset_y2 + k + 1]}));
710 return new Mesh(mesh_name, nodes, elements);
716 const std::function<
double(
double,
double)>& f)
718 std::array<double, 2> step_size{{(ur[0] - ll[0]) / (n_steps[0] - 1),
719 (ur[1] - ll[1]) / (n_steps[1] - 1)}};
721 std::vector<MeshLib::Node*> nodes;
722 for (std::size_t j(0); j < n_steps[1]; ++j)
724 for (std::size_t i(0); i < n_steps[0]; ++i)
726 std::size_t
const id = i + j * n_steps[1];
727 double const x = ll[0] + i * step_size[0];
728 double const y = ll[1] + j * step_size[1];
734 std::vector<MeshLib::Element*> sfc_eles;
735 for (std::size_t j(0); j < n_steps[1] - 1; ++j)
737 for (std::size_t i(0); i < n_steps[0] - 1; ++i)
739 std::size_t id_ll(i + j * n_steps[0]);
740 std::size_t id_lr(i + 1 + j * n_steps[0]);
741 std::size_t id_ul(i + (j + 1) * n_steps[0]);
742 std::size_t id_ur(i + 1 + (j + 1) * n_steps[0]);
744 new MeshLib::Tri({nodes[id_ll], nodes[id_lr], nodes[id_ur]}));
746 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.
MeshLib::Mesh * createSurfaceMesh(std::string const &mesh_name, MathLib::Point3d const &ll, MathLib::Point3d const &ur, std::array< std::size_t, 2 > const &n_steps, const std::function< double(double, double)> &f)
Mesh * generateRegularPrismMesh(const double x_length, const double y_length, const double z_length, const std::size_t x_subdivision, const std::size_t y_subdivision, const std::size_t z_subdivision, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
std::vector< MeshLib::Node * > generateRegularPyramidTopNodes(std::vector< double > const &x_coords, std::vector< double > const &y_coords, std::vector< double > const &z_coords, const MathLib::Point3d &origin)
std::vector< MeshLib::Node * > generateRegularNodes(const std::vector< const std::vector< double > * > &vec_xyz_coords, const MathLib::Point3d &origin=MathLib::ORIGIN)
Mesh * generateLineMesh(const BaseLib::ISubdivision &div, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
Mesh * generateRegularTriMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
Mesh * generateRegularQuadMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
Mesh * generateRegularPyramidMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, const BaseLib::ISubdivision &div_z, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
Mesh * generateRegularTetMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, const BaseLib::ISubdivision &div_z, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
Mesh * generateRegularHexMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, const BaseLib::ISubdivision &div_z, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
MeshLib::Mesh * removeElements(const MeshLib::Mesh &mesh, const std::vector< std::size_t > &removed_element_ids, const std::string &new_mesh_name)
TemplateElement< MeshLib::TetRule4 > Tet
TemplateElement< MeshLib::LineRule2 > Line
TemplateElement< MeshLib::TriRule3 > Tri
MeshLib::Mesh * addLayerToMesh(MeshLib::Mesh const &mesh, double thickness, std::string const &name, bool on_top, bool copy_material_ids)
TemplateElement< MeshLib::HexRule8 > Hex
TemplateElement< MeshLib::QuadRule4 > Quad