3 Created on Sun Jul 29 20:35:19 2018 8 from __future__
import print_function
12 def contribution(p,dir=2,point=0.5,iv=0,i4=0,all=False,verbose=0):
13 """ Return the contribution from a patch to a unitgrid_plane """ 18 lc=p.position[dir]-p.size[dir]/2.0
19 uc=p.position[dir]+p.size[dir]/2.0
20 if all
and p.guard_zones:
28 if uc+ds2 >= point
and lc-ds2 <= point:
33 i=int(max(0,min(n-1,np.floor(fi))))
51 print (
'id:{:3d} i:{:3d} w:{:5.2f}{:5.2f}'.format(p.id,i,w0,w1))
53 print (
'id:{:3d} i:{:3d} w:{:5.2f}'.format(p.id,i,w0))
56 data=p.var(iv,i4=i4,all=all)
63 f=f+dv*data[i+1,:,:]*w1
67 f=f+dv*data[:,i+1,:]*w1
71 f=f+dv*data[:,:,i+1]*w1
72 if all
and p.guard_zones:
75 f=f[m[0]:-m[0],m[1]:-m[1]]
80 def corner_indices(sn,p,dir=-1):
81 """ Return the corder indices of patch p in snapshot sn in direction dir """ 82 i=(p.position-p.size/2-sn.cartesian.origin)/p.ds
83 i=[int(k+0.5)
for k
in i]
88 return i[0],i[0]+n[0],i[1],i[1]+n[1]
90 return i[0],i[0]+n[0],i[1],i[1]+n[1],i[2],i[2]+n[2]
92 def unigrid_plane(snap,iv=0,x=None,y=None,z=None,point=0.5,dir=2,all=False,i4=0,verbose=0):
95 dim=list(snap.cartesian.dims*p.n)
109 ds=p.ds[dir]*(2*p.ng[dir]+1)
112 pp=[p
for p
in pp
if abs(point-p.position[dir]) <= (p.size[dir]+ds)/2]
114 print(
'number of patches:',len(pp))
123 k=corner_indices(snap,p,dir)
124 f,i=contribution(p,dir=dir,point=point,iv=iv,i4=i4,all=all,
127 ff[k[0]:k[1],k[2]:k[3]]+=f
130 print(
'patch:',p.id,
'range:',k,
'shape: None')
133 def unigrid_volume(snap,iv=0,i4=0,verbose=0):
135 assemble a volume from a unigrid experiment, where all 136 patches have the same size and resolution 140 dim=tuple(snap.cartesian.dims*p.n)
150 k=corner_indices(snap,p)
151 ff[k[0]:k[1],k[2]:k[3],k[4]:k[5]]=p.var(iv)