Hi, Daniel and Jonathan, thanks your suggestions

>Does matplotlib (pylab) work effectively

Yes. pylab.show() works perfectly. But pylab.show() is a function that should 
be called lastly because it doesn't return.


>See http://matplotlib.sourceforge.net/faq/installing_faq.html#backends 

I have used pylab only as a graph viewer, not as an animation viewer. I guess 
that if an animation viewer is needed then I have to use matlab directly, not 
to use pylab front end indirectly.

But I don't need animation viewers and fipy perfectly separates solver from 
viewer. So I can use other modules as in appendix1 or appendix2 to view 
results calculated by fipy solvers .

It might be easier for me to abandon animation viewers and to use other 
viewers than to find out the counter measures using the fipy viewer in Win2k.

thanks a lot

--
Kenji Kobayashi


------------ appendix1 begins ----------------------
//@@
#!/usr/bin/env python


###
## Variables definitions
###
import fipy.tools.numerix as numerix
nx = 50
ny = 50
#nx = 5
#ny = 5
steps = 200
dx = 1.0
dy = 1.0
dt = 0.5
A = 1.0
epsilon = 0.3
diffusionCoeff = 1
from fipy.meshes.grid2D import Grid2D
mesh = Grid2D(dx = dx, dy = dy, nx = nx, ny = ny)
from fipy.variables.cellVariable import CellVariable
from fipy.tools.numerix import random
phi = CellVariable(name = "phase field",mesh = mesh, value = random.random(nx * 
ny))
phiVar = phi.getArithmeticFaceValue()


###
## Define Equation
###
doubleWellDerivative = A * ( 1 - 6 * phiVar * (1 - phiVar))
from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm
from fipy.terms.transientTerm import TransientTerm
diffTerm2 = ImplicitDiffusionTerm(coeff = (diffusionCoeff * 
doubleWellDerivative,))
diffTerm4 = ImplicitDiffusionTerm(coeff = (diffusionCoeff, epsilon))
eqch = TransientTerm() == diffTerm2 - diffTerm4


###
## Define Boundary Conditions
###
from fipy.boundaryConditions.fixedValue import FixedValue
from fipy.boundaryConditions.fixedFlux import FixedFlux
from fipy.boundaryConditions.nthOrderBoundaryCondition import 
NthOrderBoundaryCondition
BCs = (FixedFlux(mesh.getFacesRight(), 0),
       FixedFlux(mesh.getFacesLeft(), 0),
       FixedFlux(mesh.getFacesTop(), 0),
       FixedFlux(mesh.getFacesBottom(), 0),
       NthOrderBoundaryCondition(mesh.getFacesLeft(), 0, 3),
       NthOrderBoundaryCondition(mesh.getFacesRight(), 0, 3),
       NthOrderBoundaryCondition(mesh.getFacesTop(), 0, 3),
       NthOrderBoundaryCondition(mesh.getFacesBottom(), 0, 3))


# ============ using mlab viewer for the phi fipy variable ==============
import scipy as sc
arAt = sc.array(phi).reshape(nx,ny)

from enthought.mayavi import mlab
#mlab.imshow(arAt, colormap='gist_earth')
mlab.imshow(arAt, colormap='blue-red')
mlab.show()
//@@@

------------ appendix1 ends ----------------------

------------ appendix2 begins ----------------------

//@@
#!/usr/bin/env python

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

BCs = (FixedValue(faces=mesh.getFacesRight(), value=valueRight),
       FixedValue(faces=mesh.getFacesLeft(), value=valueLeft))


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

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

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

import pysf.sfFnctns as sf
if __name__ == '__main__':
    #viewer = Viewer(vars=(phi, phiAnalytical),
    #                datamin=0., datamax=1.)
    #viewer.plot()
    sf.plotGr(list(phi))

x = mesh.getCellCenters()[0]
t = timeStepDuration * steps

try:
    from scipy.special import erf
    phiAnalytical.setValue(1 - erf(x / (2 * 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,
              boundaryConditions=BCs,
              dt=timeStepDuration)
    if __name__ == '__main__':
        sf.plotGr(list(phi))
        #viewer.plot()

print phi.allclose(phiAnalytical, atol = 7e-4)


if __name__ == '__main__':
    raw_input("Explicit transient diffusion. Press <return> to proceed...")


eqI = TransientTerm() == ImplicitDiffusionTerm(coeff=D)


phi.setValue(valueRight)


timeStepDuration *= 10
steps /= 10
for step in range(steps):
    eqI.solve(var=phi,
              boundaryConditions=BCs,
              dt=timeStepDuration)
    if __name__ == '__main__':
        #viewer.plot()
        sf.plotGr(list(phi))

        raw_input("wait")

//@@@
<== sf.plotGr(..) is my graph viewer using vpython.
------------ appendix2 ends ----------------------

Reply via email to