From da554b7d5413e59edf14d57125fd377ecd6339fc Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Tue, 5 Jan 2010 14:08:18 +0000 Subject: [PATCH] pp --- Geo/GModel.cpp | 88 ++++++++++++++++++++++--------------------- Geo/GModel.h | 6 ++- Geo/GModelIO_Mesh.cpp | 20 +++++++++- Geo/MLine.cpp | 1 + 4 files changed, 69 insertions(+), 46 deletions(-) diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index d07ee4dc77..124509f698 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -795,11 +795,11 @@ void GModel::_storeElementsInEntities(std::map<int, std::vector<MElement*> > &ma v = new discreteVertex(this, it->first); add(v); } - if(!v->points.empty()) { + if(!v->points.empty()) { // CAD points already have one by default v->points.clear(); v->mesh_vertices.clear(); - } // CAD points already have one by default - _addElements(v->points, it->second); + } + _addElements(v->points, it->second); } break; case TYPE_LIN: @@ -808,7 +808,7 @@ void GModel::_storeElementsInEntities(std::map<int, std::vector<MElement*> > &ma if(!e){ e = new discreteEdge(this, it->first, 0, 0); add(e); - } + } _addElements(e->lines, it->second); } break; @@ -1058,10 +1058,8 @@ int GModel::removeDuplicateMeshVertices(double tolerance) return diff; } - void GModel::createTopologyFromMesh() { - // for each discreteRegion, create topology std::vector<discreteRegion*> discRegions; for(riter it = firstRegion(); it != lastRegion(); it++) @@ -1073,13 +1071,13 @@ void GModel::createTopologyFromMesh() for (std::vector<discreteRegion*>::iterator it = discRegions.begin(); it != discRegions.end(); it++) (*it)->setBoundFaces(); - - //for each discreteFace, createTopology - std::vector<discreteFace*> discFaces; + + //for each discreteFace, createTopology + std::vector<discreteFace*> discFaces; for(fiter it = firstFace(); it != lastFace(); it++) if((*it)->geomType() == GEntity::DiscreteSurface) discFaces.push_back((discreteFace*) *it); - + //EMI TODO //check for closed faces // for (std::vector<discreteFace*>::iterator itf = discFaces.begin(); itf != discFaces.end(); itf++){ @@ -1131,19 +1129,16 @@ void GModel::createTopologyFromMesh() // } // } - - //create Topo From Faces - createTopologyFromFaces(discFaces); - - //create - exportDiscreteGEOInternals(); - + + //create Topo From Faces + createTopologyFromFaces(discFaces); + + //create + exportDiscreteGEOInternals(); } void GModel::createTopologyFromFaces(std::vector<discreteFace*> &discFaces) { - - std::vector<discreteEdge*> discEdges; for(eiter it = firstEdge(); it != lastEdge(); it++){ if((*it)->geomType() == GEntity::DiscreteCurve) @@ -1153,16 +1148,17 @@ void GModel::createTopologyFromFaces(std::vector<discreteFace*> &discFaces) // find boundary edges of each face and put them in a map_edges that // associates the MEdges with the tags of the adjacent faces std::map<MEdge, std::vector<int>, Less_Edge > map_edges; - for (std::vector<discreteFace*>::iterator it = discFaces.begin(); it != discFaces.end(); it++) + for (std::vector<discreteFace*>::iterator it = discFaces.begin(); + it != discFaces.end(); it++) (*it)->findEdges(map_edges); - + //return if no boundary edges (torus, sphere, ...) if (map_edges.empty()) return; - + // create reverse map, for each face find set of MEdges that are // candidate for new discrete Edges std::map<int, std::vector<int> > face2Edges; - + while (!map_edges.empty()){ std::vector<MEdge> myEdges; @@ -1190,7 +1186,8 @@ void GModel::createTopologyFromFaces(std::vector<discreteFace*> &discFaces) // create discreteEdges and create a map face2Edges that associate // for each face the boundary discrete Edges - for (std::vector<discreteEdge*>::iterator itE = discEdges.begin(); itE != discEdges.end(); itE++){ + for (std::vector<discreteEdge*>::iterator itE = discEdges.begin(); + itE != discEdges.end(); itE++){ bool candidate = true; for (unsigned int i = 0; i < (*itE)->getNumMeshElements(); i++){ @@ -1211,8 +1208,9 @@ void GModel::createTopologyFromFaces(std::vector<discreteFace*> &discFaces) std::vector<MEdge>::iterator itME = std::find(myEdges.begin(), myEdges.end(), me); myEdges.erase(itME); } - - for (std::vector<int>::iterator itFace = tagFaces.begin(); itFace != tagFaces.end(); itFace++) { + + for (std::vector<int>::iterator itFace = tagFaces.begin(); + itFace != tagFaces.end(); itFace++) { std::map<int, std::vector<int> >::iterator it = face2Edges.find(*itFace); if (it == face2Edges.end()) face2Edges.insert(std::make_pair(*itFace, tagEdges)); else{ @@ -1221,11 +1219,11 @@ void GModel::createTopologyFromFaces(std::vector<discreteFace*> &discFaces) it->second = allEdges; } } - + } - + } - + while (!myEdges.empty()) { std::vector<MEdge> myLines; myLines.clear(); @@ -1283,15 +1281,18 @@ void GModel::createTopologyFromFaces(std::vector<discreteFace*> &discFaces) } e->mesh_vertices.insert(e->mesh_vertices.begin(), allV.begin(),allV.end()); - for (std::vector<int>::iterator itFace = tagFaces.begin(); itFace != tagFaces.end(); itFace++) { + for (std::vector<int>::iterator itFace = tagFaces.begin(); + itFace != tagFaces.end(); itFace++) { //delete new mesh vertices of edge from adjacent faces GFace *dFace = getFaceByTag(*itFace); - for (std::vector<MVertex*>::iterator itv = allV.begin(); itv != allV.end(); itv++) { - std::vector<MVertex*>::iterator itve = std::find(dFace->mesh_vertices.begin(), dFace->mesh_vertices.end(), *itv); + for (std::vector<MVertex*>::iterator itv = allV.begin(); + itv != allV.end(); itv++) { + std::vector<MVertex*>::iterator itve = + std::find(dFace->mesh_vertices.begin(), dFace->mesh_vertices.end(), *itv); if (itve != dFace->mesh_vertices.end()) dFace->mesh_vertices.erase(itve); } - + //fill face2Edges with the new edge std::map<int, std::vector<int> >::iterator f2e = face2Edges.find(*itFace); if (f2e == face2Edges.end()){ @@ -1311,7 +1312,8 @@ void GModel::createTopologyFromFaces(std::vector<discreteFace*> &discFaces) } // set boundary edges for each face - for (std::vector<discreteFace*>::iterator it = discFaces.begin(); it != discFaces.end(); it++){ + for (std::vector<discreteFace*>::iterator it = discFaces.begin(); + it != discFaces.end(); it++){ //printf("set boundary edge for face =%d \n", (*it)->tag()); std::map<int, std::vector<int> >::iterator ite = face2Edges.find((*it)->tag()); if (ite != face2Edges.end()){ @@ -1321,12 +1323,11 @@ void GModel::createTopologyFromFaces(std::vector<discreteFace*> &discFaces) } // for each discreteEdge, create Topology - for (std::vector<discreteEdge*>::iterator it = discEdges.begin(); it != discEdges.end(); it++){ + for (std::vector<discreteEdge*>::iterator it = discEdges.begin(); + it != discEdges.end(); it++){ (*it)->createTopo(); (*it)->parametrize(); } - - } GModel *GModel::buildCutGModel(gLevelset *ls) @@ -1356,14 +1357,16 @@ GModel *GModel::buildCutGModel(gLevelset *ls) return cutGM; } -void GModel::load(std::string fileName){ +void GModel::load(std::string fileName) +{ GModel *temp = GModel::current(); GModel::setCurrent(this); MergeFile(fileName.c_str()); GModel::setCurrent(temp); } -void GModel::save(std::string fileName){ +void GModel::save(std::string fileName) +{ GModel *temp = GModel::current(); GModel::setCurrent(this); int guess = GuessFileFormatFromFileName(fileName); @@ -1371,9 +1374,11 @@ void GModel::save(std::string fileName){ GModel::setCurrent(temp); } -#ifdef HAVE_LUA + #include "Bindings.h" -void GModel::registerBindings(binding *b){ + +void GModel::registerBindings(binding *b) +{ classBinding *cb = b->addClass<GModel>("GModel"); methodBinding *cm; cm = cb->addMethod("mesh",&GModel::mesh); @@ -1381,4 +1386,3 @@ void GModel::registerBindings(binding *b){ cm = cb->addMethod("save",&GModel::save); cm = cb->setConstructor<GModel>(); } -#endif diff --git a/Geo/GModel.h b/Geo/GModel.h index a6347c6344..070c3b22a8 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -379,7 +379,8 @@ class GModel int writeMSH(const std::string &name, double version=1.0, bool binary=false, bool saveAll=false, bool saveParametric=false, double scalingFactor=1.0); int writeDistanceMSH(const std::string &name, double version=1.0, bool binary=false, - bool saveAll=false, bool saveParametric=false, double scalingFactor=1.0); + bool saveAll=false, bool saveParametric=false, + double scalingFactor=1.0); // Visual FEA file format int writeFEA(const std::string &name, int elementTagType, @@ -451,7 +452,8 @@ class GModel // Store mesh elements of a chain in a new elementary and physical entity void storeChain(int dim, std::map<int, std::vector<MElement*> > &entityMap, - std::map<int, std::map<int, std::string> > &physicalMap){ + std::map<int, std::map<int, std::string> > &physicalMap) + { _storeElementsInEntities(entityMap); _storePhysicalTagsInEntities(dim, physicalMap); _associateEntityWithMeshVertices(); diff --git a/Geo/GModelIO_Mesh.cpp b/Geo/GModelIO_Mesh.cpp index 7811137033..e3442fd7d2 100644 --- a/Geo/GModelIO_Mesh.cpp +++ b/Geo/GModelIO_Mesh.cpp @@ -697,20 +697,23 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, fprintf(fp, "%d\n", numElements); int num = 0; - std::map<MElement *, int> parentsNum; - std::map<MElement *, GEntity *>::const_iterator itP; + std::map<MElement*, int> parentsNum; + std::map<MElement*, GEntity*>::const_iterator itP; + // points writeElementHeaderMSH(binary, fp, elements, MSH_PNT); for(viter it = firstVertex(); it != lastVertex(); ++it) writeElementsMSH(fp, (*it)->points, saveAll, version, binary, num, (*it)->tag(), (*it)->physicals); + // lines writeElementHeaderMSH(binary, fp, elements, MSH_LIN_2, MSH_LIN_3, MSH_LIN_4, MSH_LIN_5); for(eiter it = firstEdge(); it != lastEdge(); ++it) writeElementsMSH(fp, (*it)->lines, saveAll, version, binary, num, (*it)->tag(), (*it)->physicals); + // triangles writeElementHeaderMSH(binary, fp, elements, MSH_TRI_3, MSH_TRI_6, MSH_TRI_9, MSH_TRI_10, MSH_TRI_12, MSH_TRI_15, MSH_TRI_15I, MSH_TRI_21); for(itP = parents[0].begin(); itP != parents[0].end(); itP++) @@ -722,6 +725,8 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, for(fiter it = firstFace(); it != lastFace(); ++it) writeElementsMSH(fp, (*it)->triangles, saveAll, version, binary, num, (*it)->tag(), (*it)->physicals); + + // quads writeElementHeaderMSH(binary, fp, elements, MSH_QUA_4, MSH_QUA_9, MSH_QUA_8, MSH_QUA_16, MSH_QUA_25, MSH_QUA_36, MSH_QUA_12, MSH_QUA_16I, MSH_QUA_20); @@ -734,6 +739,8 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, for(fiter it = firstFace(); it != lastFace(); ++it) writeElementsMSH(fp, (*it)->quadrangles, saveAll, version, binary, num, (*it)->tag(), (*it)->physicals); + + // polygons writeElementHeaderMSH(binary, fp, elements, MSH_POLYG_); for(itP = parents[0].begin(); itP != parents[0].end(); itP++) if(itP->first->getType() == TYPE_POLYG) { @@ -745,6 +752,7 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, writeElementsMSH(fp, (*it)->polygons, saveAll, version, binary, num, (*it)->tag(), (*it)->physicals, parentsNum); + // tets writeElementHeaderMSH(binary, fp, elements, MSH_TET_4, MSH_TET_10, MSH_TET_20, MSH_TET_35, MSH_TET_56, MSH_TET_52); for(itP = parents[1].begin(); itP != parents[1].end(); itP++) @@ -756,6 +764,8 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, for(riter it = firstRegion(); it != lastRegion(); ++it) writeElementsMSH(fp, (*it)->tetrahedra, saveAll, version, binary, num, (*it)->tag(), (*it)->physicals); + + // hexas writeElementHeaderMSH(binary, fp, elements, MSH_HEX_8, MSH_HEX_27, MSH_HEX_20); for(itP = parents[1].begin(); itP != parents[1].end(); itP++) if(itP->first->getType() == TYPE_HEX) { @@ -766,6 +776,8 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, for(riter it = firstRegion(); it != lastRegion(); ++it) writeElementsMSH(fp, (*it)->hexahedra, saveAll, version, binary, num, (*it)->tag(), (*it)->physicals); + + // prisms writeElementHeaderMSH(binary, fp, elements, MSH_PRI_6, MSH_PRI_18, MSH_PRI_15); for(itP = parents[1].begin(); itP != parents[1].end(); itP++) if(itP->first->getType() == TYPE_PRI) { @@ -776,6 +788,8 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, for(riter it = firstRegion(); it != lastRegion(); ++it) writeElementsMSH(fp, (*it)->prisms, saveAll, version, binary, num, (*it)->tag(), (*it)->physicals); + + // pyramids writeElementHeaderMSH(binary, fp, elements, MSH_PYR_5, MSH_PYR_14, MSH_PYR_13); for(itP = parents[1].begin(); itP != parents[1].end(); itP++) if(itP->first->getType() == TYPE_PYR) { @@ -786,6 +800,8 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, for(riter it = firstRegion(); it != lastRegion(); ++it) writeElementsMSH(fp, (*it)->pyramids, saveAll, version, binary, num, (*it)->tag(), (*it)->physicals); + + // polyhedra writeElementHeaderMSH(binary, fp, elements, MSH_POLYH_); for(itP = parents[1].begin(); itP != parents[1].end(); itP++) if(itP->first->getType() == TYPE_POLYH) { diff --git a/Geo/MLine.cpp b/Geo/MLine.cpp index 3f5d79bcc3..7ca2e9b190 100644 --- a/Geo/MLine.cpp +++ b/Geo/MLine.cpp @@ -2,6 +2,7 @@ // // See the LICENSE.txt file for license information. Please report all // bugs and problems to <gmsh@geuz.org>. + #include "GmshDefines.h" #include "MLine.h" #include "GaussLegendre1D.h" -- GitLab