polishing

This commit is contained in:
Martin Diehl 2020-02-21 19:37:26 +01:00
parent 05476ff85c
commit 0358e7343b
2 changed files with 18 additions and 21 deletions

View File

@ -37,24 +37,23 @@ class DADF5():
with h5py.File(fname,'r') as f: with h5py.File(fname,'r') as f:
try: try:
self.version_major = f.attrs['DADF5_version_major'] self.version_major = f.attrs['DADF5_version_major']
self.version_minor = f.attrs['DADF5_version_minor'] self.version_minor = f.attrs['DADF5_version_minor']
except KeyError: except KeyError:
self.version_major = f.attrs['DADF5-major'] self.version_major = f.attrs['DADF5-major']
self.version_minor = f.attrs['DADF5-minor'] self.version_minor = f.attrs['DADF5-minor']
if self.version_major != 0 or not 2 <= self.version_minor <= 6: if self.version_major != 0 or not 2 <= self.version_minor <= 6:
raise TypeError('Unsupported DADF5 version {}.{} '.format(f.attrs['DADF5_version_major'], raise TypeError('Unsupported DADF5 version {}.{} '.format(self.version_major,
f.attrs['DADF5_version_minor'])) self.version_minor))
self.structured = 'grid' in f['geometry'].attrs.keys() self.structured = 'grid' in f['geometry'].attrs.keys()
if self.structured: if self.structured:
self.grid = f['geometry'].attrs['grid'] self.grid = f['geometry'].attrs['grid']
self.size = f['geometry'].attrs['size'] self.size = f['geometry'].attrs['size']
if self.version_major == 0 and self.version_minor >= 5: self.origin = f['geometry'].attrs['origin'] if self.version_major == 0 and self.version_minor >= 5 else \
self.origin = f['geometry'].attrs['origin'] np.zeros(3)
r=re.compile('inc[0-9]+') r=re.compile('inc[0-9]+')
increments_unsorted = {int(i[3:]):i for i in f.keys() if r.match(i)} increments_unsorted = {int(i[3:]):i for i in f.keys() if r.match(i)}
@ -67,12 +66,12 @@ class DADF5():
self.con_physics = [] self.con_physics = []
for c in self.constituents: for c in self.constituents:
self.con_physics += f['/'.join([self.increments[0],'constituent',c])].keys() self.con_physics += f['/'.join([self.increments[0],'constituent',c])].keys()
self.con_physics = list(set(self.con_physics)) # make unique self.con_physics = list(set(self.con_physics)) # make unique
self.mat_physics = [] self.mat_physics = []
for m in self.materialpoints: for m in self.materialpoints:
self.mat_physics += f['/'.join([self.increments[0],'materialpoint',m])].keys() self.mat_physics += f['/'.join([self.increments[0],'materialpoint',m])].keys()
self.mat_physics = list(set(self.mat_physics)) # make unique self.mat_physics = list(set(self.mat_physics)) # make unique
self.selection= {'increments': self.increments, self.selection= {'increments': self.increments,
@ -563,7 +562,7 @@ class DADF5():
@staticmethod @staticmethod
def _add_deviator(T): def _add_deviator(T):
if not np.all(np.array(T['data'].shape[1:]) == np.array([3,3])): if not T['data'].shape[1:] == (3,3):
raise ValueError raise ValueError
return { return {
@ -833,7 +832,7 @@ class DADF5():
@staticmethod @staticmethod
def _add_rotational_part(F): def _add_rotational_part(F):
if not np.all(np.array(F['data'].shape[1:]) == np.array([3,3])): if not F['data'].shape[1:] == (3,3):
raise ValueError raise ValueError
return { return {
'data': mechanics.rotational_part(F['data']), 'data': mechanics.rotational_part(F['data']),
@ -854,13 +853,12 @@ class DADF5():
Label of deformation gradient dataset. Label of deformation gradient dataset.
""" """
self.__add_generic_pointwise(self._add_rotational_part,{'F':F}) self.__add_generic_pointwise(self._add_rotational_part,{'F':F})
@staticmethod @staticmethod
def _add_spherical(T): def _add_spherical(T):
if not np.all(np.array(T['data'].shape[1:]) == np.array([3,3])): if not T['data'].shape[1:] == (3,3):
raise ValueError raise ValueError
return { return {
@ -887,8 +885,9 @@ class DADF5():
@staticmethod @staticmethod
def _add_strain_tensor(F,t,m): def _add_strain_tensor(F,t,m):
if not np.all(np.array(F['data'].shape[1:]) == np.array([3,3])): if not F['data'].shape[1:] == (3,3):
raise ValueError raise ValueError
return { return {
'data': mechanics.strain_tensor(F['data'],t,m), 'data': mechanics.strain_tensor(F['data'],t,m),
'label': 'epsilon_{}^{}({})'.format(t,m,F['label']), 'label': 'epsilon_{}^{}({})'.format(t,m,F['label']),
@ -920,7 +919,7 @@ class DADF5():
@staticmethod @staticmethod
def _add_stretch_tensor(F,t): def _add_stretch_tensor(F,t):
if not np.all(np.array(F['data'].shape[1:]) == np.array([3,3])): if not F['data'].shape[1:] == (3,3):
raise ValueError raise ValueError
return { return {

View File

@ -6,8 +6,6 @@ import shlex
from fractions import Fraction from fractions import Fraction
from functools import reduce from functools import reduce
from optparse import Option from optparse import Option
from queue import Queue
from threading import Thread
import numpy as np import numpy as np