19#include <range/v3/view/join.hpp>
20#include <range/v3/view/transform.hpp>
39 std::vector<std::size_t>
const& id_map,
42 auto const number_of_components =
property.getNumberOfGlobalComponents();
46 number_of_components);
48 auto get_components = [&](std::size_t
const bulk_id)
51 number_of_components);
53 sfc_prop->assign(id_map | ranges::views::transform(get_components) |
59 std::vector<std::size_t>
const& node_ids_map,
60 std::vector<std::size_t>
const& element_ids_map)
64 if (node_ids_map.size() != n_nodes)
66 ERR(
"createSfcMeshProperties() - Incorrect number of node IDs ({:d}) "
67 "compared to actual number of surface nodes ({:d}).",
68 node_ids_map.size(), n_nodes);
72 if (element_ids_map.size() != n_elems)
74 ERR(
"createSfcMeshProperties() - Incorrect number of element IDs "
75 "({:d}) compared to actual number of surface elements ({:d}).",
76 element_ids_map.size(), n_elems);
79 std::map<MeshLib::MeshItemType, std::vector<std::size_t>
const*>
const
83 std::size_t vectors_copied(0);
84 std::size_t vectors_skipped(0);
85 for (
auto [name, property] : properties)
91 "Skipping property vector '{:s}' - not defined on cells or "
98 auto const& id_map = *id_maps.at(property->getMeshItemType());
105 else if (
auto const* p =
111 else if (
auto const* p =
117 else if (
auto const* p =
123 else if (
auto const* p =
129 else if (
auto const* p =
136 else if (
auto const* p =
143 else if (
auto const* p =
150 else if (
auto const* p =
157 else if (
auto const* p =
166 "Skipping property vector '{:s}' - no matching data type "
168 name,
typeid(*property).name());
172 INFO(
"{:d} property vectors copied, {:d} vectors skipped.", vectors_copied,
177std::tuple<std::vector<MeshLib::Node*>, std::vector<std::size_t>>
179 std::size_t
const n_all_nodes)
181 std::vector<MeshLib::Node const*> tmp_nodes(n_all_nodes,
nullptr);
182 for (
auto const* elem : elements)
184 auto const n_nodes = elem->getNumberOfNodes();
185 for (
unsigned j = 0; j < n_nodes; ++j)
188 tmp_nodes[node->
getID()] = node;
192 std::vector<MeshLib::Node*> nodes;
193 std::vector<std::size_t> node_id_map(n_all_nodes);
194 for (
unsigned i = 0; i < n_all_nodes; ++i)
198 node_id_map[i] = nodes.size();
202 return {nodes, node_id_map};
208 std::vector<double> node_area_vec;
211 ERR(
"Error in MeshSurfaceExtraction::getSurfaceAreaForNodes() - Given "
212 "mesh is no surface mesh (dimension != 2).");
213 return node_area_vec;
216 double total_area(0);
219 const std::vector<MeshLib::Node*>& nodes = mesh.
getNodes();
221 for (std::size_t n = 0; n < nNodes; ++n)
226 const std::size_t nConnElems(conn_elems.size());
228 for (std::size_t i = 0; i < nConnElems; ++i)
231 const unsigned nElemParts =
234 const double area = conn_elems[i]->getContent() / nElemParts;
239 node_area_vec.push_back(node_area);
242 INFO(
"Total surface Area: {:f}", total_area);
244 return node_area_vec;
248 const MeshLib::Mesh& subsfc_mesh, Eigen::Vector3d
const& dir,
double angle,
249 std::string_view subsfc_node_id_prop_name,
250 std::string_view subsfc_element_id_prop_name,
251 std::string_view face_id_prop_name)
254 if (angle < 0 || angle > 91)
256 ERR(
"Supported angle between 0 and 90 degrees only.");
260 INFO(
"Extracting mesh surface...");
261 std::vector<MeshLib::Element*> sfc_elements;
262 std::vector<std::size_t> element_ids_map;
263 std::vector<std::size_t> face_ids_map;
265 element_ids_map, face_ids_map, dir, angle,
268 if (sfc_elements.empty())
280 std::for_each(sfc_elements.begin(), sfc_elements.end(),
284 std::vector<std::size_t>
const id_map(sfc_node_ids.begin(),
289 new_elements,
true ));
292 subsfc_element_id_prop_name, element_ids_map,
293 face_id_prop_name, face_ids_map);
298 ERR(
"Transferring subsurface properties failed.");
304 const std::vector<MeshLib::Element*>& all_elements,
305 std::vector<MeshLib::Element*>& sfc_elements,
306 std::vector<std::size_t>& element_to_bulk_element_id_map,
307 std::vector<std::size_t>& element_to_bulk_face_id_map,
308 Eigen::Vector3d
const& dir,
double angle,
unsigned mesh_dimension)
310 if (mesh_dimension < 2 || mesh_dimension > 3)
312 ERR(
"Cannot handle meshes of dimension {}", mesh_dimension);
315 bool const complete_surface = (dir.dot(dir) == 0);
317 double const cos_theta(std::cos(angle * std::numbers::pi / 180.0));
318 Eigen::Vector3d
const norm_dir(dir.normalized());
320 for (
auto const* elem : all_elements)
322 const unsigned element_dimension(elem->getDimension());
323 if (element_dimension < mesh_dimension)
328 if (element_dimension == 2)
330 if (!complete_surface)
333 norm_dir) > cos_theta)
338 sfc_elements.push_back(elem->clone());
339 element_to_bulk_element_id_map.push_back(elem->getID());
340 element_to_bulk_face_id_map.push_back(0);
344 if (!elem->isBoundaryElement())
348 const unsigned nFaces(elem->getNumberOfFaces());
349 for (
unsigned j = 0; j < nFaces; ++j)
351 if (elem->getNeighbor(j) !=
nullptr)
357 std::unique_ptr<MeshLib::Element const>{elem->getFace(j)};
358 if (!complete_surface)
362 .dot(norm_dir) < cos_theta)
367 switch (face->getCellType())
390 DBUG(
"unknown cell type");
392 element_to_bulk_element_id_map.push_back(elem->getID());
393 element_to_bulk_face_id_map.push_back(j);
400 const MeshLib::Mesh& mesh, Eigen::Vector3d
const& dir,
double angle)
402 INFO(
"Extracting surface nodes...");
403 std::vector<MeshLib::Element*> sfc_elements;
404 std::vector<std::size_t> element_to_bulk_element_id_map;
405 std::vector<std::size_t> element_to_bulk_face_id_map;
408 mesh.
getElements(), sfc_elements, element_to_bulk_element_id_map,
409 element_to_bulk_face_id_map, dir, angle, mesh.
getDimension());
411 std::vector<MeshLib::Node*> surface_nodes;
412 std::tie(surface_nodes, std::ignore) =
415 for (
auto e : sfc_elements)
420 return surface_nodes;
425 std::vector<MeshLib::Element*>& surface_elements,
426 std::vector<std::size_t>& element_to_bulk_element_id_map,
427 std::vector<std::size_t>& element_to_bulk_face_id_map)
430 for (
unsigned j = 0; j < n_faces; ++j)
437 surface_elements.push_back(
439 element_to_bulk_face_id_map.push_back(j);
440 element_to_bulk_element_id_map.push_back(surface_element.
getID());
444std::tuple<std::vector<MeshLib::Element*>, std::vector<std::size_t>,
445 std::vector<std::size_t>>
448 std::vector<std::size_t> element_to_bulk_element_id_map;
449 std::vector<std::size_t> element_to_bulk_face_id_map;
450 std::vector<MeshLib::Element*> surface_elements;
452 auto const& bulk_elements = bulk_mesh.
getElements();
455 for (
auto const* elem : bulk_elements)
457 const unsigned element_dimension(elem->getDimension());
458 if (element_dimension < mesh_dimension)
463 if (!elem->isBoundaryElement())
468 element_to_bulk_element_id_map,
469 element_to_bulk_face_id_map);
471 return {surface_elements, element_to_bulk_element_id_map,
472 element_to_bulk_face_id_map};
475namespace BoundaryExtraction
479 std::string_view subsfc_node_id_prop_name,
480 std::string_view subsfc_element_id_prop_name,
481 std::string_view face_id_prop_name)
484 if (mesh_dimension < 2 || mesh_dimension > 3)
486 ERR(
"Cannot handle meshes of dimension {}", mesh_dimension);
490 auto [boundary_elements, element_to_bulk_element_id_map,
499 boundary_elements, boundary_nodes, &node_id_map);
500 for (
auto* e : boundary_elements)
507 std::vector<std::size_t>
const nodes_to_bulk_nodes_id_map(
508 boundary_node_ids.begin(), boundary_node_ids.end());
510 std::unique_ptr<MeshLib::Mesh> boundary_mesh(
512 new_elements,
true ));
515 *boundary_mesh, subsfc_node_id_prop_name, nodes_to_bulk_nodes_id_map,
516 subsfc_element_id_prop_name, element_to_bulk_element_id_map,
517 face_id_prop_name, element_to_bulk_face_id_map);
521 nodes_to_bulk_nodes_id_map,
522 element_to_bulk_element_id_map))
524 ERR(
"Transferring subsurface properties failed.");
526 return boundary_mesh;
475namespace BoundaryExtraction {
…}
533 std::string_view node_to_bulk_node_id_map_name,
534 std::vector<std::size_t>
const& node_to_bulk_node_id_map,
535 std::string_view element_to_bulk_element_id_map_name,
536 std::vector<std::size_t>
const& element_to_bulk_element_id_map,
537 std::string_view element_to_bulk_face_id_map_name,
538 std::vector<std::size_t>
const& element_to_bulk_face_id_map)
541 if (!node_to_bulk_node_id_map_name.empty())
544 surface_mesh, node_to_bulk_node_id_map_name,
549 if (!element_to_bulk_element_id_map_name.empty())
552 surface_mesh, element_to_bulk_element_id_map_name,
557 if (!element_to_bulk_face_id_map_name.empty())
560 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)
void addPropertyToMesh(Mesh &mesh, std::string_view name, MeshItemType item_type, std::size_t number_of_components, std::span< T const > values)
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)