diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp index 098ce28541d3adb452856c0e69ccb21631f4d14d..1eaf4a9565a0dcdf2b6e980613a328bf310baf17 100644 --- a/Fltk/onelabGroup.cpp +++ b/Fltk/onelabGroup.cpp @@ -916,7 +916,7 @@ static void onelab_add_solver_cb(Fl_Widget *w, void *data) { for(int i = 0; i < NUM_SOLVERS; i++){ if(opt_solver_name(i, GMSH_GET, "").empty() || i == (NUM_SOLVERS - 1)){ - const char *name = fl_input("Client name:", ""); + const char *name = fl_input("Solver name:", ""); if(name){ FlGui::instance()->onelab->addSolver(name, "", "", i); } diff --git a/Geo/GModelFactory.cpp b/Geo/GModelFactory.cpp index 34d114f459c79e5a065bf0c18d35df25e35ef60f..070a8b5de49bcb4249bb3ed9d88068916c3878f2 100644 --- a/Geo/GModelFactory.cpp +++ b/Geo/GModelFactory.cpp @@ -462,7 +462,7 @@ std::vector<GEntity*> GeoFactory::extrudeBoundaryLayer(GModel *gm, GEntity *e, #include <BRepAlgoAPI_Section.hxx> #include <GProp_GProps.hxx> -#include <BRepGProp.hxx> +#include <BRepGProp.hxx> #include <TopoDS_Shape.hxx> #include <BRepTools.hxx> #include <BRepBndLib.hxx> @@ -483,7 +483,7 @@ std::vector<GEntity*> GeoFactory::extrudeBoundaryLayer(GModel *gm, GEntity *e, #include <TopTools_ListOfShape.hxx> #include "OCC_Connect.h" #if defined(HAVE_SALOME) - #include "Partition_Spliter.hxx" +#include "Partition_Spliter.hxx" #endif GVertex *OCCFactory::addVertex(GModel *gm, double x, double y, double z, double lc) @@ -654,7 +654,7 @@ GEdge *OCCFactory::addNURBS(GModel *gm, GVertex *start, GVertex *end, GFace *OCCFactory::add2Drect(GModel *gm,double x0, double y0, double dx, double dy) { Msg::Info("Default working plane is XY in add2D* functions..."); - + if (!gm->_occ_internals) gm->_occ_internals = new OCC_Internals; @@ -677,23 +677,24 @@ GFace *OCCFactory::add2Drect(GModel *gm,double x0, double y0, double dx, double /* add2Dellips: ellips face, given lower left point and width/height (in X-Y plane)*/ GFace *OCCFactory::add2Dellips(GModel *gm, double xc, double yc, double rx, double ry) { - Msg::Info("Default working plane is XY in add2D* functions..."); - - if (!gm->_occ_internals) - gm->_occ_internals = new OCC_Internals; - - gp_Dir N_dir(0., 0., 1.); - gp_Dir x_dir(1., 0., 0.); - gp_Pnt center(xc, yc, 0.); - gp_Ax2 axis(center, N_dir, x_dir); - gp_Elips ellipse = gp_Elips(axis, rx, ry); - // gp_Ax2(gp_Pnt(xc,yc;0),gp_Dir(0.,0.,1.)),rx,ry - TopoDS_Edge ellipsEdge = BRepBuilderAPI_MakeEdge(ellipse); - TopoDS_Wire ellipsWire = BRepBuilderAPI_MakeWire(ellipsEdge); - TopoDS_Face ellipsFace = BRepBuilderAPI_MakeFace(ellipsWire); - // TopoDS_Edge ellipsEdge = BRepBuilderAPI_MakeEdge( gp_Elips2d(gp_Ax22d(gp_Pnt2d(xc,yc),gp_Dir2d(1.,0.), gp_Dir2d(0.,1.)),rx,ry) ); - - return gm->_occ_internals->addFaceToModel(gm, TopoDS::Face(ellipsFace)); + Msg::Info("Default working plane is XY in add2D* functions..."); + + if (!gm->_occ_internals) + gm->_occ_internals = new OCC_Internals; + + gp_Dir N_dir(0., 0., 1.); + gp_Dir x_dir(1., 0., 0.); + gp_Pnt center(xc, yc, 0.); + gp_Ax2 axis(center, N_dir, x_dir); + gp_Elips ellipse = gp_Elips(axis, rx, ry); + // gp_Ax2(gp_Pnt(xc,yc;0),gp_Dir(0.,0.,1.)),rx,ry + TopoDS_Edge ellipsEdge = BRepBuilderAPI_MakeEdge(ellipse); + TopoDS_Wire ellipsWire = BRepBuilderAPI_MakeWire(ellipsEdge); + TopoDS_Face ellipsFace = BRepBuilderAPI_MakeFace(ellipsWire); + // TopoDS_Edge ellipsEdge = BRepBuilderAPI_MakeEdge( gp_Elips2d(gp_Ax22d(gp_Pnt2d(xc,yc), + // gp_Dir2d(1.,0.), gp_Dir2d(0.,1.)),rx,ry) ); + + return gm->_occ_internals->addFaceToModel(gm, TopoDS::Face(ellipsFace)); } /* @@ -727,6 +728,7 @@ GEdge *OCCFactory::addBezierSurface(GModel *gm, return gm->_occ_internals->addFaceToModel(gm, TopoDS::Face(aResult)); } */ + GEntity *OCCFactory::revolve(GModel *gm, GEntity* base, std::vector<double> p1, std::vector<double> p2, double angle) @@ -932,25 +934,25 @@ GEntity *OCCFactory::addBlock(GModel *gm, std::vector<double> p1, return gm->_occ_internals->getOCCRegionByNativePtr(gm, TopoDS::Solid(shape)); } -GEntity *OCCFactory::add3DBlock(GModel *gm,std::vector<double> p1, - double dx, double dy, double dz) +GEntity *OCCFactory::add3DBlock(GModel *gm,std::vector<double> p1, + double dx, double dy, double dz) { - if (!gm->_occ_internals) - gm->_occ_internals = new OCC_Internals; - - gp_Pnt P1(p1[0], p1[1], p1[2]); - BRepPrimAPI_MakeBox MB(P1, dx, dy, dz); - MB.Build(); - if (!MB.IsDone()) { - Msg::Error("Box can not be computed from the given point"); - return 0; - } - TopoDS_Shape shape = MB.Shape(); - gm->_occ_internals->buildShapeFromLists(shape); - gm->destroy(); - gm->_occ_internals->buildLists(); - gm->_occ_internals->buildGModel(gm); - return gm->_occ_internals->getOCCRegionByNativePtr(gm, TopoDS::Solid(shape)); + if (!gm->_occ_internals) + gm->_occ_internals = new OCC_Internals; + + gp_Pnt P1(p1[0], p1[1], p1[2]); + BRepPrimAPI_MakeBox MB(P1, dx, dy, dz); + MB.Build(); + if (!MB.IsDone()) { + Msg::Error("Box can not be computed from the given point"); + return 0; + } + TopoDS_Shape shape = MB.Shape(); + gm->_occ_internals->buildShapeFromLists(shape); + gm->destroy(); + gm->_occ_internals->buildLists(); + gm->_occ_internals->buildGModel(gm); + return gm->_occ_internals->getOCCRegionByNativePtr(gm, TopoDS::Solid(shape)); } GModel *OCCFactory::computeBooleanUnion(GModel* obj, GModel* tool, @@ -1039,323 +1041,310 @@ GModel *OCCFactory::computeBooleanIntersection(GModel* obj, GModel* tool, void OCCFactory::salomeconnect(GModel *gm) { #if defined(HAVE_SALOME) - Msg::Info("- cutting and connecting faces with Salome's Partition_Spliter"); - TopExp_Explorer e2; - Partition_Spliter ps; - TopoDS_Shape shape = gm->_occ_internals->getShape(); - for (e2.Init(shape, TopAbs_SOLID); e2.More(); e2.Next()) - ps.AddShape(e2.Current()); - try{ - ps.Compute(); - shape = ps.Shape(); - gm->destroy(); - gm->_occ_internals->loadShape(&shape); - gm->_occ_internals->buildLists(); - gm->_occ_internals->buildGModel(gm); - } - catch(Standard_Failure &err){ - Msg::Error("%s", err.GetMessageString()); - } + Msg::Info("- cutting and connecting faces with Salome's Partition_Spliter"); + TopExp_Explorer e2; + Partition_Spliter ps; + TopoDS_Shape shape = gm->_occ_internals->getShape(); + for (e2.Init(shape, TopAbs_SOLID); e2.More(); e2.Next()) + ps.AddShape(e2.Current()); + try{ + ps.Compute(); + shape = ps.Shape(); + gm->destroy(); + gm->_occ_internals->loadShape(&shape); + gm->_occ_internals->buildLists(); + gm->_occ_internals->buildGModel(gm); + } + catch(Standard_Failure &err){ + Msg::Error("%s", err.GetMessageString()); + } #else - Msg::Info("You need to recompile with Salome support to use Salome's Partition_Spliter"); + Msg::Info("You need to recompile with Salome support to use Salome's Partition_Spliter"); #endif } /* same as checkbox GUI - does not work at all, though!*/ void OCCFactory::occconnect(GModel *gm) { - Msg::Info("- cutting and connecting faces with OCC_Connect"); - OCC_Connect connect(1); - TopoDS_Shape shape = gm->_occ_internals->getShape(); - for(TopExp_Explorer p(shape, TopAbs_SOLID); p.More(); p.Next()) - connect.Add(p.Current()); - connect.Connect(); - shape = connect; - gm->destroy(); - gm->_occ_internals->loadShape(&shape); - gm->_occ_internals->buildLists(); - gm->_occ_internals->buildGModel(gm); + Msg::Info("- cutting and connecting faces with OCC_Connect"); + OCC_Connect connect(1); + TopoDS_Shape shape = gm->_occ_internals->getShape(); + for(TopExp_Explorer p(shape, TopAbs_SOLID); p.More(); p.Next()) + connect.Add(p.Current()); + connect.Connect(); + shape = connect; + gm->destroy(); + gm->_occ_internals->loadShape(&shape); + gm->_occ_internals->buildLists(); + gm->_occ_internals->buildGModel(gm); } - /* IsEqualG : a tolerance function for setPeriodicAllFaces */ -bool IsEqualG(double x, double y); bool IsEqualG(double x, double y) { - const double epsilon = 0.00000000001; - return fabs(x - y) <= epsilon * (std::max(fabs(x),fabs(y))); + const double epsilon = 0.00000000001; + return fabs(x - y) <= epsilon * (std::max(fabs(x),fabs(y))); } -/* setPeriodicAllFaces: detects T-periodic pair of faces and -uses setPeriodicPairOfFaces to make them all periodic */ -void OCCFactory::setPeriodicAllFaces(GModel *gm, std::vector<double> FaceTranslationVector) -{ - Msg::Info("Experimental: search for 'translated' faces and calls setPeriodicPairOfFaces automatically"); - TopoDS_Shape shape = gm->_occ_internals->getShape(); - gp_Trsf theTransformation; - gp_Vec theVectorOfTranslation(FaceTranslationVector[0], FaceTranslationVector[1], FaceTranslationVector[2]); - int numFaceMaster , numFaceSlave; - std::list<GEdge*> ListOfEdgeMaster, ListOfEdgeSlave; - for(TopExp_Explorer aFaceExplorer(shape, TopAbs_FACE); aFaceExplorer.More(); aFaceExplorer.Next()) - { - TopoDS_Face aFace1 = TopoDS::Face(aFaceExplorer.Current()); - for(TopExp_Explorer aFaceExplorer2(shape, TopAbs_FACE); aFaceExplorer2.More(); aFaceExplorer2.Next()) - { - TopoDS_Face aFace2 = TopoDS::Face(aFaceExplorer2.Current()); - // Get number of Edges - int NumberOfEdgesInFace1=0; - int NumberOfEdgesInFace2=0; - for (TopExp_Explorer aEdgeExplorer1(aFace1,TopAbs_EDGE); aEdgeExplorer1.More(); aEdgeExplorer1.Next()) {NumberOfEdgesInFace1++;} - for (TopExp_Explorer aEdgeExplorer2(aFace2,TopAbs_EDGE); aEdgeExplorer2.More(); aEdgeExplorer2.Next()) {NumberOfEdgesInFace2++;} - // Get Surfaces of Faces (occtopo=>occgeom) - Handle(Geom_Surface) Surf1=BRep_Tool::Surface(aFace1); - Handle(Geom_Surface) Surf2=BRep_Tool::Surface(aFace2); - // Get barycenter and area - GProp_GProps FaceProps1; - GProp_GProps FaceProps2; - BRepGProp::SurfaceProperties(aFace1,FaceProps1); - BRepGProp::SurfaceProperties(aFace2,FaceProps2); - gp_Pnt BarycenterFace1 = FaceProps1.CentreOfMass (); - gp_Pnt BarycenterFace2 = FaceProps2.CentreOfMass (); - Standard_Real Area1 = FaceProps1.Mass(); - Standard_Real Area2 = FaceProps2.Mass(); - // Get surface normal - Standard_Real umin, vmin;//umax,vmax - GeomLProp_SLProps props1(Surf1, umin, vmin, 1, 0.01); - GeomLProp_SLProps props2(Surf2, umin, vmin, 1, 0.01); - gp_Dir norm1=props1.Normal(); - gp_Dir norm2=props2.Normal(); - - if( NumberOfEdgesInFace1==NumberOfEdgesInFace2 - && IsEqualG(Area1,Area2) - && IsEqualG(BarycenterFace1.X()+FaceTranslationVector[0],BarycenterFace2.X()) - && IsEqualG(BarycenterFace1.Y()+FaceTranslationVector[1],BarycenterFace2.Y()) - && IsEqualG(BarycenterFace1.Z()+FaceTranslationVector[2],BarycenterFace2.Z()) - ){ - numFaceMaster = gm->getOCCInternals()->getGTagOfOCCFaceByNativePtr(gm,aFace1); - numFaceSlave = gm->getOCCInternals()->getGTagOfOCCFaceByNativePtr(gm,aFace2); - //Msg::Info("Face %d (slave) is most likely Face %d (master) translated by (%.2e,%.2e,%.2e)!", - // numFaceSlave,numFaceMaster,FaceTranslationVector[0],FaceTranslationVector[1],FaceTranslationVector[2]); - - std::vector<int> EdgeListMaster(NumberOfEdgesInFace1); - std::vector<int> EdgeListSlave(NumberOfEdgesInFace2); - int i1=0,i2=0; - - // ici il faut imbriquer la seconde boucle pour fournir des edges qui match slave/master - for (TopExp_Explorer aEdgeExplorer1(aFace1,TopAbs_EDGE); aEdgeExplorer1.More(); aEdgeExplorer1.Next()) { - TopoDS_Edge aEdge1 = TopoDS::Edge(aEdgeExplorer1.Current()); - int numEdgeMaster = gm->getOCCInternals()->getGTagOfOCCEdgeByNativePtr(gm,aEdge1); - EdgeListMaster[i1] = numEdgeMaster; - i2=0; - for (TopExp_Explorer aEdgeExplorer2(aFace2,TopAbs_EDGE); aEdgeExplorer2.More(); aEdgeExplorer2.Next()) { - TopoDS_Edge aEdge2 = TopoDS::Edge(aEdgeExplorer2.Current()); - GProp_GProps EdgeProps1; - GProp_GProps EdgeProps2; - BRepGProp::LinearProperties(aEdge1, EdgeProps1); - BRepGProp::LinearProperties(aEdge2, EdgeProps2); - gp_Pnt BarycenterEdge1 = EdgeProps1.CentreOfMass (); - gp_Pnt BarycenterEdge2 = EdgeProps2.CentreOfMass (); - Standard_Real Length1 = EdgeProps1.Mass(); - Standard_Real Length2 = EdgeProps2.Mass(); - if( IsEqualG(Length1,Length2) - && IsEqualG(BarycenterEdge1.X()+FaceTranslationVector[0],BarycenterEdge2.X()) - && IsEqualG(BarycenterEdge1.Y()+FaceTranslationVector[1],BarycenterEdge2.Y()) - && IsEqualG(BarycenterEdge1.Z()+FaceTranslationVector[2],BarycenterEdge2.Z()) - ){ - int numEdgeSlave = gm->getOCCInternals()->getGTagOfOCCEdgeByNativePtr(gm,aEdge2); - EdgeListSlave[i1] = numEdgeSlave; - } - } - i1++; - } - if(NumberOfEdgesInFace1==4) - Msg::Info("Setting Periodic : Face %d {%d,%d,%d,%d} (slave) and Face %d {%d,%d,%d,%d} (master)", - numFaceSlave ,EdgeListSlave[0] ,EdgeListSlave[1] ,EdgeListSlave[2] ,EdgeListSlave[3] , - numFaceMaster,EdgeListMaster[0],EdgeListMaster[1],EdgeListMaster[2],EdgeListMaster[3]); - setPeriodicPairOfFaces(gm, numFaceMaster, EdgeListMaster, numFaceSlave, EdgeListSlave); - } - else ; - } - } +/* setPeriodicAllFaces: detects T-periodic pair of faces and uses + setPeriodicPairOfFaces to make them all periodic */ +void OCCFactory::setPeriodicAllFaces(GModel *gm, std::vector<double> FaceTranslationVector) +{ + Msg::Info("Experimental: search for 'translated' faces and calls setPeriodicPairOfFaces automatically"); + TopoDS_Shape shape = gm->_occ_internals->getShape(); + gp_Trsf theTransformation; + gp_Vec theVectorOfTranslation(FaceTranslationVector[0], + FaceTranslationVector[1], + FaceTranslationVector[2]); + int numFaceMaster , numFaceSlave; + std::list<GEdge*> ListOfEdgeMaster, ListOfEdgeSlave; + for(TopExp_Explorer aFaceExplorer(shape, TopAbs_FACE); aFaceExplorer.More(); aFaceExplorer.Next()){ + TopoDS_Face aFace1 = TopoDS::Face(aFaceExplorer.Current()); + for(TopExp_Explorer aFaceExplorer2(shape, TopAbs_FACE); aFaceExplorer2.More(); aFaceExplorer2.Next()){ + TopoDS_Face aFace2 = TopoDS::Face(aFaceExplorer2.Current()); + // Get number of Edges + int NumberOfEdgesInFace1=0; + int NumberOfEdgesInFace2=0; + for (TopExp_Explorer aEdgeExplorer1(aFace1,TopAbs_EDGE); aEdgeExplorer1.More(); + aEdgeExplorer1.Next()) {NumberOfEdgesInFace1++;} + for (TopExp_Explorer aEdgeExplorer2(aFace2,TopAbs_EDGE); aEdgeExplorer2.More(); + aEdgeExplorer2.Next()) {NumberOfEdgesInFace2++;} + // Get Surfaces of Faces (occtopo=>occgeom) + Handle(Geom_Surface) Surf1=BRep_Tool::Surface(aFace1); + Handle(Geom_Surface) Surf2=BRep_Tool::Surface(aFace2); + // Get barycenter and area + GProp_GProps FaceProps1; + GProp_GProps FaceProps2; + BRepGProp::SurfaceProperties(aFace1,FaceProps1); + BRepGProp::SurfaceProperties(aFace2,FaceProps2); + gp_Pnt BarycenterFace1 = FaceProps1.CentreOfMass (); + gp_Pnt BarycenterFace2 = FaceProps2.CentreOfMass (); + Standard_Real Area1 = FaceProps1.Mass(); + Standard_Real Area2 = FaceProps2.Mass(); + // Get surface normal + //Standard_Real umin, vmin;//umax,vmax + //GeomLProp_SLProps props1(Surf1, umin, vmin, 1, 0.01); + //GeomLProp_SLProps props2(Surf2, umin, vmin, 1, 0.01); + //gp_Dir norm1=props1.Normal(); + //gp_Dir norm2=props2.Normal(); + + if(NumberOfEdgesInFace1==NumberOfEdgesInFace2 + && IsEqualG(Area1,Area2) + && IsEqualG(BarycenterFace1.X()+FaceTranslationVector[0],BarycenterFace2.X()) + && IsEqualG(BarycenterFace1.Y()+FaceTranslationVector[1],BarycenterFace2.Y()) + && IsEqualG(BarycenterFace1.Z()+FaceTranslationVector[2],BarycenterFace2.Z())){ + numFaceMaster = gm->getOCCInternals()->getGTagOfOCCFaceByNativePtr(gm,aFace1); + numFaceSlave = gm->getOCCInternals()->getGTagOfOCCFaceByNativePtr(gm,aFace2); + //Msg::Info("Face %d (slave) is most likely Face %d (master) translated by (%.2e,%.2e,%.2e)!", + // numFaceSlave,numFaceMaster,FaceTranslationVector[0],FaceTranslationVector[1], + // FaceTranslationVector[2]); + + std::vector<int> EdgeListMaster(NumberOfEdgesInFace1); + std::vector<int> EdgeListSlave(NumberOfEdgesInFace2); + int i1=0,i2=0; + + // ici il faut imbriquer la seconde boucle pour fournir des edges qui match slave/master + for (TopExp_Explorer aEdgeExplorer1(aFace1,TopAbs_EDGE); aEdgeExplorer1.More(); + aEdgeExplorer1.Next()) { + TopoDS_Edge aEdge1 = TopoDS::Edge(aEdgeExplorer1.Current()); + int numEdgeMaster = gm->getOCCInternals()->getGTagOfOCCEdgeByNativePtr(gm,aEdge1); + EdgeListMaster[i1] = numEdgeMaster; + i2=0; + for (TopExp_Explorer aEdgeExplorer2(aFace2,TopAbs_EDGE); aEdgeExplorer2.More(); + aEdgeExplorer2.Next()) { + TopoDS_Edge aEdge2 = TopoDS::Edge(aEdgeExplorer2.Current()); + GProp_GProps EdgeProps1; + GProp_GProps EdgeProps2; + BRepGProp::LinearProperties(aEdge1, EdgeProps1); + BRepGProp::LinearProperties(aEdge2, EdgeProps2); + gp_Pnt BarycenterEdge1 = EdgeProps1.CentreOfMass (); + gp_Pnt BarycenterEdge2 = EdgeProps2.CentreOfMass (); + Standard_Real Length1 = EdgeProps1.Mass(); + Standard_Real Length2 = EdgeProps2.Mass(); + if(IsEqualG(Length1,Length2) + && IsEqualG(BarycenterEdge1.X()+FaceTranslationVector[0],BarycenterEdge2.X()) + && IsEqualG(BarycenterEdge1.Y()+FaceTranslationVector[1],BarycenterEdge2.Y()) + && IsEqualG(BarycenterEdge1.Z()+FaceTranslationVector[2],BarycenterEdge2.Z())){ + int numEdgeSlave = gm->getOCCInternals()->getGTagOfOCCEdgeByNativePtr(gm,aEdge2); + EdgeListSlave[i1] = numEdgeSlave; + } + } + i1++; + } + if(NumberOfEdgesInFace1==4) + Msg::Info("Setting Periodic : Face %d {%d,%d,%d,%d} (slave) and Face %d " + "{%d,%d,%d,%d} (master)", + numFaceSlave ,EdgeListSlave[0] ,EdgeListSlave[1] ,EdgeListSlave[2], + EdgeListSlave[3], numFaceMaster,EdgeListMaster[0],EdgeListMaster[1], + EdgeListMaster[2],EdgeListMaster[3]); + setPeriodicPairOfFaces(gm, numFaceMaster, EdgeListMaster, numFaceSlave, EdgeListSlave); + } + else ; + } + } } -/* setPeriodicPairOfFaces: set periodic given a -Slave/Master pair of numFace-Edgelist */ -void OCCFactory::setPeriodicPairOfFaces(GModel *gm, int numFaceMaster, std::vector<int> EdgeListMaster, int numFaceSlave, std::vector<int> EdgeListSlave) +/* setPeriodicPairOfFaces: set periodic given a Slave/Master pair of + numFace-Edgelist */ +void OCCFactory::setPeriodicPairOfFaces(GModel *gm, int numFaceMaster, std::vector<int> EdgeListMaster, + int numFaceSlave, std::vector<int> EdgeListSlave) { - int NEdges=EdgeListMaster.size(); - if (EdgeListMaster.size() != EdgeListSlave.size()) - { - Msg::Error("Slave/Master faces don't have the same number of edges!"); - } - else - { - Surface *s_slave = FindSurface(abs(numFaceSlave)); - if(s_slave) - { - GModel::current()->getGEOInternals()->periodicFaces[numFaceSlave] = numFaceMaster; - for (int i = 0; i < NEdges; i++) - { - GModel::current()->getGEOInternals()->periodicEdges[EdgeListSlave[i]] = EdgeListMaster[i]; - s_slave->edgeCounterparts[EdgeListSlave[i]] = EdgeListMaster[i]; - } - } - else - { - GFace *gf = GModel::current()->getFaceByTag(abs(numFaceSlave)); - if(gf) - { - gf->setMeshMaster(numFaceMaster); - for (int i = 0; i < NEdges; i++) - { - gf->edgeCounterparts[EdgeListSlave[i]] = EdgeListMaster[i]; - GEdge *ges = GModel::current()->getEdgeByTag(abs(EdgeListSlave[i])); - ges->setMeshMaster(EdgeListMaster[i]); - } - } - else Msg::Error("Slave surface %d not found", numFaceSlave); - } - } + int NEdges=EdgeListMaster.size(); + if (EdgeListMaster.size() != EdgeListSlave.size()){ + Msg::Error("Slave/Master faces don't have the same number of edges!"); + } + else{ + Surface *s_slave = FindSurface(abs(numFaceSlave)); + if(s_slave){ + GModel::current()->getGEOInternals()->periodicFaces[numFaceSlave] = numFaceMaster; + for (int i = 0; i < NEdges; i++){ + GModel::current()->getGEOInternals()->periodicEdges[EdgeListSlave[i]] = EdgeListMaster[i]; + s_slave->edgeCounterparts[EdgeListSlave[i]] = EdgeListMaster[i]; + } + } + else{ + GFace *gf = GModel::current()->getFaceByTag(abs(numFaceSlave)); + if(gf){ + gf->setMeshMaster(numFaceMaster); + for (int i = 0; i < NEdges; i++){ + gf->edgeCounterparts[EdgeListSlave[i]] = EdgeListMaster[i]; + GEdge *ges = GModel::current()->getEdgeByTag(abs(EdgeListSlave[i])); + ges->setMeshMaster(EdgeListMaster[i]); + } + } + else Msg::Error("Slave surface %d not found", numFaceSlave); + } + } } -/* setPhysicalNumToEntitiesInBox allows to set a physical number to all entities -of a given type (0:vertex, 1:edge, 2:face, 3:volume) lying inside a 3D box -defined by 2 points */ -void OCCFactory::setPhysicalNumToEntitiesInBox(GModel *gm, int EntityType, int PhysicalGroupNumber, std::vector<double> p1, std::vector<double> p2) +/* setPhysicalNumToEntitiesInBox allows to set a physical number to all entities + of a given type (0:vertex, 1:edge, 2:face, 3:volume) lying inside a 3D box + defined by 2 points */ +void OCCFactory::setPhysicalNumToEntitiesInBox(GModel *gm, int EntityType, int PhysicalGroupNumber, + std::vector<double> p1, std::vector<double> p2) { - std::vector<int> ListOfGVerticeTagsInbox; - std::vector<int> ListOfGEdgesTagsInbox; - std::vector<int> ListOfGFacesTagsInbox; - std::vector<int> ListOfGRegionsTagsInbox; - - Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; - TopoDS_Shape shape = gm->_occ_internals->getShape(); - switch (EntityType) { - case 0 : - for(TopExp_Explorer aVertexExplorer(shape, TopAbs_VERTEX); aVertexExplorer.More(); aVertexExplorer.Next()) - { - TopoDS_Vertex aVertex = TopoDS::Vertex(aVertexExplorer.Current()); - Bnd_Box VertexBB; - BRepBndLib::Add(aVertex,VertexBB); - VertexBB.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - if( aXmin>p1[0] - && aYmin>p1[1] - && aZmin>p1[2] - && aXmax<p2[0] - && aYmax<p2[1] - && aZmax<p2[2] - ){ - int GVertexTag = gm->getOCCInternals()->getGTagOfOCCVertexByNativePtr(gm,aVertex); - //Msg::Info("This volume %d (xmin,ymin,zmin)=(%lf,%lf,%lf) (xmax,ymax,zmax)=(%lf,%lf,%lf)",GVertexTag); - ListOfGVerticeTagsInbox.push_back(GVertexTag); - } - } - Msg::Info("These edges have OCC bounding boxes inside the given box!"); - for (std::vector<int>::iterator it = ListOfGVerticeTagsInbox.begin() ; it != ListOfGVerticeTagsInbox.end(); ++it) - { - Msg::Info("- %d",*it); - GVertex *gv = gm->getVertexByTag(*it); - if(gv) - { - gv->addPhysicalEntity(PhysicalGroupNumber); - } - } - break; - case 1 : - for(TopExp_Explorer aEdgeExplorer(shape, TopAbs_EDGE); aEdgeExplorer.More(); aEdgeExplorer.Next()) - { - TopoDS_Edge aEdge = TopoDS::Edge(aEdgeExplorer.Current()); - Bnd_Box EdgeBB; - BRepBndLib::Add(aEdge,EdgeBB); - EdgeBB.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - - if( aXmin>p1[0] - && aYmin>p1[1] - && aZmin>p1[2] - && aXmax<p2[0] - && aYmax<p2[1] - && aZmax<p2[2] - ){ - int GEdgeTag = gm->getOCCInternals()->getGTagOfOCCEdgeByNativePtr(gm,aEdge); - //Msg::Info("This edge %d (xmin,ymin,zmin)=(%lf,%lf,%lf) (xmax,ymax,zmax)=(%lf,%lf,%lf)",GEdgeTag); - ListOfGEdgesTagsInbox.push_back(GEdgeTag); - } - } - Msg::Info("These edges have OCC bounding boxes inside the given box!"); - for (std::vector<int>::iterator it = ListOfGEdgesTagsInbox.begin() ; it != ListOfGEdgesTagsInbox.end(); ++it) - { - Msg::Info("- %d",*it); - GEdge *ge = gm->getEdgeByTag(*it); - if(ge) - { - ge->addPhysicalEntity(PhysicalGroupNumber); - } - } - break; - case 2 : - for(TopExp_Explorer aFaceExplorer(shape, TopAbs_FACE); aFaceExplorer.More(); aFaceExplorer.Next()) - { - TopoDS_Face aFace = TopoDS::Face(aFaceExplorer.Current()); - Bnd_Box FaceBB; - BRepBndLib::Add(aFace,FaceBB); - FaceBB.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - - if( aXmin>p1[0] - && aYmin>p1[1] - && aZmin>p1[2] - && aXmax<p2[0] - && aYmax<p2[1] - && aZmax<p2[2] - ){ - int GFaceTag = gm->getOCCInternals()->getGTagOfOCCFaceByNativePtr(gm,aFace); - //Msg::Info("This face %d (xmin,ymin,zmin)=(%lf,%lf,%lf) (xmax,ymax,zmax)=(%lf,%lf,%lf)",GFaceTag); - ListOfGFacesTagsInbox.push_back(GFaceTag); - } - } - Msg::Info("This faces have OCC bounding boxes inside the given box!"); - for (std::vector<int>::iterator it = ListOfGFacesTagsInbox.begin() ; it != ListOfGFacesTagsInbox.end(); ++it) - { - Msg::Info("- %d",*it); - GFace *gf = gm->getFaceByTag(*it); - if(gf) - { - gf->addPhysicalEntity(PhysicalGroupNumber); - } - } - break; - case 3 : - for(TopExp_Explorer aSolidExplorer(shape, TopAbs_SOLID); aSolidExplorer.More(); aSolidExplorer.Next()) - { - TopoDS_Solid aSolid = TopoDS::Solid(aSolidExplorer.Current()); - Bnd_Box SolidBB; - BRepBndLib::Add(aSolid,SolidBB); - SolidBB.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - if( aXmin>p1[0] - && aYmin>p1[1] - && aZmin>p1[2] - && aXmax<p2[0] - && aYmax<p2[1] - && aZmax<p2[2] - ){ - int GSolidTag = gm->getOCCInternals()->getGTagOfOCCSolidByNativePtr(gm,aSolid); - //Msg::Info("This volume %d (xmin,ymin,zmin)=(%lf,%lf,%lf) (xmax,ymax,zmax)=(%lf,%lf,%lf)",GSolidTag); - ListOfGRegionsTagsInbox.push_back(GSolidTag); - } - } - Msg::Info("These edges have OCC bounding boxes inside the given box!"); - for (std::vector<int>::iterator it = ListOfGRegionsTagsInbox.begin() ; it != ListOfGRegionsTagsInbox.end(); ++it) - { - Msg::Info("- %d",*it); - GRegion *gr = gm->getRegionByTag(*it); - if(gr) - { - gr->addPhysicalEntity(PhysicalGroupNumber); - } - } - break; - default: - Msg::Error("First argument of setPhysicalNumToEntitiesInBox should be 0,1,2 or 3 (Vertice, Edge, Surface or Volume)"); - } + std::vector<int> ListOfGVerticeTagsInbox; + std::vector<int> ListOfGEdgesTagsInbox; + std::vector<int> ListOfGFacesTagsInbox; + std::vector<int> ListOfGRegionsTagsInbox; + + Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; + TopoDS_Shape shape = gm->_occ_internals->getShape(); + switch (EntityType) { + case 0 : + for(TopExp_Explorer aVertexExplorer(shape, TopAbs_VERTEX); aVertexExplorer.More(); aVertexExplorer.Next()){ + TopoDS_Vertex aVertex = TopoDS::Vertex(aVertexExplorer.Current()); + Bnd_Box VertexBB; + BRepBndLib::Add(aVertex,VertexBB); + VertexBB.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + if(aXmin>p1[0] + && aYmin>p1[1] + && aZmin>p1[2] + && aXmax<p2[0] + && aYmax<p2[1] + && aZmax<p2[2]){ + int GVertexTag = gm->getOCCInternals()->getGTagOfOCCVertexByNativePtr(gm,aVertex); + //Msg::Info("This volume %d (xmin,ymin,zmin)=(%lf,%lf,%lf) (xmax,ymax,zmax)=(%lf,%lf,%lf)",GVertexTag); + ListOfGVerticeTagsInbox.push_back(GVertexTag); + } + } + Msg::Info("These edges have OCC bounding boxes inside the given box!"); + for (std::vector<int>::iterator it = ListOfGVerticeTagsInbox.begin() ; + it != ListOfGVerticeTagsInbox.end(); ++it){ + Msg::Info("- %d",*it); + GVertex *gv = gm->getVertexByTag(*it); + if(gv){ + gv->addPhysicalEntity(PhysicalGroupNumber); + } + } + break; + case 1 : + for(TopExp_Explorer aEdgeExplorer(shape, TopAbs_EDGE); aEdgeExplorer.More(); aEdgeExplorer.Next()){ + TopoDS_Edge aEdge = TopoDS::Edge(aEdgeExplorer.Current()); + Bnd_Box EdgeBB; + BRepBndLib::Add(aEdge,EdgeBB); + EdgeBB.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + + if(aXmin>p1[0] + && aYmin>p1[1] + && aZmin>p1[2] + && aXmax<p2[0] + && aYmax<p2[1] + && aZmax<p2[2]){ + int GEdgeTag = gm->getOCCInternals()->getGTagOfOCCEdgeByNativePtr(gm,aEdge); + //Msg::Info("This edge %d (xmin,ymin,zmin)=(%lf,%lf,%lf) (xmax,ymax,zmax)=(%lf,%lf,%lf)",GEdgeTag); + ListOfGEdgesTagsInbox.push_back(GEdgeTag); + } + } + Msg::Info("These edges have OCC bounding boxes inside the given box!"); + for (std::vector<int>::iterator it = ListOfGEdgesTagsInbox.begin() ; it != ListOfGEdgesTagsInbox.end(); ++it){ + Msg::Info("- %d",*it); + GEdge *ge = gm->getEdgeByTag(*it); + if(ge){ + ge->addPhysicalEntity(PhysicalGroupNumber); + } + } + break; + case 2 : + for(TopExp_Explorer aFaceExplorer(shape, TopAbs_FACE); aFaceExplorer.More(); aFaceExplorer.Next()){ + TopoDS_Face aFace = TopoDS::Face(aFaceExplorer.Current()); + Bnd_Box FaceBB; + BRepBndLib::Add(aFace,FaceBB); + FaceBB.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + + if(aXmin>p1[0] + && aYmin>p1[1] + && aZmin>p1[2] + && aXmax<p2[0] + && aYmax<p2[1] + && aZmax<p2[2]){ + int GFaceTag = gm->getOCCInternals()->getGTagOfOCCFaceByNativePtr(gm,aFace); + //Msg::Info("This face %d (xmin,ymin,zmin)=(%lf,%lf,%lf) (xmax,ymax,zmax)=(%lf,%lf,%lf)",GFaceTag); + ListOfGFacesTagsInbox.push_back(GFaceTag); + } + } + Msg::Info("This faces have OCC bounding boxes inside the given box!"); + for (std::vector<int>::iterator it = ListOfGFacesTagsInbox.begin() ; + it != ListOfGFacesTagsInbox.end(); ++it){ + Msg::Info("- %d",*it); + GFace *gf = gm->getFaceByTag(*it); + if(gf){ + gf->addPhysicalEntity(PhysicalGroupNumber); + } + } + break; + case 3 : + for(TopExp_Explorer aSolidExplorer(shape, TopAbs_SOLID); aSolidExplorer.More(); + aSolidExplorer.Next()){ + TopoDS_Solid aSolid = TopoDS::Solid(aSolidExplorer.Current()); + Bnd_Box SolidBB; + BRepBndLib::Add(aSolid,SolidBB); + SolidBB.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + if(aXmin>p1[0] + && aYmin>p1[1] + && aZmin>p1[2] + && aXmax<p2[0] + && aYmax<p2[1] + && aZmax<p2[2] + ){ + int GSolidTag = gm->getOCCInternals()->getGTagOfOCCSolidByNativePtr(gm,aSolid); + //Msg::Info("This volume %d (xmin,ymin,zmin)=(%lf,%lf,%lf) (xmax,ymax,zmax)=(%lf,%lf,%lf)",GSolidTag); + ListOfGRegionsTagsInbox.push_back(GSolidTag); + } + } + Msg::Info("These edges have OCC bounding boxes inside the given box!"); + for (std::vector<int>::iterator it = ListOfGRegionsTagsInbox.begin() ; + it != ListOfGRegionsTagsInbox.end(); ++it){ + Msg::Info("- %d",*it); + GRegion *gr = gm->getRegionByTag(*it); + if(gr){ + gr->addPhysicalEntity(PhysicalGroupNumber); + } + } + break; + default: + Msg::Error("First argument of setPhysicalNumToEntitiesInBox should be 0,1,2 or 3 (Vertice, Edge, Surface or Volume)"); + } } void OCCFactory::fillet(GModel *gm, std::vector<int> edges, double radius) diff --git a/Geo/boundaryLayersData.cpp b/Geo/boundaryLayersData.cpp index 20e19a48f2fa6218564006083ec8e70ca8cd6d7d..a9db02fd49a5d8f9fd777fadc37ca9c035cd76da 100644 --- a/Geo/boundaryLayersData.cpp +++ b/Geo/boundaryLayersData.cpp @@ -25,7 +25,8 @@ SVector3 interiorNormal (SPoint2 p1, SPoint2 p2, SPoint2 p3) return n*(-1.); } -double computeAngle (GFace *gf, const MEdge &e1, const MEdge &e2, SVector3 &n1, SVector3 &n2) +double computeAngle (GFace *gf, const MEdge &e1, const MEdge &e2, + SVector3 &n1, SVector3 &n2) { double cosa = dot(n1,n2); SPoint2 p0,p1,p2; @@ -150,7 +151,8 @@ edgeColumn BoundaryLayerColumns::getColumns(MVertex *v1, MVertex *v2 , int side) else return edgeColumn(c11,c20); } - // Msg::Error ("Impossible Boundary Layer Configuration : one side and no fans %d %d",N1,N2); + // Msg::Error ("Impossible Boundary Layer Configuration : " + // "one side and no fans %d %d", N1, N2); // FIXME WRONG return N1 ? edgeColumn (getColumn (v1,0),getColumn(v1,0)) : edgeColumn (getColumn (v2,0),getColumn(v2,0)); @@ -191,7 +193,9 @@ edgeColumn BoundaryLayerColumns::getColumns(MVertex *v1, MVertex *v2 , int side) */ -static void treat2Connections (GFace *gf, MVertex *_myVert, MEdge &e1, MEdge &e2, double _treshold, BoundaryLayerColumns *_columns, std::vector<SVector3> &_dirs, bool test = false) +static void treat2Connections (GFace *gf, MVertex *_myVert, MEdge &e1, MEdge &e2, + double _treshold, BoundaryLayerColumns *_columns, + std::vector<SVector3> &_dirs, bool test = false) { std::vector<SVector3> N1,N2; for (std::multimap<MEdge,SVector3,Less_Edge>::iterator itm = @@ -200,12 +204,12 @@ static void treat2Connections (GFace *gf, MVertex *_myVert, MEdge &e1, MEdge &e2 for (std::multimap<MEdge,SVector3,Less_Edge>::iterator itm = _columns->_normals.lower_bound(e2); itm != _columns->_normals.upper_bound(e2); ++itm) N2.push_back(itm->second); - if (test)printf("%d %d\n",N1.size(),N2.size()); + if (test) printf("%d %d\n", (int)N1.size(), (int)N2.size()); if (N1.size() == N2.size()){ for (unsigned int SIDE = 0; SIDE < N1.size() ; SIDE++){ // IF THE ANGLE IS GREATER THAN THRESHOLD, ADD DIRECTIONS !! double angle = computeAngle (gf,e1,e2,N1[SIDE],N2[SIDE]); - if (test)printf("angle %12.5E\n",180*angle/M_PI); + if (test) printf("angle %12.5E\n", 180*angle/M_PI); if (angle < _treshold /*&& angle > - _treshold*/){ SVector3 x = N1[SIDE]*1.01+N2[SIDE]; x.normalize(); @@ -245,7 +249,10 @@ static void treat2Connections (GFace *gf, MVertex *_myVert, MEdge &e1, MEdge &e2 } } -static void treat3Connections (GFace *gf, MVertex *_myVert, MEdge &e1, MEdge &e2, MEdge &e3, double _treshold, BoundaryLayerColumns *_columns, std::vector<SVector3> &_dirs) +static void treat3Connections (GFace *gf, MVertex *_myVert, MEdge &e1, + MEdge &e2, MEdge &e3, double _treshold, + BoundaryLayerColumns *_columns, + std::vector<SVector3> &_dirs) { std::vector<SVector3> N1,N2,N3; for (std::multimap<MEdge,SVector3,Less_Edge>::iterator itm = @@ -489,7 +496,8 @@ bool buildAdditionalPoints2D (GFace *gf, BoundaryLayerColumns *_columns) // < ------------------------------- > // if (endOfTheBL){ - printf("%g %g %d %d %g\n",(*it)->x(),(*it)->y(),DIR,_dirs.size(),dot(n,dirEndOfBL)); + printf("%g %g %d %d %g\n", (*it)->x(), (*it)->y(), DIR, (int)_dirs.size(), + dot(n, dirEndOfBL)); } if (endOfTheBL && dot(n,dirEndOfBL) > .99){ printf( "coucou c'est moi\n");