diff --git a/FemLib/ProcessInfo.h b/FemLib/ProcessInfo.h index 229c9ed816149cbd2ec1ac7630bba9aed9063ac7..876a84983a938b72d546316f567862eb2c40d609 100644 --- a/FemLib/ProcessInfo.h +++ b/FemLib/ProcessInfo.h @@ -41,7 +41,7 @@ public: * @param pcs a pointer to the process * @return */ - ProcessInfo (FiniteElement::ProcessType pcs_type, FiniteElement::PrimaryVariable pcs_pv/*, CRFProcess* pcs*/); + ProcessInfo (FiniteElement::ProcessType pcs_type, FiniteElement::PrimaryVariable pcs_pv/* TODO6 , CRFProcess* pcs*/); /** * Sets the process type. diff --git a/FileIO/MeshIO/GMSHInterface.cpp b/FileIO/MeshIO/GMSHInterface.cpp index 9d68a46e8b1478fad06893a7cb001bc34788c31d..3287168a5140ef1930e2127ded84869a2708b9f8 100644 --- a/FileIO/MeshIO/GMSHInterface.cpp +++ b/FileIO/MeshIO/GMSHInterface.cpp @@ -12,6 +12,7 @@ #include "swap.h" #include "Configure.h" #include "BuildInfo.h" +#include "StringTools.h" // FileIO #include "GMSHInterface.h" @@ -81,7 +82,7 @@ bool GMSHInterface::isGMSHMeshFile(const std::string& fname) return false; } -void GMSHInterface::readGMSHMesh(std::string const& fname, MeshLib::Mesh* mesh) +MeshLib::Mesh* GMSHInterface::readGMSHMesh(std::string const& fname) { std::string line; std::ifstream in(fname.c_str(), std::ios::in); @@ -103,9 +104,12 @@ void GMSHInterface::readGMSHMesh(std::string const& fname, MeshLib::Mesh* mesh) long id; double x, y, z; in >> n_nodes >> std::ws; + nodes.resize(n_nodes); + std::map<unsigned, unsigned> id_map; for (size_t i = 0; i < n_nodes; i++) { in >> id >> x >> y >> z >> std::ws; - nodes.push_back(new MeshLib::Node(x,y,z,id)); + id_map.insert(std::map<unsigned, unsigned>::value_type(id, i)); + nodes[i] = new MeshLib::Node(x,y,z,id); } getline(in, line); // End Node keyword $EndNodes @@ -127,38 +131,41 @@ void GMSHInterface::readGMSHMesh(std::string const& fname, MeshLib::Mesh* mesh) switch (type) { case 1: - readNodeIDs(in, 2, node_ids); + readNodeIDs(in, 2, node_ids, id_map); elem = new MeshLib::Edge(nodes[node_ids[0]], nodes[node_ids[1]], 0); break; case 2: - readNodeIDs(in, 3, node_ids); + readNodeIDs(in, 3, node_ids, id_map); elem = new MeshLib::Tri(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[2]], mat_id); break; case 3: - readNodeIDs(in, 4, node_ids); + readNodeIDs(in, 4, node_ids, id_map); elem = new MeshLib::Quad(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[2]], nodes[node_ids[3]], mat_id); break; case 4: - readNodeIDs(in, 4, node_ids); + readNodeIDs(in, 4, node_ids, id_map); elem = new MeshLib::Tet(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[2]], nodes[node_ids[3]], mat_id); break; case 5: - readNodeIDs(in, 8, node_ids); + readNodeIDs(in, 8, node_ids, id_map); elem = new MeshLib::Hex(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[2]], nodes[node_ids[3]], nodes[node_ids[4]], nodes[node_ids[5]], nodes[node_ids[6]], nodes[node_ids[7]], mat_id); break; case 6: - readNodeIDs(in, 6, node_ids); + readNodeIDs(in, 6, node_ids, id_map); elem = new MeshLib::Prism(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[2]], nodes[node_ids[3]], nodes[node_ids[4]], nodes[node_ids[5]], mat_id); break; case 7: - readNodeIDs(in, 5, node_ids); + readNodeIDs(in, 5, node_ids, id_map); elem = new MeshLib::Pyramid(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[2]], nodes[node_ids[3]], nodes[node_ids[4]], mat_id); break; + case 15: + in >> dummy; // skip rest of line + continue; + break; default: - in >> dummy; // skip rest of line (e.g. for type "15" ... whatever that is ... std::cout << "Error in GMSHInterface::readGMSHMesh() - Unknown element type " << type << "." << std::endl; } in >> std::ws; @@ -168,45 +175,19 @@ void GMSHInterface::readGMSHMesh(std::string const& fname, MeshLib::Mesh* mesh) } getline(in, line); // END keyword -/* TODO6: testen ob es auch so funktioniert - // ordering nodes and closing gaps TK - std::vector<size_t> gmsh_id; - size_t counter(0); - for (size_t i = 0; i < mesh->nod_vector.size(); i++) { - const size_t diff = mesh->nod_vector[i]->GetIndex() - counter; - if (diff == 0) { - gmsh_id.push_back(i); - counter++; - } else { - for (size_t j = 0; j < diff; j++) { - gmsh_id.push_back(i); - counter++; - } - i--; - } - } - - for (size_t i = 0; i < mesh->ele_vector.size(); i++) - for (long j = 0; j < mesh->ele_vector[i]->GetVertexNumber(); j++) - mesh->ele_vector[i]->getNodeIndices()[j] - = gmsh_id[mesh->ele_vector[i]->GetNodeIndex(j) + 1]; - - for (size_t i = 0; i < mesh->nod_vector.size(); i++) - mesh->nod_vector[i]->SetIndex(i); - // END OF: ordering nodes and closing gaps TK -*/ - } /*End while*/ + } } in.close(); + return new MeshLib::Mesh(BaseLib::getFileNameFromPath(fname), nodes, elements); } -void GMSHInterface::readNodeIDs(std::ifstream &in, unsigned n_nodes, std::vector<unsigned> &node_ids) +void GMSHInterface::readNodeIDs(std::ifstream &in, unsigned n_nodes, std::vector<unsigned> &node_ids, std::map<unsigned, unsigned> &id_map) { unsigned idx; for (unsigned i=0; i<n_nodes; i++) { in >> idx; - node_ids.push_back(--idx); + node_ids.push_back(id_map[idx]); } } diff --git a/FileIO/MeshIO/GMSHInterface.h b/FileIO/MeshIO/GMSHInterface.h index 9b969d2aae00125dda4f670e1bbb777fb1b78372..90f599a9cfa91b935d20a7216a819a25446f0928 100644 --- a/FileIO/MeshIO/GMSHInterface.h +++ b/FileIO/MeshIO/GMSHInterface.h @@ -72,10 +72,9 @@ public: /** * reads a mesh created by GMSH - this implementation is based on the former function GMSH2MSH * @param fname the file name of the mesh (including the path) - * @param mesh the new mesh * @return */ - static void readGMSHMesh (std::string const& fname, MeshLib::Mesh* mesh); + static MeshLib::Mesh* readGMSHMesh (std::string const& fname); protected: int write(std::ostream& stream); @@ -88,7 +87,7 @@ private: */ void writeGMSHInputFile(std::ostream & out); - static void readNodeIDs(std::ifstream &in, unsigned n_nodes, std::vector<unsigned> &node_ids); + static void readNodeIDs(std::ifstream &in, unsigned n_nodes, std::vector<unsigned> &node_ids, std::map<unsigned, unsigned> &id_map); void writePoints(std::ostream& out) const; diff --git a/Gui/mainwindow.cpp b/Gui/mainwindow.cpp index 1bebccf278b980a7ee62cb8baccee9107064726c..ef813286d67308f13f2943e7a50874e9452ce65b 100644 --- a/Gui/mainwindow.cpp +++ b/Gui/mainwindow.cpp @@ -477,19 +477,12 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) { if (fi.suffix().toLower() == "gli") { -#ifndef NDEBUG - QTime myTimer0; - myTimer0.start(); -#endif std::string unique_name; std::vector<std::string> errors; if (! readGLIFileV4(fileName.toStdString(), _geoModels, unique_name, errors)) { for (size_t k(0); k<errors.size(); k++) OGSError::box(QString::fromStdString(errors[k])); } -#ifndef NDEBUG - std::cout << myTimer0.elapsed() << " ms" << std::endl; -#endif } else if (fi.suffix().toLower() == "gsp") { @@ -515,16 +508,19 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) // OpenGeoSys mesh files else if (fi.suffix().toLower() == "msh") { +#ifndef NDEBUG QTime myTimer0; myTimer0.start(); - +#endif FileIO::MeshIO meshIO; std::string name = fileName.toStdString(); MeshLib::Mesh* msh = meshIO.loadMeshFromFile(name); if (msh) { _meshModels->addMesh(msh); +#ifndef NDEBUG std::cout << "Total mesh loading time: " << myTimer0.elapsed() << " ms" << std::endl; +#endif } else OGSError::box("Failed to load a mesh file."); @@ -555,8 +551,7 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) } else if (t == ImportFileType::GMS) { - // GMS borehole files - if (fi.suffix().toLower() == "txt") + if (fi.suffix().toLower() == "txt") // GMS borehole files { std::vector<GeoLib::Point*>* boreholes = new std::vector<GeoLib::Point*>(); std::string name = fi.baseName().toStdString(); @@ -566,8 +561,7 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) else OGSError::box("Error reading GMS file."); } - // GMS mesh files - else if (fi.suffix().toLower() == "3dm") + else if (fi.suffix().toLower() == "3dm") // GMS mesh files { std::string name = fileName.toStdString(); MeshLib::Mesh* mesh = GMSInterface::readGMS3DMMesh(name); @@ -577,17 +571,20 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) } else if (t == ImportFileType::GMSH) { - OGSError::box("Interface not yet integrated"); - // TODO6 + std::string msh_name (fileName.toStdString()); + if (FileIO::GMSHInterface::isGMSHMeshFile (msh_name)) + { + MeshLib::Mesh* mesh = FileIO::GMSHInterface::readGMSHMesh(msh_name); + if (mesh) + _meshModels->addMesh(mesh); + return; + } } - else if (t == ImportFileType::NETCDF) + else if (t == ImportFileType::NETCDF) // CH 01.2012 { - // NetCDF files - // CH 01.2012 - std::string name = fileName.toStdString(); MeshLib::Mesh* mesh (NULL); - NetCdfConfigureDialog dlg(name); + NetCdfConfigureDialog dlg(fileName.toStdString()); dlg.exec(); if (dlg.getMesh() != NULL) { diff --git a/MeshLib/Node.h b/MeshLib/Node.h index 703afbb8d2c3ed2cc8ef9b9fb3e7ce712c3444f2..82565618c3f2c20a8b01a6beaaa887464f079b6e 100644 --- a/MeshLib/Node.h +++ b/MeshLib/Node.h @@ -30,9 +30,7 @@ class Element; class Node : public GeoLib::PointWithID { /* friend functions: */ - friend class Mesh;//void Mesh::setElementInformationForNodes(); - //friend void Mesh::addElement(Element*); - + friend class Mesh; public: /// Constructor using a coordinate array