I'm trying to use Python to access Nastran quad element shell forces via the H5 file. I've had good luck with processing SPC, MPC, CBUSH, and BAR forces, but when trying to extract shell forces from a large model my Python script is taking a SUPER long time. For example, I have an H5 file that contains results for 93,407 Quad4 elements for 28 subcases. The snippet of code below is what I'm using:
out = open("outfile.csv,"w") # - open the CSV file to write to
for i in quad_ids:
out.write("%d"%i)
for case in subcases:
print "case = %s"%case['subtitle']
domid = case['domid']
for a in quad.where("(DOMAIN_ID == %d) & (%s == %d)"%(domid,keyid,i)):
for b in keys:
out.write(",%f" % (a[b][0]))
out.write("\n")
out.close()
data.close()
The quad_ids[] list contains all the quad element ids, and the subcases{} is a dictionary that contains the subcase title and domain id.
I ran this code on the H5 file and it ran for 6 hours straight before I finally killed it. It was working ok, but it ran super, super slow. The total number of records in the QUAD4_CN table is 94,407 x 28 = 2,615,396.
I'm a novice at using PyTables, so I tried my best to optimize the speed using the in-line query (which supposedly uses the C-compiled search). Has anyone else experienced this slowness and can offer any advice on speeding up my code?
Ok, I've been investigating Pandas and here's what I got so far:
I tried using the following to read the h5 file in a Python script,
import pandas as pd
data = pd.read_hdf("big_model.h5",'/NASTRAN/RESULT/ELEMENTAL/ELEMENT_FORCE/QUAD4_CN')
>> ValueError: Wrong number of items passed 5, placement implies 1
The ValueError message is appearing because several columns of data in the h5 file contain not a single value but a list object containing 5 values (e.g., [4,1,2,180,179] for the 'GRID' column which has the number of nodes and the 4 node ids for this quad element). The results file contains these lists because the Nastran output request was for centroid and element corner node forces (5 data values) for each element.
One solution would be to only request centroid forces in the Nastran bdf file which would write out only one value for the columns in the h5 file. However, I'd like to find a way to get this to work with the corner forces written to the h5 file.
Ok, I've been investigating Pandas and here's what I got so far:
I tried using the following to read the h5 file in a Python script,
import pandas as pd
data = pd.read_hdf("big_model.h5",'/NASTRAN/RESULT/ELEMENTAL/ELEMENT_FORCE/QUAD4_CN')
>> ValueError: Wrong number of items passed 5, placement implies 1
The ValueError message is appearing because several columns of data in the h5 file contain not a single value but a list object containing 5 values (e.g., [4,1,2,180,179] for the 'GRID' column which has the number of nodes and the 4 node ids for this quad element). The results file contains these lists because the Nastran output request was for centroid and element corner node forces (5 data values) for each element.
One solution would be to only request centroid forces in the Nastran bdf file which would write out only one value for the columns in the h5 file. However, I'd like to find a way to get this to work with the corner forces written to the h5 file.