MeshLib::Mesh* MshEditor::getMeshSurface(const MeshLib::Mesh &mesh, const double* dir) { INFO ("Extracting mesh surface..."); const std::vector<MeshLib::Element*> all_elements (mesh.getElements()); const std::vector<MeshLib::Node*> all_nodes (mesh.getNodes()); std::vector<MeshLib::Element*> sfc_elements; get2DSurfaceElements(all_elements, sfc_elements, dir, mesh.getDimension()); std::vector<MeshLib::Node*> sfc_nodes; std::vector<unsigned> node_id_map(mesh.getNNodes()); get2DSurfaceNodes(all_nodes, sfc_nodes, sfc_elements, node_id_map); // create new elements vector with newly created nodes const size_t nNewElements (sfc_elements.size()); std::vector<MeshLib::Element*> new_elements(sfc_elements.size()); for (unsigned i=0; i<nNewElements; ++i) { MeshLib::Element* elem (sfc_elements[i]); if (elem->getType() == MshElemType::TRIANGLE) { MeshLib::Node** tri_nodes = new MeshLib::Node*[3]; for (unsigned k(0); k<3; k++) tri_nodes[k] = sfc_nodes[node_id_map[elem->getNode(k)->getID()]]; new_elements[i] = new MeshLib::Tri(tri_nodes); } else { MeshLib::Node** quad_nodes = new MeshLib::Node*[4]; for (unsigned k(0); k<3; k++) quad_nodes[k] = sfc_nodes[node_id_map[elem->getNode(k)->getID()]]; new_elements[i] = new MeshLib::Quad(quad_nodes); } delete sfc_elements[i]; } return new Mesh("SurfaceMesh", sfc_nodes, new_elements); }
void Array<T>::resize(Idx size) { BOOST_CONCEPT_ASSERT((boost::Assignable<T>)); std::unique_ptr<T[]> new_elements(new T[size]); for(Idx i = 0; i < size_ && i < size; ++i) { new_elements[i] = elements_[i]; } size_ = size; elements_ = std::move(new_elements); }
TEST(MeshLib, Duplicate) { MeshLib::Mesh* mesh (MeshLib::MeshGenerator::generateRegularQuadMesh(10, 5, 1)); std::vector<MeshLib::Node*> new_nodes (MeshLib::copyNodeVector(mesh->getNodes())); std::vector<MeshLib::Element*> new_elements (MeshLib::copyElementVector(mesh->getElements(), new_nodes)); MeshLib::Mesh new_mesh ("new", new_nodes, new_elements); ASSERT_EQ (mesh->getNElements(), new_mesh.getNElements()); ASSERT_EQ (mesh->getNNodes(), new_mesh.getNNodes()); std::vector<std::size_t> del_idx(1,1); MeshLib::removeMeshNodes(*mesh, del_idx); ASSERT_EQ (mesh->getNElements(), new_mesh.getNElements()-2); ASSERT_EQ (mesh->getNNodes(), new_mesh.getNNodes()-2); ASSERT_DOUBLE_EQ (4.0, MathLib::sqrDist(*mesh->getNode(0), *new_mesh.getNode(0))); ASSERT_DOUBLE_EQ (0.0, MathLib::sqrDist(*mesh->getNode(0), *new_mesh.getNode(2))); ASSERT_DOUBLE_EQ (4.0, MathLib::sqrDist(*mesh->getElement(0)->getNode(0), *new_mesh.getElement(0)->getNode(0))); ASSERT_DOUBLE_EQ (0.0, MathLib::sqrDist(*mesh->getElement(0)->getNode(0), *new_mesh.getElement(2)->getNode(0))); }