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:
parent
7310c53f73
commit
c311ac47ca
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<h5ds>
|
<h5ds>
|
||||||
|
<!--Top level attributes-->
|
||||||
<history>
|
<history>
|
||||||
<type>attr</type>
|
<type>attr</type>
|
||||||
<h5path>/</h5path>
|
<h5path>/</h5path>
|
||||||
|
@ -12,174 +13,186 @@
|
||||||
<h5path>/</h5path>
|
<h5path>/</h5path>
|
||||||
<category></category>
|
<category></category>
|
||||||
<description></description>
|
<description></description>
|
||||||
<log></log>
|
|
||||||
</inc>
|
</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>
|
<ip>
|
||||||
<type>scalar</type>
|
<type>Scalar</type>
|
||||||
<h5path>/ip</h5path>
|
<h5path>/Geometry/ip</h5path>
|
||||||
<category></category>
|
<category>Geometry</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
<log></log>
|
|
||||||
</ip>
|
</ip>
|
||||||
|
|
||||||
<node>
|
<node>
|
||||||
<type>scalar</type>
|
<type>Scalar</type>
|
||||||
<h5path>/node</h5path>
|
<h5path>/Geometry/node</h5path>
|
||||||
<category></category>
|
<category>Geometry</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
<log></log>
|
|
||||||
</node>
|
</node>
|
||||||
|
|
||||||
<grain>
|
<grain>
|
||||||
<type>vector</type>
|
<type>Scalar</type>
|
||||||
<h5path>/grain</h5path>
|
<h5path>/Geometry/grain</h5path>
|
||||||
<category></category>
|
<category>Geometry</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
<log></log>
|
|
||||||
</grain>
|
</grain>
|
||||||
|
|
||||||
<pos>
|
<pos>
|
||||||
<type>vector</type>
|
<type>Vector</type>
|
||||||
<h5path>/pos</h5path>
|
<h5path>/Geometry/pos</h5path>
|
||||||
<category></category>
|
<category>Geometry</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
<log></log>
|
|
||||||
</pos>
|
</pos>
|
||||||
|
|
||||||
<elem>
|
<elem>
|
||||||
<type>integer</type>
|
<type>Scalar</type>
|
||||||
<h5path>/elem</h5path>
|
<h5path>/Geometry/elem</h5path>
|
||||||
<category></category>
|
<category>Geometry</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
<log></log>
|
|
||||||
</elem>
|
</elem>
|
||||||
|
|
||||||
|
<!--Crystallite section-->
|
||||||
<phase>
|
<phase>
|
||||||
<type>integer</type>
|
<type>Scalar</type>
|
||||||
<h5path>/phase</h5path>
|
<h5path>/Crystallite/phase</h5path>
|
||||||
<category>Crystallite</category>
|
<category>Crystallite</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
<log></log>
|
|
||||||
</phase>
|
</phase>
|
||||||
|
|
||||||
<texture>
|
<texture>
|
||||||
<type>integer</type>
|
<type>Scalar</type>
|
||||||
<h5path>/texture</h5path>
|
<h5path>/Crystallite/texture</h5path>
|
||||||
<category>Crystallite</category>
|
<category>Crystallite</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
<log></log>
|
|
||||||
</texture>
|
</texture>
|
||||||
|
|
||||||
<volume>
|
<volume>
|
||||||
<type>scalar</type>
|
<type>Scalar</type>
|
||||||
<h5path>/volume</h5path>
|
<h5path>/Crystallite/volume</h5path>
|
||||||
<category>Crystallite</category>
|
<category>Crystallite</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
<log></log>
|
|
||||||
</volume>
|
</volume>
|
||||||
|
|
||||||
<orientation>
|
<orientation>
|
||||||
<type>vector</type>
|
<type>Vector</type>
|
||||||
<h5path>/orientation</h5path>
|
<h5path>/Crystallite/orientation</h5path>
|
||||||
<category>Crystallite</category>
|
<category>Crystallite</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
<log></log>
|
|
||||||
</orientation>
|
</orientation>
|
||||||
|
|
||||||
<eulerangles>
|
<eulerangles>
|
||||||
<type>vector</type>
|
<type>Vector</type>
|
||||||
<h5path>/eulerangles</h5path>
|
<h5path>/Crystallite/eulerangles</h5path>
|
||||||
<category>Crystallite</category>
|
<category>Crystallite</category>
|
||||||
<description>Bunnge Euler angles in degrees</description>
|
<description>Bunnge Euler angles in degrees</description>
|
||||||
<log></log>
|
|
||||||
</eulerangles>
|
</eulerangles>
|
||||||
|
|
||||||
<grainrotation>
|
<grainrotation>
|
||||||
<type>vector</type>
|
<type>Vector</type>
|
||||||
<h5path>/grainrotation</h5path>
|
<h5path>/Crystallite/grainrotation</h5path>
|
||||||
<category>Crystallite</category>
|
<category>Crystallite</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
<log></log>
|
|
||||||
</grainrotation>
|
</grainrotation>
|
||||||
|
|
||||||
<f>
|
<f>
|
||||||
<type>tensor</type>
|
<type>Tensor</type>
|
||||||
<h5path>/f</h5path>
|
<h5path>/Crystallite/f</h5path>
|
||||||
<category>Crystallite</category>
|
<category>Crystallite</category>
|
||||||
<description>deformation gradient (F)</description>
|
<description>deformation gradient (F)</description>
|
||||||
<log></log>
|
|
||||||
</f>
|
</f>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<type>tensor</type>
|
<type>Tensor</type>
|
||||||
<h5path>/p</h5path>
|
<h5path>/Crystallite/p</h5path>
|
||||||
<category>Crystallite</category>
|
<category>Crystallite</category>
|
||||||
<description>Pikola Kirkhoff stress</description>
|
<description>Pikola Kirkhoff stress</description>
|
||||||
<log></log>
|
|
||||||
</p>
|
</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>
|
<resistance_slip>
|
||||||
<type>vector</type>
|
<type>Vector</type>
|
||||||
<h5path>/resistance_slip</h5path>
|
<h5path>/Constitutive/resistance_slip</h5path>
|
||||||
<category>Constitutive</category>
|
<category>Constitutive</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
</resistance_slip>
|
</resistance_slip>
|
||||||
|
|
||||||
<shearrate_slip>
|
<shearrate_slip>
|
||||||
<type>vector</type>
|
<type>Vector</type>
|
||||||
<h5path>/shearrate_slip</h5path>
|
<h5path>/Constitutive/shearrate_slip</h5path>
|
||||||
<category>Constitutive</category>
|
<category>Constitutive</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
</shearrate_slip>
|
</shearrate_slip>
|
||||||
|
|
||||||
<resolvedstress_slip>
|
<resolvedstress_slip>
|
||||||
<type>vector</type>
|
<type>Vector</type>
|
||||||
<h5path>/resolvedstress_slip</h5path>
|
<h5path>/Constitutive/resolvedstress_slip</h5path>
|
||||||
<category>Constitutive</category>
|
<category>Constitutive</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
</resolvedstress_slip>
|
</resolvedstress_slip>
|
||||||
|
|
||||||
<totalshear>
|
<totalshear>
|
||||||
<type>scalar</type>
|
<type>Scalar</type>
|
||||||
<h5path>/totalshear</h5path>
|
<h5path>/Constitutive/totalshear</h5path>
|
||||||
<category>Constitutive</category>
|
<category>Constitutive</category>
|
||||||
<description></description>
|
<description></description>
|
||||||
</totalshear>
|
</totalshear>
|
||||||
|
|
||||||
<accumulatedshear_slip>
|
<accumulatedshear_slip>
|
||||||
<type>vector</type>
|
<type>Matrix</type>
|
||||||
<h5path>/accumulatedshear_slip</h5path>
|
<h5path>/Constitutive/accumulatedshear_slip</h5path>
|
||||||
<category>Constitutive</category>
|
<category>Constitutive</category>
|
||||||
<description>vector contains accumulated shear per slip system</description>
|
<description>vector contains accumulated shear per slip system</description>
|
||||||
</accumulatedshear_slip>
|
</accumulatedshear_slip>
|
||||||
|
|
||||||
<Cauchy>
|
<!--Derived section-->
|
||||||
<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>
|
|
||||||
|
|
||||||
</h5ds>
|
</h5ds>
|
|
@ -23,12 +23,6 @@ except(NameError):
|
||||||
unicode=str
|
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):
|
def lables_to_path(label, dsXMLPath=None):
|
||||||
"""read the xml definition file and return the path."""
|
"""read the xml definition file and return the path."""
|
||||||
if dsXMLPath is None:
|
if dsXMLPath is None:
|
||||||
|
@ -41,23 +35,26 @@ def lables_to_path(label, dsXMLPath=None):
|
||||||
"DS_HDF5.xml")
|
"DS_HDF5.xml")
|
||||||
# This current implementation requires that all variables
|
# This current implementation requires that all variables
|
||||||
# stay under the root node, the nesting is defined through the
|
# stay under the root node, the nesting is defined through the
|
||||||
# h5path. This could be improved easily with more advanced parsing
|
# h5path.
|
||||||
# using ET interface, but for now I can not see the benefits in doing
|
# Allow new derived data to be put under the root
|
||||||
# so.
|
|
||||||
tree = ET.parse(dsXMLPath)
|
tree = ET.parse(dsXMLPath)
|
||||||
|
try:
|
||||||
dataType = tree.find('{}/type'.format(label)).text
|
dataType = tree.find('{}/type'.format(label)).text
|
||||||
h5path = tree.find('{}/h5path'.format(label)).text
|
h5path = tree.find('{}/h5path'.format(label)).text
|
||||||
|
except:
|
||||||
|
dataType = "Scalar"
|
||||||
|
h5path = "/{}".format(label) # just put it under root
|
||||||
return (dataType, h5path)
|
return (dataType, h5path)
|
||||||
|
|
||||||
|
|
||||||
class H5Table(object):
|
class H5Table(object):
|
||||||
"""Interface class for h5py
|
"""light weight interface class for h5py
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
Interface/wrapper class for manipulating data in HDF5 with DAMASK
|
Interface/wrapper class for manipulating data in HDF5 with DAMASK
|
||||||
specialized data structure.
|
specialized data structure.
|
||||||
-->Minimal API design.
|
-->try to maintain a minimal API design.
|
||||||
PARAMETERS
|
PARAMETERS
|
||||||
----------
|
----------
|
||||||
h5f_path: str
|
h5f_path: str
|
||||||
|
@ -114,7 +111,8 @@ class H5Table(object):
|
||||||
dsXMLPath=self.dsXMLFile)
|
dsXMLPath=self.dsXMLFile)
|
||||||
with h5py.File(self.h5f_path, 'a') as h5f:
|
with h5py.File(self.h5f_path, 'a') as h5f:
|
||||||
h5f_dst = h5f[h5f_path] # get the handle for target dataset(table)
|
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
|
return rst_data
|
||||||
|
|
||||||
def add_data(self, feature_name, dataset, cmd_log=None):
|
def add_data(self, feature_name, dataset, cmd_log=None):
|
||||||
|
|
|
@ -7,6 +7,11 @@
|
||||||
# new one to the system wide definition file #
|
# new one to the system wide definition file #
|
||||||
# <DAMASK_ROOT>/lib/damask/DS_HDF5.xml #
|
# <DAMASK_ROOT>/lib/damask/DS_HDF5.xml #
|
||||||
# or specify your own when initializing HDF5 class #
|
# 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
|
import os
|
||||||
|
@ -14,13 +19,24 @@ import damask
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
|
||||||
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
||||||
scriptID = ' '.join([scriptName,damask.version])
|
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"
|
desp_msg = "Convert DAMASK ascii table to HDF5 file"
|
||||||
parser = OptionParser(option_class=damask.extendableOption,
|
parser = OptionParser(option_class=damask.extendableOption,
|
||||||
usage='%prog options [file[s]]',
|
usage='%prog options [file[s]]',
|
||||||
|
@ -31,8 +47,14 @@ parser.add_option('-D', '--DefinitionFile',
|
||||||
type = 'string',
|
type = 'string',
|
||||||
metavar = 'string',
|
metavar = 'string',
|
||||||
help = 'definition file for H5 data storage')
|
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()
|
(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 = [labels_idx[i+1] - labels_idx[i] for i in xrange(len(labels)-1)]
|
||||||
featuresDim.append(fullTable.shape[1] - labels_idx[-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 -----#
|
# ----- create a new HDF5 file and save the data -----#
|
||||||
# Will overwrite existing HDF5 file with the same name
|
# Will overwrite existing HDF5 file with the same name
|
||||||
|
|
||||||
h5f = damask.H5Table(filename.replace(".txt", ".h5"),
|
h5f = damask.H5Table(filename.replace(".txt", ".h5"),
|
||||||
new_file=True,
|
new_file=True,
|
||||||
dsXMLFile=defFile)
|
dsXMLFile=defFile)
|
||||||
# adding increment number as root level attributes
|
# adding increment number as root level attributes
|
||||||
h5f.add_attr('inc', incNum)
|
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)):
|
for fi in xrange(len(labels)):
|
||||||
featureName = labels[fi]
|
featureName = labels[fi]
|
||||||
if featureName == 'inc': continue
|
if 'inc' in featureName: continue
|
||||||
# remove trouble maker "("" and ")"
|
# remove trouble maker "("" and ")"
|
||||||
if "(" in featureName: featureName = featureName.replace("(", "")
|
if "(" in featureName: featureName = featureName.replace("(", "")
|
||||||
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]
|
featureDim = featuresDim[fi]
|
||||||
# grab the data hook
|
# grab the data hook
|
||||||
dataset = fullTable[:, featureIdx:featureIdx+featureDim]
|
dataset = fullTable[:, featureIdx:featureIdx+featureDim]
|
||||||
# reshape tensor to 3x3 --> just make life slightly easier
|
# mapping 2D data onto a 3D rectangular mesh to get 4D data
|
||||||
if dataset.shape[1] == 9:
|
dataset = dataset.reshape((mshGridDim[0], mshGridDim[1], mshGridDim[2],
|
||||||
dataset = dataset.reshape((dataset.shape[0], 3, 3))
|
dataset.shape[1]))
|
||||||
# write out data
|
# write out data
|
||||||
h5f.add_data(featureName, dataset)
|
h5f.add_data(featureName, dataset)
|
||||||
|
|
Loading…
Reference in New Issue