From 322dc0d9d6beb94b7dc3ee5f61164366bb2526e6 Mon Sep 17 00:00:00 2001 From: antjost Date: Mon, 17 Jun 2024 13:55:37 +0200 Subject: [PATCH] [IBM] Add more info of the output of the IBM mesh & project size for extrude. --- Cassiopee/Connector/Connector/IBM.py | 31 ++++++++++++++------ Cassiopee/Generator/Generator/IBM.py | 42 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/Cassiopee/Connector/Connector/IBM.py b/Cassiopee/Connector/Connector/IBM.py index d57cbf8aa..4ac7edd59 100644 --- a/Cassiopee/Connector/Connector/IBM.py +++ b/Cassiopee/Connector/Connector/IBM.py @@ -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 @@ -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) @@ -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 diff --git a/Cassiopee/Generator/Generator/IBM.py b/Cassiopee/Generator/Generator/IBM.py index e98dcbbb3..6f8d6b0f3 100644 --- a/Cassiopee/Generator/Generator/IBM.py +++ b/Cassiopee/Generator/Generator/IBM.py @@ -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 +