18 #include <unordered_map>
38 std::vector<std::vector<Element const*>> elements_connected_to_nodes;
40 elements_connected_to_nodes.resize(nodes.size());
44 unsigned const number_nodes(element->getNumberOfNodes());
45 for (
unsigned j = 0; j < number_nodes; ++j)
47 auto const node_id = element->getNode(j)->getID();
48 elements_connected_to_nodes[node_id].push_back(element);
51 return elements_connected_to_nodes;
62 _edge_length(std::numeric_limits<double>::max(), 0),
63 _node_distance(std::numeric_limits<double>::max(), 0),
64 _name(std::move(
name)),
65 _nodes(std::move(nodes)),
66 _elements(std::move(elements)),
67 _properties(properties)
82 _edge_length(mesh._edge_length.first, mesh._edge_length.second),
83 _node_distance(mesh._node_distance.first, mesh._node_distance.second),
85 _nodes(mesh.getNumberOfNodes()),
86 _elements(mesh.getNumberOfElements()),
87 _properties(mesh._properties)
89 const std::vector<Node*>& nodes(mesh.
getNodes());
90 const std::size_t nNodes(nodes.size());
91 for (
unsigned i = 0; i < nNodes; ++i)
96 const std::vector<Element*>& elements(mesh.
getElements());
97 const std::size_t nElements(elements.size());
98 for (
unsigned i = 0; i < nElements; ++i)
100 const std::size_t nElemNodes = elements[i]->getNumberOfNodes();
102 for (
unsigned j = 0; j < nElemNodes; ++j)
118 const std::size_t nElements(
_elements.size());
119 for (std::size_t i = 0; i < nElements; ++i)
124 const std::size_t nNodes(
_nodes.size());
125 for (std::size_t i = 0; i < nNodes; ++i)
138 const std::size_t nNodes(
_nodes.size());
139 for (std::size_t i = 0; i < nNodes; ++i)
147 const std::size_t nElements(this->
_elements.size());
148 for (
unsigned i = 0; i < nElements; ++i)
156 const std::size_t nElements(
_elements.size());
157 for (
unsigned i = 0; i < nElements; ++i)
169 for (std::size_t i = 0; i < nElems; ++i)
171 auto const& [min_length, max_length] =
182 std::vector<Element const*> neighbors;
187 const std::size_t nNodes(element->getNumberOfBaseNodes());
188 for (
unsigned n(0); n < nNodes; ++n)
190 auto const& conn_elems(
192 neighbors.insert(neighbors.end(), conn_elems.begin(),
195 std::sort(neighbors.begin(), neighbors.end());
196 auto const neighbors_new_end =
197 std::unique(neighbors.begin(), neighbors.end());
199 for (
auto neighbor = neighbors.begin(); neighbor != neighbors_new_end;
202 std::optional<unsigned>
const opposite_face_id =
203 element->addNeighbor(
const_cast<Element*
>(*neighbor));
204 if (opposite_face_id)
217 [
this](
auto const*
const node) {
233 std::size_t
const node_id)
const
239 Node const& node)
const
245 std::string
const& property_name,
250 WARN(
"Did not find PropertyVector '{:s}' for scaling.", property_name);
254 std::transform(pv.begin(), pv.end(), pv.begin(),
255 [factor](
auto const& v) { return v * factor; });
263 ? properties.getPropertyVector<
int>(
269 std::string mesh_name, std::vector<MeshLib::Element*>
const& elements)
271 DBUG(
"Found {:d} elements in the mesh", elements.size());
274 std::vector<std::size_t> bulk_element_ids;
275 bulk_element_ids.reserve(elements.size());
276 std::transform(begin(elements), end(elements),
277 std::back_inserter(bulk_element_ids),
278 [&](
auto const& e) {
return e->getID(); });
281 std::unordered_map<const MeshLib::Node*, MeshLib::Node*> nodes_map;
285 for (
auto& e : elements)
288 unsigned const n_nodes = e->getNumberOfNodes();
289 for (
unsigned i = 0; i < n_nodes; ++i)
292 auto const it = nodes_map.find(n);
293 if (it == nodes_map.end())
296 e->setNode(i, new_node_in_map);
300 e->setNode(i, it->second);
306 std::vector<MeshLib::Node*> element_nodes;
307 element_nodes.reserve(nodes_map.size());
308 std::transform(begin(nodes_map), end(nodes_map),
309 std::back_inserter(element_nodes),
310 [](
auto const& pair) {
return pair.second; });
313 std::vector<std::size_t> bulk_node_ids;
314 bulk_node_ids.reserve(nodes_map.size());
315 std::transform(begin(nodes_map), end(nodes_map),
316 std::back_inserter(bulk_node_ids),
317 [](
auto const& pair) {
return pair.first->getID(); });
319 auto mesh = std::make_unique<MeshLib::Mesh>(
320 std::move(mesh_name), std::move(element_nodes), std::move(elements));
321 assert(mesh !=
nullptr);
336 std::vector<std::vector<Node*>> nodes_connected_by_elements;
337 auto const& nodes = mesh.
getNodes();
338 nodes_connected_by_elements.resize(nodes.size());
339 for (std::size_t i = 0; i < nodes.size(); ++i)
341 auto& adjacent_nodes = nodes_connected_by_elements[i];
342 auto const* node = nodes[i];
345 auto const& connected_elements =
346 elements_connected_to_nodes[node->getID()];
349 for (
Element const*
const element : connected_elements)
351 Node*
const*
const single_elem_nodes = element->getNodes();
352 std::size_t
const nnodes = element->getNumberOfNodes();
353 for (std::size_t n = 0; n < nnodes; n++)
355 adjacent_nodes.push_back(single_elem_nodes[n]);
361 std::sort(adjacent_nodes.begin(), adjacent_nodes.end(),
362 [](
Node* a,
Node* b) { return a->getID() < b->getID(); });
364 std::unique(adjacent_nodes.begin(), adjacent_nodes.end());
365 adjacent_nodes.erase(last, adjacent_nodes.end());
367 return nodes_connected_by_elements;
371 std::vector<Element const*>
const& elements_connected_to_node)
374 if (elements_connected_to_node.empty())
380 auto const e = elements_connected_to_node[0];
382 auto const n_base_nodes = e->getNumberOfBaseNodes();
384 return local_index < n_base_nodes;
Definition of the Element class.
Definition of the Hex class.
void DBUG(char const *fmt, Args const &... args)
void WARN(char const *fmt, Args const &... args)
static std::size_t global_mesh_counter
Mesh counter used to uniquely identify meshes by id.
Definition of the Mesh class.
Definition of the Prism class.
Definition of the Pyramid class.
Definition of the Quad class.
Definition of the RunTime class.
Definition of the Tet class.
Definition of the Tri class.
std::size_t getID() const
void setNeighbor(Element *neighbor, unsigned const face_id)
virtual unsigned getNumberOfNodes() const =0
virtual unsigned getNumberOfBaseNodes() const =0
std::size_t getNumberOfBaseNodes() const
Get the number of base nodes.
void calcEdgeLengthRange()
Set the minimum and maximum length over the edges of the mesh.
std::vector< std::vector< Element const * > > _elements_connected_to_nodes
Mesh(std::string name, std::vector< Node * > nodes, std::vector< Element * > elements, Properties const &properties=Properties())
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
void addElement(Element *elem)
Add an element to the mesh.
std::pair< double, double > _edge_length
The minimal and maximal edge length over all elements in the mesh.
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
std::size_t getID() const
Get id of the mesh.
void resetNodeIDs()
Resets the IDs of all mesh-nodes to their position in the node vector.
std::vector< Element * > _elements
void setDimension()
Sets the dimension of the mesh.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
void resetElementIDs()
Resets the IDs of all mesh-elements to their position in the element vector.
void setElementNeighbors()
virtual ~Mesh()
Destructor.
Properties & getProperties()
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
bool hasNonlinearElement() const
Check if the mesh contains any nonlinear element.
const Node * getNode(std::size_t idx) const
Get the node with the given index.
std::size_t getNumberOfElements() const
Get the number of elements.
std::vector< Node * > _nodes
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
PropertyVector< T > const * getPropertyVector(std::string const &name) const
bool existsPropertyVector(std::string const &name) const
std::vector< std::vector< Node * > > calculateNodesConnectedByElements(Mesh const &mesh)
std::vector< std::vector< Element const * > > findElementsConnectedToNodes(Mesh const &mesh)
PropertyVector< int > const * materialIDs(Mesh const &mesh)
std::pair< double, double > computeSqrEdgeLengthRange(Element const &element)
Compute the minimum and maximum squared edge length for this element.
unsigned getNodeIDinElement(Element const &element, const MeshLib::Node *node)
Returns the position of the given node in the node array of this element.
std::unique_ptr< MeshLib::Mesh > createMeshFromElementSelection(std::string mesh_name, std::vector< MeshLib::Element * > const &elements)
void addPropertyToMesh(Mesh &mesh, std::string const &name, MeshItemType item_type, std::size_t number_of_components, std::vector< T > const &values)
bool isBaseNode(Node const &node, std::vector< Element const * > const &elements_connected_to_node)
void scaleMeshPropertyVector(MeshLib::Mesh &mesh, std::string const &property_name, double factor)
unsigned getDimension(MeshLib::MeshElemType eleType)