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)
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);
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++)
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]);
253 std::string
const& mesh_name)
255 std::vector<double> vec_x(div_x());
256 std::vector<double> vec_y(div_y());
257 std::vector<MeshLib::Node*> nodes(
259 const unsigned n_x_nodes(vec_x.size());
262 std::vector<MeshLib::Element*> elements;
263 const unsigned n_x_cells(vec_x.size() - 1);
264 const unsigned n_y_cells(vec_y.size() - 1);
265 elements.reserve(n_x_cells * n_y_cells);
267 for (std::size_t j = 0; j < n_y_cells; j++)
269 const std::size_t offset_y1 = j * n_x_nodes;
270 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
271 for (std::size_t k = 0; k < n_x_cells; k++)
274 {nodes[offset_y1 + k], nodes[offset_y1 + k + 1],
275 nodes[offset_y2 + k + 1], nodes[offset_y2 + k]}));
344 std::string
const& mesh_name)
346 std::vector<double> vec_x(div_x());
347 std::vector<double> vec_y(div_y());
348 std::vector<double> vec_z(div_z());
349 std::vector<MeshLib::Node*> nodes(
352 const unsigned n_x_nodes(vec_x.size());
353 const unsigned n_y_nodes(vec_y.size());
354 const unsigned n_x_cells(vec_x.size() - 1);
355 const unsigned n_y_cells(vec_y.size() - 1);
356 const unsigned n_z_cells(vec_z.size() - 1);
359 std::vector<MeshLib::Element*> elements;
360 elements.reserve(n_x_cells * n_y_cells * n_z_cells);
362 for (std::size_t i = 0; i < n_z_cells; i++)
364 const std::size_t offset_z1 = i * n_x_nodes * n_y_nodes;
365 const std::size_t offset_z2 = (i + 1) * n_x_nodes * n_y_nodes;
366 for (std::size_t j = 0; j < n_y_cells; j++)
368 const std::size_t offset_y1 = j * n_x_nodes;
369 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
370 for (std::size_t k = 0; k < n_x_cells; k++)
374 nodes[offset_z1 + offset_y1 + k],
375 nodes[offset_z1 + offset_y1 + k + 1],
376 nodes[offset_z1 + offset_y2 + k + 1],
377 nodes[offset_z1 + offset_y2 + k],
379 nodes[offset_z2 + offset_y1 + k],
380 nodes[offset_z2 + offset_y1 + k + 1],
381 nodes[offset_z2 + offset_y2 + k + 1],
382 nodes[offset_z2 + offset_y2 + k]}));
396 std::string
const& mesh_name)
398 std::vector<double> vec_x(div_x());
399 std::vector<double> vec_y(div_y());
400 std::vector<double> vec_z(div_z());
401 std::vector<MeshLib::Node*> nodes(
403 std::vector<MeshLib::Node*>
const top_nodes(
406 nodes.insert(nodes.end(), top_nodes.begin(), top_nodes.end());
408 const unsigned n_x_nodes(vec_x.size());
409 const unsigned n_y_nodes(vec_y.size());
410 const unsigned n_z_nodes(vec_z.size());
411 const unsigned n_x_cells(vec_x.size() - 1);
412 const unsigned n_y_cells(vec_y.size() - 1);
413 const unsigned n_z_cells(vec_z.size() - 1);
416 std::vector<MeshLib::Element*> elements;
417 auto const top_node_offset(n_x_nodes * n_y_nodes * n_z_nodes);
418 elements.reserve(n_x_cells * n_y_cells * n_z_cells);
420 for (std::size_t i = 0; i < n_z_cells; i++)
422 const std::size_t offset_z1 = i * n_x_nodes * n_y_nodes;
423 const std::size_t offset_z2 = (i + 1) * n_x_nodes * n_y_nodes;
424 for (std::size_t j = 0; j < n_y_cells; j++)
426 const std::size_t offset_y1 = j * n_x_nodes;
427 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
428 for (std::size_t k = 0; k < n_x_cells; k++)
431 int const pyramid_top_index(i * n_x_cells * n_y_cells +
436 nodes[offset_z1 + offset_y1 + k],
437 nodes[offset_z1 + offset_y1 + k + 1],
438 nodes[offset_z1 + offset_y2 + k + 1],
439 nodes[offset_z1 + offset_y2 + k],
441 nodes[pyramid_top_index]}});
444 nodes[offset_z2 + offset_y1 + k + 1],
445 nodes[offset_z2 + offset_y1 + k],
446 nodes[offset_z2 + offset_y2 + k],
447 nodes[offset_z2 + offset_y2 + k + 1],
449 nodes[pyramid_top_index]}});
452 nodes[offset_z1 + offset_y1 + k + 1],
453 nodes[offset_z2 + offset_y1 + k + 1],
454 nodes[offset_z2 + offset_y2 + k + 1],
455 nodes[offset_z1 + offset_y2 + k + 1],
457 nodes[pyramid_top_index]}});
460 nodes[offset_z2 + offset_y1 + k],
461 nodes[offset_z1 + offset_y1 + k],
462 nodes[offset_z1 + offset_y2 + k],
463 nodes[offset_z2 + offset_y2 + k],
465 nodes[pyramid_top_index]}});
468 nodes[offset_z2 + offset_y1 + k],
469 nodes[offset_z2 + offset_y1 + k + 1],
470 nodes[offset_z1 + offset_y1 + k + 1],
471 nodes[offset_z1 + offset_y1 + k],
473 nodes[pyramid_top_index]}});
476 nodes[offset_z1 + offset_y2 + k],
477 nodes[offset_z1 + offset_y2 + k + 1],
478 nodes[offset_z2 + offset_y2 + k + 1],
479 nodes[offset_z2 + offset_y2 + k],
481 nodes[pyramid_top_index]}});
541 std::string
const& mesh_name)
543 std::vector<double> vec_x(div_x());
544 std::vector<double> vec_y(div_y());
545 std::vector<MeshLib::Node*> nodes(
547 const unsigned n_x_nodes(vec_x.size());
548 const unsigned n_x_cells(vec_x.size() - 1);
549 const unsigned n_y_cells(vec_y.size() - 1);
552 std::vector<MeshLib::Element*> elements;
553 elements.reserve(n_x_cells * n_y_cells * 2);
555 for (std::size_t j = 0; j < n_y_cells; j++)
557 const std::size_t offset_y1 = j * n_x_nodes;
558 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
559 for (std::size_t k = 0; k < n_x_cells; k++)
561 elements.push_back(
new MeshLib::Tri({nodes[offset_y1 + k],
562 nodes[offset_y2 + k + 1],
563 nodes[offset_y2 + k]}));
565 elements.push_back(
new MeshLib::Tri({nodes[offset_y1 + k],
566 nodes[offset_y1 + k + 1],
567 nodes[offset_y2 + k + 1]}));
603 const unsigned n_x_cells,
604 const unsigned n_y_cells,
605 const unsigned n_z_cells,
606 const double cell_size_x,
607 const double cell_size_y,
608 const double cell_size_z,
610 std::string
const& mesh_name)
613 n_x_cells, n_y_cells, cell_size_x, cell_size_y, origin, mesh_name));
614 std::size_t
const n_tris(mesh->getNumberOfElements());
615 bool const copy_material_ids =
false;
616 for (std::size_t i = 0; i < n_z_cells; ++i)
619 true, copy_material_ids,
622 std::vector<std::size_t> elem_ids(n_tris);
623 std::iota(elem_ids.begin(), elem_ids.end(), 0);
664 std::string
const& mesh_name)
666 std::vector<double> vec_x(div_x());
667 std::vector<double> vec_y(div_y());
668 std::vector<double> vec_z(div_z());
669 std::vector<MeshLib::Node*> nodes(
672 const unsigned n_x_nodes(vec_x.size());
673 const unsigned n_y_nodes(vec_y.size());
674 const unsigned n_x_cells(vec_x.size() - 1);
675 const unsigned n_y_cells(vec_y.size() - 1);
676 const unsigned n_z_cells(vec_z.size() - 1);
679 std::vector<MeshLib::Element*> elements;
680 elements.reserve(n_x_cells * n_y_cells * n_z_cells * 6);
682 for (std::size_t i = 0; i < n_z_cells; i++)
684 const std::size_t offset_z1 = i * n_x_nodes * n_y_nodes;
685 const std::size_t offset_z2 = (i + 1) * n_x_nodes * n_y_nodes;
686 for (std::size_t j = 0; j < n_y_cells; j++)
688 const std::size_t offset_y1 = j * n_x_nodes;
689 const std::size_t offset_y2 = (j + 1) * n_x_nodes;
690 for (std::size_t k = 0; k < n_x_cells; k++)
695 nodes[offset_z1 + 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]}));
703 nodes[offset_z1 + 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]}));
711 nodes[offset_z1 + offset_y2 + k],
713 nodes[offset_z2 + offset_y1 + k],
714 nodes[offset_z2 + offset_y2 + k + 1],
715 nodes[offset_z2 + offset_y2 + k]}));
719 nodes[offset_z1 + offset_y1 + k],
720 nodes[offset_z1 + offset_y1 + k + 1],
721 nodes[offset_z1 + offset_y2 + k + 1],
723 nodes[offset_z2 + offset_y1 + k + 1]}));
727 nodes[offset_z1 + offset_y1 + k],
728 nodes[offset_z1 + offset_y2 + k + 1],
730 nodes[offset_z2 + offset_y1 + k],
731 nodes[offset_z2 + offset_y1 + k + 1]}));
735 nodes[offset_z1 + offset_y2 + k + 1],
737 nodes[offset_z2 + offset_y1 + k],
738 nodes[offset_z2 + offset_y1 + k + 1],
739 nodes[offset_z2 + offset_y2 + k + 1]}));
751 const std::function<
double(
double,
double)>& f)
753 std::array<double, 2>
const step_size{{(ur[0] - ll[0]) / (n_steps[0] - 1),
754 (ur[1] - ll[1]) / (n_steps[1] - 1)}};
756 std::vector<MeshLib::Node*> nodes;
757 for (std::size_t j(0); j < n_steps[1]; ++j)
759 for (std::size_t i(0); i < n_steps[0]; ++i)
761 std::size_t
const id = i + j * n_steps[1];
762 double const x = ll[0] + i * step_size[0];
763 double const y = ll[1] + j * step_size[1];
769 std::vector<MeshLib::Element*> sfc_eles;
770 for (std::size_t j(0); j < n_steps[1] - 1; ++j)
772 for (std::size_t i(0); i < n_steps[0] - 1; ++i)
774 std::size_t id_ll(i + j * n_steps[0]);
775 std::size_t id_lr(i + 1 + j * n_steps[0]);
776 std::size_t id_ul(i + (j + 1) * n_steps[0]);
777 std::size_t id_ur(i + 1 + (j + 1) * n_steps[0]);
779 new MeshLib::Tri({nodes[id_ll], nodes[id_lr], nodes[id_ur]}));
781 new MeshLib::Tri({nodes[id_ll], nodes[id_ur], nodes[id_ul]}));