Tech Articles

Exporting the grid data from HDF5 to CSV


Tech Articles ID    KB8024595
Status:    Published
Published date:    11/13/2020
Updated:    11/13/2020
Reported In:   MSC Nastran
Created with Version:   MSC Nastran
 

Abstract (Question)

I am able to export most of the FE data and results using PANDAS dataframe, however grid table is giving issue.

What is the reason and work possible work around ?

Description (Answer)

The problem with grid data is that the coordinates of grids are available as separate list with in GRID table, due to that pandas data frame is not able to recognize them.

Example: GRID, 2,0,[0.5,0.0,0.0],0

Here is a workaround using tables ,see attached code which can export the GRID information correctly.

================================

import tables
import csv

h5data=tables.open_file("sol111_single.h5")

#To list the types of COL NAME in TABLE:
for nd in h5data.iter_nodes("/NASTRAN/INPUT/NODE"):
    print("Table Name: ",nd.name,"\n", "Table details:",nd.colnames)
    
# Exporting the grid data from H5 to csv
f=open("abcd.csv","w",newline='')
w=csv.writer(f) #returns writer object to write data
#
ncord=[]
for gr in h5data.root.NASTRAN.INPUT.NODE.GRID:
    ncord.append("GRID")
    ncord.append(gr["ID"])
    ncord.append(gr["CP"])
    for n in gr["X"]:
        ncord.append(n)
    ncord.append(gr["CD"])
    w.writerow(ncord)
    ncord.clear()
f.close()

================================

English Attachment

abcd.csv
1K • < 1 minute @ 56k, < 1 minute @ broadband


Sol111_single.bdf
7K • < 1 minute @ 56k, < 1 minute @ broadband


sol111_single.h5
2MB • 6 minute(s) @ 56k, < 1 minute @ broadband


reading_grid.py
646Bytes • < 1 minute @ 56k, < 1 minute @ broadband



Rate this Page
Rate the quality of this article from 5 (high) to 1 (low):
1
2
3
4
5
 
How can we improve this?