added docstrings etc

This commit is contained in:
Martin Diehl 2016-03-04 17:55:11 +01:00
parent 24391b5398
commit d1e8f69857
4 changed files with 22 additions and 37 deletions

View File

@ -1,5 +1,5 @@
# -*- coding: UTF-8 no BOM -*-
# $Id$
"""Aggregator for configuration file handling"""
from .material import Material
from .material import Material #noqa

View File

@ -100,20 +100,19 @@ class Texture(Section):
class Material():
"""Reads, manipulates and writes material.config files"""
'''
Reads, manipulates and writes material.config files
'''
__slots__ = ['data']
def __init__(self,verbose=True):
"""generates ordered list of parts"""
self.parts = [
'homogenization',
'microstructure',
'crystallite',
'phase',
'texture',
] # ordered (!) list of parts
]
self.data = {\
'homogenization': {'__order__': []},
'microstructure': {'__order__': []},
@ -124,6 +123,7 @@ class Material():
self.verbose = verbose
def __repr__(self):
"""returns current configuration to be used as material.config"""
me = []
for part in self.parts:
if self.verbose: print('doing '+part)
@ -144,7 +144,6 @@ class Material():
re_sec = re.compile(r'^\[(.+)\]$') # pattern for section
name_section = ''
idx_section = 0
active = False
for line in content:
@ -197,8 +196,7 @@ class Material():
return saveFile
def add_section(self, part=None, section=None, initialData=None, merge = False):
'''adding/updating'''
"""adding/updating"""
part = part.lower()
section = section.lower()
if part not in self.parts: raise Exception('invalid part %s'%part)
@ -227,10 +225,10 @@ class Material():
def add_microstructure(self, section='',
components={}, # dict of phase,texture, and fraction lists
):
''' Experimental! Needs expansion to multi-constituent microstructures...'''
"""Experimental! Needs expansion to multi-constituent microstructures..."""
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']:
if type(components[key]) is not list:
@ -259,8 +257,8 @@ class Material():
section=None,
key=None,
value=None):
if type(value) is not type([]):
if type(value) is not type('s'):
if not isinstance(value,list):
if not isinstance(value,str):
value = '%s'%value
value = [value]
newlen = len(value)
@ -271,17 +269,3 @@ class Material():
if newlen is not oldlen:
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)

View File

@ -1,7 +1,7 @@
# -*- coding: UTF-8 no BOM -*-
# $Id$
"""Aggregator for geometry handling"""
from .geometry import Geometry # only one class
from .spectral import Spectral # only one class
from .marc import Marc # only one class
from .geometry import Geometry # noqa
from .spectral import Spectral # noqa
from .marc import Marc # noqa

View File

@ -5,10 +5,11 @@
import damask.geometry
class Geometry():
'''
General class for geometry parsing.
Sub-classed by the individual solvers.
'''
"""
General class for geometry parsing.
Sub-classed by the individual solvers.
"""
def __init__(self,solver=''):
solverClass = {