22 const std::vector<
const std::vector<double>*>& vec_xyz_coords,
25 auto const shift_coordinates =
26 [](
auto const& in,
auto& out,
auto const& shift)
28 std::transform(in.begin(), in.end(), std::back_inserter(out),
29 [&shift](
auto const& v) { return v + shift; });
31 std::array<std::vector<double>, 3> coords;
32 for (std::size_t i = 0; i < 3; ++i)
34 coords[i].reserve(vec_xyz_coords[i]->size());
35 shift_coordinates(*vec_xyz_coords[i], coords[i], origin[i]);
38 std::vector<MeshLib::Node*> nodes;
39 nodes.reserve(coords[0].size() * coords[1].size() * coords[2].size());
41 for (
auto const z : coords[2])
43 for (
auto const y : coords[1])
45 std::transform(coords[0].begin(), coords[0].end(),
46 std::back_inserter(nodes),
47 [&y, &z](
double const& x)
68 std::vector<double>& vec_x_coords,
69 std::vector<double>& vec_y_coords,
72 std::vector<const std::vector<double>*> vec_xyz_coords;
73 vec_xyz_coords.push_back(&vec_x_coords);
74 vec_xyz_coords.push_back(&vec_y_coords);
75 std::vector<double> dummy(1, 0.0);
76 for (
unsigned i = vec_xyz_coords.size() - 1; i < 3u; i++)
78 vec_xyz_coords.push_back(&dummy);
97 const std::array<unsigned, 3>& n_cells,
98 const std::array<double, 3>& cell_size,
101 std::vector<MeshLib::Node*> nodes;
102 nodes.reserve((n_cells[0] + 1) * (n_cells[1] + 1) * (n_cells[2] + 1));
104 for (std::size_t i = 0; i < n_cells[2] + 1; i++)
106 const double z(origin[2] + cell_size[2] * i);
107 for (std::size_t j = 0; j < n_cells[1] + 1; j++)
109 const double y(origin[1] + cell_size[1] * j);
110 for (std::size_t k = 0; k < n_cells[0] + 1; k++)
123 std::vector<double>
const& x_coords,
124 std::vector<double>
const& y_coords,
125 std::vector<double>
const& z_coords,
128 std::vector<MeshLib::Node*> nodes;
129 nodes.reserve((x_coords.size() - 1) * (y_coords.size() - 1) *
130 (z_coords.size() - 1));
132 auto const n_x_coords = x_coords.size() - 1;
133 auto const n_y_coords = y_coords.size() - 1;
134 auto const n_z_coords = z_coords.size() - 1;
136 for (std::size_t i = 0; i < n_z_coords; i++)
138 const double z((z_coords[i] + z_coords[i + 1]) / 2 + origin[2]);
139 for (std::size_t j = 0; j < n_y_coords; j++)
141 const double y((y_coords[j] + y_coords[j + 1]) / 2 + origin[1]);
142 for (std::size_t k = 0; k < n_x_coords; k++)
144 const double x((x_coords[k] + x_coords[k + 1]) / 2 + origin[0]);
246 std::string
const& mesh_name)
248 std::vector<double> vec_x(div_x());
249 std::vector<double> vec_y(div_y());
250 std::vector<MeshLib::Node*> nodes(
252 const unsigned n_x_nodes(vec_x.size());
255 std::vector<MeshLib::Element*> elements;
256 const unsigned n_x_cells(vec_x.size() - 1);
257 const unsigned n_y_cells(vec_y.size() - 1);
258 elements.reserve(n_x_cells * n_y_cells);
260 for (std::size_t j = 0; j < n_y_cells; j++)
262 const std::size_t offset_y1 = j * n_x_nodes;
263 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
264 for (std::size_t k = 0; k < n_x_cells; k++)
267 {nodes[offset_y1 + k], nodes[offset_y1 + k + 1],
268 nodes[offset_y2 + k + 1], nodes[offset_y2 + k]}));
337 std::string
const& mesh_name)
339 std::vector<double> vec_x(div_x());
340 std::vector<double> vec_y(div_y());
341 std::vector<double> vec_z(div_z());
342 std::vector<MeshLib::Node*> nodes(
345 const unsigned n_x_nodes(vec_x.size());
346 const unsigned n_y_nodes(vec_y.size());
347 const unsigned n_x_cells(vec_x.size() - 1);
348 const unsigned n_y_cells(vec_y.size() - 1);
349 const unsigned n_z_cells(vec_z.size() - 1);
352 std::vector<MeshLib::Element*> elements;
353 elements.reserve(n_x_cells * n_y_cells * n_z_cells);
355 for (std::size_t i = 0; i < n_z_cells; i++)
357 const std::size_t offset_z1 = i * n_x_nodes * n_y_nodes;
358 const std::size_t offset_z2 = (i + 1) * n_x_nodes * n_y_nodes;
359 for (std::size_t j = 0; j < n_y_cells; j++)
361 const std::size_t offset_y1 = j * n_x_nodes;
362 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
363 for (std::size_t k = 0; k < n_x_cells; k++)
367 nodes[offset_z1 + offset_y1 + k],
368 nodes[offset_z1 + offset_y1 + k + 1],
369 nodes[offset_z1 + offset_y2 + k + 1],
370 nodes[offset_z1 + offset_y2 + k],
372 nodes[offset_z2 + offset_y1 + k],
373 nodes[offset_z2 + offset_y1 + k + 1],
374 nodes[offset_z2 + offset_y2 + k + 1],
375 nodes[offset_z2 + offset_y2 + k]}));
389 std::string
const& mesh_name)
391 std::vector<double> vec_x(div_x());
392 std::vector<double> vec_y(div_y());
393 std::vector<double> vec_z(div_z());
394 std::vector<MeshLib::Node*> nodes(
396 std::vector<MeshLib::Node*>
const top_nodes(
399 nodes.insert(nodes.end(), top_nodes.begin(), top_nodes.end());
401 const unsigned n_x_nodes(vec_x.size());
402 const unsigned n_y_nodes(vec_y.size());
403 const unsigned n_z_nodes(vec_z.size());
404 const unsigned n_x_cells(vec_x.size() - 1);
405 const unsigned n_y_cells(vec_y.size() - 1);
406 const unsigned n_z_cells(vec_z.size() - 1);
409 std::vector<MeshLib::Element*> elements;
410 auto const top_node_offset(n_x_nodes * n_y_nodes * n_z_nodes);
411 elements.reserve(n_x_cells * n_y_cells * n_z_cells);
413 for (std::size_t i = 0; i < n_z_cells; i++)
415 const std::size_t offset_z1 = i * n_x_nodes * n_y_nodes;
416 const std::size_t offset_z2 = (i + 1) * n_x_nodes * n_y_nodes;
417 for (std::size_t j = 0; j < n_y_cells; j++)
419 const std::size_t offset_y1 = j * n_x_nodes;
420 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
421 for (std::size_t k = 0; k < n_x_cells; k++)
424 int const pyramid_top_index(i * n_x_cells * n_y_cells +
429 nodes[offset_z1 + offset_y1 + k],
430 nodes[offset_z1 + offset_y1 + k + 1],
431 nodes[offset_z1 + offset_y2 + k + 1],
432 nodes[offset_z1 + offset_y2 + k],
434 nodes[pyramid_top_index]}});
437 nodes[offset_z2 + offset_y1 + k + 1],
438 nodes[offset_z2 + offset_y1 + k],
439 nodes[offset_z2 + offset_y2 + k],
440 nodes[offset_z2 + offset_y2 + k + 1],
442 nodes[pyramid_top_index]}});
445 nodes[offset_z1 + offset_y1 + k + 1],
446 nodes[offset_z2 + offset_y1 + k + 1],
447 nodes[offset_z2 + offset_y2 + k + 1],
448 nodes[offset_z1 + offset_y2 + k + 1],
450 nodes[pyramid_top_index]}});
453 nodes[offset_z2 + offset_y1 + k],
454 nodes[offset_z1 + offset_y1 + k],
455 nodes[offset_z1 + offset_y2 + k],
456 nodes[offset_z2 + offset_y2 + k],
458 nodes[pyramid_top_index]}});
461 nodes[offset_z2 + offset_y1 + k],
462 nodes[offset_z2 + offset_y1 + k + 1],
463 nodes[offset_z1 + offset_y1 + k + 1],
464 nodes[offset_z1 + offset_y1 + k],
466 nodes[pyramid_top_index]}});
469 nodes[offset_z1 + offset_y2 + k],
470 nodes[offset_z1 + offset_y2 + k + 1],
471 nodes[offset_z2 + offset_y2 + k + 1],
472 nodes[offset_z2 + offset_y2 + k],
474 nodes[pyramid_top_index]}});
534 std::string
const& mesh_name)
536 std::vector<double> vec_x(div_x());
537 std::vector<double> vec_y(div_y());
538 std::vector<MeshLib::Node*> nodes(
540 const unsigned n_x_nodes(vec_x.size());
541 const unsigned n_x_cells(vec_x.size() - 1);
542 const unsigned n_y_cells(vec_y.size() - 1);
545 std::vector<MeshLib::Element*> elements;
546 elements.reserve(n_x_cells * n_y_cells * 2);
548 for (std::size_t j = 0; j < n_y_cells; j++)
550 const std::size_t offset_y1 = j * n_x_nodes;
551 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
552 for (std::size_t k = 0; k < n_x_cells; k++)
554 elements.push_back(
new MeshLib::Tri({nodes[offset_y1 + k],
555 nodes[offset_y2 + k + 1],
556 nodes[offset_y2 + k]}));
558 elements.push_back(
new MeshLib::Tri({nodes[offset_y1 + k],
559 nodes[offset_y1 + k + 1],
560 nodes[offset_y2 + k + 1]}));
596 const unsigned n_x_cells,
597 const unsigned n_y_cells,
598 const unsigned n_z_cells,
599 const double cell_size_x,
600 const double cell_size_y,
601 const double cell_size_z,
603 std::string
const& mesh_name)
606 n_x_cells, n_y_cells, cell_size_x, cell_size_y, origin, mesh_name));
607 std::size_t
const n_tris(mesh->getNumberOfElements());
608 bool const copy_material_ids =
false;
609 for (std::size_t i = 0; i < n_z_cells; ++i)
612 true, copy_material_ids,
615 std::vector<std::size_t> elem_ids(n_tris);
616 std::iota(elem_ids.begin(), elem_ids.end(), 0);
657 std::string
const& mesh_name)
659 std::vector<double> vec_x(div_x());
660 std::vector<double> vec_y(div_y());
661 std::vector<double> vec_z(div_z());
662 std::vector<MeshLib::Node*> nodes(
665 const unsigned n_x_nodes(vec_x.size());
666 const unsigned n_y_nodes(vec_y.size());
667 const unsigned n_x_cells(vec_x.size() - 1);
668 const unsigned n_y_cells(vec_y.size() - 1);
669 const unsigned n_z_cells(vec_z.size() - 1);
672 std::vector<MeshLib::Element*> elements;
673 elements.reserve(n_x_cells * n_y_cells * n_z_cells * 6);
675 for (std::size_t i = 0; i < n_z_cells; i++)
677 const std::size_t offset_z1 = i * n_x_nodes * n_y_nodes;
678 const std::size_t offset_z2 = (i + 1) * n_x_nodes * n_y_nodes;
679 for (std::size_t j = 0; j < n_y_cells; j++)
681 const std::size_t offset_y1 = j * n_x_nodes;
682 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
683 for (std::size_t k = 0; k < n_x_cells; k++)
688 nodes[offset_z1 + offset_y1 + k],
689 nodes[offset_z1 + offset_y2 + k + 1],
690 nodes[offset_z1 + offset_y2 + k],
692 nodes[offset_z2 + offset_y1 + k]}));
696 nodes[offset_z1 + offset_y2 + k + 1],
697 nodes[offset_z1 + offset_y2 + k],
699 nodes[offset_z2 + offset_y1 + k],
700 nodes[offset_z2 + offset_y2 + k + 1]}));
704 nodes[offset_z1 + offset_y2 + k],
706 nodes[offset_z2 + offset_y1 + k],
707 nodes[offset_z2 + offset_y2 + k + 1],
708 nodes[offset_z2 + offset_y2 + k]}));
712 nodes[offset_z1 + offset_y1 + k],
713 nodes[offset_z1 + offset_y1 + k + 1],
714 nodes[offset_z1 + offset_y2 + k + 1],
716 nodes[offset_z2 + offset_y1 + k + 1]}));
720 nodes[offset_z1 + offset_y1 + k],
721 nodes[offset_z1 + offset_y2 + k + 1],
723 nodes[offset_z2 + offset_y1 + k],
724 nodes[offset_z2 + offset_y1 + k + 1]}));
728 nodes[offset_z1 + offset_y2 + k + 1],
730 nodes[offset_z2 + offset_y1 + k],
731 nodes[offset_z2 + offset_y1 + k + 1],
732 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]}));