improvements!
This commit is contained in:
parent
ddc2b04661
commit
b67b5f9ef9
|
@ -10,10 +10,11 @@ class DAMASK_TOOLS():
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class MATERIAL_CONFIG():
|
class MATERIAL_CONFIG():
|
||||||
__slots__ = ['data']
|
__slots__ = ['data']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.parts = [
|
self.parts = [
|
||||||
'homogenization',
|
'homogenization',
|
||||||
|
@ -21,7 +22,7 @@ class MATERIAL_CONFIG():
|
||||||
'crystallite',
|
'crystallite',
|
||||||
'phase',
|
'phase',
|
||||||
'texture',
|
'texture',
|
||||||
]
|
] # ordered (!) list of parts
|
||||||
self.data = {\
|
self.data = {\
|
||||||
'homogenization': {'__order__': []},
|
'homogenization': {'__order__': []},
|
||||||
'microstructure': {'__order__': []},
|
'microstructure': {'__order__': []},
|
||||||
|
@ -33,18 +34,18 @@ class MATERIAL_CONFIG():
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
me = []
|
me = []
|
||||||
for part in self.parts:
|
for part in self.parts:
|
||||||
|
print 'doing',part
|
||||||
me += ['','#-----------------------------#','<%s>'%part,'#-----------------------------#',]
|
me += ['','#-----------------------------#','<%s>'%part,'#-----------------------------#',]
|
||||||
for section in self.data[part]['__order__']:
|
for section in self.data[part]['__order__']:
|
||||||
me += ['','[%s]\t\t#-----------------------'%section,'',]
|
me += ['','[%s] %s'%(section,'-'*max(0,27-len(section))),'',]
|
||||||
for key in self.data[part][section]['__order__']:
|
for key in self.data[part][section]['__order__']:
|
||||||
if key.startswith('(') and key.endswith(')'): # multiple (key)
|
if key.startswith('(') and key.endswith(')'): # multiple (key)
|
||||||
me += ['%s\t%s'%(key,' '.join(values)) for values in self.data[part][section][key]]
|
me += ['%s\t%s'%(key,' '.join(values)) for values in self.data[part][section][key]]
|
||||||
else: # plain key
|
else: # plain key
|
||||||
me += ['%s\t%s'%(key,' '.join(self.data[part][section][key]))]
|
me += ['%s\t%s'%(key,' '.join(map(str,self.data[part][section][key])))]
|
||||||
|
|
||||||
return '\n'.join(me)
|
return '\n'.join(me)
|
||||||
|
|
||||||
|
|
||||||
def parse_data(self, part=None, sections=[], content=None):
|
def parse_data(self, part=None, sections=[], content=None):
|
||||||
|
|
||||||
re_part = re.compile(r'^<(.+)>$') # pattern for part
|
re_part = re.compile(r'^<(.+)>$') # pattern for part
|
||||||
|
@ -92,22 +93,30 @@ class MATERIAL_CONFIG():
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
i=1
|
i=1
|
||||||
while os.path.exists(file+'_%i'%i):i+=1
|
while os.path.exists(file+'_%i'%i):i+=1
|
||||||
file=file+'_%i'%i
|
file+='_%i'%i
|
||||||
print('Writing material data to file %s'%file)
|
print('Writing material data to file %s'%file)
|
||||||
f=open(file,'w')
|
f=open(file,'w')
|
||||||
f.write(str(self))
|
f.write(str(self))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
def add_data(self, part=None, section=None, data={}):
|
||||||
|
if part not in self.parts: raise Exception('invalid part %s'%part)
|
||||||
|
if section not in self.data[part]: self.data[part]['__order__'] += [section]
|
||||||
|
self.data[part][section] = data
|
||||||
|
|
||||||
|
|
||||||
def add_homogenization(self, label='', type='', Ngrains=None):
|
def add_homogenization(self, label='', type='', Ngrains=None):
|
||||||
old_len=len(self.data['homogenization'])
|
if type.lower() == 'isostrain':
|
||||||
if type is 'isostrain':
|
self.add_data(part='homogenization',
|
||||||
h={'type':[type]}
|
section=label,
|
||||||
h['Ngrains']=[Ngrains]
|
data={'type':[type],
|
||||||
h['__order__']=['type','Ngrains']
|
'Ngrains':[Ngrains],
|
||||||
#return h
|
'__order__':['type','Ngrains']
|
||||||
self.data['homogenization'][label]=h
|
}
|
||||||
if len(self.data['homogenization'])>old_len: # added new label
|
)
|
||||||
self.data['homogenization']['__order__'].append(label)
|
elif type.lower() == 'rgc':
|
||||||
|
raise Exception('Please implement me')
|
||||||
|
|
||||||
def add_crystallite(self, label='', output=[]):
|
def add_crystallite(self, label='', output=[]):
|
||||||
old_len=len(self.data['crystallite'])
|
old_len=len(self.data['crystallite'])
|
||||||
|
@ -118,7 +127,7 @@ class MATERIAL_CONFIG():
|
||||||
def add_texture(self, label='',type='', eulers=[], scatter=0., fraction=1.):
|
def add_texture(self, label='',type='', eulers=[], scatter=0., fraction=1.):
|
||||||
''' Experimental! Needs expansion to multi-component textures...'''
|
''' Experimental! Needs expansion to multi-component textures...'''
|
||||||
old_len=len(self.data['texture'])
|
old_len=len(self.data['texture'])
|
||||||
if type is '(gauss)':
|
if type == '(gauss)':
|
||||||
gauss={type:[['phi1',eulers[0],'Phi',eulers[1], 'phi2',eulers[2],'scatter',scatter, 'fraction',fraction]],'__order__':label}
|
gauss={type:[['phi1',eulers[0],'Phi',eulers[1], 'phi2',eulers[2],'scatter',scatter, 'fraction',fraction]],'__order__':label}
|
||||||
self.data['texture'][label]=gauss
|
self.data['texture'][label]=gauss
|
||||||
if len(self.data['texture'])>old_len: # added new label
|
if len(self.data['texture'])>old_len: # added new label
|
||||||
|
@ -130,16 +139,13 @@ class MATERIAL_CONFIG():
|
||||||
OR
|
OR
|
||||||
-phase is dict with one key
|
-phase is dict with one key
|
||||||
'''
|
'''
|
||||||
import copy
|
|
||||||
print(file,label,phase)
|
print(file,label,phase)
|
||||||
old_len=len(self.data['phase'])
|
old_len=len(self.data['phase'])
|
||||||
if file and label and (phase is None):
|
if file and label and (phase is None):
|
||||||
data_so_far = copy.deepcopy(self.data)
|
other=MATERIAL_CONFIG()
|
||||||
self.__init__()
|
other.read(file=file)
|
||||||
self.read(file=file)
|
phase={label:other.data['phase'][label]}
|
||||||
phase={label:self.data['phase'][label]}
|
|
||||||
label=None
|
label=None
|
||||||
self.data=copy.deepcopy(data_so_far)
|
|
||||||
print phase
|
print phase
|
||||||
if len(phase)==1 and label is None:
|
if len(phase)==1 and label is None:
|
||||||
print('Adding phase %s'%phase.keys()[0])
|
print('Adding phase %s'%phase.keys()[0])
|
||||||
|
@ -150,8 +156,8 @@ class MATERIAL_CONFIG():
|
||||||
else:
|
else:
|
||||||
raise Exception('Wrong arguments')
|
raise Exception('Wrong arguments')
|
||||||
|
|
||||||
def add_microstructure(self, crystallite=None,
|
def add_microstructure(self, label=None,
|
||||||
label=None,
|
crystallite=None,
|
||||||
phases=None,
|
phases=None,
|
||||||
textures=None,
|
textures=None,
|
||||||
fractions=None):
|
fractions=None):
|
||||||
|
@ -170,10 +176,6 @@ class MATERIAL_CONFIG():
|
||||||
if len(self.data['microstructure'])>old_len: # added new label
|
if len(self.data['microstructure'])>old_len: # added new label
|
||||||
self.data['microstructure']['__order__'].append(label)
|
self.data['microstructure']['__order__'].append(label)
|
||||||
|
|
||||||
class HOMOGENIZATION():
|
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue