CGNS Tutorial
CGNS Tutorial
Marc Poinot
France
Idea/Code/Test/Change
All
Prototype
Test
Pre/Post processing
Code-coupling
Parallel
Interpreted
Actually dedicated to code gluing
Script languages are easily extensible
Python
easy to learn
Clear
syntax
Powerful
numerical extensions
Python/C/C++/Fortran arrays
scripting language
pyCGNS
mapping
Easy scripting
Perform
Python/CGNS tree
Tree representation
List
of nodes
Each
node has...
A Name
A Type
A Value
A list of sons
['Transform',(1, 2, 3),[],'int[IndexDimension]'],
['PointRange',((1, 1, 1), (1, 9, 9)),[],'IndexRange_t'],
['PointRangeDonor',((21, 1, 1), (21, 9, 9)),[],'IndexRange_t']
Marc Poinot ONERA/DSNA
AIAA-SF-2006/CGNS-Tutorial
ADF/HDF5 file
open/read/write/close
MLL keeps private tree structure in memory
ADF is per-node but still private data structure
PyCGNS
Python tree
Same
interface/Different implementation
ADF
Numeric
MPI
MLL
Python
End-user
Python
script
pyCGNS
pyCGNS example
import CGNS
import numarray as N
x=y=z=N.zeros((3,5,7),'d')
a=CGNS.pyCGNS("newfile.cgns",CGNS.MODE_WRITE)
print a.error
idb=a.basewrite("Base",3,3)
idz=a.zonewrite(idb,"Zone 01",[3,5,7],CGNS.Structured)
a.coordwrite(idb,idz,CGNS.RealDouble,CGNS.CoordinateX,x)
a.coordwrite(idb,idz,CGNS.RealDouble,CGNS.CoordinateY,y)
a.coordwrite(idb,idz,CGNS.RealDouble,CGNS.CoordinateZ,z)
a.close()
Just try it !
Versatile testing support
import CGNS
f=CGNS.pyCGNS("hydro-result.cgns",CGNS.MODE_WRITE)
f.basewrite("MASS2",3,3)
f.zonewrite(1,"Block01",(2,3,4,1,2,3,0,0,0),CGNS.Structured)
f.solwrite(1,1,"07-01-1944 06:00:00",CGNS.CellCenter)
f.fieldwrite(1,1,1,CGNS.RealDouble,"sediment",w)
f.goto(1,[(CGNS.Zone_t,1),(CGNS.FlowSolution_t,1),(CGNS.DataArray_t,1)])
f.descriptorwrite("Description","Text here")
f.descriptorwrite("Units","Text here")
f.close()
Generates connectivity
Read the file/Change in-memory tree/Send to code
Python
Numeric
ADF
pyCGNS
End-user
Python
script
Code-coupling
Use
Common baseline
Restriction input/output
Input/Output: BCDataset
Contact surface
Strong requirements for an arbitrary exchange mean
Efficiency
as E
import MPI
communicator=MPI.world.duplicate()
id = communicator.rank
if
( id == 0 ): remoteId=1
elif ( id == 1 ): remoteId=0
datatree=E.get(E.RUNTIME_TREE)
temp=pickle.dumps(datatree)
communicator.nonblocking_send(temp, remoteId, id)
return,rank,tag=communicator.receiveString(None,None)
result=pickle.loads(return)
for l in result:
if (l[0] == "RunTimeTree"):
for ll in l[2]:
if (ll[0] == "Rotor#Output"): ll[0]="Stator#Input"
if (ll[0] == "Stator#Output"): ll[0]="Rotor#Input"
E.update(E.RUNTIME_TREE,result)
Marc Poinot ONERA/DSNA
AIAA-SF-2006/CGNS-Tutorial
In-memory issues
Dedicated to a platform
One
Translation
XDR-like
Best should be
Use
an existing system
Python/Numeric (+Marshalling)
HDF5 (?)
MLL-like interface
NewBase
NewZone
NewGridCoordinates
NewCoordinates
GetByExactPath
NewDataArray
GetByRegexpPath
GetAllTreePath
T=CGNSTree()
base=newBase(T,"Base",3,3)
print T
getChildrenNameByPath(T,"/Base/Zone-002/GridCoordinates")
[['CGNSLibraryVersion', 2.4, [], 'CGNSLibraryVersion_t'],
['Base', array([3, 3]), [], 'CGNSBase_t']
]
Marc Poinot ONERA/DSNA
AIAA-SF-2006/CGNS-Tutorial
C.getChildrenType(T,"CGNSBase_t")
C.getAllTreePath(T)
C.getAllTreeType(T,"Zone_t")
C.getAllTreeType(T,"DataArray_t")
Translate
tree verification
Operate
tree as ADT
Generate code:
MLL/ADF/HDF5/XML/SQL/XDR/...
CGNS
as a data model
as component interface