def EdgeEndsOnCoordinate(aEdge, aCoordValue, aCoord, aTol): edgePoints = geompy.SubShapeAll(aEdge, geompy.ShapeType["EDGE"]) edgeCoord1 = geompy.PointCoordinates(edgePoints[0]) edgeCoord2 = geompy.PointCoordinates(edgePoints[1]) tol = math.fabs(aCoordValue - edgeCoord1[aCoord]) + fabs(aCoordValue - edgeCoord2[aCoord]) if aTol >= tol: return 1 return 0
def EdgeHasEnds(aObject, aPoint1, aPoint2, aTol): edgeEnds = geompy.SubShapeAll(aObject, geompy.ShapeType["VERTEX"]) areNear1 = PointsAreNear(aPoint1, edgeEnds[0], aTol) areNear2 = PointsAreNear(aPoint2, edgeEnds[1], aTol) areNear3 = PointsAreNear(aPoint1, edgeEnds[1], aTol) areNear4 = PointsAreNear(aPoint2, edgeEnds[0], aTol) cond1 = areNear1 * areNear2 cond2 = areNear3 * areNear4 if (cond1 or cond2): return 1 return 0
def EdgeOnEnds(aObject, aPoint1, aPoint2, aTol): allEdgesList = [] allEdgesList = geompy.SubShapeAll(aObject, geompy.ShapeType["EDGE"]) nEdges = len(allEdgesList) nSelected = 0 for jEdge in range(0, nEdges): isEdgeHasEnds = EdgeHasEnds(allEdgesList[jEdge], aPoint1, aPoint2, aTol) if isEdgeHasEnds: return allEdgesList[jEdge] print "Serious error: can\'t find edge with specified points" return 0
def VectorNorm(aVector): vectorNorm = [1., 1., 1.] vectorMag = 0. edgePoints = geompy.SubShapeAll(aVector, geompy.ShapeType["VERTEX"]) pointCoords0 = geompy.PointCoordinates(edgePoints[0]) pointCoords1 = geompy.PointCoordinates(edgePoints[1]) vLen = len(pointCoords0) for j in range(0, vLen): vectorNorm[j] = pointCoords1[j] - pointCoords0[j] for j in range(0, vLen): vectorMag = vectorMag + vectorNorm[j] * vectorNorm[j] vectorMag = math.sqrt(vectorMag) if vectorMag > 1.0E-30: for j in range(0, vLen): vectorNorm[j] = vectorNorm[j] / vectorMag return vectorNorm
def SelectEdgesParalletTo(aObject, aVector, aTol): allEdgesList = [] allEdgesList = geompy.SubShapeAll(aObject, geompy.ShapeType["EDGE"]) edgeGroup = geompy.CreateGroup(aObject, geompy.ShapeType["EDGE"]) nEdges = len(allEdgesList) nSelected = 0 for jEdge in range(0, nEdges): isParallel = VectorsAreParallel(aVector, allEdgesList[jEdge], aTol) if isParallel: edgeID = geompy.GetSubShapeID(aObject, allEdgesList[jEdge]) geompy.AddObject(edgeGroup, edgeID) nSelected = nSelected + 1 print nSelected print "done" return edgeGroup
def SelectEdgesWithLenEqualAndParallelTo(aObject, aLen, aVector, aTol): allEdgesList = [] allEdgesList = geompy.SubShapeAll(aObject, geompy.ShapeType["EDGE"]) edgeGroup = geompy.CreateGroup(aObject, geompy.ShapeType["EDGE"]) nEdges = len(allEdgesList) nSelected = 0 for jEdge in range(0, nEdges): edgeProps = geompy.BasicProperties(allEdgesList[jEdge]) edgeLen = edgeProps[0] lenDiff = math.fabs(edgeLen - aLen) isParallel = VectorsAreParallel(aVector, allEdgesList[jEdge], aTol) if (isParallel and (lenDiff <= aTol)): edgeID = geompy.GetSubShapeID(aObject, allEdgesList[jEdge]) geompy.AddObject(edgeGroup, edgeID) nSelected = nSelected + 1 return edgeGroup
def SelectFacesWithCoordinateAndGreaterRadius(aObject, aCoord, aCoordID, aCenter, aRadius, aTol): allFacesList = [] allFacesList = geompy.SubShapeAll(aObject, geompy.ShapeType["FACE"]) facesGroup = geompy.CreateGroup(aObject, geompy.ShapeType["FACE"]) nFaces = len(allFacesList) nSelected = 0 for jFace in range(0, nFaces): jFaceCOM = geompy.MakeCDG(allFacesList[jFace]) isOnCoordinate = PointOnCoordinate(jFaceCOM, aCoord, aCoordID, aTol) isGreaterRadius = PointGreaterRadius(jFaceCOM, aCenter, aRadius, aTol) if (isOnCoordinate and isGreaterRadius): faceID = geompy.GetSubShapeID(aObject, allFacesList[jFace]) geompy.AddObject(facesGroup, faceID) nSelected = nSelected + 1 print nSelected print "done" return facesGroup
def SelectFacesWithNormalParallelToVec(aObject, aVectors, aTol): allFacesList = [] allFacesList = geompy.SubShapeAll(aObject, geompy.ShapeType["FACE"]) facesGroup = geompy.CreateGroup(aObject, geompy.ShapeType["FACE"]) nFaces = len(allFacesList) nSelected = 0 for jFace in range(0, nFaces): jFaceCOM = geompy.MakeCDG(allFacesList[jFace]) jFaceNormal = geompy.GetNormal(allFacesList[jFace], jFaceCOM) isParallel = VectorsAreParallelVec(jFaceNormal, aVectors, aTol) if isParallel: faceID = geompy.GetSubShapeID(aObject, allFacesList[jFace]) geompy.AddObject(facesGroup, faceID) nSelected = nSelected + 1 print nSelected print "done" return facesGroup
def SelectFacesWithCOM_OnRadius(aObject, aCenter, aRadius, aTol): # all Faces allFacesList = [] selectedFacesList = [] allFacesList = geompy.SubShapeAll(aObject, geompy.ShapeType["FACE"]) facesGroup = geompy.CreateGroup(aObject, geompy.ShapeType["FACE"]) nFaces = len(allFacesList) nSelected = 0 for jFace in range(0, nFaces): jFaceCOM = geompy.MakeCDG(allFacesList[jFace]) isOnRadius = PointOnRadius(jFaceCOM, aCenter, aRadius, aTol) if isOnRadius: faceID = geompy.GetSubShapeID(aObject, allFacesList[jFace]) geompy.AddObject(facesGroup, faceID) nSelected = nSelected + 1 print nSelected print "done" return facesGroup
def SelectFacesWithCOM_OnCoordinate(aObject, aCoordValue, aCoordID, aTol): # 0 - X, 1 - Y, 2 - Z # all Faces allFacesList = [] selectedFacesList = [] allFacesList = geompy.SubShapeAll(aObject, geompy.ShapeType["FACE"]) facesGroup = geompy.CreateGroup(aObject, geompy.ShapeType["FACE"]) nFaces = len(allFacesList) nSelected = 0 for jFace in range(0, nFaces): jFaceCOM = geompy.MakeCDG(allFacesList[jFace]) isOnCoordinate = PointOnCoordinate(jFaceCOM, aCoordValue, aCoordID, aTol) if isOnCoordinate: faceID = geompy.GetSubShapeID(aObject, allFacesList[jFace]) geompy.AddObject(facesGroup, faceID) nSelected = nSelected + 1 print nSelected print "done" return facesGroup
#geompy.addToStudy( grfaceCompound, 'grfaceCompound' ) #solide final globalsolid = geompy.MakePartition([Box_1], [grfaceCompound], [], [], geompy.ShapeType["SOLID"], 0, [], 1) geompy.addToStudy(globalsolid, 'globalsolid') #generation des groupes groupe = [] #EDGE #Rien #FACE #infbase groupe de face qui represente le pied de la structure grinfbase = geompy.CreateGroup(globalsolid, geompy.ShapeType["FACE"]) [geomObj_248] = geompy.SubShapeAll(infbase, geompy.ShapeType["FACE"]) geomObj_temp = geompy.GetSame(globalsolid, geomObj_248) tempid = geompy.GetSubShapeID(globalsolid, geomObj_temp) geompy.AddObject(grinfbase, tempid) geompy.addToStudyInFather(globalsolid, grinfbase, "infbase") groupe.append(grinfbase) #faces de contacte hautes touttop = geompy.CreateGroup(globalsolid, geompy.ShapeType["FACE"]) for a in range(0, nsub + 1): for b in range(0, nsub + 1): grtop = geompy.CreateGroup(globalsolid, geompy.ShapeType["FACE"]) [tempgeomObj] = geompy.SubShapeAll(facenodeup[a][b], geompy.ShapeType["FACE"]) geomObj_temp = geompy.GetSame(globalsolid, tempgeomObj) geompy.UnionList(touttop, [geomObj_temp])
def CreateGEOM(injLens, injRads, injAngs, wallS): L1 = injLens[0] L2 = injLens[1] L3 = injLens[2] L4 = injLens[3] L5 = injLens[4] L6 = injLens[5] # R0 = injRads[0] R1 = injRads[1] R2 = injRads[2] R3 = injRads[3] R4 = injRads[4] # A1 = injAngs[0] # S = wallS # # Printing input # LSUMM = L1 + L2 + L3 + L4 + L5 + L6 DX1= math.tan(A1*math.pi/180.)*L3 + R3 - R0 # print "Input Data" print "L1, L2, L3, L4, L5, L6" print L1, L2, L3, L4, L5, L6 print "R0, R1, R2, R3, R4" print R0, R1, R2, R3, R4 print "A1 = ", A1 print "S = ", S # print "Intermediate variables: " print "LSUMM = ", LSUMM print "DX1 = ", DX1 # # # # oXYZ = geompy.MakeVertex(0, 0, 0) xPnt = geompy.MakeVertex(1, 0, 0) yPnt = geompy.MakeVertex(0, 1, 0) zPnt = geompy.MakeVertex(0, 0, 1) oX = geompy.MakeVector(oXYZ, xPnt) oY = geompy.MakeVector(oXYZ, yPnt) oZ = geompy.MakeVector(oXYZ, zPnt) # # Inlet and nozzle points and faces # P000 = geompy.MakeVertexWithRef(oXYZ, -(L1+L2), R1, 0) P001 = geompy.MakeVertexWithRef(oXYZ, -L2, R1, 0) P002 = geompy.MakeVertexWithRef(oXYZ, -L2, 0, 0) P003 = geompy.MakeVertexWithRef(oXYZ, -(L1+L2), 0, 0) # P004 = geompy.MakeVertexWithRef(oXYZ, 0, R2, 0) P005 = geompy.MakeVertexWithRef(oXYZ, 0, 0, 0) # P006 = geompy.MakeVertexWithRef(P000, 0, S, 0) P007 = geompy.MakeVertexWithRef(P006, L1,0, 0) P008 = geompy.MakeVertexWithRef(oXYZ, DX1,R0,0) P009 = geompy.MakeVertexWithRef(oXYZ, -(L1+L2), R0, 0) # F000 = geompy.MakeQuad4Vertices(P000, P001, P002, P003) F001 = geompy.MakeQuad4Vertices(P001, P002, P005, P004) F002 = geompy.MakeQuad4Vertices(P006, P007, P008, P009) # # Mixing chamber # P009 = geompy.MakeVertexWithRef(P004, 0, S, 0) P010 = geompy.MakeVertexWithRef(P005, L3,0, 0) P011 = geompy.MakeVertexWithRef(P010, 0,R3, 0) E000 = geompy.MakeLineTwoPnt(P008, P011) P012 = geompy.MakeVertexOnCurve(E000,0.9) P013 = geompy.MakeVertexWithRef(P010, L4, 0, 0) P014 = geompy.MakeVertexWithRef(P013, 0, R3, 0) # F003 = geompy.MakeQuad4Vertices(P009, P007, P008, P012) F004 = geompy.MakeQuad4Vertices(P004, P009, P012, P011) F005 = geompy.MakeQuad4Vertices(P004, P005, P010, P011) F006 = geompy.MakeQuad4Vertices(P010, P011, P014, P013) # # Diffusor and out tube # P015 = geompy.MakeVertexWithRef(P013, L5, 0, 0) P016 = geompy.MakeVertexWithRef(P015, 0, R4, 0) P017 = geompy.MakeVertexWithRef(P016, L6, 0, 0) P018 = geompy.MakeVertexWithRef(P017, 0, -R4,0) # F007 = geompy.MakeQuad4Vertices(P013, P014, P016, P015) F008 = geompy.MakeQuad4Vertices(P015, P016, P017, P018) # faceComp = geompy.MakeShell([F000, F001, F002, F003, F004, F005, F006, F007, F008]) # # Solid geomtry # sBase1 = geompy.MakeRotation(faceComp, oX, 0) sBase2 = geompy.MakeRotation(sBase1, oX, 45.*math.pi/180.) sBase3 = geompy.MakeRotation(sBase2, oX, 90.*math.pi/180.) # solid1 = geompy.MakeRevolution(sBase1, oX, 45.*math.pi/180.) solid2 = geompy.MakeRevolution(sBase2, oX, 90.*math.pi/180.) solid3 = geompy.MakeRevolution(sBase3, oX, 45.*math.pi/180.) # # Cutters # E002 = geompy.MakeLineTwoPnt(P005, P004) E003 = geompy.MakeRotation(E002, oX, 45.*math.pi/180.) E004 = geompy.MakeRotation(E003, oX, 90.*math.pi/180.) E005 = geompy.MakeRotation(E004, oX, 45.*math.pi/180.) P019 = geompy.MakeVertexOnCurve(E002,0.5) P020 = geompy.MakeVertexOnCurve(E003,0.5) P021 = geompy.MakeVertexOnCurve(E004,0.5) P022 = geompy.MakeVertexOnCurve(E005,0.5) zmin = geompy.PointCoordinates(oXYZ)[2] zmax = geompy.PointCoordinates(P020)[2] ymin = geompy.PointCoordinates(P022)[1] ymax = geompy.PointCoordinates(P019)[1] print "ymin, ymax, zmin, zmax" print ymin, ymax, zmin, zmax # E006 = geompy.MakeLineTwoPnt(P019, P020) E007 = geompy.MakeLineTwoPnt(P020, P021) E008 = geompy.MakeLineTwoPnt(P021, P022) E009 = geompy.MakeLineTwoPnt(P021, P022) edgeComp1 = geompy.MakeCompound([E006, E007, E008, E009]) edgeComp2 = geompy.MakeTranslation(edgeComp1, -(2*L1 + 2*L2), 0, 0) cutter1 = geompy.MakePrismVecH(edgeComp2, oX, LSUMM*2) # # Hexa solid # solid1_hex_v1 = geompy.MakePartition([solid1], [cutter1], [], [], geompy.ShapeType["SOLID"], 0, [], 0) solid2_hex_v1 = geompy.MakePartition([solid2], [cutter1], [], [], geompy.ShapeType["SOLID"], 0, [], 0) solid3_hex_v1 = geompy.MakePartition([solid3], [cutter1], [], [], geompy.ShapeType["SOLID"], 0, [], 0) dom_v1 = geompy.MakeCompound([solid1_hex_v1, solid2_hex_v1, solid3_hex_v1]) hsolids1 = geompy.SubShapeAll(dom_v1, geompy.ShapeType["SOLID"]) nSolids = len(hsolids1) hsolids2 = [] for jSolid in xrange(0,nSolids): solidCDG = geompy.MakeCDG(hsolids1[jSolid]) coordCDG = geompy.PointCoordinates(solidCDG) ys = coordCDG[1] zs = coordCDG[2] zOk = (zs >= zmin) * (zs <= zmax) yOk = (ys >= ymin) * (ys <= ymax) if not(zOk and yOk): hsolids2.append(hsolids1[jSolid]) # Creasting hexahedrons near the center sBase4 = geompy.MakeQuad4Vertices(P019, P020, P021, P022) sBase5 = geompy.MakeTranslation(sBase4, -(L1 + L2), 0, 0) hsolids2.append(geompy.MakePrismVecH(sBase5, oX, L1)) sBase6 = geompy.MakeTranslation(sBase5, L1, 0, 0) hsolids2.append(geompy.MakePrismVecH(sBase6, oX, L2)) sBase7 = geompy.MakeTranslation(sBase6, L2, 0, 0) hsolids2.append(geompy.MakePrismVecH(sBase7, oX, L3)) sBase8 = geompy.MakeTranslation(sBase7, L3, 0, 0) hsolids2.append(geompy.MakePrismVecH(sBase8, oX, L4)) sBase9 = geompy.MakeTranslation(sBase8, L4, 0, 0) hsolids2.append(geompy.MakePrismVecH(sBase9, oX, L5)) sBase10= geompy.MakeTranslation(sBase9,L5, 0, 0) hsolids2.append(geompy.MakePrismVecH(sBase10, oX, L6)) # # Domain # dom_v2 = geompy.MakeCompound(hsolids2) dom_comp = geompy.MakeGlueFaces(dom_v2,1.0E-6) return dom_comp
### import GEOM import geompy import math import SALOMEDS #----Initialisation du module geometrie geompy.init_geom(theStudy) # Caracteristiques geometriques de l'anneau rayon = 25. longu = 50. Sommet_1 = geompy.MakeVertex(0, rayon + longu, 0) [geomObj_1] = geompy.SubShapeAll(Sommet_1, geompy.ShapeType["VERTEX"]) [geomObj_2] = geompy.SubShapeAll(Sommet_1, geompy.ShapeType["VERTEX"]) Sommet_2 = geompy.MakeVertex(rayon, longu, 0) Sommet_3 = geompy.MakeVertex(rayon, 0, 0) [geomObj_3] = geompy.SubShapeAll(Sommet_3, geompy.ShapeType["VERTEX"]) [geomObj_4] = geompy.SubShapeAll(Sommet_3, geompy.ShapeType["VERTEX"]) Sommet_4 = geompy.MakeVertex(0, longu, 0) Arc_1 = geompy.MakeArcCenter(Sommet_4, Sommet_1, Sommet_2, False) Ligne_1 = geompy.MakeLineTwoPnt(Sommet_2, Sommet_3) Anneau = geompy.MakeWire([Arc_1, Ligne_1], 1e-07) # definition du point haut pour encastrement listSubShapeIDs = geompy.SubShapeAllIDs(Anneau, geompy.ShapeType["VERTEX"]) listSubShapeIDs = geompy.SubShapeAllIDs(Anneau, geompy.ShapeType["VERTEX"]) listSameIDs = geompy.GetSameIDs(Anneau, geomObj_1)
def injectorFaceGroups (injGeom, aInjLens, aInjRads, aWallS ,aTol): # L1= aInjLens[0] L2= aInjLens[1] L3= aInjLens[2] L4= aInjLens[3] L5= aInjLens[4] L6= aInjLens[5] # R0= aInjRads[0] R1= aInjRads[1] R2= aInjRads[2] R3= aInjRads[3] R4= aInjRads[4] # S = aWallS # RMAX = R0 LSUMM = L1 + L2 + L3 + L4 + L5 + L6 XMIN = -L1 -L2 XMAX = LSUMM + XMIN HALFR2= R2*0.5 # vertex1 = geompy.MakeVertex(0, 0, 0) vertex2 = geompy.MakeVertex(0, 0, 1) vector1 = geompy.MakeVector(vertex1, vertex2) # vertex3 = geompy.MakeVertex(1, 0, 0) vertex4 = geompy.MakeVertex(XMIN, 0, 0) Xvector = geompy.MakeVector(vertex1, vertex3) # symmWalls = faceSelect.SelectFacesWithNormalParallelToVec(injGeom, [vector1], aTol) # # now, remove all faces which are in small quadrangle # selGroup0faces = [] selGroup0faces = geompy.SubShapeAll(symmWalls, geompy.ShapeType["FACE"]) nFaces = len(selGroup0faces) idsToRemove = [] nToRemove=0 for jFace in range(0,nFaces): jFaceCOM = geompy.MakeCDG(selGroup0faces[jFace]) COMCoords = geompy.PointCoordinates(jFaceCOM) jFaceID = geompy.GetSubShapeID(injGeom, selGroup0faces[jFace]) ZCoord = COMCoords[2] Cond = (ZCoord >= aTol) if Cond: idsToRemove.append (jFaceID) nToRemove = nToRemove + 1 print "---" print nToRemove print "---" # for jFace in range(0,nToRemove): geompy.RemoveObject(symmWalls, idsToRemove[jFace]) # id_symmWalls = geompy.addToStudyInFather(injGeom,symmWalls,"symm-walls") # activeInlet = faceSelect.SelectFacesWithCoordinateAndLessRadius(injGeom,XMIN,0,vertex4,R1, aTol) id_activeInlet = geompy.addToStudyInFather(injGeom,activeInlet,"active-inlet") # passiveInlet = faceSelect.SelectFacesWithCoordinateAndGreaterRadius(injGeom,XMIN,0,vertex4,R1+S, aTol) id_passiveInlet = geompy.addToStudyInFather(injGeom,passiveInlet,"passive-inlet") Outlet = faceSelect.SelectFacesWithCOM_OnCoordinate(injGeom, XMAX, 0, aTol) id_Outlet = geompy.addToStudyInFather(injGeom,Outlet,"outlet") # faceGroups = [symmWalls, activeInlet, passiveInlet, Outlet] return faceGroups
### ### GEOM component ### import GEOM import geompy import math import SALOMEDS geompy.init_geom(theStudy) Centre = geompy.MakeVertex(0, 0, 0) Vertex_droite = geompy.MakeVertex(6, 34, 0) Vertex_gauche = geompy.MakeVertex(-6, 34, 0) Arc_1 = geompy.MakeArcCenter(Centre, Vertex_droite, Vertex_gauche, False) [geomObj_1] = geompy.SubShapeAll(Arc_1, geompy.ShapeType["EDGE"]) [geomObj_2] = geompy.SubShapeAll(Arc_1, geompy.ShapeType["EDGE"]) centre_loin = geompy.MakeVertex(0, 0, 42) Line_extrusion = geompy.MakeLineTwoPnt(centre_loin, Centre) Plaque = geompy.MakePrismVecH(Arc_1, Line_extrusion, -42) listSubShapeIDs = geompy.SubShapeAllIDs(Plaque, geompy.ShapeType["EDGE"]) [Edge_1, Edge_2, Edge_3, Edge_4] = geompy.ExtractShapes(Plaque, geompy.ShapeType["EDGE"], True) listSubShapeIDs = geompy.SubShapeAllIDs(Plaque, geompy.ShapeType["EDGE"]) listSubShapeIDs = geompy.SubShapeAllIDs(Plaque, geompy.ShapeType["EDGE"]) listSameIDs = geompy.GetSameIDs(Plaque, geomObj_1) listSameIDs = geompy.GetSameIDs(Plaque, geomObj_2) listSubShapeIDs = geompy.SubShapeAllIDs(Plaque, geompy.ShapeType["EDGE"])
# #rotating spiral according to direction if (math.fabs(normalSDX) >= rotTolerance) or ( math.fabs(normalSDY) >= rotTolerance) or (math.fabs(normalSDZ - 1) >= rotTolerance): spiralSkeleton = geompy.MakeRotationThreePoints(spiralSkeleton, startingPoint, endingPoint0, endingPoint) tubeCircle = geompy.MakeRotationThreePoints(tubeCircle, startingPoint, endingPoint0, endingPoint) id_sSkel = geompy.addToStudy(spiralSkeleton, "spiral") id_sCircle = geompy.addToStudy(tubeCircle, "Base Circle") #creating pipe spiralPipe = geompy.MakePipe(tubeCircle, spiralSkeleton) #exploding pipe into edges and obtaining bound faces spiralPipeExplosion = geompy.SubShapeAll(spiralPipe, geompy.ShapeType["EDGE"]) startingCircle = geompy.MakeFace(spiralPipeExplosion[1], 1) endingCircle = geompy.MakeFace(spiralPipeExplosion[2], 2) id_startingCircle = geompy.addToStudy(startingCircle, "Pipe Start") id_endingCircle = geompy.addToStudy(endingCircle, "Pipe End") id_pipeWall = geompy.addToStudy(spiralPipe, "Pipe Wall") #creating pipe shell pipeFacesList = [] pipeFacesList.append(spiralPipe) pipeFacesList.append(startingCircle) pipeFacesList.append(endingCircle) spiralPipeShell = geompy.MakeShell(pipeFacesList) id_spiralPipeShell = geompy.addToStudy(spiralPipeShell, "Pipe Shell") #creating pipe solid spiralPipeSolid = geompy.MakeSolid([spiralPipeShell]) id_spiralPipeSolid = geompy.addToStudy(spiralPipeSolid, "Pipe Solid")