OGS
ConstructMeshesFromGeometries.cpp
Go to the documentation of this file.
1
11
12#ifdef USE_PETSC
13#include <mpi.h>
14
17#endif
18
19#include "BaseLib/Logging.h"
21#include "GeoLib/GEOObjects.h"
23#include "MeshLib/Node.h"
26#include "MeshNodeSearcher.h"
27
28namespace MeshGeoToolsLib
29{
30std::string meshNameFromGeometry(std::string const& geometrical_set_name,
31 std::string const& geometry_name)
32{
33 return geometrical_set_name + "_" + geometry_name;
34}
35
36template <typename GeometryVec>
37std::vector<std::unique_ptr<MeshLib::Mesh>>
39 std::vector<GeometryVec*> const& geometries,
40 MeshGeoToolsLib::BoundaryElementsSearcher& boundary_element_searcher,
41 bool const multiple_nodes_allowed)
42{
43 std::vector<std::unique_ptr<MeshLib::Mesh>> additional_meshes;
44
45#ifdef USE_PETSC
46 // The subdomain_mesh is not yet a NodePartitionedMesh.
47 // The bulk_mesh, which is a NodePartitionedMesh, is needed to construct the
48 // subdomain NodePartitionedMesh.
49 auto const* bulk_mesh = dynamic_cast<MeshLib::NodePartitionedMesh const*>(
50 &boundary_element_searcher.mesh);
51#endif
52 for (GeometryVec* const geometry_vec : geometries)
53 {
54 // Each geometry_vec has a name, this is the first part of the full
55 // name.
56 auto const& vec_name = geometry_vec->getName();
57
58 auto const& vec_data = geometry_vec->getVector();
59
60 auto const vec_size = geometry_vec->size();
61 for (std::size_t i = 0; i < vec_size; ++i)
62 {
63 // Each geometry has a name, this is the second part of the full
64 // name.
65 std::string geometry_name;
66 bool const is_geometry_named =
67 geometry_vec->getNameOfElementByID(i, geometry_name);
68 if (!is_geometry_named)
69 {
70 continue;
71 }
72
73 auto const& geometry = *vec_data[i];
74
75 DBUG("Creating mesh from geometry {:s} {:s}.", vec_name,
76 geometry_name);
77
78 auto subdomain_mesh = createMeshFromElementSelection(
79 meshNameFromGeometry(vec_name, geometry_name),
81 boundary_element_searcher.getBoundaryElements(
82 geometry, multiple_nodes_allowed)));
83
84#ifdef USE_PETSC
85 additional_meshes.push_back(
87 bulk_mesh, subdomain_mesh.get()));
88#else
89 // Nothing special to be done in the serial case.
90 additional_meshes.emplace_back(std::move(subdomain_mesh));
91#endif
92 }
93 }
94 return additional_meshes;
95}
96
97std::vector<std::unique_ptr<MeshLib::Mesh>>
99 MeshLib::Mesh const& mesh,
100 std::unique_ptr<SearchLength>
101 search_length_algorithm,
102 bool const multiple_nodes_allowed)
103{
104 std::vector<std::unique_ptr<MeshLib::Mesh>> additional_meshes;
105
106 auto const& mesh_node_searcher =
108 mesh, std::move(search_length_algorithm));
109
110 MeshGeoToolsLib::BoundaryElementsSearcher boundary_element_searcher(
111 mesh, mesh_node_searcher);
112
113 //
114 // Points
115 //
116 {
117 auto point_meshes = constructAdditionalMeshesFromGeometries(
118 geo_objects.getPoints(), boundary_element_searcher,
119 multiple_nodes_allowed);
120 std::move(begin(point_meshes), end(point_meshes),
121 std::back_inserter(additional_meshes));
122 }
123
124 //
125 // Polylines
126 //
127 {
128 auto polyline_meshes = constructAdditionalMeshesFromGeometries(
129 geo_objects.getPolylines(), boundary_element_searcher,
130 multiple_nodes_allowed);
131 std::move(begin(polyline_meshes), end(polyline_meshes),
132 std::back_inserter(additional_meshes));
133 }
134
135 // Surfaces
136 {
137 auto surface_meshes = constructAdditionalMeshesFromGeometries(
138 geo_objects.getSurfaces(), boundary_element_searcher,
139 multiple_nodes_allowed);
140 std::move(begin(surface_meshes), end(surface_meshes),
141 std::back_inserter(additional_meshes));
142 }
143
144 // Set axial symmetry for the additional meshes to the same value as the
145 // "bulk" mesh.
146 std::for_each(begin(additional_meshes), end(additional_meshes),
147 [axial_symmetry = mesh.isAxiallySymmetric()](auto& m)
148 { m->setAxiallySymmetric(axial_symmetry); });
149 return additional_meshes;
150}
151} // namespace MeshGeoToolsLib
Definition of Duplicate functions.
Definition of the Element class.
Definition of the GEOObjects class.
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Definition of mesh class for partitioned mesh (by node) for parallel computing within the framework o...
Definition of the Node class.
Container class for geometric objects.
Definition GEOObjects.h:57
std::vector< PolylineVec * > const & getPolylines() const
Read access to polylines w/o using a name.
Definition GEOObjects.h:299
std::vector< PointVec * > const & getPoints() const
Read access to points w/o using a name.
Definition GEOObjects.h:297
std::vector< SurfaceVec * > const & getSurfaces() const
Read access to surfaces w/o using a name.
Definition GEOObjects.h:301
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:137
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:103
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::vector< Element * > cloneElements(std::vector< Element * > const &elements)
Clones a vector of elements using the Element::clone() function.
std::unique_ptr< NodePartitionedMesh > transformMeshToNodePartitionedMesh(NodePartitionedMesh const *const bulk_mesh, Mesh const *const subdomain_mesh)