Skip to content

Commit

Permalink
Merge pull request #182 from vincentcasseau/main
Browse files Browse the repository at this point in the history
All: explicit datatyping in numpy.array
  • Loading branch information
benoit128 authored Sep 17, 2024
2 parents 4e4d421 + d7dc955 commit c0ab37c
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 82 deletions.
20 changes: 10 additions & 10 deletions Cassiopee/Apps/Apps/Fast/IBM.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,10 @@ def _projectMeshSize(t, NPas=10, span=1, dictNz=None, isCartesianExtrude=False):
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)
NPTS = numpy.zeros(NP, dtype=Internal.E_NpyInt)
NCELLS = numpy.zeros(NP, dtype=Internal.E_NpyInt)
NPTS_noghost = numpy.zeros(NP, dtype=Internal.E_NpyInt)
NCELLS_noghost = numpy.zeros(NP, dtype=Internal.E_NpyInt)
if isinstance(t, str):
h = Filter.Handle(t)
t = h.loadFromProc(loadVariables=False)
Expand Down Expand Up @@ -582,15 +582,15 @@ def extrudeCartesian(t,tb, check=False, extrusion="cart", dz=0.01, NPas=10, span
Internal.createUniqueChild(Conn, name, 'GridConnectivity1to1_t')
tmp1 = Internal.getNodeFromName(Conn, name)
Internal.setValue(tmp1, z[0])
datap = numpy.empty( (3,2) , numpy.int32)
datap = numpy.empty( (3,2) , dtype=Internal.E_NpyInt)
datap[0,0]=1+ng;datap[1,0]=1+ng;datap[2,0]=ktg
datap[0,1]=zdim[0,0]-ng;datap[1,1]=zdim[1,0]-ng;datap[2,1]= ktg
Internal.createUniqueChild(tmp1 ,'PointRange', 'IndexRange_t',datap)
datap = numpy.empty( (3,2) , numpy.int32)
datap = numpy.empty( (3,2) , dtype=Internal.E_NpyInt)
datap[0,0]=1+ng;datap[1,0]=1+ng;datap[2,0]=ktgD
datap[0,1]=zdim[0,0]-ng;datap[1,1]=zdim[1,0]-ng;datap[2,1]= ktgD
Internal.createUniqueChild(tmp1 ,'PointRangeDonor', 'IndexRange_t',datap)
datap = numpy.empty( 3 , numpy.int32)
datap = numpy.empty( 3 , dtype=Internal.E_NpyInt)
datap[0]=1;datap[1]=2;datap[2]=3
Internal.createUniqueChild(tmp1 ,'Transform', '"int[IndexDimension]"',datap)
Internal.createUniqueChild(tmp1 ,'GridConnectivityProperty', 'GridConnectivityProperty_t')
Expand Down Expand Up @@ -827,8 +827,8 @@ def _distribute(t_in, tc_in, NP, algorithm='graph', tc2_in=None):
# Check number of points and cells per zone & in total
#====================================================================================
def _checkNcellsNptsPerProc(ts, NP, isAtCenter=False):
NPTS = numpy.zeros(NP)
NCELLS = numpy.zeros(NP)
NPTS = numpy.zeros(NP, dtype=Internal.E_NpyInt)
NCELLS = numpy.zeros(NP, dtype=Internal.E_NpyInt)
##Done by zone for flexibility
for z in Internal.getZones(ts):
proc_num = Cmpi.getProc(z)
Expand All @@ -845,7 +845,7 @@ def _checkNcellsNptsPerProc(ts, NP, isAtCenter=False):
ncells_percent=[]
if Cmpi.rank == 0:
for i in range(NP):
ncells_percent.append(NCELLS[i]/NcellsTot*100)
ncells_percent.append(NCELLS[i]/NcellsTot*100.)
if isAtCenter: print('Rank {} has {} cells & {} % of cells'.format(i,int(NCELLS[i]),round(ncells_percent[i],2)))
else: print('Rank {} has {} points & {} cells & {} % of cells'.format(i,int(NPTS[i]),int(NCELLS[i]),round(ncells_percent[i],2)))

Expand Down
2 changes: 1 addition & 1 deletion Cassiopee/Apps/Apps/Mesh/Dragon.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def createDragonMesh0(body, dictOfParams={}, check=False, directory_tmp_files='.

# Blanking with delta surface
print('Blanking octree width delta...')
BM = numpy.array([[1]])
BM = numpy.array([[1]], dtype=Internal.E_NpyInt)
t = X.blankCells(t, [s2], BM, blankingType='center_in', delta=1.e-12, XRaydim1=xrayDim1, XRaydim2=xrayDim2)

if check: C.convertPyTree2File(t, directory_tmp_files+'blanked.cgns')
Expand Down
32 changes: 16 additions & 16 deletions Cassiopee/Connector/Connector/IBM.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def _computeMeshInfo(t):

NP = Cmpi.size
rank = Cmpi.rank
NPTS = numpy.zeros(NP)
NCELLS = numpy.zeros(NP)
NPTS = numpy.zeros(NP, dtype=Internal.E_NpyInt)
NCELLS = numpy.zeros(NP, dtype=Internal.E_NpyInt)
for z in Internal.getZones(t):
cellN = Internal.getNodeFromName(z, 'cellN')[1]
c0 = numpy.count_nonzero(cellN == 0); nc0 += c0
Expand Down Expand Up @@ -1922,8 +1922,8 @@ def getIBMFrontType0__(tc, frontvar, dim, isFront2=False, frontType=0, SHIFTB=0.
dmin = C.getMaxValue(front, 'TurbulentDistance')

if Cmpi.KCOMM is not None:
dmin = numpy.array([dmin])
dmin_max = numpy.zeros(1)
dmin = numpy.array([dmin], dtype=numpy.float64)
dmin_max = numpy.zeros(1, dtype=numpy.float64)
Cmpi.KCOMM.Allreduce(dmin, dmin_max, Cmpi.MAX)
dmin = dmin_max[0]

Expand All @@ -1936,8 +1936,8 @@ def getIBMFrontType0__(tc, frontvar, dim, isFront2=False, frontType=0, SHIFTB=0.
dmin = C.getMaxValue(front, 'TurbulentDistance')

if Cmpi.KCOMM is not None:
dmin = numpy.array([dmin])
dmin_max = numpy.zeros(1)
dmin = numpy.array([dmin], dtype=numpy.float64)
dmin_max = numpy.zeros(1, dtype=numpy.float64)
Cmpi.KCOMM.Allreduce(dmin, dmin_max, Cmpi.MAX)
dmin = dmin_max[0]

Expand Down Expand Up @@ -2538,8 +2538,8 @@ def getIBMFrontType0Old__(tc, frontvar, dim, isFront2=False, frontType=0, SHIFTB
dmin = C.getMaxValue(front, 'TurbulentDistance')

if Cmpi.KCOMM is not None:
dmin = numpy.array([dmin])
dmin_max = numpy.zeros(1)
dmin = numpy.array([dmin], dtype=numpy.float64)
dmin_max = numpy.zeros(1, dtype=numpy.float64)
Cmpi.KCOMM.Allreduce(dmin, dmin_max, Cmpi.MAX)
dmin = dmin_max[0]
else:
Expand All @@ -2561,8 +2561,8 @@ def getIBMFrontType0Old__(tc, frontvar, dim, isFront2=False, frontType=0, SHIFTB
dmin = C.getMaxValue(front, 'TurbulentDistance')

if Cmpi.KCOMM is not None:
dmin = numpy.array([dmin])
dmin_max = numpy.zeros(1)
dmin = numpy.array([dmin], dtype=numpy.float64)
dmin_max = numpy.zeros(1, dtype=numpy.float64)
Cmpi.KCOMM.Allreduce(dmin, dmin_max, Cmpi.MAX)
dmin = dmin_max[0]

Expand All @@ -2586,8 +2586,8 @@ def getIBMFrontType0Old__(tc, frontvar, dim, isFront2=False, frontType=0, SHIFTB
dmin = C.getMaxValue(front, 'TurbulentDistance')

if Cmpi.KCOMM is not None:
dmin = numpy.array([dmin])
dmin_max = numpy.zeros(1)
dmin = numpy.array([dmin], dtype=numpy.float64)
dmin_max = numpy.zeros(1, dtype=numpy.float64)
Cmpi.KCOMM.Allreduce(dmin, dmin_max, Cmpi.MAX)
dmin = dmin_max[0]

Expand All @@ -2602,8 +2602,8 @@ def getIBMFrontType0Old__(tc, frontvar, dim, isFront2=False, frontType=0, SHIFTB
dmin = C.getMaxValue(front, 'TurbulentDistance')

if Cmpi.KCOMM is not None:
dmin = numpy.array([dmin])
dmin_max = numpy.zeros(1)
dmin = numpy.array([dmin], dtype=numpy.float64)
dmin_max = numpy.zeros(1, dtype=numpy.float64)
Cmpi.KCOMM.Allreduce(dmin, dmin_max, Cmpi.MAX)
dmin = dmin_max[0]

Expand Down Expand Up @@ -2696,8 +2696,8 @@ def _computeKcurvParameter(tc, tb):
y_extrados = numpy.delete(y_extrados, pos)

nPts = len(x_extrados)
y1_extrados = numpy.zeros(nPts)
y2_extrados = numpy.zeros(nPts)
y1_extrados = numpy.zeros(nPts, dtype=numpy.float64)
y2_extrados = numpy.zeros(nPts, dtype=numpy.float64)

# derivee premiere y1
# schema decentre pour CL
Expand Down
66 changes: 33 additions & 33 deletions Cassiopee/Connector/Connector/OversetData.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,10 @@ def _setIBCDataForZone__(z, zonesDnr, correctedPts, wallPts, interpPts, loc='nod
# direct: on stocke dans aR
# inverse: on stocke dans aD
#----------------------------------
PL = numpy.array([],numpy.int32)
PLD = numpy.array([],numpy.int32)
EXTRAP = numpy.array([],numpy.int32)
INTERPTYPE = numpy.array([],numpy.int32)
PL = numpy.array([],dtype=Internal.E_NpyInt)
PLD = numpy.array([], dtype=Internal.E_NpyInt)
EXTRAP = numpy.array([], dtype=Internal.E_NpyInt)
INTERPTYPE = numpy.array([], dtype=Internal.E_NpyInt)
CFS = numpy.array([],numpy.float64)
VOL = numpy.array([],numpy.float64)
ORPHAN = resInterp[5]
Expand Down Expand Up @@ -711,10 +711,10 @@ def _setIBCDataForZone2__(z, zonesDnr, correctedPts, wallPts, interpPts, interpP
# direct: on stocke dans aR
# inverse: on stocke dans aD
#----------------------------------
PL = numpy.array([],numpy.int32)
PLD = numpy.array([],numpy.int32)
EXTRAP = numpy.array([],numpy.int32)
INTERPTYPE = numpy.array([],numpy.int32)
PL = numpy.array([], dtype=Internal.E_NpyInt)
PLD = numpy.array([], dtype=Internal.E_NpyInt)
EXTRAP = numpy.array([], dtype=Internal.E_NpyInt)
INTERPTYPE = numpy.array([], dtype=Internal.E_NpyInt)
CFS = numpy.array([],numpy.float64)
VOL = numpy.array([],numpy.float64)
ORPHAN = resInterp[5]
Expand Down Expand Up @@ -828,10 +828,10 @@ def _setIBCDataForZone2__(z, zonesDnr, correctedPts, wallPts, interpPts, interpP
# direct: on stocke dans aR
# inverse: on stocke dans aD
#----------------------------------
PL = numpy.array([],numpy.int32)
PLD = numpy.array([],numpy.int32)
EXTRAP = numpy.array([],numpy.int32)
INTERPTYPE = numpy.array([],numpy.int32)
PL = numpy.array([], dtype=Internal.E_NpyInt)
PLD = numpy.array([], dtype=Internal.E_NpyInt)
EXTRAP = numpy.array([], dtype=Internal.E_NpyInt)
INTERPTYPE = numpy.array([], dtype=Internal.E_NpyInt)
CFS = numpy.array([],numpy.float64)
VOL = numpy.array([],numpy.float64)
ORPHAN = resInterp2[5]
Expand Down Expand Up @@ -1332,18 +1332,18 @@ def _setInterpDataChimera(aR, aD, order=2, penalty=1, nature=0, extrap=1,
ninterploc = resInterp[0][noz].size
if ninterploc>0: # domaine d'interpolation
if storage == 'direct':
if resInterp[4][noz].size == 0: extrapPts = numpy.array([],numpy.int32)
if resInterp[4][noz].size == 0: extrapPts = numpy.array([], dtype=Internal.E_NpyInt)
else: extrapPts = resInterp[4][noz]
if resInterp[6] == []: EXdir = numpy.array([],numpy.int32)
if resInterp[6] == []: EXdir = numpy.array([], dtype=Internal.E_NpyInt)
else: EXdir = resInterp[6][noz]
_createInterpRegion__(z, zonesDnr[noz][0], resInterp[0][noz], resInterp[1][noz], resInterp[3][noz], \
resInterp[2][noz], numpy.array([],numpy.float64), \
extrapPts, resInterp[5], tag='Receiver', loc=locR, EXDir=EXdir)

else: # inverse
if resInterp[4][noz].size == 0: extrapPts = numpy.array([],numpy.int32)
if resInterp[4][noz].size == 0: extrapPts = numpy.array([], dtype=Internal.E_NpyInt)
else: extrapPts = resInterp[4][noz]
if resInterp[6] == []: EXdir = numpy.array([],numpy.int32)
if resInterp[6] == []: EXdir = numpy.array([], dtype=Internal.E_NpyInt)
else: EXdir = resInterp[6][noz]
_createInterpRegion__(zonesDnr[noz], z[0], resInterp[1][noz], resInterp[0][noz], resInterp[3][noz], \
resInterp[2][noz], numpy.array([],numpy.float64), \
Expand Down Expand Up @@ -1426,10 +1426,10 @@ def _setInterpDataConservative__(aR, aD, storage='direct'):
index = resInterp[4][noi]
resInterp[4][noi]=indicesRcvOrig[index]
orphanPts = resInterp[4]
else: orphanPts = numpy.array([],numpy.int32)
else: orphanPts = numpy.array([], dtype=Internal.E_NpyInt)

extrapPts = numpy.array([],numpy.int32)
EXdir = numpy.array([],numpy.int32)
extrapPts = numpy.array([], dtype=Internal.E_NpyInt)
EXdir = numpy.array([], dtype=Internal.E_NpyInt)

# 3. stockage dans l'arbre
# on recupere les bons indices de pts interpoles (indcell ds interpPts)
Expand All @@ -1444,8 +1444,8 @@ def _setInterpDataConservative__(aR, aD, storage='direct'):
extrapPts, orphanPts, tag='Receiver', loc=locR, EXDir=EXdir)

else: # inverse
extrapPts = numpy.array([],numpy.int32)
EXdir = numpy.array([],numpy.int32)
extrapPts = numpy.array([], dtype=Internal.E_NpyInt)
EXdir = numpy.array([], dtype=Internal.E_NpyInt)
zd = allDnrZones[dnrname]
_createInterpRegion__(zd, zr[0], resInterp[1][noz], resInterp[0][noz], resInterp[3][noz], \
resInterp[2][noz], numpy.array([],numpy.float64), \
Expand Down Expand Up @@ -1473,10 +1473,10 @@ def _setInterpDataForGhostCellsNGon__(aR, aD, storage='inverse', loc='centers'):
if storage!='inverse':
print("WARNING: Connector.OversetData.__setInterpDataForGhostCellsNGon__: only valid for storage='inverse'.")

indicesExtrap = numpy.array([],numpy.int32)
indicesOrphan = numpy.array([],numpy.int32)
indicesExtrap = numpy.array([], dtype=Internal.E_NpyInt)
indicesOrphan = numpy.array([], dtype=Internal.E_NpyInt)
vols = numpy.array([],numpy.float64)
EXdir = numpy.array([],numpy.int32)
EXdir = numpy.array([], dtype=Internal.E_NpyInt)
prefix = 'ID_'
for zp in Internal.getZones(aR):
zname = zp[0]
Expand Down Expand Up @@ -1551,10 +1551,10 @@ def _setInterpDataForGhostCellsStruct__(aR, aD, storage='direct', loc='nodes'):
try: import Converter.GhostCells as GhostCells
except: raise ImportError("setInterpDataForGhostCellsStruct__ requires Converter.GhostCells module.")
# empty numpy arrays for zonesubregion nodes
indicesExtrap = numpy.array([], numpy.int32)
indicesOrphan = numpy.array([], numpy.int32)
indicesExtrap = numpy.array([], dtype=Internal.E_NpyInt)
indicesOrphan = numpy.array([], dtype=Internal.E_NpyInt)
vols = numpy.array([], numpy.float64)
EXdir = numpy.array([], numpy.int32)
EXdir = numpy.array([], dtype=Internal.E_NpyInt)

if loc == 'nodes': locR = 0; locS = 'Vertex'
else: locR = 1; locS = 'CellCenter'
Expand Down Expand Up @@ -1743,12 +1743,12 @@ def _adaptForRANSLES__(tR, tD, dictOfModels=None):
if model_zr != 'None' and model_zd != 'None':

if (model_zr=='NSTurbulent' or model_zd=='NSTurbulent') and model_zr != model_zd:
datap = numpy.ones(1, numpy.int32)
datap = numpy.ones(1, dtype=Internal.E_NpyInt)
Internal.createUniqueChild(s, 'RANSLES', 'DataArray_t', datap)
print("Info: _adaptForRANSLES__: {}/{} <-> {}/{}".format(zr[0], model_zr, zd[0], model_zd))

if (model_zr=='LBMLaminar' or model_zd=='LBMLaminar') and model_zr != model_zd:
datap = numpy.ones(1, numpy.int32)
datap = numpy.ones(1, dtype=Internal.E_NpyInt)
Internal.createUniqueChild(s, 'NSLBM', 'DataArray_t', datap)
print("Info: _adaptForNSLBM__: {}/{} <-> {}/{}".format(zr[0], model_zr, zd[0], model_zd))

Expand Down Expand Up @@ -2706,14 +2706,14 @@ def cellN2OversetHoles(t, append=False):
nb = 0
for i in range(cellN.size):
if cellN[i] == 0: nb += 1
pointList = numpy.empty((cellDim,nb), dtype=numpy.int32, order='F' )
pointList = numpy.empty((cellDim,nb), dtype=Internal.E_NpyInt, order='F' )
connector.cellN2OversetHolesStruct(pointList, cellN, im, jm, cellDim, cellN.size)
# Unstructured zone
else:
nb = 0
for i in range(cellN.size):
if cellN[i] == 0: nb += 1
pointList = numpy.empty((1,nb), dtype=numpy.int32)
pointList = numpy.empty((1,nb), dtype=Internal.E_NpyInt)
connector.cellN2OversetHolesUnStruct(pointList, cellN, cellN.size)
if nb != 0:
# Push OversetHoles Node
Expand Down Expand Up @@ -2780,11 +2780,11 @@ def setOversetHoles(z, indices):

# cree la deltaList
if type == 1: pointList = indices
elif type == 2: pointList = numpy.array(indices, dtype=numpy.int32)
elif type == 2: pointList = numpy.array(indices, dtype=Internal.E_NpyInt)
elif type == 3: pointList = numpy.concatenate(indices)
elif type == 4:
b = []
for i in indices: b.append(numpy.array(indices, dtype=numpy.int32))
for i in indices: b.append(numpy.array(indices, dtype=Internal.E_NpyInt))
pointList = numpy.concatenate(b)

# Push OversetHoles Node
Expand Down
8 changes: 4 additions & 4 deletions Cassiopee/Connector/Connector/PyTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ def _connectMatchNGON__(a, tol, dim, glob, allExtFaces=None, allExtIndices=None,
faceListR = allListRcvFaces[nm]
faceListD = allListDnrFaces[nm]
if periodic == 1:
tsign = numpy.array([signT,signT,signT])
rsign = numpy.array([signR,signR,signR])
tsign = numpy.array([signT,signT,signT], dtype=numpy.float64)
rsign = numpy.array([signR,signR,signR], dtype=numpy.float64)
C._addBC2Zone(zones[noz1],name1,'BCMatch',faceList=faceListR,\
zoneDonor=z2OppName, faceListDonor=faceListD,tol=tol,\
rotationCenter=rotationCenter, rotationAngle=rsign*rotationAngle,\
translation=tsign*Translation, unitAngle=unitAngle)

tsign = numpy.array([-signT,-signT,-signT])
rsign = numpy.array([-signR,-signR,-signR])
tsign = numpy.array([-signT,-signT,-signT], dtype=numpy.float64)
rsign = numpy.array([-signR,-signR,-signR], dtype=numpy.float64)
C._addBC2Zone(zones[noz2],name2,'BCMatch',faceList=faceListD,\
zoneDonor=z1OppName, faceListDonor=faceListR,tol=tol,\
rotationCenter=rotationCenter, rotationAngle=rsign*rotationAngle,\
Expand Down
8 changes: 4 additions & 4 deletions Cassiopee/Connector/Connector/cellN2OversetHoles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ PyObject* K_CONNECTOR::cellN2OversetHolesStruct(PyObject* self, PyObject* args)

// Get CellN array
PyArrayObject* cellNatureField = (PyArrayObject*)CellN;
double* cellN = (double*)PyArray_DATA(cellNatureField);
E_Float* cellN = (E_Float*)PyArray_DATA(cellNatureField);

// Get PointList array
PyArrayObject* pointListArray = (PyArrayObject*)PointList;
int* pointList = (int*)PyArray_DATA(pointListArray);
E_Int* pointList = (E_Int*)PyArray_DATA(pointListArray);

// Local values
E_Int nb = 0;
Expand Down Expand Up @@ -124,11 +124,11 @@ PyObject* K_CONNECTOR::cellN2OversetHolesUnStruct(PyObject* self,

// Get CellN array
PyArrayObject* cellNatureField = (PyArrayObject*)CellN;
double* cellN = (double*)PyArray_DATA(cellNatureField);
E_Float* cellN = (E_Float*)PyArray_DATA(cellNatureField);

// Get PointList array
PyArrayObject* pointListArray = (PyArrayObject*)PointList;
int* pointList = (int*)PyArray_DATA(pointListArray);
E_Int* pointList = (E_Int*)PyArray_DATA(pointListArray);

// Local values
E_Int nb = 0;
Expand Down
Loading

0 comments on commit c0ab37c

Please sign in to comment.