Skip to content

Commit e65c141

Browse files
Connector/Generator: IBM AMR (#611)
* MeshGen & IBMprep python wrapper: bug fixes * Bug fixes * generalize if statement - empty t * Apply autopep8 formatting --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 3d46707 commit e65c141

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

Cassiopee/Connector/Connector/AMR.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,14 @@ def prepareAMRData(t_case, t, IBM_parameters=None, check=False, dim=3, localDir=
245245
if different_front_flag == False: #True is default
246246
Internal._rmNodesFromName(t, "TurbulentDistance")
247247
Internal._renameNode(t, "TurbulentDistanceForCFDComputation","TurbulentDistance")
248-
if OPT:
248+
249+
# Catch 22: IBM prep needs dist2wall at the nodes (dist2wall@Node). blanking, ibm point location, etc. is doing using dist2wall@Node
250+
# CODA needs dist2wall at the cell centers. CODA doesnt recalculate this for IBM runs and must therefore be provided.
251+
# Chosen approach: OPT=True - use only the dist2wall@Node for the IBM prep & if needed recalculate the dist2wall@Centers at the end of the function.
252+
# Options for OPT=False have not been tested but do not seem like the appropriate solution : calcs on dist2wall@Centers + center2Node is counterintuitive
253+
# TODO: Remove OPT=False options ONLY after testing with IBM Local options. F. Basile prototype did some operations with dist2wall@Centers.
254+
node = Internal.getZones(t) #select cells after blanking may yields an empty zone - yields empty list or list with elements
255+
if OPT and node:
249256
varnames = C.getVarNames(t, loc="centers")[0]
250257
if "TurbulentDistance" not in varnames:
251258
DTW._distance2Walls(t, tb2, type='ortho', signed=0, dim=dim, loc='centers')
@@ -979,19 +986,41 @@ def prepareAMRIBM(tb, levelMax, vmins, dim, IBM_parameters, toffset=None, check=
979986
Usage: prepareAMRIBM(tb, levelMax, vmins, dim, IBM_parameters, toffset, check, opt, octreeMode,
980987
snears, dfars, loadBalancing, OutputAMRMesh, localDir, fileName, tbox, vminsTbox, tbv2, forceAlignment)"""
981988

989+
## =========================
990+
## ==== Mesh Generation ====
991+
## =========================
982992
t_AMR = G_AMR.generateAMRMesh(tb=tb, levelMax=levelMax, vmins=vmins, dim=dim,
983993
toffset=toffset, check=check, opt=opt, octreeMode=octreeMode, localDir=localDir,
984994
snears=0.01, dfars=10, loadBalancing=loadBalancing, tbox=tbox, vminsTbox=vminsTbox, tbv2=tbv2)
985995

986996
Cmpi.trace('AMR Mesh Dist2Walls...start', master=True)
987-
if dim == 2: tb2 = T.addkplane(tb)
997+
tb2 = Internal.copyTree(tb)
998+
if dim == 2:tb2 = T.addkplane(tb)
999+
else:
1000+
baseSYM = Internal.getNodesFromName1(tb2, "SYM")
1001+
if baseSYM:
1002+
tb2 = Internal.rmNodesByNameAndType(tb2, 'SYM', 'CGNSBase_t')
1003+
tb2 = Internal.rmNodesByNameAndType(tb2, '*_sym*', 'Zone_t')
1004+
tb = Internal.copyTree(tb2)
9881005
DTW._distance2Walls(t_AMR, tb2, type='ortho', signed=0, dim=dim, loc='centers')
9891006
DTW._distance2Walls(t_AMR, tb2, type='ortho', signed=0, dim=dim, loc='nodes')
9901007
del tb2
9911008
Cmpi.trace('AMR Mesh Dist2Walls...end', master=True)
9921009

9931010
if OutputAMRMesh: Cmpi.convertPyTree2File(t_AMR, localDir+'tAMRMesh.cgns')
1011+
## Ncells output
1012+
Ncells=C.getNCells(t_AMR)
1013+
Ncells=Cmpi.allreduce(Ncells, op=Cmpi.SUM)
1014+
if Cmpi.master: print("[MESH GEN.] Number of Cells::%ge06"%(Ncells/1e06), flush=True)
1015+
1016+
## ==================
1017+
## ==== IBM Prep ====
1018+
## ==================
9941019
t_AMR = prepareAMRData(tb, t_AMR, IBM_parameters=IBM_parameters, dim=dim, check=check, localDir=localDir, forceAlignment=forceAlignment)
1020+
## Ncells output
1021+
Ncells=C.getNCells(t_AMR)
1022+
Ncells=Cmpi.allreduce(Ncells, op=Cmpi.SUM)
1023+
if Cmpi.master: print("[IBM PREP.] Number of Cells::%ge06"%(Ncells/1e06), flush=True)
9951024

9961025
if fileName is not None:
9971026
Cmpi.convertPyTree2File(t_AMR, localDir+fileName)

Cassiopee/Generator/Generator/AMR.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ def generateListOfOffsets__(tb, snears, offsetValues=[], dim=3, opt=False, numTb
238238
bodies = [tbLocalTmp]; nbodies = 1
239239
BM = numpy.ones((1, nbodies), dtype=numpy.int32)
240240
t = C.newPyTree(["BASE", Internal.getZones(b)])
241-
if dim == 2 or blankCellsAlgo == 'xray': X._blankCells(t, bodies, BM, blankingType='node_in', dim=dim, XRaydim1=XRAYDIM1, XRaydim2=XRAYDIM2)
241+
# using the input bodies provided (tb & tbox) - safe to use blankCellsTri
242+
if dim == 2: X._blankCells(t, bodies, BM, blankingType='node_in', dim=dim, XRaydim1=XRAYDIM1, XRaydim2=XRAYDIM2) #or blankCellsAlgo == 'xray'
242243
else: X._blankCellsTri(t, bodies, BM, blankingType='node_in')
243244
C._initVars(t, '{TurbulentDistance}={TurbulentDistance}*({cellN}>0.)-{TurbulentDistance}*({cellN}<1.)')
244245
#Cmpi.convertPyTree2File(b, 'meshForOffsetBase%d.cgns'%nBase) # DEBUG ONLY
@@ -395,6 +396,7 @@ def tagOutsideBody__(o, tbTMP, dim=3, h_target=-1., opt=False, noffsets=None, co
395396
# XRAYDIM1 = max(500, min(5000, XRAYDIM1)); # XRAYDIM1 = max(5000, min(50000, XRAYDIM1)); is too expensive need to find another solution
396397
C._initVars(to, "cellNIn", 1.)
397398

399+
# tbTMP - offset body - blankCells is more tested due to uncertainties on the quality of the offset
398400
if dim == 2 or blankCellsAlgo == 'xray': to = X.blankCells(to, bodies1, BM, blankingType='node_in',
399401
XRaydim1=XRAYDIM1, XRaydim2=XRAYDIM1, dim=dim,
400402
cellNName='cellN')
@@ -424,9 +426,12 @@ def tagInsideOffset__(o, offset1=None, offset2=None, dim=3, h_target=-1., opt=Fa
424426
if dim==2:
425427
offset1 = T.addkplane(offset1)
426428
offset2 = T.addkplane(offset2)
427-
bodies1 = [Internal.getZones(offset1)] # tag for refinement outside of offset1
429+
bodies1 = [Internal.getZones(offset1)] # tag for refinement outside of offset1 (cgns base of tb or tbox)
428430
bodies2 = [Internal.getZones(offset2)] # tag for refinement inside of offset2
429431

432+
# bodies1 - tb & tbox - blankCellsTri is safe due to assure quality of the input
433+
# bodies2 - offset body - blankCells is more tested due to uncertainties on the quality of the offset
434+
430435
BM = numpy.ones((1,1), dtype=Internal.E_NpyInt)
431436

432437
bb1 = G.bbox(offset1)
@@ -466,9 +471,9 @@ def tagInsideOffset__(o, offset1=None, offset2=None, dim=3, h_target=-1., opt=Fa
466471

467472
if isTbox: C._initVars(to, '{cellN}=({cellNIn}<1)')
468473
else:
469-
if dim == 2 or blankCellsAlgo == 'xray': to = X.blankCells(to, bodies1, BM, blankingType='node_in',
470-
XRaydim1=XRAYDIM1, XRaydim2=XRAYDIM2, dim=dim,
471-
cellNName='cellNOut')
474+
if dim == 2 : to = X.blankCells(to, bodies1, BM, blankingType='node_in',
475+
XRaydim1=XRAYDIM1, XRaydim2=XRAYDIM2, dim=dim,
476+
cellNName='cellNOut') #or blankCellsAlgo == 'xray'
472477
else: to = X.blankCellsTri(to, bodies1, BM, blankingType='node_in', cellNName='cellNOut')
473478

474479
# artificial shift the location of the boundary by depthLocal cells inwards (inside the body)

0 commit comments

Comments
 (0)