运行 "examples.diffusion.mesh20x20" 时出现 ValueError
ValueError when running "examples.diffusion.mesh20x20"
我刚刚开始使用 FiPy,因此查看了示例。但是,当 运行 宁 "examples.diffusion.mesh20x20" 我得到以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-368b9682144d> in <module>
22
23 # to the top-left and bottom-right corners. Neumann boundary conditions are automatically applied to the top-right and bottom-left corners.
---> 24 X, Y = mesh.faceCenters
25
26 facesTopLeft = ((mesh.facesLeft & (Y > L / 2))
~\Anaconda3\lib\site-packages\fipy\meshes\abstractMesh.py in faceCenters(self)
93 def faceCenters(self):
94 from fipy.variables.faceVariable import FaceVariable
---> 95 return FaceVariable(mesh=self, value=self._faceCenters,
96 rank=1)
97
~\Anaconda3\lib\site-packages\fipy\meshes\uniformGrid2D.py in _faceCenters(self)
415 Vcen[1, ...] = (indices[1] + 0.5) * self.dy
416
--> 417 return numerix.concatenate((Hcen.reshape((2, self.numberOfHorizontalFaces), order="FORTRAN"),
418 Vcen.reshape((2,
419 self.numberOfVerticalFaces),
ValueError: Non-string object detected for the array ordering. Please pass in 'C', 'F', 'A', or 'K' instead
这是来自 "examples.diffusion.mesh20x20" 的代码,我正在尝试 运行:
from fipy import CellVariable, Grid2D, Viewer, TransientTerm, DiffusionTerm
from fipy.tools import numerix
nx = 20
ny = nx
dx = 1.
dy = dx
L = dx * nx
mesh = Grid2D(dx=dx, dy=dy, nx=nx, ny=ny)
# We create a CellVariable and initialize it to zero:
phi = CellVariable(name = "solution variable",
mesh = mesh,
value = 0.)
# and then create a diffusion equation. This is solved by default with an iterative conjugate gradient solver.
D = 1.
eq = TransientTerm() == DiffusionTerm(coeff=D)
# We apply Dirichlet boundary conditions
valueTopLeft = 0
valueBottomRight = 1
# to the top-left and bottom-right corners. Neumann boundary conditions are automatically applied to the top-right and bottom-left corners.
X, Y = mesh.faceCenters
facesTopLeft = ((mesh.facesLeft & (Y > L / 2))
| (mesh.facesTop & (X < L / 2)))
facesBottomRight = ((mesh.facesRight & (Y < L / 2))
| (mesh.facesBottom & (X > L / 2)))
phi.constrain(valueTopLeft, facesTopLeft)
phi.constrain(valueBottomRight, facesBottomRight)
# We create a viewer to see the results
if __name__ == '__main__':
viewer = Viewer(vars=phi, datamin=0., datamax=1.)
viewer.plot()
# and solve the equation by repeatedly looping in time:
timeStepDuration = 10 * 0.9 * dx**2 / (2 * D)
steps = 10
from builtins import range
for step in range(steps):
eq.solve(var=phi,
dt=timeStepDuration)
if __name__ == '__main__':
viewer.plot()
很遗憾,我在搜索错误信息时找不到任何解决方案。也许,我的安装有问题?希望你们中的一位能帮助我。
造成此问题的原因是您使用的 numpy 版本比测试 FiPy 的版本更新。
(参见 issue #703)。
我们将在今天或明天推出针对此问题的修复程序。
我刚刚开始使用 FiPy,因此查看了示例。但是,当 运行 宁 "examples.diffusion.mesh20x20" 我得到以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-368b9682144d> in <module>
22
23 # to the top-left and bottom-right corners. Neumann boundary conditions are automatically applied to the top-right and bottom-left corners.
---> 24 X, Y = mesh.faceCenters
25
26 facesTopLeft = ((mesh.facesLeft & (Y > L / 2))
~\Anaconda3\lib\site-packages\fipy\meshes\abstractMesh.py in faceCenters(self)
93 def faceCenters(self):
94 from fipy.variables.faceVariable import FaceVariable
---> 95 return FaceVariable(mesh=self, value=self._faceCenters,
96 rank=1)
97
~\Anaconda3\lib\site-packages\fipy\meshes\uniformGrid2D.py in _faceCenters(self)
415 Vcen[1, ...] = (indices[1] + 0.5) * self.dy
416
--> 417 return numerix.concatenate((Hcen.reshape((2, self.numberOfHorizontalFaces), order="FORTRAN"),
418 Vcen.reshape((2,
419 self.numberOfVerticalFaces),
ValueError: Non-string object detected for the array ordering. Please pass in 'C', 'F', 'A', or 'K' instead
这是来自 "examples.diffusion.mesh20x20" 的代码,我正在尝试 运行:
from fipy import CellVariable, Grid2D, Viewer, TransientTerm, DiffusionTerm
from fipy.tools import numerix
nx = 20
ny = nx
dx = 1.
dy = dx
L = dx * nx
mesh = Grid2D(dx=dx, dy=dy, nx=nx, ny=ny)
# We create a CellVariable and initialize it to zero:
phi = CellVariable(name = "solution variable",
mesh = mesh,
value = 0.)
# and then create a diffusion equation. This is solved by default with an iterative conjugate gradient solver.
D = 1.
eq = TransientTerm() == DiffusionTerm(coeff=D)
# We apply Dirichlet boundary conditions
valueTopLeft = 0
valueBottomRight = 1
# to the top-left and bottom-right corners. Neumann boundary conditions are automatically applied to the top-right and bottom-left corners.
X, Y = mesh.faceCenters
facesTopLeft = ((mesh.facesLeft & (Y > L / 2))
| (mesh.facesTop & (X < L / 2)))
facesBottomRight = ((mesh.facesRight & (Y < L / 2))
| (mesh.facesBottom & (X > L / 2)))
phi.constrain(valueTopLeft, facesTopLeft)
phi.constrain(valueBottomRight, facesBottomRight)
# We create a viewer to see the results
if __name__ == '__main__':
viewer = Viewer(vars=phi, datamin=0., datamax=1.)
viewer.plot()
# and solve the equation by repeatedly looping in time:
timeStepDuration = 10 * 0.9 * dx**2 / (2 * D)
steps = 10
from builtins import range
for step in range(steps):
eq.solve(var=phi,
dt=timeStepDuration)
if __name__ == '__main__':
viewer.plot()
很遗憾,我在搜索错误信息时找不到任何解决方案。也许,我的安装有问题?希望你们中的一位能帮助我。
造成此问题的原因是您使用的 numpy 版本比测试 FiPy 的版本更新。 (参见 issue #703)。 我们将在今天或明天推出针对此问题的修复程序。