我有以下功能:
def setupSinkGrid_(self, sinkCoords,mesh,x,y,z,patchSize=1) :
sinkGrid = CellVariable(name="source", mesh=mesh, value=0)
sinkGrid.setValue(0.)
for pos,v in sinkCoords.iteritems():
sinkGrid.setValue(v, where=(z > pos[0]-patchSize) & (z < pos[0]+patchSize) & (y > pos[1]-patchSize) & (y < pos[1]+patchSize) & (x > pos[2]-patchSize) & (x < pos[2]+patchSize))
return sinkGrid
其中,mesh、x、y和z先前定义为:
mesh=Grid3D(dx=dx,dy=dy,nx=nx,ny=ny, dz=dz, nz=nz)
phi=CellVariable(name="solutionvariable",mesh=mesh,value=0.)
x, y, z = mesh.cellCenters
sinkCoords是坐标到值的字典。例如:{(1,2,3) => 4}
表示1,2,3处的值是4。你知道吗
我们的想法是将每个这样的坐标映射到网格上。你知道吗
问题是,在调试时,我发现每个sink值都映射到多个“接近”实际目标的位置。在循环的第一次迭代(pos = <type 'tuple'>: (16, 16, 2)
)之后,我得到:
[np.unravel_index(i,(20,20,20)) for i,x in enumerate(list(sinkGrid)) if x > 0]
它返回一个值25,设置为8个不同的索引。你知道吗
0 = {tuple} <type 'tuple'>: (15, 15, 1)
1 = {tuple} <type 'tuple'>: (15, 15, 2)
2 = {tuple} <type 'tuple'>: (15, 16, 1)
3 = {tuple} <type 'tuple'>: (15, 16, 2)
4 = {tuple} <type 'tuple'>: (16, 15, 1)
5 = {tuple} <type 'tuple'>: (16, 15, 2)
6 = {tuple} <type 'tuple'>: (16, 16, 1)
7 = {tuple} <type 'tuple'>: (16, 16, 2)
根据我的观察,这些坐标总是“较低”,但是:
1)为什么只针对一些邻居?那我为什么不把整个摩尔街区都找出来?你知道吗
2)为什么只关注至少在一个维度上较低的邻居?你知道吗
3)是什么原因造成的?只是一些错误。如果是这样,我应该使用patchSize-k
或类似的东西吗?你知道吗
问题是
x
、y
和z
是细胞中心的坐标,它们位于((0.5,0.5,0.5),(1.5,0.5,0.5),…)。你知道吗(16, 16, 2) +/- 1
将包括以下位置的细胞:您有两个选择:
sinkCoords
,例如(15.5, 15.5, 1.5
patchSize
限制为单元格维数的一半不管怎样,第2项可能是个好主意。你知道吗
你需要确保你是会计或整个范围,例如,
(z > pos[0]-patchSize) & (z <= pos[0]+patchSize)
,否则你很有可能找不到任何单元格。你知道吗相关问题 更多 >
编程相关推荐