a bit more vectorized

This commit is contained in:
f.basile 2020-10-26 15:09:32 +01:00
parent d6b9783794
commit 2715e7b1a7
1 changed files with 38 additions and 31 deletions

View File

@ -855,19 +855,22 @@ class Geom:
v = VTK.from_polyData(grid_filters.node_coord0(self.grid,self.size,self.origin).reshape(-1,3,order='F')) v = VTK.from_polyData(grid_filters.node_coord0(self.grid,self.size,self.origin).reshape(-1,3,order='F'))
cells = vtk.vtkCellArray() cells = vtk.vtkCellArray()
index={}
nodes={}
nodes_PBC={}
if periodic: if periodic:
FaceYZ_per=np.empty([]) nodes_PBC['0']=np.array([])
FaceXY_per=np.empty([]) nodes_PBC['1']=np.array([])
FaceXZ_per=np.empty([]) nodes_PBC['2']=np.array([])
else: else:
FaceYZ_per=np.concatenate(( nodes_PBC['0']=np.concatenate((
np.arange(0 , np.prod(self.grid+1) , (self.grid[0]+1) ), np.arange(0 , np.prod(self.grid+1) , (self.grid[0]+1) ),
np.arange(self.grid[0] , np.prod(self.grid+1) , (self.grid[0]+1) ) )) np.arange(self.grid[0] , np.prod(self.grid+1) , (self.grid[0]+1) ) ))
FaceXY_per=np.concatenate(( nodes_PBC['2']=np.concatenate((
np.arange(0 , np.prod(self.grid[:2]+1) , 1 ), np.arange(0 , np.prod(self.grid[:2]+1) , 1 ),
np.arange(np.prod(self.grid+1) - np.prod(self.grid[:2]+1), \ np.arange(np.prod(self.grid+1) - np.prod(self.grid[:2]+1), \
np.prod(self.grid+1) , 1 ) )) np.prod(self.grid+1) , 1 ) ))
FaceXZ_per=np.concatenate(( nodes_PBC['1']=np.concatenate((
np.concatenate([np.arange((i)*np.prod(self.grid[:2]+1), \ np.concatenate([np.arange((i)*np.prod(self.grid[:2]+1), \
(i)*np.prod(self.grid[:2]+1)+ (self.grid[0]+1)) for i in range(self.grid[2]+1)]) , (i)*np.prod(self.grid[:2]+1)+ (self.grid[0]+1)) for i in range(self.grid[2]+1)]) ,
np.concatenate([np.arange( (i+1)*np.prod(self.grid[:2]+1)-(self.grid[0]+1),\ np.concatenate([np.arange( (i+1)*np.prod(self.grid[:2]+1)-(self.grid[0]+1),\
@ -880,29 +883,33 @@ class Geom:
base_nodes = np.concatenate((base_nodes,np.take(base_nodes,[0],d)),d) base_nodes = np.concatenate((base_nodes,np.take(base_nodes,[0],d)),d)
else: else:
base_nodes = np.concatenate((base_nodes,np.logical_and(np.take(base_nodes,[0],d),False)),d) base_nodes = np.concatenate((base_nodes,np.logical_and(np.take(base_nodes,[0],d),False)),d)
for p in np.argwhere(base_nodes.flatten(order='F')): nodes['{}'.format(d_s)]= np.argwhere(base_nodes.flatten(order='F'))[:,0]
if np.any(FaceYZ_per == p[0]) and d_s == 0: index['{}'.format(d_s)]= np.isin( nodes['{}'.format(d_s)] , nodes_PBC['{}'.format(d_s)] , assume_unique=True, invert=True )
pass
elif np.any(FaceXY_per == p[0]) and d_s == 2: for p in nodes['0'][index['0']]:
pass q = vtk.vtkQuad()
elif np.any(FaceXZ_per == p[0]) and d_s == 1: q.GetPointIds().SetId(0, p)
pass q.GetPointIds().SetId(1, p+(self.grid[0]+1))
else: q.GetPointIds().SetId(2, p+np.prod(self.grid[:2]+1)+(self.grid[0]+1))
q = vtk.vtkQuad() q.GetPointIds().SetId(3, p+np.prod(self.grid[:2]+1))
q.GetPointIds().SetId(0, p[0]) cells.InsertNextCell(q)
if d_s == 0:
q.GetPointIds().SetId(1, p[0]+(self.grid[0]+1)) for p in nodes['1'][index['1']]:
q.GetPointIds().SetId(2, p[0]+np.prod(self.grid[:2]+1)+(self.grid[0]+1)) q = vtk.vtkQuad()
q.GetPointIds().SetId(3, p[0]+np.prod(self.grid[:2]+1)) q.GetPointIds().SetId(0, p)
if d_s == 1: q.GetPointIds().SetId(1, p+np.prod(self.grid[:2]+1))
q.GetPointIds().SetId(1, p[0]+np.prod(self.grid[:2]+1)) q.GetPointIds().SetId(2, p+np.prod(self.grid[:2]+1)+1)
q.GetPointIds().SetId(2, p[0]+np.prod(self.grid[:2]+1)+1) q.GetPointIds().SetId(3, p+1)
q.GetPointIds().SetId(3, p[0]+1) cells.InsertNextCell(q)
if d_s == 2:
q.GetPointIds().SetId(1, p[0]+1) for p in nodes['2'][index['2']]:
q.GetPointIds().SetId(2, p[0]+(self.grid[0]+1)+1) q = vtk.vtkQuad()
q.GetPointIds().SetId(3, p[0]+(self.grid[0]+1)) q.GetPointIds().SetId(0, p)
cells.InsertNextCell(q) q.GetPointIds().SetId(1, p+1)
q.GetPointIds().SetId(2, p+(self.grid[0]+1)+1)
q.GetPointIds().SetId(3, p+(self.grid[0]+1))
cells.InsertNextCell(q)
v.vtk_data.SetPolys(cells) v.vtk_data.SetPolys(cells)
v.save('GrainBoundaries') v.save('GrainBoundaries')