Merge branch 'MiscImprovements' into development
This commit is contained in:
commit
2012297188
|
@ -10,8 +10,8 @@
|
||||||
*.pdf binary
|
*.pdf binary
|
||||||
|
|
||||||
# ignore files from MSC.Marc in language statistics
|
# ignore files from MSC.Marc in language statistics
|
||||||
installation/mods_MarcMentat/* linguist-vendored
|
installation/mods_MarcMentat/20*/* linguist-vendored
|
||||||
src/MarcInclude/* linguist-vendored
|
src/marc/include/* linguist-vendored
|
||||||
|
|
||||||
# ignore reference files for tests in language statistics
|
# ignore reference files for tests in language statistics
|
||||||
python/tests/reference/* linguist-vendored
|
python/tests/reference/* linguist-vendored
|
||||||
|
|
|
@ -75,7 +75,7 @@ class Result:
|
||||||
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,
|
||||||
'constituents': self.constituents,'materialpoints': self.materialpoints,
|
'constituents': self.constituents,'materialpoints': self.materialpoints,
|
||||||
'con_physics': self.con_physics, 'mat_physics': self.mat_physics
|
'con_physics': self.con_physics, 'mat_physics': self.mat_physics
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ class Result:
|
||||||
iterator = map(float,choice)
|
iterator = map(float,choice)
|
||||||
choice = []
|
choice = []
|
||||||
for c in iterator:
|
for c in iterator:
|
||||||
idx=np.searchsorted(self.times,c)
|
idx = np.searchsorted(self.times,c)
|
||||||
if np.isclose(c,self.times[idx]):
|
if np.isclose(c,self.times[idx]):
|
||||||
choice.append(self.increments[idx])
|
choice.append(self.increments[idx])
|
||||||
elif np.isclose(c,self.times[idx+1]):
|
elif np.isclose(c,self.times[idx+1]):
|
||||||
|
@ -141,12 +141,12 @@ class Result:
|
||||||
if action == 'set':
|
if action == 'set':
|
||||||
self.selection[what] = valid
|
self.selection[what] = valid
|
||||||
elif action == 'add':
|
elif action == 'add':
|
||||||
add=existing.union(valid)
|
add = existing.union(valid)
|
||||||
add_sorted=sorted(add, key=lambda x: int("".join([i for i in x if i.isdigit()])))
|
add_sorted = sorted(add, key=lambda x: int("".join([i for i in x if i.isdigit()])))
|
||||||
self.selection[what] = add_sorted
|
self.selection[what] = add_sorted
|
||||||
elif action == 'del':
|
elif action == 'del':
|
||||||
diff=existing.difference(valid)
|
diff = existing.difference(valid)
|
||||||
diff_sorted=sorted(diff, key=lambda x: int("".join([i for i in x if i.isdigit()])))
|
diff_sorted = sorted(diff, key=lambda x: int("".join([i for i in x if i.isdigit()])))
|
||||||
self.selection[what] = diff_sorted
|
self.selection[what] = diff_sorted
|
||||||
|
|
||||||
|
|
||||||
|
@ -350,7 +350,7 @@ class Result:
|
||||||
groups.append(group)
|
groups.append(group)
|
||||||
else:
|
else:
|
||||||
match = [e for e_ in [glob.fnmatch.filter(f[group].keys(),s) for s in sets] for e in e_]
|
match = [e for e_ in [glob.fnmatch.filter(f[group].keys(),s) for s in sets] for e in e_]
|
||||||
if len(set(match)) == len(sets) : groups.append(group)
|
if len(set(match)) == len(sets): groups.append(group)
|
||||||
return groups
|
return groups
|
||||||
|
|
||||||
|
|
||||||
|
@ -359,17 +359,17 @@ class Result:
|
||||||
message = ''
|
message = ''
|
||||||
with h5py.File(self.fname,'r') as f:
|
with h5py.File(self.fname,'r') as f:
|
||||||
for i in self.iterate('increments'):
|
for i in self.iterate('increments'):
|
||||||
message+='\n{} ({}s)\n'.format(i,self.times[self.increments.index(i)])
|
message += '\n{} ({}s)\n'.format(i,self.times[self.increments.index(i)])
|
||||||
for o,p in zip(['constituents','materialpoints'],['con_physics','mat_physics']):
|
for o,p in zip(['constituents','materialpoints'],['con_physics','mat_physics']):
|
||||||
for oo in self.iterate(o):
|
for oo in self.iterate(o):
|
||||||
message+=' {}\n'.format(oo)
|
message += ' {}\n'.format(oo)
|
||||||
for pp in self.iterate(p):
|
for pp in self.iterate(p):
|
||||||
message+=' {}\n'.format(pp)
|
message += ' {}\n'.format(pp)
|
||||||
group = '/'.join([i,o[:-1],oo,pp]) # o[:-1]: plural/singular issue
|
group = '/'.join([i,o[:-1],oo,pp]) # o[:-1]: plural/singular issue
|
||||||
for d in f[group].keys():
|
for d in f[group].keys():
|
||||||
try:
|
try:
|
||||||
dataset = f['/'.join([group,d])]
|
dataset = f['/'.join([group,d])]
|
||||||
message+=' {} / ({}): {}\n'.\
|
message += ' {} / ({}): {}\n'.\
|
||||||
format(d,dataset.attrs['Unit'].decode(),dataset.attrs['Description'].decode())
|
format(d,dataset.attrs['Unit'].decode(),dataset.attrs['Description'].decode())
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
@ -385,7 +385,7 @@ class Result:
|
||||||
try:
|
try:
|
||||||
f[k]
|
f[k]
|
||||||
path.append(k)
|
path.append(k)
|
||||||
except KeyError as e:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
for o,p in zip(['constituents','materialpoints'],['con_physics','mat_physics']):
|
for o,p in zip(['constituents','materialpoints'],['con_physics','mat_physics']):
|
||||||
for oo in self.iterate(o):
|
for oo in self.iterate(o):
|
||||||
|
@ -394,7 +394,7 @@ class Result:
|
||||||
try:
|
try:
|
||||||
f[k]
|
f[k]
|
||||||
path.append(k)
|
path.append(k)
|
||||||
except KeyError as e:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
@ -425,7 +425,7 @@ class Result:
|
||||||
for pa in path:
|
for pa in path:
|
||||||
label = pa.split('/')[2]
|
label = pa.split('/')[2]
|
||||||
|
|
||||||
if (pa.split('/')[1] == 'geometry'):
|
if pa.split('/')[1] == 'geometry':
|
||||||
dataset = np.array(f[pa])
|
dataset = np.array(f[pa])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -661,8 +661,8 @@ class Result:
|
||||||
|
|
||||||
lattice = q['meta']['Lattice']
|
lattice = q['meta']['Lattice']
|
||||||
|
|
||||||
for i,q in enumerate(q['data']):
|
for i,qu in enumerate(q['data']):
|
||||||
o = Orientation(np.array([q['w'],q['x'],q['y'],q['z']]),lattice).reduced()
|
o = Orientation(np.array([qu['w'],qu['x'],qu['y'],qu['z']]),lattice).reduced()
|
||||||
colors[i] = np.uint8(o.IPFcolor(d_unit)*255)
|
colors[i] = np.uint8(o.IPFcolor(d_unit)*255)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -814,8 +814,8 @@ class Result:
|
||||||
m = util.scale_to_coprime(pole)
|
m = util.scale_to_coprime(pole)
|
||||||
coords = np.empty((len(q['data']),2))
|
coords = np.empty((len(q['data']),2))
|
||||||
|
|
||||||
for i,q in enumerate(q['data']):
|
for i,qu in enumerate(q['data']):
|
||||||
o = Rotation(np.array([q['w'],q['x'],q['y'],q['z']]))
|
o = Rotation(np.array([qu['w'],qu['x'],qu['y'],qu['z']]))
|
||||||
rotatedPole = o*unit_pole # rotate pole according to crystal orientation
|
rotatedPole = o*unit_pole # rotate pole according to crystal orientation
|
||||||
(x,y) = rotatedPole[0:2]/(1.+abs(unit_pole[2])) # stereographic projection
|
(x,y) = rotatedPole[0:2]/(1.+abs(unit_pole[2])) # stereographic projection
|
||||||
coords[i] = [np.sqrt(x*x+y*y),np.arctan2(y,x)] if polar else [x,y]
|
coords[i] = [np.sqrt(x*x+y*y),np.arctan2(y,x)] if polar else [x,y]
|
||||||
|
@ -1048,7 +1048,7 @@ class Result:
|
||||||
|
|
||||||
N_digits = int(np.floor(np.log10(int(self.increments[-1][3:]))))+1
|
N_digits = int(np.floor(np.log10(int(self.increments[-1][3:]))))+1
|
||||||
|
|
||||||
for i,inc in enumerate(util.show_progress(self.iterate('increments'),len(self.selection['increments']))):
|
for inc in util.show_progress(self.iterate('increments'),len(self.selection['increments'])):
|
||||||
|
|
||||||
materialpoints_backup = self.selection['materialpoints'].copy()
|
materialpoints_backup = self.selection['materialpoints'].copy()
|
||||||
self.pick('materialpoints',False)
|
self.pick('materialpoints',False)
|
||||||
|
|
|
@ -292,7 +292,7 @@ class Rotation:
|
||||||
if degrees: ax[ 3] = np.radians(ax[3])
|
if degrees: ax[ 3] = np.radians(ax[3])
|
||||||
if normalise: ax[0:3] /= np.linalg.norm(ax[0:3])
|
if normalise: ax[0:3] /= np.linalg.norm(ax[0:3])
|
||||||
if ax[3] < 0.0 or ax[3] > np.pi:
|
if ax[3] < 0.0 or ax[3] > np.pi:
|
||||||
raise ValueError('Axis angle rotation angle outside of [0..π].\n'.format(ax[3]))
|
raise ValueError('Axis angle rotation angle outside of [0..π].\n{}'.format(ax[3]))
|
||||||
if not np.isclose(np.linalg.norm(ax[0:3]), 1.0):
|
if not np.isclose(np.linalg.norm(ax[0:3]), 1.0):
|
||||||
raise ValueError('Axis angle rotation axis is not of unit length.\n{} {} {}'.format(*ax[0:3]))
|
raise ValueError('Axis angle rotation axis is not of unit length.\n{} {} {}'.format(*ax[0:3]))
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@ class Rotation:
|
||||||
if not np.isclose(np.linalg.norm(ro[0:3]), 1.0):
|
if not np.isclose(np.linalg.norm(ro[0:3]), 1.0):
|
||||||
raise ValueError('Rodrigues rotation axis is not of unit length.\n{} {} {}'.format(*ro[0:3]))
|
raise ValueError('Rodrigues rotation axis is not of unit length.\n{} {} {}'.format(*ro[0:3]))
|
||||||
if ro[3] < 0.0:
|
if ro[3] < 0.0:
|
||||||
raise ValueError('Rodrigues rotation angle not positive.\n'.format(ro[3]))
|
raise ValueError('Rodrigues rotation angle not positive.\n{}'.format(ro[3]))
|
||||||
|
|
||||||
return Rotation(Rotation.ro2qu(ro))
|
return Rotation(Rotation.ro2qu(ro))
|
||||||
|
|
||||||
|
@ -365,8 +365,7 @@ class Rotation:
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fromAverage(rotations,
|
def fromAverage(rotations,weights = None):
|
||||||
weights = []):
|
|
||||||
"""
|
"""
|
||||||
Average rotation.
|
Average rotation.
|
||||||
|
|
||||||
|
@ -387,7 +386,7 @@ class Rotation:
|
||||||
raise TypeError("Only instances of Rotation can be averaged.")
|
raise TypeError("Only instances of Rotation can be averaged.")
|
||||||
|
|
||||||
N = len(rotations)
|
N = len(rotations)
|
||||||
if weights == [] or not weights:
|
if not weights:
|
||||||
weights = np.ones(N,dtype='i')
|
weights = np.ones(N,dtype='i')
|
||||||
|
|
||||||
for i,(r,n) in enumerate(zip(rotations,weights)):
|
for i,(r,n) in enumerate(zip(rotations,weights)):
|
||||||
|
|
|
@ -327,9 +327,9 @@ class Table:
|
||||||
seen = set()
|
seen = set()
|
||||||
labels = []
|
labels = []
|
||||||
for l in [x for x in self.data.columns if not (x in seen or seen.add(x))]:
|
for l in [x for x in self.data.columns if not (x in seen or seen.add(x))]:
|
||||||
if(self.shapes[l] == (1,)):
|
if self.shapes[l] == (1,):
|
||||||
labels.append('{}'.format(l))
|
labels.append('{}'.format(l))
|
||||||
elif(len(self.shapes[l]) == 1):
|
elif len(self.shapes[l]) == 1:
|
||||||
labels += ['{}_{}'.format(i+1,l) \
|
labels += ['{}_{}'.format(i+1,l) \
|
||||||
for i in range(self.shapes[l][0])]
|
for i in range(self.shapes[l][0])]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -103,7 +103,7 @@ class VTK:
|
||||||
Spatial position of the points.
|
Spatial position of the points.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
vtk_points= vtk.vtkPoints()
|
vtk_points = vtk.vtkPoints()
|
||||||
vtk_points.SetData(np_to_vtk(points))
|
vtk_points.SetData(np_to_vtk(points))
|
||||||
|
|
||||||
geom = vtk.vtkPolyData()
|
geom = vtk.vtkPolyData()
|
||||||
|
@ -168,11 +168,11 @@ class VTK:
|
||||||
Filename for writing.
|
Filename for writing.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if (isinstance(self.geom,vtk.vtkRectilinearGrid)):
|
if isinstance(self.geom,vtk.vtkRectilinearGrid):
|
||||||
writer = vtk.vtkXMLRectilinearGridWriter()
|
writer = vtk.vtkXMLRectilinearGridWriter()
|
||||||
elif(isinstance(self.geom,vtk.vtkUnstructuredGrid)):
|
elif isinstance(self.geom,vtk.vtkUnstructuredGrid):
|
||||||
writer = vtk.vtkXMLUnstructuredGridWriter()
|
writer = vtk.vtkXMLUnstructuredGridWriter()
|
||||||
elif(isinstance(self.geom,vtk.vtkPolyData)):
|
elif isinstance(self.geom,vtk.vtkPolyData):
|
||||||
writer = vtk.vtkXMLPolyDataWriter()
|
writer = vtk.vtkXMLPolyDataWriter()
|
||||||
|
|
||||||
default_ext = writer.GetDefaultFileExtension()
|
default_ext = writer.GetDefaultFileExtension()
|
||||||
|
@ -234,17 +234,17 @@ class VTK:
|
||||||
|
|
||||||
ren = vtk.vtkRenderer()
|
ren = vtk.vtkRenderer()
|
||||||
|
|
||||||
renWin = vtk.vtkRenderWindow()
|
window = vtk.vtkRenderWindow()
|
||||||
renWin.AddRenderer(ren)
|
window.AddRenderer(ren)
|
||||||
|
|
||||||
ren.AddActor(actor)
|
ren.AddActor(actor)
|
||||||
ren.SetBackground(0.2,0.2,0.2)
|
ren.SetBackground(0.2,0.2,0.2)
|
||||||
|
|
||||||
renWin.SetSize(Environment().screen_width,Environment().screen_height)
|
window.SetSize(Environment().screen_width,Environment().screen_height)
|
||||||
|
|
||||||
iren = vtk.vtkRenderWindowInteractor()
|
iren = vtk.vtkRenderWindowInteractor()
|
||||||
iren.SetRenderWindow(renWin)
|
iren.SetRenderWindow(window)
|
||||||
|
|
||||||
iren.Initialize()
|
iren.Initialize()
|
||||||
renWin.Render()
|
window.Render()
|
||||||
iren.Start()
|
iren.Start()
|
||||||
|
|
|
@ -41,10 +41,10 @@ def curl(size,field):
|
||||||
e[0, 2, 1] = e[2, 1, 0] = e[1, 0, 2] = -1.0
|
e[0, 2, 1] = e[2, 1, 0] = e[1, 0, 2] = -1.0
|
||||||
|
|
||||||
field_fourier = np.fft.rfftn(field,axes=(0,1,2))
|
field_fourier = np.fft.rfftn(field,axes=(0,1,2))
|
||||||
curl = (np.einsum('slm,ijkl,ijkm ->ijks', e,k_s,field_fourier)*2.0j*np.pi if n == 3 else # vector, 3 -> 3
|
curl_ = (np.einsum('slm,ijkl,ijkm ->ijks', e,k_s,field_fourier)*2.0j*np.pi if n == 3 else # vector, 3 -> 3
|
||||||
np.einsum('slm,ijkl,ijknm->ijksn',e,k_s,field_fourier)*2.0j*np.pi) # tensor, 3x3 -> 3x3
|
np.einsum('slm,ijkl,ijknm->ijksn',e,k_s,field_fourier)*2.0j*np.pi) # tensor, 3x3 -> 3x3
|
||||||
|
|
||||||
return np.fft.irfftn(curl,axes=(0,1,2),s=field.shape[:3])
|
return np.fft.irfftn(curl_,axes=(0,1,2),s=field.shape[:3])
|
||||||
|
|
||||||
|
|
||||||
def divergence(size,field):
|
def divergence(size,field):
|
||||||
|
@ -61,10 +61,10 @@ def divergence(size,field):
|
||||||
k_s = _ks(size,field.shape[:3],True)
|
k_s = _ks(size,field.shape[:3],True)
|
||||||
|
|
||||||
field_fourier = np.fft.rfftn(field,axes=(0,1,2))
|
field_fourier = np.fft.rfftn(field,axes=(0,1,2))
|
||||||
divergence = (np.einsum('ijkl,ijkl ->ijk', k_s,field_fourier)*2.0j*np.pi if n == 3 else # vector, 3 -> 1
|
div_ = (np.einsum('ijkl,ijkl ->ijk', k_s,field_fourier)*2.0j*np.pi if n == 3 else # vector, 3 -> 1
|
||||||
np.einsum('ijkm,ijklm->ijkl',k_s,field_fourier)*2.0j*np.pi) # tensor, 3x3 -> 3
|
np.einsum('ijkm,ijklm->ijkl',k_s,field_fourier)*2.0j*np.pi) # tensor, 3x3 -> 3
|
||||||
|
|
||||||
return np.fft.irfftn(divergence,axes=(0,1,2),s=field.shape[:3])
|
return np.fft.irfftn(div_,axes=(0,1,2),s=field.shape[:3])
|
||||||
|
|
||||||
|
|
||||||
def gradient(size,field):
|
def gradient(size,field):
|
||||||
|
@ -81,10 +81,10 @@ def gradient(size,field):
|
||||||
k_s = _ks(size,field.shape[:3],True)
|
k_s = _ks(size,field.shape[:3],True)
|
||||||
|
|
||||||
field_fourier = np.fft.rfftn(field,axes=(0,1,2))
|
field_fourier = np.fft.rfftn(field,axes=(0,1,2))
|
||||||
gradient = (np.einsum('ijkl,ijkm->ijkm', field_fourier,k_s)*2.0j*np.pi if n == 1 else # scalar, 1 -> 3
|
grad_ = (np.einsum('ijkl,ijkm->ijkm', field_fourier,k_s)*2.0j*np.pi if n == 1 else # scalar, 1 -> 3
|
||||||
np.einsum('ijkl,ijkm->ijklm',field_fourier,k_s)*2.0j*np.pi) # vector, 3 -> 3x3
|
np.einsum('ijkl,ijkm->ijklm',field_fourier,k_s)*2.0j*np.pi) # vector, 3 -> 3x3
|
||||||
|
|
||||||
return np.fft.irfftn(gradient,axes=(0,1,2),s=field.shape[:3])
|
return np.fft.irfftn(grad_,axes=(0,1,2),s=field.shape[:3])
|
||||||
|
|
||||||
|
|
||||||
def cell_coord0(grid,size,origin=np.zeros(3)):
|
def cell_coord0(grid,size,origin=np.zeros(3)):
|
||||||
|
|
Loading…
Reference in New Issue