FIPY:Grid2D cellToFaceDistanceVectors 的问题给出了错误“UniformGrid2D"对象没有属性“_cellToFaceDistanceVectors" [英] FIPY: problem with Grid2D cellToFaceDistanceVectors gives error 'UniformGrid2D' object has no attribute '_cellToFaceDistanceVectors'

查看:71
本文介绍了FIPY:Grid2D cellToFaceDistanceVectors 的问题给出了错误“UniformGrid2D"对象没有属性“_cellToFaceDistanceVectors"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Grid2D 创建一个网格,如下所示

I create a mesh using Grid2D as follows

L = 2.
N = 50
dL = L/N
mesh = Grid2D(nx=N, ny=N, dx=dL, dy=dL)

但是当我尝试让单元格面对距离向量时:

but when I try to get the cell to face distance vector:

mesh.cellToFaceDistanceVectors

出现以下错误:

AttributeError                            Traceback (most recent call last)

<ipython-input-7-9ab623a3d90d> in <module>()
----> 1 mesh.cellToFaceDistanceVectors

/usr/local/lib/python3.6/dist-packages/fipy/meshes/abstractMesh.py in <lambda>(s)
     96                             rank=1)
     97 
---> 98     cellToFaceDistanceVectors  = property(lambda s: s._cellToFaceDistanceVectors)
     99     cellDistanceVectors        = property(lambda s: s._cellDistanceVectors)
    100     cellVolumes                = property(lambda s: s._scaledCellVolumes)

AttributeError: 'UniformGrid2D' object has no attribute '_cellToFaceDistanceVectors'

其他属性也会发生同样的情况,例如:

It happens the same for other attributes such as:

mesh.cellDistanceVectors

有人知道我怎样才能得到面部到细胞的距离向量吗?

Does anybody know how can I get the face to cell distance vectors?

推荐答案

看起来我们从来没有为 Grids 实现过,而且我从来没有对 Robin 的讨论做过很多测试.我已提交问题.

It doesn't look like we ever implemented that for Grids and it looks like I never did much testing of the Robin discussion. I've filed an issue.

作为一种解决方法,您可以这样做

As a workaround, you can do

from fipy.tools import numerix
MA = numerix.MA

tmp = MA.repeat(mesh._faceCenters[..., numerix.NewAxis,:], 2, 1)
cellToFaceDistanceVectors = tmp - numerix.take(mesh._cellCenters, mesh.faceCellIDs, axis=1)

tmp = numerix.take(mesh._cellCenters, mesh.faceCellIDs, axis=1)
tmp = tmp[..., 1,:] - tmp[..., 0,:]
cellDistanceVectors = MA.filled(MA.where(MA.getmaskarray(tmp), cellToFaceDistanceVectors[:, 0], tmp))

这篇关于FIPY:Grid2D cellToFaceDistanceVectors 的问题给出了错误“UniformGrid2D"对象没有属性“_cellToFaceDistanceVectors"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆