void Centerline::run() { double t1 = Cpu(); if (update_needed){ std::ifstream input; //std::string pattern = FixRelativePath(fileName, "./"); //Msg::StatusBar(true, "Reading TEST '%s'...", pattern.c_str()); //input.open(pattern.c_str()); input.open(fileName.c_str()); if(StatFile(fileName)) Msg::Fatal("Centerline file '%s' does not exist ", fileName.c_str()); importFile(fileName); buildKdTree(); update_needed = false; } if (is_cut) cutMesh(); else{ GFace *gf = current->getFaceByTag(1); gf->addPhysicalEntity(1); current->setPhysicalName("wall", 2, 1);//tag 1 current->createTopologyFromMesh(); NV = current->getMaxElementaryNumber(0); NE = current->getMaxElementaryNumber(1); NF = current->getMaxElementaryNumber(2); NR = current->getMaxElementaryNumber(3); } //identify the boundary edges by looping over all discreteFaces std::vector<GEdge*> boundEdges; double dist_inlet = 1.e6; GEdge *gin = NULL; for (int i= 0; i< NF; i++){ GFace *gf = current->getFaceByTag(i+1); std::list<GEdge*> l_edges = gf->edges(); for(std::list<GEdge*>::iterator it = l_edges.begin(); it != l_edges.end(); it++){ std::vector<GEdge*>::iterator ite = std::find(boundEdges.begin(), boundEdges.end(), *it); if (ite != boundEdges.end()) boundEdges.erase(ite); else boundEdges.push_back(*it); GVertex *gv = (*it)->getBeginVertex(); SPoint3 pt(gv->x(), gv->y(), gv->z()); double dist = pt.distance(ptin); if(dist < dist_inlet){ dist_inlet = dist; gin = *it; } } } if (is_closed) createClosedVolume(gin, boundEdges); if (is_extruded) extrudeBoundaryLayerWall(gin, boundEdges); double t2 = Cpu(); Msg::Info("Centerline operators computed in %g (s) ",t2-t1); }
void Centerline::createClosedVolume(GEdge *gin, std::vector<GEdge*> boundEdges) { current->setFactory("Gmsh"); std::vector<std::vector<GFace *> > myFaceLoops; std::vector<GFace *> myFaces; for (unsigned int i = 0; i< boundEdges.size(); i++){ std::vector<std::vector<GEdge *> > myEdgeLoops; std::vector<GEdge *> myEdges; GEdge * gec; if(is_cut) gec = current->getEdgeByTag(NE+boundEdges[i]->tag()); else gec = current->getEdgeByTag(boundEdges[i]->tag()); myEdges.push_back(gec); myEdgeLoops.push_back(myEdges); GFace *newFace = current->addPlanarFace(myEdgeLoops); if (gin==boundEdges[i]) { newFace->addPhysicalEntity(2); current->setPhysicalName("inlet", 2, 2);//tag 2 } else{ newFace->addPhysicalEntity(3); current->setPhysicalName("outlets", 2, 3);//tag 3 } myFaces.push_back(newFace); } Msg::Info("Centerline: action (closeVolume) has created %d in/out planar faces ", (int)boundEdges.size()); for (int i = 0; i < NF; i++){ GFace * gf; if(is_cut) gf = current->getFaceByTag(NF+i+1); else gf = current->getFaceByTag(i+1); myFaces.push_back(gf); } myFaceLoops.push_back(myFaces); GRegion *reg = current->addVolume(myFaceLoops); reg->addPhysicalEntity(reg->tag()); current->setPhysicalName("lumenVolume", 3, reg->tag()); Msg::Info("Centerline: action (closeVolume) has created volume %d ", reg->tag()); }
void Centerline::createSplitCompounds() { //number of discrete vertices, edges, faces and regions for the mesh NV = current->getMaxElementaryNumber(0); NE = current->getMaxElementaryNumber(1); NF = current->getMaxElementaryNumber(2); NR = current->getMaxElementaryNumber(3); // Remesh new faces (Compound Lines and Compound Surfaces) Msg::Info("Centerline: creating split compounds ..."); //Parametrize Compound Lines for (int i=0; i < NE; i++){ std::vector<GEdge*>e_compound; GEdge *pe = current->getEdgeByTag(i+1);//current edge e_compound.push_back(pe); int num_gec = NE+i+1; Msg::Info("Create Compound Line (%d) = %d discrete edge", num_gec, pe->tag()); GEdge *gec = current->addCompoundEdge(e_compound,num_gec); if (CTX::instance()->mesh.algo2d != ALGO_2D_BAMG){ gec->meshAttributes.method = MESH_TRANSFINITE; gec->meshAttributes.nbPointsTransfinite = nbPoints+1; gec->meshAttributes.typeTransfinite = 0; gec->meshAttributes.coeffTransfinite = 1.0; } } // Parametrize Compound surfaces std::list<GEdge*> U0; for (int i=0; i < NF; i++){ std::vector<GFace*> f_compound; GFace *pf = current->getFaceByTag(i+1);//current face f_compound.push_back(pf); int num_gfc = NF+i+1; Msg::Info("Create Compound Surface (%d) = %d discrete face", num_gfc, pf->tag()); //1=conf_spectral 4=convex_circle, 7=conf_fe GFace *gfc = current->addCompoundFace(f_compound, 7, 0, num_gfc); gfc->meshAttributes.recombine = recombine; gfc->addPhysicalEntity(1); current->setPhysicalName("wall", 2, 1);//tag 1 } }
void Centerline::extrudeBoundaryLayerWall(GEdge* gin, std::vector<GEdge*> boundEdges) { Msg::Info("Centerline: extrude boundary layer wall (%d, %g%%R) ", nbElemLayer, hLayer); //orient extrude direction outward int dir = 0; MElement *e = current->getFaceByTag(1)->getMeshElement(0); SVector3 ne = e->getFace(0).normal(); SVector3 ps(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z()); double xyz[3] = {ps.x(), ps.y(), ps.z()}; ANNidx index[1]; ANNdist dist[1]; kdtree->annkSearch(xyz, 1, index, dist); ANNpointArray nodes = kdtree->thePoints(); SVector3 pc(nodes[index[0]][0], nodes[index[0]][1], nodes[index[0]][2]); SVector3 nc = ps-pc; if (dot(ne,nc) < 0) dir = 1; if (dir == 1 && hLayer > 0 ) hLayer *= -1.0; //int shift = 0; //if(is_cut) shift = NE; for (int i= 0; i< NF; i++){ GFace *gfc ; if (is_cut) gfc = current->getFaceByTag(NF+i+1); else gfc = current->getFaceByTag(i+1); current->setFactory("Gmsh"); //view -5 to scale hLayer by radius in BoundaryLayers.cpp std::vector<GEntity*> extrudedE = current->extrudeBoundaryLayer (gfc, nbElemLayer, hLayer, dir, -5); GFace *eFace = (GFace*) extrudedE[0]; eFace->addPhysicalEntity(5); current->setPhysicalName("outerWall", 2, 5);//dim 2 tag 5 GRegion *eRegion = (GRegion*) extrudedE[1]; eRegion->addPhysicalEntity(6); current->setPhysicalName("wallVolume", 3, 6);//dim 3 tag 6 //if double extruded layer if (nbElemSecondLayer > 0){ std::vector<GEntity*> extrudedESec = current->extrudeBoundaryLayer (eFace, nbElemSecondLayer, hSecondLayer, dir, -5); GFace *eFaceSec = (GFace*) extrudedESec[0]; eFaceSec->addPhysicalEntity(9); //tag 9 current->setPhysicalName("outerSecondWall", 2, 9);//dim 2 tag 9 GRegion *eRegionSec = (GRegion*) extrudedESec[1]; eRegionSec->addPhysicalEntity(10); //tag 10 current->setPhysicalName("wallVolume", 3, 10);//dim 3 tag 10 } //end double extrusion for (unsigned int j = 2; j < extrudedE.size(); j++){ GFace *elFace = (GFace*) extrudedE[j]; std::list<GEdge*> l_edges = elFace->edges(); for(std::list<GEdge*>::iterator it = l_edges.begin(); it != l_edges.end(); it++){ GEdge *myEdge = *it; if (is_cut) myEdge = current->getEdgeByTag((*it)->tag()-NE); if( std::find(boundEdges.begin(), boundEdges.end(), myEdge) != boundEdges.end() ){ if (myEdge==gin){ elFace->addPhysicalEntity(7); current->setPhysicalName("inletRing", 2, 7);//tag 7 } else{ elFace->addPhysicalEntity(8); current->setPhysicalName("outletRings", 2, 8);//tag 8 } } } } } }