added docstrings etc
This commit is contained in:
parent
24391b5398
commit
d1e8f69857
|
@ -1,5 +1,5 @@
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
# $Id$
|
"""Aggregator for configuration file handling"""
|
||||||
|
|
||||||
from .material import Material
|
from .material import Material #noqa
|
||||||
|
|
|
@ -100,20 +100,19 @@ class Texture(Section):
|
||||||
|
|
||||||
|
|
||||||
class Material():
|
class Material():
|
||||||
|
"""Reads, manipulates and writes material.config files"""
|
||||||
|
|
||||||
'''
|
|
||||||
Reads, manipulates and writes material.config files
|
|
||||||
'''
|
|
||||||
__slots__ = ['data']
|
__slots__ = ['data']
|
||||||
|
|
||||||
def __init__(self,verbose=True):
|
def __init__(self,verbose=True):
|
||||||
|
"""generates ordered list of parts"""
|
||||||
self.parts = [
|
self.parts = [
|
||||||
'homogenization',
|
'homogenization',
|
||||||
'microstructure',
|
'microstructure',
|
||||||
'crystallite',
|
'crystallite',
|
||||||
'phase',
|
'phase',
|
||||||
'texture',
|
'texture',
|
||||||
] # ordered (!) list of parts
|
]
|
||||||
self.data = {\
|
self.data = {\
|
||||||
'homogenization': {'__order__': []},
|
'homogenization': {'__order__': []},
|
||||||
'microstructure': {'__order__': []},
|
'microstructure': {'__order__': []},
|
||||||
|
@ -124,6 +123,7 @@ class Material():
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
"""returns current configuration to be used as material.config"""
|
||||||
me = []
|
me = []
|
||||||
for part in self.parts:
|
for part in self.parts:
|
||||||
if self.verbose: print('doing '+part)
|
if self.verbose: print('doing '+part)
|
||||||
|
@ -144,7 +144,6 @@ class Material():
|
||||||
re_sec = re.compile(r'^\[(.+)\]$') # pattern for section
|
re_sec = re.compile(r'^\[(.+)\]$') # pattern for section
|
||||||
|
|
||||||
name_section = ''
|
name_section = ''
|
||||||
idx_section = 0
|
|
||||||
active = False
|
active = False
|
||||||
|
|
||||||
for line in content:
|
for line in content:
|
||||||
|
@ -197,8 +196,7 @@ class Material():
|
||||||
return saveFile
|
return saveFile
|
||||||
|
|
||||||
def add_section(self, part=None, section=None, initialData=None, merge = False):
|
def add_section(self, part=None, section=None, initialData=None, merge = False):
|
||||||
'''adding/updating'''
|
"""adding/updating"""
|
||||||
|
|
||||||
part = part.lower()
|
part = part.lower()
|
||||||
section = section.lower()
|
section = section.lower()
|
||||||
if part not in self.parts: raise Exception('invalid part %s'%part)
|
if part not in self.parts: raise Exception('invalid part %s'%part)
|
||||||
|
@ -227,10 +225,10 @@ class Material():
|
||||||
def add_microstructure(self, section='',
|
def add_microstructure(self, section='',
|
||||||
components={}, # dict of phase,texture, and fraction lists
|
components={}, # dict of phase,texture, and fraction lists
|
||||||
):
|
):
|
||||||
''' Experimental! Needs expansion to multi-constituent microstructures...'''
|
"""Experimental! Needs expansion to multi-constituent microstructures..."""
|
||||||
|
|
||||||
microstructure = Microstructure()
|
microstructure = Microstructure()
|
||||||
components=dict((k.lower(), v) for k,v in components.iteritems()) # make keys lower case (http://stackoverflow.com/questions/764235/dictionary-to-lowercase-in-python)
|
# make keys lower case (http://stackoverflow.com/questions/764235/dictionary-to-lowercase-in-python)
|
||||||
|
components=dict((k.lower(), v) for k,v in components.iteritems())
|
||||||
|
|
||||||
for key in ['phase','texture','fraction','crystallite']:
|
for key in ['phase','texture','fraction','crystallite']:
|
||||||
if type(components[key]) is not list:
|
if type(components[key]) is not list:
|
||||||
|
@ -259,8 +257,8 @@ class Material():
|
||||||
section=None,
|
section=None,
|
||||||
key=None,
|
key=None,
|
||||||
value=None):
|
value=None):
|
||||||
if type(value) is not type([]):
|
if not isinstance(value,list):
|
||||||
if type(value) is not type('s'):
|
if not isinstance(value,str):
|
||||||
value = '%s'%value
|
value = '%s'%value
|
||||||
value = [value]
|
value = [value]
|
||||||
newlen = len(value)
|
newlen = len(value)
|
||||||
|
@ -271,17 +269,3 @@ class Material():
|
||||||
if newlen is not oldlen:
|
if newlen is not oldlen:
|
||||||
print('Length of value was changed from %i to %i!'%(oldlen,newlen))
|
print('Length of value was changed from %i to %i!'%(oldlen,newlen))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ex1():
|
|
||||||
mat=Material()
|
|
||||||
p=Phase({'constitution':'lump'})
|
|
||||||
t=Texture()
|
|
||||||
t.add_component('gauss',{'eulers':[1,2,3]})
|
|
||||||
mat.add_section('phase','phase1',p)
|
|
||||||
mat.add_section('texture','tex1',t)
|
|
||||||
mat.add_microstructure('mustruct1',{'phase':['phase1']*2,'texture':['tex1']*2,'fraction':[0.2]*2})
|
|
||||||
print(mat)
|
|
||||||
mat.write(file='poop')
|
|
||||||
mat.write(file='poop',overwrite=True)
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
# $Id$
|
"""Aggregator for geometry handling"""
|
||||||
|
|
||||||
from .geometry import Geometry # only one class
|
from .geometry import Geometry # noqa
|
||||||
from .spectral import Spectral # only one class
|
from .spectral import Spectral # noqa
|
||||||
from .marc import Marc # only one class
|
from .marc import Marc # noqa
|
||||||
|
|
|
@ -5,10 +5,11 @@
|
||||||
import damask.geometry
|
import damask.geometry
|
||||||
|
|
||||||
class Geometry():
|
class Geometry():
|
||||||
'''
|
"""
|
||||||
General class for geometry parsing.
|
General class for geometry parsing.
|
||||||
Sub-classed by the individual solvers.
|
|
||||||
'''
|
Sub-classed by the individual solvers.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self,solver=''):
|
def __init__(self,solver=''):
|
||||||
solverClass = {
|
solverClass = {
|
||||||
|
|
Loading…
Reference in New Issue