36 std::vector<std::size_t>
const& id_map,
39 auto const number_of_components =
property.getNumberOfGlobalComponents();
43 number_of_components);
45 sfc_prop->reserve(id_map.size());
47 for (
auto bulk_id : id_map)
50 number_of_components, back_inserter(*sfc_prop));
56 std::vector<std::size_t>
const& node_ids_map,
57 std::vector<std::size_t>
const& element_ids_map)
61 if (node_ids_map.size() != n_nodes)
63 ERR(
"createSfcMeshProperties() - Incorrect number of node IDs ({:d}) "
64 "compared to actual number of surface nodes ({:d}).",
65 node_ids_map.size(), n_nodes);
69 if (element_ids_map.size() != n_elems)
71 ERR(
"createSfcMeshProperties() - Incorrect number of element IDs "
72 "({:d}) compared to actual number of surface elements ({:d}).",
73 element_ids_map.size(), n_elems);
76 std::map<MeshLib::MeshItemType, std::vector<std::size_t>
const*>
const
80 std::size_t vectors_copied(0);
81 std::size_t vectors_skipped(0);
82 for (
auto [name, property] : properties)
88 "Skipping property vector '{:s}' - not defined on cells or "
95 auto const& id_map = *id_maps.at(property->getMeshItemType());
102 else if (
auto const* p =
108 else if (
auto const* p =
114 else if (
auto const* p =
120 else if (
auto const* p =
126 else if (
auto const* p =
133 else if (
auto const* p =
140 else if (
auto const* p =
147 else if (
auto const* p =
154 else if (
auto const* p =
163 "Skipping property vector '{:s}' - no matching data type "
165 name,
typeid(*property).name());
169 INFO(
"{:d} property vectors copied, {:d} vectors skipped.", vectors_copied,
174std::tuple<std::vector<MeshLib::Node*>, std::vector<std::size_t>>
176 std::size_t
const n_all_nodes)
178 std::vector<MeshLib::Node const*> tmp_nodes(n_all_nodes,
nullptr);
179 for (
auto const* elem : elements)
181 auto const n_nodes = elem->getNumberOfNodes();
182 for (
unsigned j = 0; j < n_nodes; ++j)
185 tmp_nodes[node->
getID()] = node;
189 std::vector<MeshLib::Node*> nodes;
190 std::vector<std::size_t> node_id_map(n_all_nodes);
191 for (
unsigned i = 0; i < n_all_nodes; ++i)
195 node_id_map[i] = nodes.size();
199 return {nodes, node_id_map};
205 std::vector<double> node_area_vec;
208 ERR(
"Error in MeshSurfaceExtraction::getSurfaceAreaForNodes() - Given "
209 "mesh is no surface mesh (dimension != 2).");
210 return node_area_vec;
213 double total_area(0);
216 const std::vector<MeshLib::Node*>& nodes = mesh.
getNodes();
218 for (std::size_t n = 0; n < nNodes; ++n)
223 const std::size_t nConnElems(conn_elems.size());
225 for (std::size_t i = 0; i < nConnElems; ++i)
228 const unsigned nElemParts =
231 const double area = conn_elems[i]->getContent() / nElemParts;
236 node_area_vec.push_back(node_area);
239 INFO(
"Total surface Area: {:f}", total_area);
241 return node_area_vec;
245 const MeshLib::Mesh& subsfc_mesh, Eigen::Vector3d
const& dir,
double angle,
246 std::string_view subsfc_node_id_prop_name,
247 std::string_view subsfc_element_id_prop_name,
248 std::string_view face_id_prop_name)
251 if (angle < 0 || angle > 91)
253 ERR(
"Supported angle between 0 and 90 degrees only.");
257 INFO(
"Extracting mesh surface...");
258 std::vector<MeshLib::Element*> sfc_elements;
259 std::vector<std::size_t> element_ids_map;
260 std::vector<std::size_t> face_ids_map;
262 element_ids_map, face_ids_map, dir, angle,
265 if (sfc_elements.empty())
277 std::for_each(sfc_elements.begin(), sfc_elements.end(),
281 std::vector<std::size_t>
const id_map(sfc_node_ids.begin(),
286 new_elements,
true ));
289 subsfc_element_id_prop_name, element_ids_map,
290 face_id_prop_name, face_ids_map);
295 ERR(
"Transferring subsurface properties failed.");
301 const std::vector<MeshLib::Element*>& all_elements,
302 std::vector<MeshLib::Element*>& sfc_elements,
303 std::vector<std::size_t>& element_to_bulk_element_id_map,
304 std::vector<std::size_t>& element_to_bulk_face_id_map,
305 Eigen::Vector3d
const& dir,
double angle,
unsigned mesh_dimension)
307 if (mesh_dimension < 2 || mesh_dimension > 3)
309 ERR(
"Cannot handle meshes of dimension {}", mesh_dimension);
312 bool const complete_surface = (dir.dot(dir) == 0);
314 double const cos_theta(std::cos(angle * std::numbers::pi / 180.0));
315 Eigen::Vector3d
const norm_dir(dir.normalized());
317 for (
auto const* elem : all_elements)
319 const unsigned element_dimension(elem->getDimension());
320 if (element_dimension < mesh_dimension)
325 if (element_dimension == 2)
327 if (!complete_surface)
330 norm_dir) > cos_theta)
335 sfc_elements.push_back(elem->clone());
336 element_to_bulk_element_id_map.push_back(elem->getID());
337 element_to_bulk_face_id_map.push_back(0);
341 if (!elem->isBoundaryElement())
345 const unsigned nFaces(elem->getNumberOfFaces());
346 for (
unsigned j = 0; j < nFaces; ++j)
348 if (elem->getNeighbor(j) !=
nullptr)
354 std::unique_ptr<MeshLib::Element const>{elem->getFace(j)};
355 if (!complete_surface)
359 .dot(norm_dir) < cos_theta)
364 switch (face->getCellType())
387 DBUG(
"unknown cell type");
389 element_to_bulk_element_id_map.push_back(elem->getID());
390 element_to_bulk_face_id_map.push_back(j);
397 const MeshLib::Mesh& mesh, Eigen::Vector3d
const& dir,
double angle)
399 INFO(
"Extracting surface nodes...");
400 std::vector<MeshLib::Element*> sfc_elements;
401 std::vector<std::size_t> element_to_bulk_element_id_map;
402 std::vector<std::size_t> element_to_bulk_face_id_map;
405 mesh.
getElements(), sfc_elements, element_to_bulk_element_id_map,
406 element_to_bulk_face_id_map, dir, angle, mesh.
getDimension());
408 std::vector<MeshLib::Node*> surface_nodes;
409 std::tie(surface_nodes, std::ignore) =
412 for (
auto e : sfc_elements)
417 return surface_nodes;
422 std::vector<MeshLib::Element*>& surface_elements,
423 std::vector<std::size_t>& element_to_bulk_element_id_map,
424 std::vector<std::size_t>& element_to_bulk_face_id_map)
427 for (
unsigned j = 0; j < n_faces; ++j)
434 surface_elements.push_back(
436 element_to_bulk_face_id_map.push_back(j);
437 element_to_bulk_element_id_map.push_back(surface_element.
getID());
441std::tuple<std::vector<MeshLib::Element*>, std::vector<std::size_t>,
442 std::vector<std::size_t>>
445 std::vector<std::size_t> element_to_bulk_element_id_map;
446 std::vector<std::size_t> element_to_bulk_face_id_map;
447 std::vector<MeshLib::Element*> surface_elements;
449 auto const& bulk_elements = bulk_mesh.
getElements();
452 for (
auto const* elem : bulk_elements)
454 const unsigned element_dimension(elem->getDimension());
455 if (element_dimension < mesh_dimension)
460 if (!elem->isBoundaryElement())
465 element_to_bulk_element_id_map,
466 element_to_bulk_face_id_map);
468 return {surface_elements, element_to_bulk_element_id_map,
469 element_to_bulk_face_id_map};
472namespace BoundaryExtraction
476 std::string_view subsfc_node_id_prop_name,
477 std::string_view subsfc_element_id_prop_name,
478 std::string_view face_id_prop_name)
481 if (mesh_dimension < 2 || mesh_dimension > 3)
483 ERR(
"Cannot handle meshes of dimension {}", mesh_dimension);
487 auto [boundary_elements, element_to_bulk_element_id_map,
496 boundary_elements, boundary_nodes, &node_id_map);
497 for (
auto* e : boundary_elements)
504 std::vector<std::size_t>
const nodes_to_bulk_nodes_id_map(
505 boundary_node_ids.begin(), boundary_node_ids.end());
507 std::unique_ptr<MeshLib::Mesh> boundary_mesh(
509 new_elements,
true ));
512 *boundary_mesh, subsfc_node_id_prop_name, nodes_to_bulk_nodes_id_map,
513 subsfc_element_id_prop_name, element_to_bulk_element_id_map,
514 face_id_prop_name, element_to_bulk_face_id_map);
518 nodes_to_bulk_nodes_id_map,
519 element_to_bulk_element_id_map))
521 ERR(
"Transferring subsurface properties failed.");
523 return boundary_mesh;
530 std::string_view node_to_bulk_node_id_map_name,
531 std::vector<std::size_t>
const& node_to_bulk_node_id_map,
532 std::string_view element_to_bulk_element_id_map_name,
533 std::vector<std::size_t>
const& element_to_bulk_element_id_map,
534 std::string_view element_to_bulk_face_id_map_name,
535 std::vector<std::size_t>
const& element_to_bulk_face_id_map)
538 if (!node_to_bulk_node_id_map_name.empty())
542 node_to_bulk_node_id_map);
546 if (!element_to_bulk_element_id_map_name.empty())
549 surface_mesh, element_to_bulk_element_id_map_name,
554 if (!element_to_bulk_face_id_map_name.empty())
557 surface_mesh, element_to_bulk_face_id_map_name,
Definition of Duplicate functions.
Definition of the Line class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the Mesh class.
Definition of the Quad class.
Definition of the Tri class.
std::size_t getID() const
virtual MeshElemType getGeomType() const =0
virtual unsigned getNumberOfBoundaries() const =0
std::size_t getID() const
Returns the ID of the element.
virtual const Element * getNeighbor(unsigned i) const =0
Get the specified neighbor.
virtual const Element * getBoundary(unsigned i) const =0
static Eigen::Vector3d getSurfaceNormal(Element const &e)
Returns the surface normal of a 2D element.
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Properties & getProperties()
const std::string getName() const
Get name of the mesh.
std::size_t getNumberOfNodes() const
Get the number of nodes.
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
std::size_t getNumberOfElements() const
Get the number of elements.
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
MeshItemType getMeshItemType() const
std::string const & getPropertyName() const
PROP_VAL_TYPE & getComponent(std::size_t tuple_index, int component)
Returns the value for the given component stored in the given tuple.
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
PropertyVector< T > * getOrCreateMeshProperty(Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)
std::vector< Element * > copyElementVector(std::vector< Element * > const &elements, std::vector< Node * > const &new_nodes, std::vector< std::size_t > const *const node_id_map)
void addPropertyToMesh(Mesh &mesh, std::string_view name, MeshItemType item_type, std::size_t number_of_components, std::vector< T > const &values)