force using rectangular mesh

Paraview cannot handle large number of polyvertices using xdmf, forcing a meshed structure to by pass the problem.
This commit is contained in:
chen 2016-10-12 20:20:15 -04:00
parent 7310c53f73
commit c311ac47ca
3 changed files with 152 additions and 105 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0"?>
<h5ds>
<!--Top level attributes-->
<history>
<type>attr</type>
<h5path>/</h5path>
@ -12,174 +13,186 @@
<h5path>/</h5path>
<category></category>
<description></description>
<log></log>
</inc>
<!--Geometry section-->
<Vx>
<type>Scalar</type>
<h5path>/Geometry/Vx</h5path>
<category>Geometry</category>
<description>Vector along x define the spectral mesh</description>
</Vx>
<Vy>
<type>Scalar</type>
<h5path>/Geometry/Vy</h5path>
<category>Geometry</category>
<description>Vector along y defines the spectral mesh</description>
</Vy>
<Vz>
<type>Scalar</type>
<h5path>/Geometry/Vz</h5path>
<category>Geometry</category>
<description>Vector along z defines the spectral mesh</description>
</Vz>
<ip>
<type>scalar</type>
<h5path>/ip</h5path>
<category></category>
<type>Scalar</type>
<h5path>/Geometry/ip</h5path>
<category>Geometry</category>
<description></description>
<log></log>
</ip>
<node>
<type>scalar</type>
<h5path>/node</h5path>
<category></category>
<type>Scalar</type>
<h5path>/Geometry/node</h5path>
<category>Geometry</category>
<description></description>
<log></log>
</node>
<grain>
<type>vector</type>
<h5path>/grain</h5path>
<category></category>
<type>Scalar</type>
<h5path>/Geometry/grain</h5path>
<category>Geometry</category>
<description></description>
<log></log>
</grain>
<pos>
<type>vector</type>
<h5path>/pos</h5path>
<category></category>
<type>Vector</type>
<h5path>/Geometry/pos</h5path>
<category>Geometry</category>
<description></description>
<log></log>
</pos>
<elem>
<type>integer</type>
<h5path>/elem</h5path>
<category></category>
<type>Scalar</type>
<h5path>/Geometry/elem</h5path>
<category>Geometry</category>
<description></description>
<log></log>
</elem>
<!--Crystallite section-->
<phase>
<type>integer</type>
<h5path>/phase</h5path>
<type>Scalar</type>
<h5path>/Crystallite/phase</h5path>
<category>Crystallite</category>
<description></description>
<log></log>
</phase>
<texture>
<type>integer</type>
<h5path>/texture</h5path>
<type>Scalar</type>
<h5path>/Crystallite/texture</h5path>
<category>Crystallite</category>
<description></description>
<log></log>
</texture>
<volume>
<type>scalar</type>
<h5path>/volume</h5path>
<type>Scalar</type>
<h5path>/Crystallite/volume</h5path>
<category>Crystallite</category>
<description></description>
<log></log>
</volume>
<orientation>
<type>vector</type>
<h5path>/orientation</h5path>
<type>Vector</type>
<h5path>/Crystallite/orientation</h5path>
<category>Crystallite</category>
<description></description>
<log></log>
</orientation>
<eulerangles>
<type>vector</type>
<h5path>/eulerangles</h5path>
<type>Vector</type>
<h5path>/Crystallite/eulerangles</h5path>
<category>Crystallite</category>
<description>Bunnge Euler angles in degrees</description>
<log></log>
</eulerangles>
<grainrotation>
<type>vector</type>
<h5path>/grainrotation</h5path>
<type>Vector</type>
<h5path>/Crystallite/grainrotation</h5path>
<category>Crystallite</category>
<description></description>
<log></log>
</grainrotation>
<f>
<type>tensor</type>
<h5path>/f</h5path>
<type>Tensor</type>
<h5path>/Crystallite/f</h5path>
<category>Crystallite</category>
<description>deformation gradient (F)</description>
<log></log>
</f>
<p>
<type>tensor</type>
<h5path>/p</h5path>
<type>Tensor</type>
<h5path>/Crystallite/p</h5path>
<category>Crystallite</category>
<description>Pikola Kirkhoff stress</description>
<log></log>
</p>
<Cauchy>
<type>Tensor</type>
<h5path>/Crystallite/Cauchy</h5path>
<category>Crystallite</category>
<description>Cauchy stress tensor</description>
</Cauchy>
<lnV>
<type>Tensor</type>
<h5path>/Crystallite/lnV</h5path>
<category>Crystallite</category>
<description></description>
</lnV>
<MisesCauchy>
<type>Scalar</type>
<h5path>/Crystallite/MisesCauchy</h5path>
<category>Crystallite</category>
<description>von Mises equivalent of Cauchy stress</description>
</MisesCauchy>
<MiseslnV>
<type>Scalar</type>
<h5path>/Crystallite/MiseslnV</h5path>
<category>Crystallite</category>
<description>left von Mises strain</description>
</MiseslnV>
<!--Constitutive section-->
<resistance_slip>
<type>vector</type>
<h5path>/resistance_slip</h5path>
<type>Vector</type>
<h5path>/Constitutive/resistance_slip</h5path>
<category>Constitutive</category>
<description></description>
</resistance_slip>
<shearrate_slip>
<type>vector</type>
<h5path>/shearrate_slip</h5path>
<type>Vector</type>
<h5path>/Constitutive/shearrate_slip</h5path>
<category>Constitutive</category>
<description></description>
</shearrate_slip>
<resolvedstress_slip>
<type>vector</type>
<h5path>/resolvedstress_slip</h5path>
<type>Vector</type>
<h5path>/Constitutive/resolvedstress_slip</h5path>
<category>Constitutive</category>
<description></description>
</resolvedstress_slip>
<totalshear>
<type>scalar</type>
<h5path>/totalshear</h5path>
<type>Scalar</type>
<h5path>/Constitutive/totalshear</h5path>
<category>Constitutive</category>
<description></description>
</totalshear>
<accumulatedshear_slip>
<type>vector</type>
<h5path>/accumulatedshear_slip</h5path>
<type>Matrix</type>
<h5path>/Constitutive/accumulatedshear_slip</h5path>
<category>Constitutive</category>
<description>vector contains accumulated shear per slip system</description>
</accumulatedshear_slip>
<Cauchy>
<type>tensor</type>
<h5path>/Cauchy</h5path>
<category>Derived</category>
<description>Cauchy stress tensor</description>
</Cauchy>
<lnV>
<type>tensor</type>
<h5path>/lnV</h5path>
<category>Derived</category>
<description></description>
</lnV>
<MisesCauchy>
<type>scalar</type>
<h5path>/MisesCauchy</h5path>
<category>Derived</category>
<description>von Mises equivalent of Cauchy stress</description>
</MisesCauchy>
<MiseslnV>
<type>scalar</type>
<h5path>/MiseslnV</h5path>
<category>Derived</category>
<description>left von Mises strain</description>
</MiseslnV>
<!--Derived section-->
</h5ds>

View File

@ -23,12 +23,6 @@ except(NameError):
unicode=str
# ------------------------------------------------------- #
# Singleton class for converting feature name to H5F path #
# ------------------------------------------------------- #
# NOTE:
# use simple function to mimic the singleton class in
# C++/Java
def lables_to_path(label, dsXMLPath=None):
"""read the xml definition file and return the path."""
if dsXMLPath is None:
@ -41,23 +35,26 @@ def lables_to_path(label, dsXMLPath=None):
"DS_HDF5.xml")
# This current implementation requires that all variables
# stay under the root node, the nesting is defined through the
# h5path. This could be improved easily with more advanced parsing
# using ET interface, but for now I can not see the benefits in doing
# so.
# h5path.
# Allow new derived data to be put under the root
tree = ET.parse(dsXMLPath)
dataType = tree.find('{}/type'.format(label)).text
h5path = tree.find('{}/h5path'.format(label)).text
try:
dataType = tree.find('{}/type'.format(label)).text
h5path = tree.find('{}/h5path'.format(label)).text
except:
dataType = "Scalar"
h5path = "/{}".format(label) # just put it under root
return (dataType, h5path)
class H5Table(object):
"""Interface class for h5py
"""light weight interface class for h5py
DESCRIPTION
-----------
Interface/wrapper class for manipulating data in HDF5 with DAMASK
specialized data structure.
-->Minimal API design.
-->try to maintain a minimal API design.
PARAMETERS
----------
h5f_path: str
@ -114,7 +111,8 @@ class H5Table(object):
dsXMLPath=self.dsXMLFile)
with h5py.File(self.h5f_path, 'a') as h5f:
h5f_dst = h5f[h5f_path] # get the handle for target dataset(table)
rst_data = h5f_dst.read_direct(np.zeros(h5f_dst.shape))
rst_data = np.zeros(h5f_dst.shape)
h5f_dst.read_direct(rst_data)
return rst_data
def add_data(self, feature_name, dataset, cmd_log=None):

View File

@ -7,6 +7,11 @@
# new one to the system wide definition file #
# <DAMASK_ROOT>/lib/damask/DS_HDF5.xml #
# or specify your own when initializing HDF5 class #
# 2. Somehow the point cloud structure cannot be properly handled #
# by Xdmf, which is a descriptive wrapper for visualizing HDF5 #
# using Paraview. The current solution is using cell structured #
# HDF5 so that Xdmf can describe the data shape as a rectangular #
# mesh rather than polyvertex. #
# ------------------------------------------------------------------- #
import os
@ -14,13 +19,24 @@ import damask
import numpy as np
from optparse import OptionParser
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
# --------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------
# ----- helper function ----- #
def get_rectMshVectors(xyz_array, posNum):
"""take in a xyz array from rectangular mesh and figure out Vx, Vy, Vz"""
# need some improvement, and only works for rectangular grid
v = sorted(list(set(xyz_array[:, posNum])))
v_interval = (v[2]+v[1])/2.0 - (v[1]+v[0])/2.0
v_start = (v[1]+v[0])/2.0 - v_interval
v_end = (v[-1]+v[-2])/2.0 + v_interval
V = np.linspace(v_start, v_end, len(v)+1)
return V
# ----- MAIN ---- #
desp_msg = "Convert DAMASK ascii table to HDF5 file"
parser = OptionParser(option_class=damask.extendableOption,
usage='%prog options [file[s]]',
@ -31,8 +47,14 @@ parser.add_option('-D', '--DefinitionFile',
type = 'string',
metavar = 'string',
help = 'definition file for H5 data storage')
parser.add_option('-p',
'--pos', '--position',
dest = 'pos',
type = 'string', metavar = 'string',
help = 'label of coordinates [%default]')
parser.set_defaults(DefinitionFile='default')
parser.set_defaults(DefinitionFile='default',
pos='pos')
(options,filenames) = parser.parse_args()
@ -54,17 +76,31 @@ labels_idx = [asciiTable.label_index(label) for label in labels]
featuresDim = [labels_idx[i+1] - labels_idx[i] for i in xrange(len(labels)-1)]
featuresDim.append(fullTable.shape[1] - labels_idx[-1])
# ----- figure out size and grid ----- #
pos_idx = asciiTable.label_index('pos')
xyz_array = asciiTable.data[:, pos_idx:pos_idx+3]
Vx = get_rectMshVectors(xyz_array, 0)
Vy = get_rectMshVectors(xyz_array, 1)
Vz = get_rectMshVectors(xyz_array, 2)
# use the dimension of the rectangular grid to reshape all other data
mshGridDim = (len(Vx)-1, len(Vy)-1, len(Vz)-1)
# ----- create a new HDF5 file and save the data -----#
# Will overwrite existing HDF5 file with the same name
h5f = damask.H5Table(filename.replace(".txt", ".h5"),
new_file=True,
dsXMLFile=defFile)
# adding increment number as root level attributes
h5f.add_attr('inc', incNum)
# add the mesh grid data now
h5f.add_data("Vx", Vx)
h5f.add_data("Vy", Vy)
h5f.add_data("Vz", Vz)
# add the rest of data from table
for fi in xrange(len(labels)):
featureName = labels[fi]
if featureName == 'inc': continue
if 'inc' in featureName: continue
# remove trouble maker "("" and ")"
if "(" in featureName: featureName = featureName.replace("(", "")
if ")" in featureName: featureName = featureName.replace(")", "")
@ -72,8 +108,8 @@ for fi in xrange(len(labels)):
featureDim = featuresDim[fi]
# grab the data hook
dataset = fullTable[:, featureIdx:featureIdx+featureDim]
# reshape tensor to 3x3 --> just make life slightly easier
if dataset.shape[1] == 9:
dataset = dataset.reshape((dataset.shape[0], 3, 3))
# mapping 2D data onto a 3D rectangular mesh to get 4D data
dataset = dataset.reshape((mshGridDim[0], mshGridDim[1], mshGridDim[2],
dataset.shape[1]))
# write out data
h5f.add_data(featureName, dataset)