Merge branch 'development' into modularize-mech
This commit is contained in:
commit
3fa1a03021
|
@ -385,38 +385,3 @@ class ASCIItable():
|
||||||
self.data = np.loadtxt(self.__IO__['in'],usecols=use,ndmin=2)
|
self.data = np.loadtxt(self.__IO__['in'],usecols=use,ndmin=2)
|
||||||
|
|
||||||
return labels_missing
|
return labels_missing
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def data_write(self):
|
|
||||||
"""Write current data array and report alive output back."""
|
|
||||||
if len(self.data) == 0: return True
|
|
||||||
|
|
||||||
if isinstance(self.data[0],list):
|
|
||||||
return self.output_write(['\t'.join(map(self._quote,items)) for items in self.data])
|
|
||||||
else:
|
|
||||||
return self.output_write( '\t'.join(map(self._quote,self.data)))
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def data_writeArray(self):
|
|
||||||
"""Write whole numpy array data."""
|
|
||||||
for row in self.data:
|
|
||||||
try:
|
|
||||||
output = list(map(repr,row))
|
|
||||||
except Exception:
|
|
||||||
output = [repr(row)]
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.__IO__['out'].write('\t'.join(output) + '\n')
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def data_append(self,
|
|
||||||
what):
|
|
||||||
if isinstance(what, str):
|
|
||||||
self.data += [what]
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
for item in what: self.data_append(item)
|
|
||||||
except TypeError:
|
|
||||||
self.data += [str(what)]
|
|
||||||
|
|
|
@ -785,7 +785,7 @@ class Geom:
|
||||||
"""
|
"""
|
||||||
def mp(entry,mapper):
|
def mp(entry,mapper):
|
||||||
return mapper[entry] if entry in mapper else entry
|
return mapper[entry] if entry in mapper else entry
|
||||||
|
|
||||||
mp = np.vectorize(mp)
|
mp = np.vectorize(mp)
|
||||||
mapper = dict(zip(from_material,to_material))
|
mapper = dict(zip(from_material,to_material))
|
||||||
|
|
||||||
|
@ -796,6 +796,20 @@ class Geom:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def sort(self):
|
||||||
|
"""Sort material indices such that min(material) is located at (0,0,0)."""
|
||||||
|
a = self.material.flatten(order='F')
|
||||||
|
from_ma = pd.unique(a)
|
||||||
|
sort_idx = np.argsort(from_ma)
|
||||||
|
ma = np.unique(a)[sort_idx][np.searchsorted(from_ma,a,sorter = sort_idx)]
|
||||||
|
|
||||||
|
return Geom(material = ma.reshape(self.grid,order='F'),
|
||||||
|
size = self.size,
|
||||||
|
origin = self.origin,
|
||||||
|
comments = self.comments+[util.execution_stamp('Geom','sort')],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def vicinity_offset(self,vicinity=1,offset=None,trigger=[],periodic=True):
|
def vicinity_offset(self,vicinity=1,offset=None,trigger=[],periodic=True):
|
||||||
"""
|
"""
|
||||||
Offset material index of points in the vicinity of xxx.
|
Offset material index of points in the vicinity of xxx.
|
||||||
|
@ -822,15 +836,11 @@ class Geom:
|
||||||
def tainted_neighborhood(stencil,trigger):
|
def tainted_neighborhood(stencil,trigger):
|
||||||
|
|
||||||
me = stencil[stencil.shape[0]//2]
|
me = stencil[stencil.shape[0]//2]
|
||||||
if len(trigger) == 0:
|
return np.any(stencil != me
|
||||||
return np.any(stencil != me)
|
if len(trigger) == 0 else
|
||||||
if me in trigger:
|
np.in1d(stencil,np.array(list(set(trigger) - {me}))))
|
||||||
trigger = set(trigger)
|
|
||||||
trigger.remove(me)
|
|
||||||
trigger = list(trigger)
|
|
||||||
return np.any(np.in1d(stencil,np.array(trigger)))
|
|
||||||
|
|
||||||
offset_ = np.nanmax(self.material) if offset is None else offset
|
offset_ = np.nanmax(self.material)+1 if offset is None else offset
|
||||||
mask = ndimage.filters.generic_filter(self.material,
|
mask = ndimage.filters.generic_filter(self.material,
|
||||||
tainted_neighborhood,
|
tainted_neighborhood,
|
||||||
size=1+2*vicinity,
|
size=1+2*vicinity,
|
||||||
|
|
|
@ -316,12 +316,6 @@ class Test:
|
||||||
return self.compare_Array(refName,curName)
|
return self.compare_Array(refName,curName)
|
||||||
|
|
||||||
|
|
||||||
def compare_ArrayCurCur(self,cur0,cur1):
|
|
||||||
|
|
||||||
cur0Name = self.fileInCurrent(cur0)
|
|
||||||
cur1Name = self.fileInCurrent(cur1)
|
|
||||||
return self.compare_Array(cur0Name,cur1Name)
|
|
||||||
|
|
||||||
def compare_Table(self,headings0,file0,
|
def compare_Table(self,headings0,file0,
|
||||||
headings1,file1,
|
headings1,file1,
|
||||||
normHeadings='',normType=None,
|
normHeadings='',normType=None,
|
||||||
|
|
|
@ -6,6 +6,7 @@ from damask import Geom
|
||||||
from damask import Table
|
from damask import Table
|
||||||
from damask import Rotation
|
from damask import Rotation
|
||||||
from damask import util
|
from damask import util
|
||||||
|
from damask import seeds
|
||||||
from damask import grid_filters
|
from damask import grid_filters
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,6 +205,11 @@ class TestGeom:
|
||||||
assert np.array_equiv(t,f) or (not geom_equal(modified,default))
|
assert np.array_equiv(t,f) or (not geom_equal(modified,default))
|
||||||
assert geom_equal(default, modified.substitute(t,f))
|
assert geom_equal(default, modified.substitute(t,f))
|
||||||
|
|
||||||
|
def test_sort(self):
|
||||||
|
grid = np.random.randint(5,20,3)
|
||||||
|
m = Geom(np.random.randint(1,20,grid)*3,np.ones(3)).sort().material.flatten(order='F')
|
||||||
|
for i,v in enumerate(m):
|
||||||
|
assert i==0 or v > m[:i].max() or v in m[:i]
|
||||||
|
|
||||||
@pytest.mark.parametrize('axis_angle',[np.array([1,0,0,86.7]), np.array([0,1,0,90.4]), np.array([0,0,1,90]),
|
@pytest.mark.parametrize('axis_angle',[np.array([1,0,0,86.7]), np.array([0,1,0,90.4]), np.array([0,0,1,90]),
|
||||||
np.array([1,0,0,175]),np.array([0,-1,0,178]),np.array([0,0,1,180])])
|
np.array([1,0,0,175]),np.array([0,-1,0,178]),np.array([0,0,1,180])])
|
||||||
|
@ -384,3 +390,13 @@ class TestGeom:
|
||||||
t = Table(np.column_stack((coords,z)),{'coords':3,'z':1})
|
t = Table(np.column_stack((coords,z)),{'coords':3,'z':1})
|
||||||
g = Geom.from_table(t,'coords',['1_coords','z'])
|
g = Geom.from_table(t,'coords',['1_coords','z'])
|
||||||
assert g.N_materials == g.grid[0]*2 and (g.material[:,:,-1]-g.material[:,:,0] == grid[0]).all()
|
assert g.N_materials == g.grid[0]*2 and (g.material[:,:,-1]-g.material[:,:,0] == grid[0]).all()
|
||||||
|
|
||||||
|
|
||||||
|
def test_from_table_recover(self,tmp_path):
|
||||||
|
grid = np.random.randint(60,100,3)
|
||||||
|
size = np.ones(3)+np.random.rand(3)
|
||||||
|
s = seeds.from_random(size,np.random.randint(60,100))
|
||||||
|
geom = Geom.from_Voronoi_tessellation(grid,size,s)
|
||||||
|
coords = grid_filters.cell_coord0(grid,size)
|
||||||
|
t = Table(np.column_stack((coords.reshape(-1,3,order='F'),geom.material.flatten(order='F'))),{'c':3,'m':1})
|
||||||
|
assert geom_equal(geom.sort().renumber(),Geom.from_table(t,'c',['m']))
|
||||||
|
|
Loading…
Reference in New Issue