【发布时间】: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,))
【问题讨论】: