Return to examples

Python scripts reading Results

 

 

Purpose of the scripts

 

The scripts illustrate the reading of Nastran Results with FeResPost Python extension.

 

Script 1 : Python importation of Results from Nastran OP2 file

from FeResPost import *
import sys

os=sys.stdout

# Creates  and initializes the DataBase :

db=NastranDb()
db.Name="tmpDB"
db.readBdf("../../MODEL/MAINS/orbit_unit_xyz.bdf")
db.readGroupsFromPatranSession("../../MODEL/PATRAN/groups.ses")


...

# Reading Results :

db.readOp2("../../MODEL/EXEC_OP2/orbit_unit_xyz.op2","Results")
  
...

# Maximum Von Mises stress :

targetGrp=db.getGroupCopy("pan_PZ_Al_2024")
stress=db.getResultCopy("ORBIT_ONE_MS2_Z","Statics","Stress Tensor","ElemCorners",targetGrp,[])
scalar=stress.deriveTensorToOneScal("VonMises")
   
...

 

Explanations

 

The different steps of the Nastran reading of Results in script above are:

The full script can be found in the Python example (TESTSAT/PYTHON/EX05/printStressMax.py).

Script 2 : Python importation of Results from Nastran XDB file

from FeResPost import *
import sys

os=sys.stdout

# Creates  and initializes the DataBase :

db=NastranDb()
db.Name="tmpDB"
db.readBdf("../../MODEL/MAINS/orbit_unit_xyz.bdf")
db.readGroupsFromPatranSession("../../MODEL/PATRAN/groups.ses")


...

# Reading or generating Results :

lcNames=[]
lcNames.append("SINUS_X")

scNames=[]
scNames.append("Output 70 (f = 119.0000)")
scNames.append("Output 30 (f = 79.0000)")
scNames.append("Output 1 (f = 50.0000)")

resNames=[]
resNames.append("Accelerations, Translational (RI)")
resNames.append("MPC Forces, Forces (RI)")
resNames.append("MPC Forces, Moments (RI)")

xdbFileName="../../MODEL/EXEC_XDB/sol111_ri_xyz.xdb"
db.readXdb(xdbFileName,lcNames,scNames,resNames)


...

 
# Extracted Results :

resRI=db.getResultCopy(lcName,scName,"Accelerations, Translational (RI)","Nodes",tmpGroup,[])
Util.printRes(sys.stdout,"Accelerations resRI",resRI)
   
...

 

Explanations

 

The different steps of the Nastran reading of Results in script above are:

The full script can be found in the Python example (TESTSAT/PYTHON/EX17/manipComplex.py).

Script 3 : Python importation of Results from Nastran XDB file (by attachment)

from FeResPost import *
import sys

os=sys.stdout

# Creates  and initializes the DataBase :

db=NastranDb()
db.Name="tmpDB"
db.readBdf("../../MODEL/MAINS/orbit_unit_xyz.bdf")
db.readGroupsFromPatranSession("../../MODEL/PATRAN/groups.ses")


...

# Reading Results :

xdbFileName="../../MODEL/EXEC_XDB/sol111_ri_xyz.xdb"
db.attachXdb(xdbFileName)
  
# Extracting Results :

lcName="SINUS_X"

scNames=[]
scNames.append("Output 13 (f = 62.0000)")
scNames.append("Output 14 (f = 63.0000)")
scNames.append("Output 15 (f = 64.0000)")
scNames.append("Output 16 (f = 65.0000)")
scNames.append("Output 17 (f = 66.0000)")
scNames.append("Output 18 (f = 67.0000)")

resNames=[]
resNames.append("Accelerations, Rotational (RI)")
resNames.append("Accelerations, Translational (RI)")
resNames.append("Displacements, Rotational (RI)")
resNames.append("Displacements, Translational (RI)")

grp=db.getGroupCopy("pan_MZ")

h=db.getAttachmentResults(xdbFileName,lcName,scNames,resNames,"Nodes",grp)
for id,res in h.iteritems():
    lcName=id[0]
    scName=id[1]
    resName=id[2]
    size=res.Size
    sys.stdout.write("%s - %s - %s : %d\n"%(lcName,scName,resName,size))
   
...

 

Explanations

 

The different steps of the Nastran reading of Results in script above are:

The full script can be found in the Python example (TESTSAT/PYTHON/EX17/printXdbLcScResSizes.py).

Script 4 : Python importation of Results from Nastran HDF file (by attachment)

from FeResPost import *
import sys

os=sys.stdout

Post.loadHdf5Library("C:/NewProgs/HDF5/HDF5-1.8.20-win64/bin/hdf5.dll")

# Creates  and initializes the DataBase :

dirName="D:/SHARED/FERESPOST/TESTSAT/MODEL/EXEC_HDF5"
baseName="unit_xyz"

lcIndex=0
scIndex=0

bdfName=("%s/%s.bdf"%(dirName,baseName))
hdfName=("%s/%s.h5"%(dirName,baseName))
xdbName=("%s/%s.xdb"%(dirName,baseName))

db=NastranDb()
db.readBdf(bdfName)


...

# Reading Results :

db.attachHdf(hdfName)


lcNames=db.getHdfAttachmentLcNames(hdfName)
lcName=lcNames[lcIndex]
scNames=db.getHdfAttachmentScNames(hdfName,lcName)
scName=scNames[scIndex]
resNames=db.getHdfAttachmentResNames(hdfName,lcName)
hdfResNames=list(resNames)
   
db.readHdfAttachmentResults(hdfName,lcName,scName,resNames)
   
for lcName in db.iter_resultKeyCaseId():
    os.write("LOADCASE: \"%s\"\n"%(lcName))

for scName in db.iter_resultKeySubCaseId():
    os.write("SUBCASE: \"%s\"\n"%(scName))
for lcName,scName in db.iter_resultKeyLcScId():
    os.write("LOADCASE and SUBCASE: \"%s\" - \"%s\"\n"%(lcName,scName))
for resName in db.iter_resultKeyResId():
    os.write("RESULT: \"%s\"\n"%(resName))

for tpName in hdfResNames:
    tmpRes=db.getResultCopy(lcName,scName,tpName)
    if (tmpRes):
        os.write("%-20s%-25s%-60s%-10d\n"%(lcName,scName,tpName,tmpRes.Size))
        os.write("%10d%10d%14g%14g : %s\n"%(tmpRes.getIntId(0),tmpRes.getIntId(1),tmpRes.getRealId(0),tmpRes.getRealId(1),tmpRes.Name))
        Util.printRes(os,tmpRes.Name,tmpRes)
    else:
        print(lcName,scName,tpName)






   
...

 

Explanations

 

The different steps of the Nastran reading of Results in script above are:

The full script can be found in the Python example (TESTSAT/PYTHON/EX23/testHDF.py).

References

 

More information on this example, and the manual explaining the functions used in this example are given in FeResPost Reference Manual.

 


 

FeResPost Home Page

 

ferespost_gg.gif