Created
April 27, 2014 14:12
-
-
Save sanromd/11346554 to your computer and use it in GitHub Desktop.
PETSc xmf hyperslab descriptor (in progress)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
from glob import glob | |
import pickle | |
def xmdf_write(path,pkl_base='claw.pkl',ptc_base='claw.ptc',xmf_base='claw.meta',debug=False): | |
pkl_file_name = glob(os.path.join(path,'*.pkl*')) | |
if debug: | |
print pkl_file_name | |
for pkl_file in pkl_file_name: | |
filestr = pickle.Unpickler(file(pkl_file)) | |
data1 = filestr.load() | |
data2 = filestr.load() | |
data = dict(data1.items() + data2.items()) | |
file_number = pkl_file.split(pkl_base)[1] | |
xmf_file_name = os.path.join(path,xmf_base+file_number+'.xmf') | |
ptc_file = ptc_base+file_number | |
if debug: | |
print xmf_file_name | |
""" | |
Write out the .xmf file | |
""" | |
fd = file(xmf_file_name, 'w') | |
fd.write("<?xml version=\"1.0\" ?>\n") | |
fd.write("<!DOCTYPE Xdmf SYSTEM \"Xdmf.dtd\" [\n") | |
fd.write("<!ENTITY HeavyData \"" + ptc_file + "\">\n") | |
fd.write("]>\n") | |
fd.write("\n") | |
fd.write("<Xdmf Version=\"2.0\">\n") | |
fd.write(" <Domain>\n") | |
fd.write(" <Grid GridType=\"Uniform\">\n") | |
fd.write(" <Topology TopologyType=\"3DCoRectMesh\" Dimensions=\"" + | |
str(data['num_cells'][0]+1) + " " + | |
str(data['num_cells'][1]+1) + " " + | |
str(data['num_cells'][2]+1) + "\"/>\n") | |
fd.write(" <Geometry GeometryType=\"Origin_DxDyDz\">\n") | |
fd.write(" <DataItem Dimensions=\"3\" Format=\"XML\">\n") | |
fd.write(" 0 0 0\n") | |
fd.write(" </DataItem>\n") | |
fd.write(" <DataItem Dimensions=\"3\" Format=\"XML\">\n") | |
fd.write(" " + | |
str(data['delta'][0]) + " " + | |
str(data['delta'][1]) + " " + | |
str(data['delta'][2]) + "\n") | |
fd.write(" </DataItem>\n") | |
fd.write(" </Geometry>\n") | |
if debug: | |
print data['num_eqn'] | |
for i in range(0, data['num_eqn']): | |
fd.write(" <Attribute Name=\"A" + str(i+1) + "\" AttributeType=\"Scalar\" Center=\"Cell\">\n") | |
fd.write(" <DataItem ItemType=\"HyperSlab\" Dimensions=\"" + | |
str(data['num_cells'][0]) + " " + | |
str(data['num_cells'][1]) + " " + | |
str(data['num_cells'][2]) + | |
"\" Type=\"HyperSlab\">\n") | |
fd.write(" <DataItem Dimensions=\"3 4\" Format=\"XML\">\n") | |
fd.write(" 0 0 0 " + str(i) + "\n") | |
fd.write(" 1 1 1 " + str(data['num_eqn']) + "\n") | |
fd.write(" " + | |
str(data['num_cells'][0]) + " " + | |
str(data['num_cells'][1]) + " " + | |
str(data['num_cells'][2]) + | |
" 1\n") | |
fd.write(" </DataItem>\n") | |
fd.write(" <DataItem Dimensions=\"" + | |
str(data['num_cells'][0]) + " " + | |
str(data['num_cells'][1]) + " " + | |
str(data['num_cells'][2]) + " " + | |
str(data['num_eqn']) + | |
"\" NumberType=\"Float\" Precision=\"8\" Format=\"Binary\" Endian=\"Big\" Seek=\"8\">\n") | |
""" | |
fd.write(" " + ptc_file + "\n") | |
""" | |
fd.write(" &HeavyData;\n") | |
fd.write(" </DataItem>\n") | |
fd.write(" </DataItem>\n") | |
fd.write(" </Attribute>\n") | |
fd.write(" </Grid>\n") | |
fd.write(" </Domain>\n") | |
fd.write("</Xdmf>\n") | |
fd.close() | |
if __name__ == "__main__": | |
import sys | |
path = sys.argv[1] | |
xmdf_write(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment