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