Skip to content

Commit

Permalink
[IBM] prepareIBMData: check if for t_in cartesian=True or cartesian=F…
Browse files Browse the repository at this point in the history
…alse.
  • Loading branch information
antjost committed Sep 4, 2024
1 parent 50c51c1 commit 5302adf
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 9 deletions.
29 changes: 20 additions & 9 deletions Cassiopee/Connector/Connector/IBM.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,26 @@ def prepareIBMData(t_case, t_out, tc_out, t_in=None, to=None, tbox=None, tinit=N

if isinstance(t_case, str): tb = C.convertFile2PyTree(t_case)
else: tb = Internal.copyTree(t_case)

##THIS IS TEMPORARY -> a more comprehensive test is in the works and will make this
## print redundant.
if cartesian and t_in:
RED = "\033[1;31;40m"
END = "\033[0m"
print(RED + "===========================================" + END)
print("Note: Assuming " + RED + "CARTESIAN " + END + "grid")
print(RED + "===========================================" + END)

## Note: cartesian = True is left as an input argument to avoid regressing during the non-regression test.
## In the near future the ref. values for the non-regression tests will be updated with cartesian=True.
## At this point, cartesian=True input argument can be deleted.
## Note: when cartesian = True is deleted as an input argument the line below must be uncommented and the cartesian in the if statement but be deleted.
#cartesian = True
if t_in and cartesian:
cartesian = G_IBM.checkCartesian(t_in, nghost=2)
if cartesian:
RED = "\033[1;31;40m"
END = "\033[0m"
print("===========================================")
print("Note: t_in is a " + RED + "CARTESIAN " + END + "grid")
print("===========================================")
else:
RED = "\033[1;31;40m"
END = "\033[0m"
print("===========================================")
print("Note: t_in is " + RED + "NOT" + END + " a " + RED + "CARTESIAN " + END + "grid")
print("===========================================")

##[AJ] keep for now...will delete in the near future
##if isinstance(tc_out, str):
Expand Down
47 changes: 47 additions & 0 deletions Cassiopee/Generator/Generator/IBM.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,3 +1309,50 @@ def extrudeCartesianZDir(t, tb, check=False, extrusion="cart", dz=0.01, NPas=10,
X_IBM._redispatch__(t=t)
return t, tb


def checkCartesian(t, nghost=0):
dimPb = Internal.getNodeFromName(t, 'EquationDimension')
if dimPb is None: raise ValueError('prepareIBMData: EquationDimension is missing in input tree.')
dimPb = Internal.getValue(dimPb)

nghostZ=0
if dimPb==3: nghostZ=nghost

isCartesian=1
for z in Internal.getZones(t):
##X Direction
coord = Internal.getNodeFromName(z,'CoordinateX')[1]
i = 0
dx = coord[i+1+nghost, 0+nghost, 0+nghostZ] - coord[i +nghost, 0+nghost, 0+nghostZ]
for i in range(1,4):
dx2 = coord[i+1+nghost, 0+nghost, 0+nghostZ] - coord[i +nghost, 0+nghost, 0+nghostZ]
diff = abs(dx2-dx)
if diff>1e-12: isCartesian=0
if isCartesian<1:break

##Y Direction
coord = Internal.getNodeFromName(z,'CoordinateY')[1]
i = 0
dx = coord[0+nghost,i+1+nghost,0+nghostZ] - coord[0+nghost,i +nghost,0+nghostZ]
for i in range(1,4):
dx2 = coord[0+nghost,i+1+nghost,0+nghostZ] - coord[0+nghost,i +nghost,0+nghostZ]
diff = abs(dx2-dx)
if diff>1e-12: isCartesian=0
if isCartesian<1:break


##Z Direction
if dimPb==3:
coord = Internal.getNodeFromName(z,'CoordinateZ')[1]
i = 0
dx = coord[0+nghost,0+nghost,i+1+nghost] - coord[0+nghost,0+nghost,i +nghost]
for i in range(1,4):
dx2 = coord[0+nghost,0+nghost,i+1+nghost] - coord[0+nghost,0+nghost,i +nghost]
diff = abs(dx2-dx)
if diff>1e-12: isCartesian=0
if isCartesian<1:break

isCartesian=Cmpi.allreduce(isCartesian,op=Cmpi.MIN)
if isCartesian==1:cartesian=True
else: cartesian=False
return cartesian
79 changes: 79 additions & 0 deletions Cassiopee/Generator/test/checkCartesian_m1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# - check if mesh is cartesian -
import Transform.PyTree as T
import KCore.test as test
import Converter.PyTree as C
import Converter.Internal as Internal
import Generator.PyTree as G
import Generator.IBM as G_IBM
import Distributor2.PyTree as D2
import Converter.Mpi as Cmpi
import random

if Cmpi.rank==0:
a = G.cart((0.,0.,0.), (0.1,0.1,1), (40,40,40))
t = C.newPyTree(['CARTESIAN', a])
C._addState(t, 'EquationDimension', 3)

t = T.splitNParts(t, 10)
t,stats = D2.distribute(t, 2)
C.convertPyTree2File(t,'t_TMP.cgns')
t=Cmpi.convertFile2PyTree('t_TMP.cgns',proc=Cmpi.rank)

##Test 1 - Cartesian
cartesian=G_IBM.checkCartesian(t)
isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
if Cmpi.rank==0:
test.testT(t,1)
print('Is Cartesian::',cartesian,isCartesian)
tsave = Internal.copyTree(t)
#C.convertPyTree2File(t,'t_test1.cgns')

## Test 2 - Z direction is non homogenous --> non Cartesian mesh
Internal._rmNode(t, Internal.getNodeFromName(t, 'TMP_Node'))
coord = Internal.getNodeFromName(Internal.getZones(t)[0],'CoordinateZ')[1]
for i in range(6): coord[:,:,i]=coord[:,:,i]*i/10+coord[:,:,i]
cartesian=G_IBM.checkCartesian(t)

isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
if Cmpi.rank==0:
test.testT(t,2)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test2.cgns')

## Test 3 - Y direction is non homogenous --> non Cartesian mesh
t = Internal.copyTree(tsave)
Internal._rmNode(t, Internal.getNodeFromName(t, 'TMP_Node'))
coord = Internal.getNodeFromName(Internal.getZones(t)[0],'CoordinateY')[1]
for i in range(6): coord[:,i,:]=coord[:,i,:]*i/10+coord[:,i,:]
cartesian=G_IBM.checkCartesian(t)

isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
if Cmpi.rank==0:
test.testT(t,3)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test3.cgns')

## Test 4 - Z direction is non homogenous --> non Cartesian mesh
t = Internal.copyTree(tsave)
Internal._rmNode(t, Internal.getNodeFromName(t, 'TMP_Node'))
coord = Internal.getNodeFromName(Internal.getZones(t)[0],'CoordinateX')[1]
for i in range(6): coord[i,:,:]=coord[i,:,:]*i/10+coord[i,:,:]
cartesian=G_IBM.checkCartesian(t)

isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
if Cmpi.rank==0:
test.testT(t,4)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test4.cgns')
67 changes: 67 additions & 0 deletions Cassiopee/Generator/test/checkCartesian_t1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# - check if mesh is cartesian -
import Transform.PyTree as T
import KCore.test as test
import Converter.PyTree as C
import Converter.Internal as Internal
import Generator.PyTree as G
import Generator.IBM as G_IBM
import random

a = G.cart((0.,0.,0.), (0.1,0.1,1), (20,20,20))
t = C.newPyTree(['CARTESIAN', a])
C._addState(t, 'EquationDimension', 3)

##Test 1 - Cartesian
cartesian=G_IBM.checkCartesian(t)
isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
test.testT(t,1)
tsave = Internal.copyTree(t)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test1.cgns')

## Test 2 - Z direction is non homogenous --> non Cartesian mesh
Internal._rmNode(t, Internal.getNodeFromName(t, 'TMP_Node'))
coord = Internal.getNodeFromName(t,'CoordinateZ')[1]
for i in range(6): coord[:,:,i]=coord[:,:,i]*i/10+coord[:,:,i]
cartesian=G_IBM.checkCartesian(t)

isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
test.testT(t,2)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test2.cgns')

## Test 3 - Y direction is non homogenous --> non Cartesian mesh
t = Internal.copyTree(tsave)
Internal._rmNode(t, Internal.getNodeFromName(t, 'TMP_Node'))
coord = Internal.getNodeFromName(t,'CoordinateY')[1]
for i in range(6): coord[:,i,:]=coord[:,i,:]*i/10+coord[:,i,:]
cartesian=G_IBM.checkCartesian(t)

isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
test.testT(t,3)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test3.cgns')

## Test 4 - Z direction is non homogenous --> non Cartesian mesh
t = Internal.copyTree(tsave)
Internal._rmNode(t, Internal.getNodeFromName(t, 'TMP_Node'))
coord = Internal.getNodeFromName(t,'CoordinateX')[1]
for i in range(6): coord[i,:,:]=coord[i,:,:]*i/10+coord[i,:,:]
cartesian=G_IBM.checkCartesian(t)

isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
test.testT(t,4)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test4.cgns')
53 changes: 53 additions & 0 deletions Cassiopee/Generator/test/checkCartesian_t2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# - check if mesh is cartesian -
import Transform.PyTree as T
import KCore.test as test
import Converter.PyTree as C
import Converter.Internal as Internal
import Generator.PyTree as G
import Generator.IBM as G_IBM
import random

a = G.cart((0.,0.,0.), (0.1,0.1,1), (20,20,2))
t = C.newPyTree(['CARTESIAN', a])
C._addState(t, 'EquationDimension', 2)

##Test 1 - Cartesian
cartesian=G_IBM.checkCartesian(t)
isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
test.testT(t,1)
tsave = Internal.copyTree(t)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test1.cgns')

## Test 2 - Y direction is non homogenous --> non Cartesian mesh
t = Internal.copyTree(tsave)
Internal._rmNode(t, Internal.getNodeFromName(t, 'TMP_Node'))
coord = Internal.getNodeFromName(t,'CoordinateY')[1]
for i in range(6): coord[:,i,:]=coord[:,i,:]*i/10+coord[:,i,:]
cartesian=G_IBM.checkCartesian(t)

isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
test.testT(t,2)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test2.cgns')

## Test 3 - Z direction is non homogenous --> non Cartesian mesh
t = Internal.copyTree(tsave)
Internal._rmNode(t, Internal.getNodeFromName(t, 'TMP_Node'))
coord = Internal.getNodeFromName(t,'CoordinateX')[1]
for i in range(6): coord[i,:,:]=coord[i,:,:]*i/10+coord[i,:,:]
cartesian=G_IBM.checkCartesian(t)

isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
test.testT(t,3)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test3.cgns')
69 changes: 69 additions & 0 deletions Cassiopee/Generator/test/checkCartesian_t3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# - check if mesh is cartesian -
import Transform.PyTree as T
import KCore.test as test
import Converter.PyTree as C
import Converter.Internal as Internal
import Generator.PyTree as G
import Generator.IBM as G_IBM
import random

a = G.cart((0.,0.,0.), (0.1,0.1,1), (40,40,40))
t = C.newPyTree(['CARTESIAN', a])
C._addState(t, 'EquationDimension', 3)

t = T.splitNParts(t, 10)

##Test 1 - Cartesian
cartesian=G_IBM.checkCartesian(t)
isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
test.testT(t,1)
tsave = Internal.copyTree(t)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test1.cgns')

## Test 2 - Z direction is non homogenous --> non Cartesian mesh
Internal._rmNode(t, Internal.getNodeFromName(t, 'TMP_Node'))
coord = Internal.getNodeFromName(Internal.getZones(t)[0],'CoordinateZ')[1]
for i in range(6): coord[:,:,i]=coord[:,:,i]*i/10+coord[:,:,i]
cartesian=G_IBM.checkCartesian(t)

isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
test.testT(t,2)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test2.cgns')

## Test 3 - Y direction is non homogenous --> non Cartesian mesh
t = Internal.copyTree(tsave)
Internal._rmNode(t, Internal.getNodeFromName(t, 'TMP_Node'))
coord = Internal.getNodeFromName(Internal.getZones(t)[0],'CoordinateY')[1]
for i in range(6): coord[:,i,:]=coord[:,i,:]*i/10+coord[:,i,:]
cartesian=G_IBM.checkCartesian(t)

isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
test.testT(t,3)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test3.cgns')

## Test 4 - Z direction is non homogenous --> non Cartesian mesh
t = Internal.copyTree(tsave)
Internal._rmNode(t, Internal.getNodeFromName(t, 'TMP_Node'))
coord = Internal.getNodeFromName(Internal.getZones(t)[0],'CoordinateX')[1]
for i in range(6): coord[i,:,:]=coord[i,:,:]*i/10+coord[i,:,:]
cartesian=G_IBM.checkCartesian(t)

isCartesian=0
if cartesian:isCartesian=1
Internal._createUniqueChild(t, 'TMP_Node', 'UserDefinedData_t')
Internal._createUniqueChild(Internal.getNodeFromName1(t, 'TMP_Node'), 'Cartesian', 'DataArray_t', value=isCartesian)
test.testT(t,4)
print('Is Cartesian::',cartesian,isCartesian)
#C.convertPyTree2File(t,'t_test4.cgns')

0 comments on commit 5302adf

Please sign in to comment.