int GModel::importGEOInternals() { if(Tree_Nbr(_geo_internals->Points)) { List_T *points = Tree2List(_geo_internals->Points); for(int i = 0; i < List_Nbr(points); i++){ Vertex *p; List_Read(points, i, &p); GVertex *v = getVertexByTag(p->Num); if(!v){ v = new gmshVertex(this, p); add(v); } if(!p->Visible) v->setVisibility(0); } List_Delete(points); } if(Tree_Nbr(_geo_internals->Curves)) { List_T *curves = Tree2List(_geo_internals->Curves); for(int i = 0; i < List_Nbr(curves); i++){ Curve *c; List_Read(curves, i, &c); if(c->Num >= 0){ GEdge *e = getEdgeByTag(c->Num); if(!e && c->Typ == MSH_SEGM_COMPOUND){ std::vector<GEdge*> comp; for(unsigned int j = 0; j < c->compound.size(); j++){ GEdge *ge = getEdgeByTag(c->compound[j]); if(ge) comp.push_back(ge); } e = new GEdgeCompound(this, c->Num, comp); e->meshAttributes.method = c->Method; e->meshAttributes.nbPointsTransfinite = c->nbPointsTransfinite; e->meshAttributes.typeTransfinite = c->typeTransfinite; e->meshAttributes.coeffTransfinite = c->coeffTransfinite; e->meshAttributes.extrude = c->Extrude; e->meshAttributes.reverseMesh = c->ReverseMesh; add(e); } else if(!e && c->beg && c->end){ e = new gmshEdge(this, c, getVertexByTag(c->beg->Num), getVertexByTag(c->end->Num)); add(e); } else if(!e){ e = new gmshEdge(this, c, 0, 0); add(e); } if(!c->Visible) e->setVisibility(0); if(c->Color.type) e->setColor(c->Color.mesh); if(c->degenerated) { e->setTooSmall(true); } } } List_Delete(curves); } if(Tree_Nbr(_geo_internals->Surfaces)) { List_T *surfaces = Tree2List(_geo_internals->Surfaces); for(int i = 0; i < List_Nbr(surfaces); i++){ Surface *s; List_Read(surfaces, i, &s); GFace *f = getFaceByTag(s->Num); if(!f && s->Typ == MSH_SURF_COMPOUND){ std::list<GFace*> comp; for(unsigned int j = 0; j < s->compound.size(); j++){ GFace *gf = getFaceByTag(s->compound[j]); if(gf) comp.push_back(gf); } std::list<GEdge*> b[4]; for(int j = 0; j < 4; j++){ for(unsigned int k = 0; k < s->compoundBoundary[j].size(); k++){ GEdge *ge = getEdgeByTag(s->compoundBoundary[j][k]); if(ge) b[j].push_back(ge); } } int param = CTX::instance()->mesh.remeshParam; GFaceCompound::typeOfCompound typ = GFaceCompound::HARMONIC_CIRCLE; if (param == 1) typ = GFaceCompound::CONFORMAL_SPECTRAL; if (param == 2) typ = GFaceCompound::RADIAL_BASIS; if (param == 3) typ = GFaceCompound::HARMONIC_PLANE; if (param == 4) typ = GFaceCompound::CONVEX_CIRCLE; if (param == 5) typ = GFaceCompound::CONVEX_PLANE; if (param == 6) typ = GFaceCompound::HARMONIC_SQUARE; if (param == 7) typ = GFaceCompound::CONFORMAL_FE; int algo = CTX::instance()->mesh.remeshAlgo; f = new GFaceCompound(this, s->Num, comp, b[0], b[1], b[2], b[3], typ, algo); f->meshAttributes.recombine = s->Recombine; f->meshAttributes.recombineAngle = s->RecombineAngle; f->meshAttributes.method = s->Method; f->meshAttributes.extrude = s->Extrude; // transfinite import Added by Trevor Strickler. This helps when experimenting // to create compounds from transfinite surfs. Not having it does not break // anything Gmsh *officially* does right now, but maybe it was left out by mistake??? and could // cause problems later? f->meshAttributes.transfiniteArrangement = s->Recombine_Dir; f->meshAttributes.corners.clear(); for(int i = 0; i < List_Nbr(s->TrsfPoints); i++){ Vertex *corn; List_Read(s->TrsfPoints, i, &corn); GVertex *gv = f->model()->getVertexByTag(corn->Num); if(gv) f->meshAttributes.corners.push_back(gv); else Msg::Error("Unknown vertex %d in transfinite attributes", corn->Num); } add(f); if(s->EmbeddedCurves){ for(int i = 0; i < List_Nbr(s->EmbeddedCurves); i++){ Curve *c; List_Read(s->EmbeddedCurves, i, &c); GEdge *e = getEdgeByTag(abs(c->Num)); if(e) f->addEmbeddedEdge(e); else Msg::Error("Unknown curve %d", c->Num); } } if(s->EmbeddedPoints){ for(int i = 0; i < List_Nbr(s->EmbeddedPoints); i++){ Vertex *v; List_Read(s->EmbeddedPoints, i, &v); GVertex *gv = getVertexByTag(v->Num); if(gv) f->addEmbeddedVertex(gv); else Msg::Error("Unknown point %d", v->Num); } } } else if(!f){ f = new gmshFace(this, s); add(f); } else f->resetMeshAttributes(); if(!s->Visible) f->setVisibility(0); if(s->Color.type) f->setColor(s->Color.mesh); } List_Delete(surfaces); } if(Tree_Nbr(_geo_internals->Volumes)) { List_T *volumes = Tree2List(_geo_internals->Volumes); for(int i = 0; i < List_Nbr(volumes); i++){ Volume *v; List_Read(volumes, i, &v); GRegion *r = getRegionByTag(v->Num); if(!r && v->Typ == MSH_VOLUME_COMPOUND){ std::vector<GRegion*> comp; for(unsigned int j = 0; j < v->compound.size(); j++){ GRegion *gr = getRegionByTag(v->compound[j]); if(gr) comp.push_back(gr); } r = new GRegionCompound(this, v->Num, comp); if(v->EmbeddedSurfaces){ for(int i = 0; i < List_Nbr(v->EmbeddedSurfaces); i++){ Surface *s; List_Read(v->EmbeddedSurfaces, i, &s); GFace *gf = getFaceByTag(abs(s->Num)); if(gf) r->addEmbeddedFace(gf); else Msg::Error("Unknown surface %d", s->Num); } } add(r); } else if(!r){ r = new gmshRegion(this, v); add(r); } else r->resetMeshAttributes(); if(!v->Visible) r->setVisibility(0); if(v->Color.type) r->setColor(v->Color.mesh); } List_Delete(volumes); } for(int i = 0; i < List_Nbr(_geo_internals->PhysicalGroups); i++){ PhysicalGroup *p; List_Read(_geo_internals->PhysicalGroups, i, &p); for(int j = 0; j < List_Nbr(p->Entities); j++){ int num; List_Read(p->Entities, j, &num); GEntity *ge = 0; int tag = CTX::instance()->geom.orientedPhysicals ? abs(num) : num; switch(p->Typ){ case MSH_PHYSICAL_POINT: ge = getVertexByTag(tag); break; case MSH_PHYSICAL_LINE: ge = getEdgeByTag(tag); break; case MSH_PHYSICAL_SURFACE: ge = getFaceByTag(tag); break; case MSH_PHYSICAL_VOLUME: ge = getRegionByTag(tag); break; } int pnum = CTX::instance()->geom.orientedPhysicals ? (sign(num) * p->Num) : p->Num; if(ge && std::find(ge->physicals.begin(), ge->physicals.end(), pnum) == ge->physicals.end()) ge->physicals.push_back(pnum); } } // create periodic mesh relationships for (std::map<int,int>::iterator it = _geo_internals->periodicEdges.begin(); it != _geo_internals->periodicEdges.end(); ++it){ GEdge *ge = getEdgeByTag(abs(it->first)); if (ge){ int MASTER = it->second * (it->first > 0 ? 1 : -1); ge->setMeshMaster(MASTER); } } for (std::map<int,int>::iterator it = _geo_internals->periodicFaces.begin(); it != _geo_internals->periodicFaces.end(); ++it){ GFace *gf = getFaceByTag(abs(it->first)); if (gf)gf->setMeshMaster(it->second * (it->first > 0 ? 1 : -1)); } for (eiter it = firstEdge() ; it != lastEdge() ; ++it){ int meshMaster = (*it)->meshMaster(); if (meshMaster != (*it)->tag()){ GEdge *ge_master = getEdgeByTag(abs(meshMaster)); if(ge_master)(*it)->getBeginVertex()->setMeshMaster ( (meshMaster > 0) ? ge_master->getBeginVertex()->tag() : ge_master->getEndVertex()->tag()); if(ge_master)(*it)->getEndVertex()->setMeshMaster ( (meshMaster < 0) ? ge_master->getBeginVertex()->tag() : ge_master->getEndVertex()->tag()); } } Msg::Debug("Gmsh model (GModel) imported:"); Msg::Debug("%d Vertices", vertices.size()); Msg::Debug("%d Edges", edges.size()); Msg::Debug("%d Faces", faces.size()); Msg::Debug("%d Regions", regions.size()); return 1; }