Loading [MathJax]/extensions/tex2jax.js
OGS
ConstructMeshesFromGeometries.cpp
Go to the documentation of this file.
1 
11 
12 #include "BaseLib/Logging.h"
14 #include "GeoLib/GEOObjects.h"
17 #include "MeshLib/Node.h"
18 #include "MeshNodeSearcher.h"
19 
20 namespace MeshGeoToolsLib
21 {
22 std::string meshNameFromGeometry(std::string const& geometrical_set_name,
23  std::string const& geometry_name)
24 {
25  return geometrical_set_name + "_" + geometry_name;
26 }
27 
28 template <typename GeometryVec>
29 std::vector<std::unique_ptr<MeshLib::Mesh>>
31  std::vector<GeometryVec*> const& geometries,
32  MeshGeoToolsLib::BoundaryElementsSearcher& boundary_element_searcher,
33  bool const multiple_nodes_allowed)
34 {
35  std::vector<std::unique_ptr<MeshLib::Mesh>> additional_meshes;
36 
37  for (GeometryVec* const geometry_vec : geometries)
38  {
39  // Each geometry_vec has a name, this is the first part of the full
40  // name.
41  auto const& vec_name = geometry_vec->getName();
42 
43  auto const& vec_data = *geometry_vec->getVector();
44 
45  auto const vec_size = geometry_vec->size();
46  for (std::size_t i = 0; i < vec_size; ++i)
47  {
48  // Each geometry has a name, this is the second part of the full
49  // name.
50  std::string geometry_name;
51  bool const is_geometry_named =
52  geometry_vec->getNameOfElementByID(i, geometry_name);
53  if (!is_geometry_named)
54  {
55  continue;
56  }
57 
58  auto const& geometry = *vec_data[i];
59 
60  DBUG("Creating mesh from geometry {:s} {:s}.", vec_name,
61  geometry_name);
62 
63  additional_meshes.emplace_back(createMeshFromElementSelection(
64  meshNameFromGeometry(vec_name, geometry_name),
66  boundary_element_searcher.getBoundaryElements(
67  geometry, multiple_nodes_allowed))));
68  }
69  }
70  return additional_meshes;
71 }
72 
73 std::vector<std::unique_ptr<MeshLib::Mesh>>
75  MeshLib::Mesh const& mesh,
76  std::unique_ptr<SearchLength>
77  search_length_algorithm,
78  bool const multiple_nodes_allowed)
79 {
80  std::vector<std::unique_ptr<MeshLib::Mesh>> additional_meshes;
81 
82  auto const& mesh_node_searcher =
84  mesh, std::move(search_length_algorithm));
85 
86  MeshGeoToolsLib::BoundaryElementsSearcher boundary_element_searcher(
87  mesh, mesh_node_searcher);
88 
89  //
90  // Points
91  //
92  {
93  auto point_meshes = constructAdditionalMeshesFromGeometries(
94  geo_objects.getPoints(), boundary_element_searcher,
95  multiple_nodes_allowed);
96  std::move(begin(point_meshes), end(point_meshes),
97  std::back_inserter(additional_meshes));
98  }
99 
100  //
101  // Polylines
102  //
103  {
104  auto polyline_meshes = constructAdditionalMeshesFromGeometries(
105  geo_objects.getPolylines(), boundary_element_searcher,
106  multiple_nodes_allowed);
107  std::move(begin(polyline_meshes), end(polyline_meshes),
108  std::back_inserter(additional_meshes));
109  }
110 
111  // Surfaces
112  {
113  auto surface_meshes = constructAdditionalMeshesFromGeometries(
114  geo_objects.getSurfaces(), boundary_element_searcher,
115  multiple_nodes_allowed);
116  std::move(begin(surface_meshes), end(surface_meshes),
117  std::back_inserter(additional_meshes));
118  }
119 
120  // Set axial symmetry for the additional meshes to the same value as the
121  // "bulk" mesh.
122  std::for_each(begin(additional_meshes), end(additional_meshes),
123  [axial_symmetry = mesh.isAxiallySymmetric()](auto& m)
124  { m->setAxiallySymmetric(axial_symmetry); });
125  return additional_meshes;
126 }
127 } // namespace MeshGeoToolsLib
Definition of Duplicate functions.
Definition of the Element class.
Definition of the GEOObjects class.
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
Definition of the Node class.
Container class for geometric objects.
Definition: GEOObjects.h:61
std::vector< PointVec * > const & getPoints() const
Read access to points w/o using a name.
Definition: GEOObjects.h:286
std::vector< SurfaceVec * > const & getSurfaces() const
Read access to surfaces w/o using a name.
Definition: GEOObjects.h:290
std::vector< PolylineVec * > const & getPolylines() const
Read access to polylines w/o using a name.
Definition: GEOObjects.h:288
std::vector< MeshLib::Element * > const & getBoundaryElements(GeoLib::GeoObject const &geoObj, bool const multiple_nodes_allowed)
static MeshNodeSearcher const & getMeshNodeSearcher(MeshLib::Mesh const &mesh, std::unique_ptr< MeshGeoToolsLib::SearchLength > &&search_length_algorithm)
bool isAxiallySymmetric() const
Definition: Mesh.h:126
std::string meshNameFromGeometry(std::string const &geometrical_set_name, std::string const &geometry_name)
std::vector< std::unique_ptr< MeshLib::Mesh > > constructAdditionalMeshesFromGeoObjects(GeoLib::GEOObjects const &geo_objects, MeshLib::Mesh const &mesh, std::unique_ptr< SearchLength > search_length_algorithm, bool const multiple_nodes_allowed)
std::vector< std::unique_ptr< MeshLib::Mesh > > constructAdditionalMeshesFromGeometries(std::vector< GeometryVec * > const &geometries, MeshGeoToolsLib::BoundaryElementsSearcher &boundary_element_searcher, bool const multiple_nodes_allowed)
std::unique_ptr< MeshLib::Mesh > createMeshFromElementSelection(std::string mesh_name, std::vector< MeshLib::Element * > const &elements)
Definition: Mesh.cpp:268
std::vector< Element * > cloneElements(std::vector< Element * > const &elements)
Clones a vector of elements using the Element::clone() function.