Skip to content

Commit

Permalink
[IBM] Add more info of the output of the IBM mesh & project size for …
Browse files Browse the repository at this point in the history
…extrude.
  • Loading branch information
antjost committed Jun 17, 2024
1 parent db287b5 commit 322dc0d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
31 changes: 23 additions & 8 deletions Cassiopee/Connector/Connector/IBM.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ def computeMeshInfo__(z, dim):
def _computeMeshInfo(t):
np_total, nc_total, nf_total, nzones = 0,0,0,0
nc0, nc1, nc2 = 0,0,0


NP = Cmpi.size
rank = Cmpi.rank
NPTS = numpy.zeros(NP)
NCELLS = numpy.zeros(NP)
for z in Internal.getZones(t):
cellN = Internal.getNodeFromName(z, 'cellN')[1]
c0 = numpy.count_nonzero(cellN == 0); nc0 += c0
Expand All @@ -142,10 +146,22 @@ def _computeMeshInfo(t):
np_total += np
nc_total += nc
nf_total += nf
nzones += 1

Cmpi.barrier()
print("Info: mesh info for rank {}: number of points: {:.2f}M / number of cells: {:.2f}M".format(Cmpi.rank, np_total/1.e6, nc_total/1.e6))
nzones += 1

zNoGhost = C.rmGhostCells(z, z, 2)
NPTS[rank] += C.getNPts(zNoGhost)
NCELLS[rank] += C.getNCells(zNoGhost)

NPTS = Cmpi.allreduce(NPTS ,op=Cmpi.SUM)
NCELLS = Cmpi.allreduce(NCELLS,op=Cmpi.SUM)
print("Info: mesh info for rank {}: number of points: {:.2f}M / number of cells: {:.2f}M".format(rank, np_total/1.e6, nc_total/1.e6),flush=True)
if rank ==0:
NcellsTot = numpy.sum(NCELLS)
ncells_percent= []
for i in range(NP):
ncells_percent.append(NCELLS[i]/NcellsTot*100)
print('Info: Rank {} has {:.3f}e06 points & {:.3f}e06 cells & {} % of cells - no ghost cells'.format(i,int(NPTS[i])/1e06,int(NCELLS[i])/1e06,round(ncells_percent[i],2)),flush=True)
print('Info: Range of % of cells: {} - {}'.format(round(min(ncells_percent),2),round(max(ncells_percent),2)),flush=True)
Cmpi.barrier()

np_total = Cmpi.allreduce(np_total, op=Cmpi.SUM)
Expand All @@ -157,9 +173,8 @@ def _computeMeshInfo(t):
natures = [ncx/float(nc_total)*100. for ncx in [nc2, nc1, nc0]]

if Cmpi.rank == 0:
print("Info: global mesh info: Interpolated cells (cellN 2): {:.2f}%, Computed cells (cellN 1): {:.2f}%, Blanked cells (cellN 0): {:.2f}%".format(*natures))
print("Info: global mesh info: total number of points: {:.2f}M / total number of cells: {:.2f}M".format(np_total/1.e6, nc_total/1.e6))

print("Info: global mesh info: Interpolated cells (cellN 2): {:.2f}%, Computed cells (cellN 1): {:.2f}%, Blanked cells (cellN 0): {:.2f}%".format(*natures),flush=True)
print("Info: global mesh info: total number of points: {:.2f}M / total number of cells: {:.2f}M".format(np_total/1.e6, nc_total/1.e6),flush=True)
Cmpi.barrier()

return None
Expand Down
42 changes: 42 additions & 0 deletions Cassiopee/Generator/Generator/IBM.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,3 +1089,45 @@ def buildParentOctrees__(o, tb, snears=None, snearFactor=4., dfar=10., dfarList=
return OCTREEPARENTS



def _projectMeshSize(t, NPas=10, span=1, dictNz=None, isCartesianExtrude=False):
"""Predicts the final size of the mesh when extruding 2D to 3D in the z-direction.
Usage: loads(t, NPas, span, dictNz, isCartesianExtrude)"""
NP = Cmpi.size
rank = Cmpi.rank
NPTS = numpy.zeros(NP)
NCELLS = numpy.zeros(NP)
NPTS_noghost = numpy.zeros(NP)
NCELLS_noghost = numpy.zeros(NP)
if isinstance(t, str):
h = Filter.Handle(t)
t = h.loadFromProc(loadVariables=False)
h._loadVariables(t, var=['CoordinateX'])


for z in Internal.getZones(t):
name_zone = z[0]
if not isCartesianExtrude:
if dictNz is not None: Nk = int(dictNz[name_zone])
else: Nk = NPas-1
else:
h = abs(C.getValue(z,'CoordinateX',0)-C.getValue(z,'CoordinateX',1))
NPas_local = int(round(span/h)/4)
if NPas_local < 2:
print("WARNING:: MPI rank %d || Zone %s has Nz=%d and is being clipped to Nz=2"%(rank,z[0],NPas_local))
NPas_local = 2
Nk = NPas_local
Nk += 1
NPTS[rank] += C.getNPts(z)/2*(Nk+4)
NCELLS[rank] += C.getNCells(z)*(Nk+3)
NPTS_noghost[rank] += C.getNPts(C.rmGhostCells(z, z, 2))*Nk
NCELLS_noghost[rank] += C.getNCells(C.rmGhostCells(z, z, 2))*(Nk-1)
NPTS = Cmpi.allreduce(NPTS ,op=Cmpi.SUM)
NCELLS = Cmpi.allreduce(NCELLS,op=Cmpi.SUM)
NPTS_noghost = Cmpi.allreduce(NPTS_noghost ,op=Cmpi.SUM)
NCELLS_noghost = Cmpi.allreduce(NCELLS_noghost,op=Cmpi.SUM)
if rank ==0:
print('Projected mesh size with ghost: {} million points & {} million cells'.format(numpy.sum(NPTS)/1.e6,numpy.sum(NCELLS)/1.e6))
print('Projected mesh size without ghost: {} million points & {} million cells'.format(numpy.sum(NPTS_noghost)/1.e6,numpy.sum(NCELLS_noghost)/1.e6))
return None

0 comments on commit 322dc0d

Please sign in to comment.