On 04/10/2006 22:54 Daniel Wheeler wrote the following:
On Oct 4, 2006, at 4:04 PM, Jonathan Guyer wrote:
On Oct 4, 2006, at 3:22 PM, hzhatlboro wrote:
On 04/10/2006 19:01 Jonathan Guyer wrote the following:
On Oct 4, 2006, at 12:51 PM, hzhatlboro wrote:
Hi, could someone help why I did not get the initial condition that I want as specified in the attached PDF file?  The code I used as below.  Thanks for your time!  hzh
It looks right to me. What's the problem?
I am not sure what kind of result was displayed on your computer.
The result I see with the gist viewer is exactly what's shown in your schematic (page 1 of 2), rather than what's in your graph (page 2 of 2). I've printed out the values with the TSVViewer just to be sure. Therefore, what you're seeing are display glitches with the matplotlib viewer, not problems with the initial conditions you are setting.
The problem is in fipy/viewers/matplotlibViewer/matplotlibGrid2DViewer. As far as I can tell it is line 111, it is:
    >>> return reshape(array(self.vars[0]), self.vars[0].getMesh().getShape())
it should be:
    >>> return reshape(array(self.vars[0]), self.vars[0].getMesh().getShape()[::-1])
to reverse the axis. Things seem to display nicely with that fix.
Jon, shall I go ahead and fix this on trunk and branch-version-1_1?

hzhatlboro, You can explicitly use a different viewer to get around this problem.
One choice, replace:
   >>> from fipy.viewers import make
   >>> viewer = make(vars=c, limits={'datamin':0., 'datamax':1.})
with:
   >>> from fipy.viewers.matplotlibViewer.matplotlib2DViewer import Matplotlib2DViewer
   >>> viewer = Matplotlib2DViewer(vars=c, limits={'datamin':0., 'datamax':1.})
in your script.

Not sure if I understand your solution properly.  I replaced the viewer part with your code and the figure looks better but without a color bar.  The error message prompted is listed below:-

Traceback (most recent call last):
  File "C:/Python23/hzh/Q061004-fixed.py", line 26, in ?
    viewer = Matplotlib2DViewer(vars=c, limits={'datamin':0., 'datamax':1.})
  File "C:\Python23\Lib\site-packages\fipy\viewers\matplotlibViewer\matplotlib2DViewer.py", line 83, in __init__
    self.colorbar = pylab.colorbar(array(self.vars[0]))
  File "C:\Python23\Lib\site-packages\matplotlib\pylab.py", line 363, in colorbar
    edgecolor=edgecolor)
  File "C:\Python23\Lib\site-packages\matplotlib\figure.py", line 701, in colorbar
    cmap = mappable.cmap
AttributeError: cmap

The updated code is as below:-

H=0.25
Calpha0=0.002
Cimc0=0.4105
Cliq0=0.9769

nx=16
ny=90
dx=H
dy=dx

from fipy.meshes.grid2D import Grid2D
mesh=Grid2D(dx=dx, dy=dy, nx=nx, ny=ny)

from fipy.variables.cellVariable import CellVariable

c=CellVariable(name="Concentration",
               mesh=mesh,
               value=Calpha0)

y=mesh.getCellCenters()[...,1]

c.setValue(Cimc0, where=(41*H<y) & (y<45*H))
c.setValue(Cliq0, where=(y>45*H))

from fipy.viewers.matplotlibViewer.matplotlib2DViewer import Matplotlib2DViewer
viewer = Matplotlib2DViewer(vars=c, limits={'datamin':0., 'datamax':1.})
viewer.plot()

Reply via email to