Hi,
I think there is a bug somewhere (may be Matplotlib was updated?). If
I run the mesh20x20.py or mesh1d.py examples FiPy opens a Matplotlib
viewer without a problem. When running circle.py it fails to open a
Matplotlib viewer (and that is why it defaults to the Mayavi viewer). I
modified the circle.py example to explicitly open a Matplotlib viewer,
and it produces the following error:
Traceback (most recent call last):
File "mycircle.py", line 57, in <module>
viewer = MatplotlibViewer(vars=phi, datamin=-1, datamax=1.)
File
"/Users/ajacobo/Work/Python/FiPy-3.0/fipy/viewers/matplotlibViewer/__init__.py",
line 119, in MatplotlibViewer
return Matplotlib2DViewer(vars=vars, title=title, cmap=cmap,
colorbar=colorbar, axes=axes, **kwlimits)
File
"/Users/ajacobo/Work/Python/FiPy-3.0/fipy/viewers/matplotlibViewer/matplotlib2DViewer.py",
line 90, in __init__
**kwlimits)
File
"/Users/ajacobo/Work/Python/FiPy-3.0/fipy/viewers/matplotlibViewer/matplotlibViewer.py",
line 90, in __init__
w, h = pylab.figaspect(self.figaspect(figaspect))
File
"/Users/ajacobo/Work/Python/FiPy-3.0/fipy/viewers/matplotlibViewer/matplotlib2DViewer.py",
line 48, in figaspect
figaspect = self.vars[0].mesh.aspect2D
File
"/Users/ajacobo/Work/Python/FiPy-3.0/fipy/meshes/abstractMesh.py", line
1410, in aspect2D
xCoords = numerix.take(self.vertexCoords[0], vertexIDs)
File "/Users/ajacobo/Work/Python/FiPy-3.0/fipy/tools/numerix.py",
line 601, in take
taken = MA.take(a, MA.filled(indices, 0), axis=axis)
File "/usr/local/lib/python2.7/site-packages/numpy/ma/core.py", line
5986, in take
return a.take(indices, axis=axis, out=out, mode=mode)
File "/usr/local/lib/python2.7/site-packages/numpy/ma/core.py", line
5231, in take
out = _data.take(indices, axis=axis, mode=mode).view(cls)
TypeError: Cannot cast array data from dtype('float64') to
dtype('int64') according to the rule 'safe'
I send you attached a copy of the script. The wierdest thing is
that if I save the variable phi to a file and then reopen the file and
display it, it opens a Matplotlib viewer without problems.
Speaking of which, do I need to do something special if I want to
save a variable when running in parallel? I'm unable so save the
variable to a file and then open it in a serial script for viewing (the
viewing script starts filling up all the available memory, and crashes).
Thank you so much for all your help! sorry to bother you with so many
questions!
Adrian.
On Tue, Mar 12, 2013 at 10:16 AM, Adrian Jacobo
<[email protected] <mailto:[email protected]>>
wrote:
Hi,
Thanks for your help. I gave up trying to make Trilinos work with my
macports installation and ended up installing everything with
homebrew,
following the guide on the wiki (there are a few hicups along the way
because some things don't work right away in Mountain Lion, but
nothing
critical).
I've noticed something with this new installation. When I ran the
diffusion.circle example using my previous installation the FiPy
opened
a matplotlib viewer, and now with the homebrew based installation it
opens a Mayavi viewer. Is this normal?
It should open a Matplotlib viewer by default unless it isn't available.
how does FiPy determine which
kind of viewer to use?
See this
http://www.ctcms.nist.gov/fipy/documentation/USAGE.html#envvar-FIPY_VIEWER.
Set "FIPY_VIEWER" to "matplotlib" or "mayavi" and it should take care
of it. You can also instantiate the viewers directly, see the viewers
at http://matforge.org/fipy/browser/fipy/fipy/viewers.
Cheers
--
Daniel Wheeler
_______________________________________________
fipy mailing list
[email protected]
http://www.ctcms.nist.gov/fipy
[ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
#!/usr/bin/env python
## This script was derived from
## 'examples/diffusion/circle.py'
# Solve the diffusion equation in a circular domain meshed with triangles.
#
# This example demonstrates how to solve a simple diffusion problem on a
# non-standard mesh with varying boundary conditions. The :term:`Gmsh` package
# is used to create the mesh. Firstly, define some parameters for the
# creation of the mesh,
#
cellSize = 0.05
radius = 1.
#
# The `cellSize` is the preferred edge length of each mesh element and
# the `radius` is the radius of the circular mesh domain. In the
# following code section a file is created with the geometry that
# describes the mesh. For details of how to write such geometry files
# for :term:`Gmsh`, see the `gmsh manual`_.
#
# .. _gmsh manual: http://www.geuz.org/gmsh/doc/texinfo/gmsh.html
#
# The mesh created by :term:`Gmsh` is then imported into :term:`FiPy` using the
# :class:`~fipy.meshes.gmshMesh.Gmsh2D` object.
#
from fipy import *
mesh = Gmsh2D('''
cellSize = %(cellSize)g;
radius = %(radius)g;
Point(1) = {0, 0, 0, cellSize};
Point(2) = {-radius, 0, 0, cellSize};
Point(3) = {0, radius, 0, cellSize};
Point(4) = {radius, 0, 0, cellSize};
Point(5) = {0, -radius, 0, cellSize};
Circle(6) = {2, 1, 3};
Circle(7) = {3, 1, 4};
Circle(8) = {4, 1, 5};
Circle(9) = {5, 1, 2};
Line Loop(10) = {6, 7, 8, 9};
Plane Surface(11) = {10};
''' % locals()) # doctest: +GMSH
#
# Using this mesh, we can construct a solution variable
#
# .. index::
# object: fipy.variables.cellVariable.CellVariable
#
phi = CellVariable(name = "solution variable",
mesh = mesh,
value = 0.) # doctest: +GMSH
#
# We can now create a :class:`Viewer <~fipy.viewers.viewer.AbstractViewer>` to see the mesh
#
viewer = None
if __name__ == '__main__':
viewer = MatplotlibViewer(vars=phi, datamin=-1, datamax=1.)
viewer.plotMesh()
#
# .. image:: circleMesh.*
# :width: 90%
# :align: center
# :alt: circular mesh generated by Gmsh
#
# We set up a transient diffusion equation
#
# .. index:
# object: fipy.terms.transientTerm.TransientTerm
# object: fipy.terms.implicitDiffusionTerm.DiffusionTerm
#
D = 1.
eq = TransientTerm() == DiffusionTerm(coeff=D)
#
# The following line extracts the :math:`x` coordinate values on the exterior
# faces. These are used as the boundary condition fixed values.
#
X, Y = mesh.faceCenters # doctest: +GMSH
#
phi.constrain(X, mesh.exteriorFaces) # doctest: +GMSH
#
# We first step through the transient problem
#
timeStepDuration = 10 * 0.9 * cellSize**2 / (2 * D)
steps = 10
for step in range(steps):
eq.solve(var=phi,
dt=timeStepDuration) # doctest: +GMSH
if viewer is not None:
viewer.plot() # doctest: +GMSH
#
# .. image:: circleTransient.*
# :width: 90%
# :align: center
# :alt: evolution of diffusion problem on a circular mesh
#
# -----
#
# If we wanted to plot or analyze the results of this calculation with
# another application, we could export tab-separated-values with
#
# .. index::
# object: fipy.viewers.tsvViewer.TSVViewer
#
# ::
#
# TSVViewer(vars=(phi, phi.grad)).plot(filename="myTSV.tsv")
#
# .. literalinclude:: myTSV.tsv
#
# The values are listed at the cell centers.
# Particularly for irregular meshes, no specific ordering should be relied upon.
# Vector quantities are listed in multiple columns, one for each mesh dimension.
#
# -----
#
# This problem again has an analytical solution that depends on the error
# function, but it's a bit more complicated due to the varying boundary
# conditions and the different horizontal diffusion length at different
# vertical positions
#
x, y = mesh.cellCenters # doctest: +GMSH
t = timeStepDuration * steps
#
phiAnalytical = CellVariable(name="analytical value",
mesh=mesh) # doctest: +GMSH
#
# .. index::
# module: scipy
# single: sqrt; arcsin; cos
#
x0 = radius * numerix.cos(numerix.arcsin(y)) # doctest: +GMSH
try:
from scipy.special import erf # doctest: +SCIPY
## This function can sometimes throw nans on OS X
## see http://projects.scipy.org/scipy/scipy/ticket/325
phiAnalytical.setValue(x0 * (erf((x0+x) / (2 * numerix.sqrt(D * t)))
- erf((x0-x) / (2 * numerix.sqrt(D * t))))) # doctest: +GMSH, +SCIPY
except ImportError:
print "The SciPy library is not available to test the solution to \
the transient diffusion equation"
#
print phi.allclose(phiAnalytical, atol = 7e-2) # doctest: +GMSH, +SCIPY
# Expected:
## 1
#
if __name__ == '__main__':
raw_input("Transient diffusion. Press <return> to proceed...")
#
# -----
#
# As in the earlier examples, we can also directly solve the steady-state
# diffusion problem.
#
DiffusionTerm(coeff=D).solve(var=phi) # doctest: +GMSH
#
# The values at the elements should be equal to their `x` coordinate
#
print phi.allclose(x, atol = 0.03) # doctest: +GMSH
# Expected:
## 1
#
# Display the results if run as a script.
#
if viewer is not None:
viewer.plot()
raw_input("Steady-state diffusion. Press <return> to proceed...")
#
# .. image:: circleSteadyState.*
# :width: 90%
# :align: center
# :alt: steady-state solution to diffusion on a circular mesh
_______________________________________________
fipy mailing list
[email protected]
http://www.ctcms.nist.gov/fipy
[ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]