1
from fipy import *


nx = 50
dx = 1.
mesh = Grid1D(nx=nx, dx=dx)

phi = CellVariable(name="solution variable",
                   mesh=mesh,
                   value=0.)

D = 1.

valueLeft = 1
valueRight = 0

phi.constrain(valueRight, mesh.facesRight)
phi.constrain(valueLeft, mesh.facesLeft)

eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D)

timeStepDuration = 0.9 * dx**2 / (2 * D)
steps = 100

phiAnalytical = CellVariable(name="analytical value",
                             mesh=mesh)


viewer = Viewer(vars=(phi, phiAnalytical),
                    datamin=0., datamax=1.)
viewer.plot()

x = mesh.cellCenters[0]
t = timeStepDuration * steps

try:
    from scipy.special import erf
    phiAnalytical.setValue(1 - erf(x / (2 * numerix.sqrt(D * t))))
except ImportError:
    print "The SciPy library is not available to test the solution to \
the transient diffusion equation"

for step in range(steps):
     eqX.solve(var=phi,
               dt=timeStepDuration)

     viewer.plot()

I am trying to implement an example from the fipy examples list which is the 1D diffusion problem. but I am not able to view the result as a plot. I have defined viewer correctly as suggested in the code for the example. Still not helping. The solution vector runs fine. But I am not able to plot using the viewer function. can anyone help? thank you!

sankethrg
  • 23
  • 2
  • 1
    You might want to add the error from the console to your question. Also, import a specific viewer with something like `from fipy.viewers.matplotlibViewer.matplotlib1DViewer import Matplotlib1DViewer as Viewer` below the `fipy` import to help diagnose the problem. There are `try` and `except` blocks around some of the viewer imports that can mask the error. – wd15 Apr 10 '15 at 14:19
  • thanks for the response. importing matplotlib viewer solved the problem. – sankethrg Apr 13 '15 at 19:13

1 Answers1

0

Your code works fine on my computer. Probably is a problem with a plotting library used by FiPy.

Check if the original example works (just run this from the fipy folder)

python examples/diffusion/mesh1D.py

If not, download FiPy from the github page of the project https://github.com/usnistgov/fipy and try the example again. If not, check if the plotting libraries are correctly installed.

Anyways, you should specify the platform you are using and the errors you are getting. The first time I had some problems with the plotting libraries too.