Merge branch 'development' into new-ASCII

This commit is contained in:
Martin Diehl 2019-11-26 10:29:05 +01:00
commit 81abc43920
29 changed files with 592 additions and 590 deletions

View File

@ -1 +1 @@
v2.0.3-957-gccbcc0d0
v2.0.3-1097-ga7fca4df

View File

@ -14,7 +14,7 @@ SolidSolutionStrength 1.5e8 # Strength due to elements in solid solution
### Dislocation glide parameters ###
#per family
Nslip 12 0
Nslip 12
slipburgers 2.72e-10 # Burgers vector of slip system [m]
rhoedge0 1.0e12 # Initial edge dislocation density [m/m**3]
rhoedgedip0 1.0 # Initial edged dipole dislocation density [m/m**3]

View File

@ -65,7 +65,7 @@ for filename in options.filenames:
x = results.get_dataset_location(label)
if len(x) == 0:
continue
array = results.read_dataset(x,0)
array = results.read_dataset(x,0,plain=True)
d = int(np.product(np.shape(array)[1:]))
data = np.concatenate((data,np.reshape(array,[np.product(results.grid),d])),1)
@ -80,7 +80,7 @@ for filename in options.filenames:
x = results.get_dataset_location(label)
if len(x) == 0:
continue
array = results.read_dataset(x,0)
array = results.read_dataset(x,0,plain=True)
d = int(np.product(np.shape(array)[1:]))
data = np.concatenate((data,np.reshape(array,[np.product(results.grid),d])),1)

View File

@ -132,7 +132,4 @@ for name in filenames:
damask.util.croak(geom.update(np.where(mask,geom.microstructure,fill)))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -61,7 +61,7 @@ for name in filenames:
canvas = np.full(new,options.fill if options.fill is not None
else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype)
l = np.clip( offset, 0,np.minimum(old +offset,new))
l = np.clip( offset, 0,np.minimum(old +offset,new)) # noqa
r = np.clip( offset+old,0,np.minimum(old*2+offset,new))
L = np.clip(-offset, 0,np.minimum(new -offset,old))
R = np.clip(-offset+new,0,np.minimum(new*2-offset,old))
@ -71,7 +71,4 @@ for name in filenames:
damask.util.croak(geom.update(canvas,origin=origin+offset*size/old,rescale=True))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -5,9 +5,6 @@ import sys
from io import StringIO
from optparse import OptionParser
from scipy import ndimage
import numpy as np
import damask
@ -15,11 +12,6 @@ scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
def mostFrequent(arr):
unique, inverse = np.unique(arr, return_inverse=True)
return unique[np.argmax(np.bincount(inverse))]
#--------------------------------------------------------------------------------------------------
# MAIN
#--------------------------------------------------------------------------------------------------
@ -45,13 +37,6 @@ for name in filenames:
damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
damask.util.croak(geom.update(ndimage.filters.generic_filter(
geom.microstructure,mostFrequent,
size=(options.stencil,)*3).astype(geom.microstructure.dtype)))
damask.util.croak(geom.clean(options.stencil))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -86,7 +86,7 @@ for name in filenames:
* inFile[os.path.join(group_geom,'SPACING')][...]
grid = inFile[os.path.join(group_geom,'DIMENSIONS')][...]
origin = inFile[os.path.join(group_geom,'ORIGIN')][...]
except:
except KeyError:
errors.append('Geometry data ({}) not found'.format(group_geom))
@ -98,13 +98,13 @@ for name in filenames:
try:
quats = np.reshape(inFile[dataset][...],(np.product(grid),4))
rot = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in quats]
except:
except KeyError:
errors.append('Pointwise orientation (quaternion) data ({}) not readable'.format(dataset))
dataset = os.path.join(group_pointwise,options.phase)
try:
phase = np.reshape(inFile[dataset][...],(np.product(grid)))
except:
except KeyError:
errors.append('Pointwise phase data ({}) not readable'.format(dataset))
microstructure = np.arange(1,np.product(grid)+1,dtype=int).reshape(grid,order='F')
@ -116,7 +116,7 @@ for name in filenames:
dataset = os.path.join(group_pointwise,options.microstructure)
try:
microstructure = np.transpose(inFile[dataset][...].reshape(grid[::-1]),(2,1,0)) # convert from C ordering
except:
except KeyError:
errors.append('Link between pointwise and grain average data ({}) not readable'.format(dataset))
group_average = os.path.join(rootDir,options.basegroup,options.average)
@ -124,13 +124,13 @@ for name in filenames:
dataset = os.path.join(group_average,options.quaternion)
try:
rot = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in inFile[dataset][...][1:]] # skip first entry (unindexed)
except:
except KeyError:
errors.append('Average orientation data ({}) not readable'.format(dataset))
dataset = os.path.join(group_average,options.phase)
try:
phase = [i[0] for i in inFile[dataset][...]][1:] # skip first entry (unindexed)
except:
except KeyError:
errors.append('Average phase data ({}) not readable'.format(dataset))
if errors != []:
@ -155,4 +155,4 @@ for name in filenames:
homogenization=options.homogenization,comments=header)
damask.util.croak(geom)
geom.to_file(os.path.splitext(name)[0]+'.geom')
geom.to_file(os.path.splitext(name)[0]+'.geom',pack=False)

View File

@ -89,7 +89,4 @@ geom=damask.Geom(microstructure,options.size,
comments=[scriptID + ' ' + ' '.join(sys.argv[1:])])
damask.util.croak(geom)
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -145,7 +145,4 @@ geom = damask.Geom(microstructure.reshape(grid),
homogenization=options.homogenization,comments=header)
damask.util.croak(geom)
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -63,7 +63,4 @@ geom = damask.Geom(microstructure=np.full(options.grid,options.fill,dtype=dtype)
comments=scriptID + ' ' + ' '.join(sys.argv[1:]))
damask.util.croak(geom)
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -152,7 +152,4 @@ for name in filenames:
homogenization=options.homogenization,comments=header)
damask.util.croak(geom)
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(os.path.splitext(name)[0]+'.geom')
geom.to_file(sys.stdout if name is None else os.path.splitext(name)[0]+'.geom',pack=False)

View File

@ -302,7 +302,4 @@ for name in filenames:
homogenization=options.homogenization,comments=header)
damask.util.croak(geom)
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(os.path.splitext(name)[0]+'.geom')
geom.to_file(sys.stdout if name is None else os.path.splitext(name)[0]+'.geom',pack=False)

View File

@ -172,7 +172,4 @@ for name in filenames:
damask.util.croak(geom.update(microstructure[0:grid_original[0],0:grid_original[1],0:grid_original[2]]))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -5,8 +5,6 @@ import sys
from io import StringIO
from optparse import OptionParser
import numpy as np
import damask
@ -38,35 +36,12 @@ parser.set_defaults(reflect = False)
(options, filenames) = parser.parse_args()
if options.directions is None:
parser.error('no direction given.')
if not set(options.directions).issubset(validDirections):
invalidDirections = [str(e) for e in set(options.directions).difference(validDirections)]
parser.error('invalid directions {}. '.format(*invalidDirections))
limits = [None,None] if options.reflect else [-2,0]
if filenames == []: filenames = [None]
for name in filenames:
damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
microstructure = geom.get_microstructure()
if 'z' in options.directions:
microstructure = np.concatenate([microstructure,microstructure[:,:,limits[0]:limits[1]:-1]],2)
if 'y' in options.directions:
microstructure = np.concatenate([microstructure,microstructure[:,limits[0]:limits[1]:-1,:]],1)
if 'x' in options.directions:
microstructure = np.concatenate([microstructure,microstructure[limits[0]:limits[1]:-1,:,:]],0)
damask.util.croak(geom.update(microstructure,rescale=True))
damask.util.croak(geom.mirror(options.directions,options.reflect))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -34,41 +34,4 @@ for name in filenames:
damask.util.croak(geom)
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
compressType = None
former = start = -1
reps = 0
if name is None:
f = sys.stdout
else:
f= open(name,'w')
for current in geom.microstructure.flatten('F'):
if abs(current - former) == 1 and (start - current) == reps*(former - current):
compressType = 'to'
reps += 1
elif current == former and start == former:
compressType = 'of'
reps += 1
else:
if compressType is None:
f.write('\n'.join(geom.get_header())+'\n')
elif compressType == '.':
f.write('{}\n'.format(former))
elif compressType == 'to':
f.write('{} to {}\n'.format(start,former))
elif compressType == 'of':
f.write('{} of {}\n'.format(reps,former))
compressType = '.'
start = current
reps = 1
former = current
if compressType == '.':
f.write('{}\n'.format(former))
elif compressType == 'to':
f.write('{} to {}\n'.format(start,former))
elif compressType == 'of':
f.write('{} of {}\n'.format(reps,former))
geom.to_file(sys.stdout if name is None else name,pack=True)

View File

@ -5,8 +5,6 @@ import sys
from io import StringIO
from optparse import OptionParser
import numpy as np
import damask
@ -32,15 +30,6 @@ for name in filenames:
damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
renumbered = np.empty(geom.get_grid(),dtype=geom.microstructure.dtype)
for i, oldID in enumerate(np.unique(geom.microstructure)):
renumbered = np.where(geom.microstructure == oldID, i+1, renumbered)
damask.util.croak(geom.update(renumbered))
damask.util.croak(geom.renumber())
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -2,11 +2,10 @@
import os
import sys
import numpy as np
from io import StringIO
from optparse import OptionParser
from scipy import ndimage
import numpy as np
import damask
@ -55,20 +54,7 @@ for name in filenames:
np.array([o*float(n.lower().replace('x','')) if n.lower().endswith('x') \
else float(n) for o,n in zip(size,options.size)],dtype=float)
damask.util.croak(geom.update(microstructure =
ndimage.interpolation.zoom(
geom.microstructure,
new_grid/grid,
output=geom.microstructure.dtype,
order=0,
mode='nearest',
prefilter=False,
) if np.any(new_grid != grid) \
else None,
size = new_size))
geom.scale(new_grid)
damask.util.croak(geom.update(microstructure = None,size = new_size))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -95,7 +95,4 @@ for name in filenames:
damask.util.croak(geom.update(microstructure,origin=origin-(np.asarray(microstructure.shape)-grid)/2*size/grid,rescale=True))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -58,7 +58,4 @@ for name in filenames:
damask.util.croak(geom.update(substituted,origin=geom.get_origin()+options.origin))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -34,7 +34,4 @@ for name in filenames:
damask.util.croak(geom)
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -82,7 +82,4 @@ for name in filenames:
geom.microstructure + offset,geom.microstructure)))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None:
sys.stdout.write(str(geom.show()))
else:
geom.to_file(name)
geom.to_file(sys.stdout if name is None else name,pack=False)

View File

@ -2,7 +2,7 @@ import os
import sys
import re
import shlex
from collections import Iterable
from collections.abc import Iterable
import numpy as np
@ -15,7 +15,7 @@ except NameError:
# ------------------------------------------------------------------
class ASCIItable():
"""Read and write to ASCII tables"""
"""Read and write to ASCII tables."""
tmpext = '_tmp' # filename extension for in-place access
@ -27,6 +27,7 @@ class ASCIItable():
labeled = True, # assume table has labels
readonly = False, # no reading from file
):
"""Read and write to ASCII tables."""
self.__IO__ = {'output': [],
'buffered': buffered,
'labeled': labeled, # header contains labels
@ -72,7 +73,7 @@ class ASCIItable():
# ------------------------------------------------------------------
def _removeCRLF(self,
string):
"""Delete any carriage return and line feed from string"""
"""Delete any carriage return and line feed from string."""
try:
return string.replace('\n','').replace('\r','')
except AttributeError:
@ -82,7 +83,7 @@ class ASCIItable():
# ------------------------------------------------------------------
def _quote(self,
what):
"""Quote empty or white space-containing output"""
"""Quote empty or white space-containing output."""
return '{quote}{content}{quote}'.format(
quote = ('"' if str(what)=='' or re.search(r"\s",str(what)) else ''),
content = what)
@ -103,7 +104,7 @@ class ASCIItable():
# ------------------------------------------------------------------
def output_write(self,
what):
"""Aggregate a single row (string) or list of (possibly containing further lists of) rows into output"""
"""Aggregate a single row (string) or list of (possibly containing further lists of) rows into output."""
if isinstance(what, (str, unicode)):
self.__IO__['output'] += [what]
else:
@ -143,7 +144,7 @@ class ASCIItable():
# ------------------------------------------------------------------
def head_read(self):
"""
Get column labels
Get column labels.
by either reading the first row or,
if keyword "head[*]" is present, the last line of the header
@ -154,7 +155,7 @@ class ASCIItable():
pass
firstline = self.__IO__['in'].readline().strip()
m = re.search('(\d+)\s+head', firstline.lower()) # search for "head" keyword
m = re.search(r'(\d+)\s+head', firstline.lower()) # search for "head" keyword
if m: # proper ASCIItable format
@ -194,7 +195,7 @@ class ASCIItable():
# ------------------------------------------------------------------
def head_write(self,
header = True):
"""Write current header information (info + labels)"""
"""Write current header information (info + labels)."""
head = ['{}\theader'.format(len(self.info)+self.__IO__['labeled'])] if header else []
head.append(self.info)
if self.__IO__['labeled']:
@ -205,7 +206,7 @@ class ASCIItable():
# ------------------------------------------------------------------
def head_getGeom(self):
"""Interpret geom header"""
"""Interpret geom header."""
identifiers = {
'grid': ['a','b','c'],
'size': ['x','y','z'],
@ -247,7 +248,7 @@ class ASCIItable():
def labels_append(self,
what,
reset = False):
"""Add item or list to existing set of labels (and switch on labeling)"""
"""Add item or list to existing set of labels (and switch on labeling)."""
if isinstance(what, (str, unicode)):
self.tags += [self._removeCRLF(what)]
else:
@ -261,7 +262,7 @@ class ASCIItable():
# ------------------------------------------------------------------
def labels_clear(self):
"""Delete existing labels and switch to no labeling"""
"""Delete existing labels and switch to no labeling."""
self.tags = []
self.__IO__['labeled'] = False
@ -392,7 +393,7 @@ class ASCIItable():
# ------------------------------------------------------------------
def info_append(self,
what):
"""Add item or list to existing set of infos"""
"""Add item or list to existing set of infos."""
if isinstance(what, (str, unicode)):
self.info += [self._removeCRLF(what)]
else:
@ -403,7 +404,7 @@ class ASCIItable():
# ------------------------------------------------------------------
def info_clear(self):
"""Delete any info block"""
"""Delete any info block."""
self.info = []
# ------------------------------------------------------------------
@ -416,7 +417,7 @@ class ASCIItable():
# ------------------------------------------------------------------
def data_skipLines(self,
count):
"""Wind forward by count number of lines"""
"""Wind forward by count number of lines."""
for i in range(count):
alive = self.data_read()
@ -426,7 +427,7 @@ class ASCIItable():
def data_read(self,
advance = True,
respectLabels = True):
"""Read next line (possibly buffered) and parse it into data array"""
"""Read next line (possibly buffered) and parse it into data array."""
self.line = self.__IO__['readBuffer'].pop(0) if len(self.__IO__['readBuffer']) > 0 \
else self.__IO__['in'].readline().strip() # take buffered content or get next data row from file
@ -446,9 +447,11 @@ class ASCIItable():
# ------------------------------------------------------------------
def data_readArray(self,
labels = []):
"""Read whole data of all (given) labels as numpy array"""
try: self.data_rewind() # try to wind back to start of data
except: pass # assume/hope we are at data start already...
"""Read whole data of all (given) labels as numpy array."""
try:
self.data_rewind() # try to wind back to start of data
except IOError:
pass # assume/hope we are at data start already...
if labels is None or labels == []:
use = None # use all columns (and keep labels intact)
@ -480,7 +483,7 @@ class ASCIItable():
# ------------------------------------------------------------------
def data_write(self,
delimiter = '\t'):
"""Write current data array and report alive output back"""
"""Write current data array and report alive output back."""
if len(self.data) == 0: return True
if isinstance(self.data[0],list):
@ -492,16 +495,16 @@ class ASCIItable():
def data_writeArray(self,
fmt = None,
delimiter = '\t'):
"""Write whole numpy array data"""
"""Write whole numpy array data."""
for row in self.data:
try:
output = [fmt % value for value in row] if fmt else list(map(repr,row))
except:
except Exception:
output = [fmt % row] if fmt else [repr(row)]
try:
self.__IO__['out'].write(delimiter.join(output) + '\n')
except:
except Exception:
pass
# ------------------------------------------------------------------
@ -545,7 +548,7 @@ class ASCIItable():
grid,
type = 'i',
strict = False):
"""Read microstructure data (from .geom format)"""
"""Read microstructure data (from .geom format)."""
def datatype(item):
return int(item) if type.lower() == 'i' else float(item)

View File

@ -369,7 +369,7 @@ class DADF5():
return f[self.get_dataset_location('orientation')[0]].attrs['Lattice'].astype('str') # np.bytes_ to string
def read_dataset(self,path,c):
def read_dataset(self,path,c=0,plain=False):
"""
Dataset for all points/cells.
@ -402,6 +402,9 @@ class DADF5():
a=a.reshape([a.shape[0],1])
dataset[p,:] = a[u,:]
if plain and dataset.dtype.names is not None:
return dataset.view(('float64',len(dataset.dtype.names)))
else:
return dataset
@ -620,7 +623,7 @@ class DADF5():
raise ValueError
return {
'data': mechanics.deviator(x['data']),
'data': mechanics.deviatoric_part(x['data']),
'label': 's_{}'.format(x['label']),
'meta': {
'Unit': x['meta']['Unit'],

View File

@ -2,6 +2,7 @@ import os
from io import StringIO
import numpy as np
from scipy import ndimage
import vtk
from vtk.util import numpy_support
@ -30,7 +31,6 @@ class Geom():
comments lines.
"""
self.__transforms__ = \
self.set_microstructure(microstructure)
self.set_size(size)
self.set_origin(origin)
@ -250,7 +250,11 @@ class Geom():
geometry file to read.
"""
with (open(fname) if isinstance(fname,str) else fname) as f:
try:
f = open(fname)
except TypeError:
f = fname
f.seek(0)
header_length,keyword = f.readline().split()[:2]
header_length = int(header_length)
@ -286,7 +290,6 @@ class Geom():
abs(int(items[2])-int(items[0]))+1,dtype=float)
else: items = list(map(float,items))
else: items = list(map(float,items))
microstructure[i:i+len(items)] = items
i += len(items)
@ -299,7 +302,8 @@ class Geom():
return cls(microstructure.reshape(grid),size,origin,homogenization,comments)
def to_file(self,fname):
def to_file(self,fname,pack=None):
"""
Writes a geom file.
@ -307,16 +311,62 @@ class Geom():
----------
fname : str or file handle
geometry file to write.
pack : bool, optional
compress geometry with 'x of y' and 'a to b'.
"""
header = self.get_header()
grid = self.get_grid()
format_string = '%{}i'.format(1+int(np.floor(np.log10(np.nanmax(self.microstructure))))) if self.microstructure.dtype == int \
else '%g'
if pack is None:
plain = grid.prod()/np.unique(self.microstructure).size < 250
else:
plain = not pack
if plain:
format_string = '%g' if self.microstructure.dtype in np.sctypes['float'] else \
'%{}i'.format(1+int(np.floor(np.log10(np.nanmax(self.microstructure)))))
np.savetxt(fname,
self.microstructure.reshape([grid[0],np.prod(grid[1:])],order='F').T,
header='\n'.join(header), fmt=format_string, comments='')
else:
try:
f = open(fname,'w')
except TypeError:
f = fname
compressType = None
former = start = -1
reps = 0
for current in self.microstructure.flatten('F'):
if abs(current - former) == 1 and (start - current) == reps*(former - current):
compressType = 'to'
reps += 1
elif current == former and start == former:
compressType = 'of'
reps += 1
else:
if compressType is None:
f.write('\n'.join(self.get_header())+'\n')
elif compressType == '.':
f.write('{}\n'.format(former))
elif compressType == 'to':
f.write('{} to {}\n'.format(start,former))
elif compressType == 'of':
f.write('{} of {}\n'.format(reps,former))
compressType = '.'
start = current
reps = 1
former = current
if compressType == '.':
f.write('{}\n'.format(former))
elif compressType == 'to':
f.write('{} to {}\n'.format(start,former))
elif compressType == 'of':
f.write('{} of {}\n'.format(reps,former))
def to_vtk(self,fname=None):
@ -387,3 +437,91 @@ class Geom():
self.to_file(f)
f.seek(0)
return ''.join(f.readlines())
def mirror(self,directions,reflect=False):
"""
Mirror microstructure along given directions.
Parameters
----------
directions : iterable containing str
direction(s) along which the microstructure is mirrored. Valid entries are 'x', 'y', 'z'.
reflect : bool, optional
reflect (include) outermost layers.
"""
valid = {'x','y','z'}
if not all(isinstance(d, str) for d in directions):
raise TypeError('Directions are not of type str.')
elif not set(directions).issubset(valid):
raise ValueError('Invalid direction specified {}'.format(*set(directions).difference(valid)))
limits = [None,None] if reflect else [-2,0]
ms = self.get_microstructure()
if 'z' in directions:
ms = np.concatenate([ms,ms[:,:,limits[0]:limits[1]:-1]],2)
if 'y' in directions:
ms = np.concatenate([ms,ms[:,limits[0]:limits[1]:-1,:]],1)
if 'x' in directions:
ms = np.concatenate([ms,ms[limits[0]:limits[1]:-1,:,:]],0)
return self.update(ms,rescale=True)
#self.add_comments('tbd')
def scale(self,grid):
"""
Scale microstructure to new grid.
Parameters
----------
grid : iterable of int
new grid dimension
"""
return self.update(
ndimage.interpolation.zoom(
self.microstructure,
grid/self.get_grid(),
output=self.microstructure.dtype,
order=0,
mode='nearest',
prefilter=False
)
)
#self.add_comments('tbd')
def clean(self,stencil=3):
"""
Smooth microstructure by selecting most frequent index within given stencil at each location.
Parameters
----------
stencil : int, optional
size of smoothing stencil.
"""
def mostFrequent(arr):
unique, inverse = np.unique(arr, return_inverse=True)
return unique[np.argmax(np.bincount(inverse))]
return self.update(ndimage.filters.generic_filter(
self.microstructure,
mostFrequent,
size=(stencil,)*3
).astype(self.microstructure.dtype)
)
#self.add_comments('tbd')
def renumber(self):
"""Renumber sorted microstructure indices to 1,...,N."""
renumbered = np.empty(self.get_grid(),dtype=self.microstructure.dtype)
for i, oldID in enumerate(np.unique(self.microstructure)):
renumbered = np.where(self.microstructure == oldID, i+1, renumbered)
return self.update(renumbered)
#self.add_comments('tbd')

View File

@ -48,10 +48,10 @@ def strain_tensor(F,t,m):
if m > 0.0:
eps = 1.0/(2.0*abs(m)) * (+ np.matmul(n,np.einsum('ij,ikj->ijk',w**m,n))
- np.broadcast_to(np.ones(3),[F_.shape[0],3]))
- np.broadcast_to(np.eye(3),[F_.shape[0],3,3]))
elif m < 0.0:
eps = 1.0/(2.0*abs(m)) * (- np.matmul(n,np.einsum('ij,ikj->ijk',w**m,n))
+ np.broadcast_to(np.ones(3),[F_.shape[0],3]))
+ np.broadcast_to(np.eye(3),[F_.shape[0],3,3]))
else:
eps = np.matmul(n,np.einsum('ij,ikj->ijk',0.5*np.log(w),n))
@ -190,7 +190,7 @@ def rotational_part(x):
Tensor of which the rotational part is computed.
"""
return __polar_decomposition(x,'R')
return __polar_decomposition(x,'R')[0]
def left_stretch(x):
@ -203,7 +203,7 @@ def left_stretch(x):
Tensor of which the left stretch is computed.
"""
return __polar_decomposition(x,'V')
return __polar_decomposition(x,'V')[0]
def right_stretch(x):
@ -216,7 +216,7 @@ def right_stretch(x):
Tensor of which the right stretch is computed.
"""
return __polar_decomposition(x,'U')
return __polar_decomposition(x,'U')[0]
def __polar_decomposition(x,requested):
@ -227,7 +227,7 @@ def __polar_decomposition(x,requested):
----------
x : numpy.array of shape (:,3,3) or (3,3)
Tensor of which the singular values are computed.
requested : list of str
requested : iterable of str
Requested outputs: R for the rotation tensor,
V for left stretch tensor and U for right stretch tensor.

View File

@ -79,9 +79,9 @@ class Marc(Solver):
exitnumber = -1
fid_out = open(outFile,'r')
for line in fid_out:
if (string.find(line,'tress iteration') is not -1):
if (string.find(line,'tress iteration') != -1):
print(line)
elif (string.find(line,'Exit number') is not -1):
elif (string.find(line,'Exit number') != -1):
substr = line[string.find(line,'Exit number'):len(line)]
exitnumber = int(substr[12:16])

View File

@ -1,10 +1,8 @@
# -*- coding: UTF-8 no BOM -*-
import os,sys,shutil
import logging,logging.config
import damask
import numpy as np
from collections import Iterable
from collections.abc import Iterable
from optparse import OptionParser
class Test():
@ -17,7 +15,7 @@ class Test():
variants = []
def __init__(self, **kwargs):
"""New test."""
defaults = {'description': '',
'keep': False,
'accept': False,
@ -120,22 +118,22 @@ class Test():
"""Delete directory tree containing current results."""
try:
shutil.rmtree(self.dirCurrent())
except:
except FileNotFoundError:
logging.warning('removal of directory "{}" not possible...'.format(self.dirCurrent()))
try:
os.mkdir(self.dirCurrent())
return True
except:
except FileExistsError:
logging.critical('creation of directory "{}" failed.'.format(self.dirCurrent()))
return False
def prepareAll(self):
"""Do all necessary preparations for the whole test"""
"""Do all necessary preparations for the whole test."""
return True
def prepare(self,variant):
"""Do all necessary preparations for the run of each test variant"""
"""Do all necessary preparations for the run of each test variant."""
return True
@ -207,9 +205,9 @@ class Test():
for source,target in zip(list(map(mapA,A)),list(map(mapB,B))):
try:
shutil.copy2(source,target)
except:
except FileNotFoundError:
logging.critical('error copying {} to {}'.format(source,target))
raise
raise FileNotFoundError
def copy_Reference2Current(self,sourcefiles=[],targetfiles=[]):
@ -218,9 +216,9 @@ class Test():
for i,f in enumerate(sourcefiles):
try:
shutil.copy2(self.fileInReference(f),self.fileInCurrent(targetfiles[i]))
except:
except FileNotFoundError:
logging.critical('Reference2Current: Unable to copy file "{}"'.format(f))
raise
raise FileNotFoundError
def copy_Base2Current(self,sourceDir,sourcefiles=[],targetfiles=[]):
@ -230,10 +228,10 @@ class Test():
for i,f in enumerate(sourcefiles):
try:
shutil.copy2(os.path.join(source,f),self.fileInCurrent(targetfiles[i]))
except:
except FileNotFoundError:
logging.error(os.path.join(source,f))
logging.critical('Base2Current: Unable to copy file "{}"'.format(f))
raise
raise FileNotFoundError
def copy_Current2Reference(self,sourcefiles=[],targetfiles=[]):
@ -242,9 +240,9 @@ class Test():
for i,f in enumerate(sourcefiles):
try:
shutil.copy2(self.fileInCurrent(f),self.fileInReference(targetfiles[i]))
except:
except FileNotFoundError:
logging.critical('Current2Reference: Unable to copy file "{}"'.format(f))
raise
raise FileNotFoundError
def copy_Proof2Current(self,sourcefiles=[],targetfiles=[]):
@ -253,9 +251,9 @@ class Test():
for i,f in enumerate(sourcefiles):
try:
shutil.copy2(self.fileInProof(f),self.fileInCurrent(targetfiles[i]))
except:
except FileNotFoundError:
logging.critical('Proof2Current: Unable to copy file "{}"'.format(f))
raise
raise FileNotFoundError
def copy_Current2Current(self,sourcefiles=[],targetfiles=[]):
@ -263,9 +261,10 @@ class Test():
for i,f in enumerate(sourcefiles):
try:
shutil.copy2(self.fileInReference(f),self.fileInCurrent(targetfiles[i]))
except:
except FileNotFoundError:
logging.critical('Current2Current: Unable to copy file "{}"'.format(f))
raise
raise FileNotFoundError
def execute_inCurrentDir(self,cmd,streamIn=None,env=None):
@ -439,7 +438,7 @@ class Test():
stdTol = 1.0e-6,
preFilter = 1.0e-9):
"""
Calculate statistics of tables
Calculate statistics of tables.
threshold can be used to ignore small values (a negative number disables this feature)
"""
@ -492,7 +491,7 @@ class Test():
rtol = 1e-5,
atol = 1e-8,
debug = False):
"""Compare multiple tables with np.allclose"""
"""Compare multiple tables with np.allclose."""
if not (isinstance(files, Iterable) and not isinstance(files, str)): # check whether list of files is requested
files = [str(files)]

View File

@ -1,3 +0,0 @@
"""Test functionality."""
from .test import Test # noqa