diff --git a/MeshLib/Mesh.cpp b/MeshLib/Mesh.cpp index bbf41b4b304413fab8103a5fa53dd9391c9a8963..b8424090221be2093e6555037929868fbdee531d 100644 --- a/MeshLib/Mesh.cpp +++ b/MeshLib/Mesh.cpp @@ -64,6 +64,7 @@ Mesh::Mesh(std::string name, nodes, std::vector<Element*> elements, + bool const compute_element_neighbors, Properties const& properties) : _id(global_mesh_counter++), _mesh_dimension(0), @@ -71,7 +72,8 @@ Mesh::Mesh(std::string name, _name(std::move(name)), _nodes(std::move(nodes)), _elements(std::move(elements)), - _properties(properties) + _properties(properties), + _compute_element_neighbors(compute_element_neighbors) { this->resetNodeIDs(); this->resetElementIDs(); @@ -79,7 +81,10 @@ Mesh::Mesh(std::string name, _elements_connected_to_nodes = findElementsConnectedToNodes(*this); - this->setElementNeighbors(); + if (_compute_element_neighbors) + { + this->setElementNeighbors(); + } } Mesh::Mesh(const Mesh& mesh) @@ -89,7 +94,8 @@ Mesh::Mesh(const Mesh& mesh) _name(mesh.getName()), _nodes(mesh.getNumberOfNodes()), _elements(mesh.getNumberOfElements()), - _properties(mesh._properties) + _properties(mesh._properties), + _compute_element_neighbors(mesh._compute_element_neighbors) { const std::vector<Node*>& nodes(mesh.getNodes()); const std::size_t nNodes(nodes.size()); @@ -114,8 +120,12 @@ Mesh::Mesh(const Mesh& mesh) { this->setDimension(); } + _elements_connected_to_nodes = findElementsConnectedToNodes(*this); - this->setElementNeighbors(); + if (_compute_element_neighbors) + { + this->setElementNeighbors(); + } } Mesh::Mesh(Mesh&& mesh) = default; diff --git a/MeshLib/Mesh.h b/MeshLib/Mesh.h index ada2d9d42a6e44b6e8860e801d28d8ffe1e42bd6..d05a130ec24e6aeee6ec51b86b3184df99e0dcda 100644 --- a/MeshLib/Mesh.h +++ b/MeshLib/Mesh.h @@ -51,12 +51,15 @@ public: /// @param name Mesh name. /// @param nodes A vector of mesh nodes. /// @param elements An array of mesh elements. + /// @param compute_element_neighbors switch to compute element neighbors or + /// not /// @param properties Mesh properties. Mesh(std::string name, std::vector<Node*> nodes, std::vector<Element*> elements, + bool const compute_element_neighbors = false, Properties const& properties = Properties()); /// Copy constructor @@ -158,6 +161,7 @@ protected: std::vector<std::vector<Element const*>> _elements_connected_to_nodes; bool _is_axially_symmetric = false; + bool const _compute_element_neighbors; }; /* class */ /// Computes the element-connectivity of nodes. Two nodes i and j are