Skip to content

Commit

Permalink
OCC: update surface struct mesher
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit128 committed Sep 2, 2024
1 parent 4d7be99 commit 7cd4161
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 62 deletions.
110 changes: 55 additions & 55 deletions Cassiopee/OCC/OCC/OCC.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,60 @@ def _enforceEdgesInFace(a, edges):
c += npts
return None

# hmax: hmax sur les edges et dans les faces (constant)
# hausd: erreur de corde, pas pris en compte
def ultimate(hook, hmax, hausd=-1, metric=True):
mesh = []
FAILED1 = []; FAILED2 = []
nbFaces = occ.getNbFaces(hook)

for i in range(nbFaces):
print('Meshing face %d ======================'%i)

# maillage des edges de la Face (sortie par wire)
wires = occ.meshEdgesByFace3(hook, i+1, hmax, hausd)

# sortie a plat de tous les edges
#plat = []
#for w in wires: plat += w
#Converter.convertArrays2File(plat, '%03d_edgeXY.plt'%i)

# join des edges par wire (structured)
edges = []
for w in wires:
e = Transform.join(w)
edges.append(e)

# sauvegarde des edges
edgesSav = []
for e in edges: edgesSav.append(Converter.copy(e))

# TRIMESH METRIC TRY
SUCCESS = False
if metric:
SUCCESS = meshFaceWithMetric(hook, i, edges, hmax, hausd, 1.1, mesh, FAILED1)

if not SUCCESS: # TRIMESH sans metric
edges = edgesSav
meshFaceInUV(hook, i, edges, 1., mesh, FAILED2)

FAIL1 = len(FAILED1)
print("METRICFAILURE = %d / %d"%(FAIL1, nbFaces))
for f in FAILED1:
print("METRICFAILED on face = %03d_edgeUV.plt"%f)
FAIL2 = len(FAILED2)
print("FINAL FAILURE = %d / %d"%(FAIL2,nbFaces))
for f in FAILED2:
print("FINAL FAILED on face = %03d_edgeUV.plt"%f)

return mesh

#=======================================================================================
# BACK AGAIN
#=======================================================================================

#===============================================================================
# Mesh Face no i of CAD with TRIs from parametrized edges
# TRI Mesh Face no i of CAD from parametrized edges
# IN: hook; cad hook
# IN: i: no de la face
# IN: edges structured one per wire
Expand Down Expand Up @@ -518,7 +570,7 @@ def meshFaceWithMetric(hook, i, edges, hmin, hmax, hausd, mesh, FAILED):

return SUCCESS

# Mesh face regular in UV space
# TRI mesh face regular in UV space
def meshFaceInUV(hook, i, edges, grading, mesh, FAILED):

# save edges
Expand Down Expand Up @@ -549,59 +601,7 @@ def meshFaceInUV(hook, i, edges, grading, mesh, FAILED):

return SUCCESS

# hmax: hmax sur les edges et dans les faces (constant)
# hausd: erreur de corde, pas pris en compte
def ultimate(hook, hmax, hausd=-1, metric=True):
mesh = []
FAILED1 = []; FAILED2 = []
nbFaces = occ.getNbFaces(hook)

for i in range(nbFaces):
print('Meshing face %d ======================'%i)

# maillage des edges de la Face (sortie par wire)
wires = occ.meshEdgesByFace3(hook, i+1, hmax, hausd)

# sortie a plat de tous les edges
#plat = []
#for w in wires: plat += w
#Converter.convertArrays2File(plat, '%03d_edgeXY.plt'%i)

# join des edges par wire (structured)
edges = []
for w in wires:
e = Transform.join(w)
edges.append(e)

# sauvegarde des edges
edgesSav = []
for e in edges: edgesSav.append(Converter.copy(e))

# TRIMESH METRIC TRY
SUCCESS = False
if metric:
SUCCESS = meshFaceWithMetric(hook, i, edges, hmax, hausd, 1.1, mesh, FAILED1)

if not SUCCESS: # TRIMESH sans metric
edges = edgesSav
meshFaceInUV(hook, i, edges, 1., mesh, FAILED2)

FAIL1 = len(FAILED1)
print("METRICFAILURE = %d / %d"%(FAIL1, nbFaces))
for f in FAILED1:
print("METRICFAILED on face = %03d_edgeUV.plt"%f)
FAIL2 = len(FAILED2)
print("FINAL FAILURE = %d / %d"%(FAIL2,nbFaces))
for f in FAILED2:
print("FINAL FAILED on face = %03d_edgeUV.plt"%f)

return mesh

#=======================================================================================
# BACK AGAIN
#=======================================================================================

# mesh all CAD edges
# mesh all CAD edges with hmax, hausd
def meshAllEdges(hook, hmax, hausd):
nbEdges = occ.getNbEdges(hook)
dedges = []
Expand Down
44 changes: 37 additions & 7 deletions Cassiopee/OCC/OCC/PyTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,17 @@ def _unlinkCAD2Tree(t):
if l is not None: l[1] = 0
return None

# a mettre en convertCAD2PyTree?
# Get the first tree for structured CAD meshing
def getTree(hook, N=11, hmax=-1, hausd=-1.):
"""Get a first TRI meshed tree linked to CAD."""

t = C.newPyTree(['EDGES', 'SURFACES'])
t = C.newPyTree(['EDGES', 'FACES'])

# Add CAD top container containing the CAD file name
fileName, fileFmt = OCC.occ.getFileAndFormat(hook)
CAD = Internal.createChild(t, 'CAD', 'UserDefinedData_t')
Internal._createChild(CAD, 'file', 'DataArray_t', value=fileName)
Internal._createChild(CAD, 'format', 'DataArray_t', value=fileFmt)

# Edges
if hmax > 0.: edges = OCC.occ.meshGlobalEdges1(hook, hmax)
Expand All @@ -364,10 +370,10 @@ def getTree(hook, N=11, hmax=-1, hausd=-1.):
b[2].append(z)

# Faces
b = Internal.getNodeFromName1(t, 'SURFACES')
b = Internal.getNodeFromName1(t, 'FACES')
faceNo = []
m = OCC.meshTRI__(hook, N=N, hmax=hmax, hausd=hausd, faceNo=faceNo)
#m = OCC.meshSTRUCT__(hook, N=N, faceNo=faceNo)
#m = OCC.meshTRI__(hook, N=N, hmax=hmax, hausd=hausd, faceNo=faceNo)
m = OCC.meshSTRUCT__(hook, N=N, faceNo=faceNo)

for c, f in enumerate(m):
noface = faceNo[c]
Expand All @@ -382,15 +388,39 @@ def getTree(hook, N=11, hmax=-1, hausd=-1.):
Internal._createChild(r, "type", "DataArray_t", value="face")
Internal._createChild(r, "no", "DataArray_t", value=noface)
Internal._createChild(r, "edgeList", "DataArray_t", value=edgeNo)
Internal._createChild(r, "hsize", "DataArray_t", value=[0.])
#Internal._createChild(r, "hook", "UserDefinedData_t", value=hook)
b[2].append(z)

# build face list of edges
edgeOfFaces = {}
b = Internal.getNodeFromName1(t, 'EDGES')
for e in Internal.getZones(b):
edgeno = getNo(e)
edgeOfFaces[edgeno] = []

b = Internal.getNodeFromName1(t, 'FACES')
for f in Internal.getZones(b):
faceno = getNo(f)
cad = Internal.getNodeFromName1(f, 'CAD')
edgeList = Internal.getNodeFromName1(cad, 'edgeList')
edgeList = edgeList[1]
for i in edgeList: edgeOfFaces[i].append(faceno)

b = Internal.getNodeFromName1(t, 'EDGES')
for e in Internal.getZones(b):
edgeno = getNo(e)
cad = Internal.getNodeFromName1(e, 'CAD')
faces = edgeOfFaces[edgeno]
n = numpy.array(faces, dtype=Internal.E_NpyInt)
Internal._createChild(cad, 'faceList', 'DataArray_t', value=n)

return t

# remesh tree from edges with new ue from EDGES
def remeshTreeFromEdges(hook, tp):

t = C.newPyTree(['EDGES', 'SURFACES'])
t = C.newPyTree(['EDGES', 'FACES'])

# Edges
b = Internal.getNodeFromName1(tp, 'EDGES')
Expand All @@ -413,7 +443,7 @@ def remeshTreeFromEdges(hook, tp):
b[2].append(z)

# Faces
b = Internal.getNodeFromName1(t, 'SURFACES')
b = Internal.getNodeFromName1(t, 'FACES')
faceNo = []
m = OCC.meshTRIU__(hook, arrays, faceNo=faceNo)
for c, f in enumerate(m):
Expand Down

0 comments on commit 7cd4161

Please sign in to comment.