【问题标题】:Problems re-implementing the fipy mesh20x20 example from my own IDE从我自己的 IDE 重新实现 fipy mesh20x20 示例的问题
【发布时间】:2020-11-11 09:41:15
【问题描述】:

我目前正在使用 fipy,但对于与包相关的细微差别仍然相对较新。虽然我已经能够使用命令行从 mesh20x20 扩散示例的示例文件夹中重新生成所需的热图,但我一直在努力在 Spyder IDE 中复制它。我正在使用 python 版本 3.8 。使用命令行the command line image generated 中的“示例”文件夹生成它很简单,但是,当我尝试“重新编程”它时,我最终会得到以下迭代。 the following result。我希望能够从示例文件夹中重新生成平滑的颜色过渡,而不是我目前受限的离散二色选项。我相信查看器在某些方面存在一些问题我相信过去可能已经出现了一些相关问题,可能与彩条重新格式化有关,尽管我还没有能力有效地实施这些变通办法来生成想要的图像。 datamin and datamax in Viewer() did not work

我将非常感谢社区可以提供的任何帮助。

from fipy.terms.transientTerm import TransientTerm
from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm
from fipy.terms.explicitDiffusionTerm import ExplicitDiffusionTerm
from fipy.meshes.nonUniformGrid2D import NonUniformGrid2D
from fipy.variables.cellVariable import CellVariable
from fipy.viewers.matplotlibViewer.matplotlib2DViewer import Matplotlib2DViewer


####
#Global Inputs
D=1
steps=10


#Dimensional Inputs
nx=20
dx=1
ny=20
dy=1
L=dx*nx

#Temporal Inputs
#nt=20
#dt=1

#cell variable initial values
value=0

#construct mesh from dimensional pts
mesh=NonUniformGrid2D(nx=nx, dx=dx, ny=ny, dy=dy)


#construct term variables phi with name, mesh design
phi=CellVariable(name="solutionvariable", mesh=mesh, value=0)


#construct boundary conditions
#dirichlet ---> we can an automatic application of neumann to top right and bottom left
valueTopLeft=0
valueBottomRight=1

#assign boundary conditions to a face or cell
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)))


#constrain variables
phi.constrain(valueTopLeft, facesTopLeft)
phi.constrain(valueBottomRight, facesBottomRight)


#equation construction
eq=TransientTerm()==ExplicitDiffusionTerm(coeff=D)


#equation solving and either viewing and/or extraction
timestepduration=0.9 *(dx**2)/(2*D)
for step in range(steps):
    eq.solve(var=phi, dt=timestepduration)
    print(phi[step])
    viewer=Matplotlib2DViewer(vars=phi, datamin=0, datamax=1)
    viewer.axes.set_title("Solutionvbl(Step %d)" % (step+1,))

【问题讨论】:

    标签: python viewer fipy


    【解决方案1】:

    我想明白了。我使用的是 ExplicitDiffusion,示例使用了 ImplicitDiffusion。当我尝试这个时,我得到的只是一张空白的单色图像(最后为我的 phi[step] 返回了零。我很高兴地报告,一旦在 cellVariable 的值部分中提供了“kickstart”值(我使用0.001),并与 ImplicitDiffusion 结合使用,时间步长从其限制 0.9x**2/2D 增加到使用的 9x**2/2D 在示例文档中使用它或多或少地遵循从命令行运行时生成的图像。感谢对它进行排序。希望这对可能遇到类似问题的其他人提供帮助。

    【讨论】:

    • 很高兴听到你整理好了
    猜你喜欢
    • 2021-12-19
    • 2013-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-26
    • 1970-01-01
    相关资源
    最近更新 更多