MeshLib::CFEMesh* MshEditor::removeMeshNodes(MeshLib::CFEMesh* mesh, const std::vector<size_t>& nodes) { MeshLib::CFEMesh* new_mesh(new MeshLib::CFEMesh(*mesh)); // delete nodes and their connected elements and replace them with null // pointers size_t delNodes = nodes.size(); for (size_t i = 0; i < delNodes; i++) { MeshLib::CNode* node = new_mesh->nod_vector[nodes[i]]; std::vector<size_t> conn_elems = node->getConnectedElementIDs(); for (size_t j = 0; j < conn_elems.size(); j++) { delete new_mesh->ele_vector[conn_elems[j]]; new_mesh->ele_vector[conn_elems[j]] = NULL; } delete new_mesh->nod_vector[nodes[i]]; new_mesh->nod_vector[nodes[i]] = NULL; } // create map to adjust node indices in element vector size_t nNodes = new_mesh->nod_vector.size(); std::vector<int> id_map; size_t count = 0; for (size_t i = 0; i < nNodes; i++) { if (new_mesh->nod_vector[i]) { new_mesh->nod_vector[i]->SetIndex(count); id_map.push_back(count); count++; } else id_map.push_back(-1); } // erase null pointers from node- and element vectors for (std::vector<MeshLib::CElem*>::iterator it = new_mesh->ele_vector.begin(); it != new_mesh->ele_vector.end();) { if (*it) ++it; else it = new_mesh->ele_vector.erase(it); } for (std::vector<MeshLib::CNode*>::iterator it = new_mesh->nod_vector.begin(); it != new_mesh->nod_vector.end();) { if (*it) ++it; else it = new_mesh->nod_vector.erase(it); } // re-adjust node indices size_t nElems = new_mesh->ele_vector.size(); for (size_t i = 0; i < nElems; i++) { MeshLib::CElem* elem = new_mesh->ele_vector[i]; size_t nElemNodes = elem->GetNodesNumber(false); for (size_t j = 0; j < nElemNodes; j++) elem->SetNodeIndex(j, id_map[elem->GetNodeIndex(j)]); } return new_mesh; }
MeshLib::CFEMesh* GMSInterface::readGMS3DMMesh(std::string filename) { std::string buffer(""); std::ifstream in(filename.c_str()); if (!in.is_open()) { std::cout << "GMSInterface::readGMS3DMMesh() - Could not open file..." << "\n"; return NULL; } // Read data from file getline(in, buffer); // "MESH3D" if (buffer.compare("MESH3D") != 0) { std::cout << "GMSInterface::readGMS3DMMesh() - Could not read expected file header..." << "\n"; return NULL; } std::cout << "Read GMS-3DM data..."; MeshLib::CFEMesh* mesh (new MeshLib::CFEMesh()); while (!in.eof()) { MeshLib::CElem* elem = new MeshLib::CElem(); std::string element_id(""); in >> element_id; if (element_id.compare("E6W") == 0) { elem->SetElementType(MshElemType::PRISM); elem->Read(in, 8); mesh->ele_vector.push_back(elem); } else if (element_id.compare("E4T") == 0) { elem->SetElementType(MshElemType::TETRAHEDRON); elem->Read(in, 8); mesh->ele_vector.push_back(elem); } else if ((element_id.compare("E4P") == 0) || (element_id.compare("E5P") == 0)) // KR both versions exist! { size_t i(0); long node_index[5]; elem->SetElementType(MshElemType::TETRAHEDRON); elem->Read(in, 8); mesh->ele_vector.push_back(elem); for (size_t j = 0; j < 4; j++) node_index[j] = elem->GetNodeIndex(j); in >> node_index[4]; i = elem->GetPatchIndex(); elem->SetPatchIndex(node_index[4] - 1); node_index[4] = i; elem->SetNodeIndex(0, node_index[0]); elem->SetNodeIndex(1, node_index[1]); elem->SetNodeIndex(2, node_index[3]); elem->SetNodeIndex(3, node_index[4]); MeshLib::CElem* elem2 = new MeshLib::CElem( mesh->ele_vector.size() - 1, elem); elem2->SetNodeIndex(0, node_index[1]); elem2->SetNodeIndex(1, node_index[2]); elem2->SetNodeIndex(2, node_index[3]); elem2->SetNodeIndex(3, node_index[4]); mesh->ele_vector.push_back(elem2); } else if (element_id.compare("ND") == 0)