Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plotMesh call throwing deprecation warning and failing to plot in circle diffusion example #693

Closed
amine-aboufirass opened this issue Jan 21, 2020 · 8 comments

Comments

@amine-aboufirass
Copy link

amine-aboufirass commented Jan 21, 2020

I tried to replicate the circle diffusion example as follows. I used pygmsh to generate the geometry string that fipy required:


from fipy import CellVariable, Gmsh2D, TransientTerm, DiffusionTerm, Viewer
from fipy.tools import numerix
import pygmsh, meshio

cellSize = 0.05
radius = 1.

geom = pygmsh.built_in.Geometry()
p1 = geom.add_point((0.,0.,0.), lcar = cellSize)
p2 = geom.add_point((-radius,0.,0.), lcar = cellSize)
p3 = geom.add_point((0.,radius,0.), lcar = cellSize)
p4 = geom.add_point((radius,0., 0.), lcar = cellSize)
p5 = geom.add_point((0.,-radius,0.), lcar = cellSize)
l6 = geom.add_circle_arc(p2, p1, p3)
l7 = geom.add_circle_arc(p3, p1, p4)
l8 = geom.add_circle_arc(p4, p1, p5)
l9 = geom.add_circle_arc(p5, p1, p2)
ll10 = geom.add_line_loop((l6, l7, l8, l9))
s11 = geom.add_surface(ll10)

geom_string = geom.get_code()
mesh = Gmsh2D(geom_string)

phi = CellVariable(name = "solution variable", mesh = mesh, value = 0.)
viewer = Viewer(vars=phi, datamin=-1, datamax=1.)
viewer.plotMesh()

The above returns a warning (in jupyter) and the mesh fails to plot:

C:\Users\aboufira\AppData\Local\Continuum\miniconda3\envs\CGF_1\lib\site-packages\fipy\viewers\matplotlibViewer\matplotlibViewer.py:229: MatplotlibDeprecationWarning:
The set_norm function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use ScalarMappable.set_norm instead.
self._cb.set_norm(value)
C:\Users\aboufira\AppData\Local\Continuum\miniconda3\envs\CGF_1\lib\site-packages\fipy\viewers\matplotlibViewer\matplotlibViewer.py:240: MatplotlibDeprecationWarning:
The set_norm function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use ScalarMappable.set_norm instead.
self._cb.set_norm(self.viewer.norm)

I also found a related issue #586 in which @cashTangoTangoCash attempts a workaround involving writing to and reading from a .msh file. I'd like to avoid this if I can, if the .plotMesh method works. Does anyone know why the above warning occurs? Is the plotMesh method currently working?

@amine-aboufirass
Copy link
Author

I'm also noticing that there are a few different classes for matplotlib 2D viewers. A couple are:

  • matplotlib2DViewer
  • matplotlib2DGridViewer

What's the difference between these? Is the second one meant to plot meshes perhaps?

@amine-aboufirass
Copy link
Author

amine-aboufirass commented Jan 21, 2020

Well I had to get down and dirty with it. Ended up using a combination of gmsh and pyvista to get what I want:

from fipy import CellVariable, Gmsh2D, TransientTerm, DiffusionTerm, Viewer
from fipy.tools import numerix
import pygmsh, pyvista

cellSize = 0.05
radius = 1.

geom = pygmsh.built_in.Geometry()
p1 = geom.add_point((0.,0.,0.), lcar = cellSize)
p2 = geom.add_point((-radius,0.,0.), lcar = cellSize)
p3 = geom.add_point((0.,radius,0.), lcar = cellSize)
p4 = geom.add_point((radius,0., 0.), lcar = cellSize)
p5 = geom.add_point((0.,-radius,0.), lcar = cellSize)
l6 = geom.add_circle_arc(p2, p1, p3)
l7 = geom.add_circle_arc(p3, p1, p4)
l8 = geom.add_circle_arc(p4, p1, p5)
l9 = geom.add_circle_arc(p5, p1, p2)
ll10 = geom.add_line_loop((l6, l7, l8, l9))
s11 = geom.add_surface(ll10)

geom_string = geom.get_code()
mesh = Gmsh2D(geom_string)

ugrid= pyvista.UnstructuredGrid(mesh.VTKCellDataSet._vtk_obj)
plotter = pyvista.Plotter()
plotter.set_background('white')
plotter.add_mesh(ugrid, style='wireframe', color='black')
plotter.add_bounding_box(color='red')
plotter.show_grid(color="red")
plotter.view_xy()
plotter.show()

download

Although I do note that the mesh looks slightly different from what is provided in the example in the documentation. On another note, would it be worth investigating the following?:

  • integration of existing plotters in the pyvista project into fipy's Viewer architecture. pyvista looks like a healthy project with excellent VTK plotting capabilities.
  • enabling Gmsh2D to accept a pygmsh.built_in.Geometry() object or even a pygmsh mesh object? It seems reasonable to delegate the meshing operations to a specialized library, and letting fipy do the mathematical modeling of the underlying physical phenomena instead of being bogged down by computational geometry.

Just some suggestions which I think might improve fipy's already excellent functionality and allow it to better integrate with existing libraries...

@guyer
Copy link
Member

guyer commented Jan 22, 2020

.plotMesh() is not presently implemented for any of our Viewers. It used to be implemented for the obsolete gist package, but we've evidently never written the code for anything else.

The deprecation warnings are unrelated. That's just a sign that our Matplotlib Viewers are using an old interface to Matplotlib and need to be updated.

@guyer
Copy link
Member

guyer commented Jan 22, 2020

Matplotlib2DGridViewer is optimized to display variables defined on grid meshes. Matplotlib2DViewer is a general tool that can display variables defined on arbitrary 2D meshes.

@guyer
Copy link
Member

guyer commented Jan 22, 2020

A contribution of a PyVista viewer class would be most welcome

@guyer
Copy link
Member

guyer commented Jan 22, 2020

We are open to using pygmsh, but according to its author, it doesn't handle parallel partitioning, which limits its utility for FiPy.

@amine-aboufirass
Copy link
Author

@guyer thanks for your responses. For the moment I am only using pygmsh to feed the geometry string into fipy's Gmsh2D object. This is not so difficult so getting Gmsh2D to accept a pygmsh.built_in.Geometry() may be a bit of an overkill... It works and that's what matters.

I am happy to look into implementing a pyvista viewer class, but perhaps some consideration of the discussion at pyvista/pyvista-support#108 might be necessary.

@guyer
Copy link
Member

guyer commented Jan 24, 2020

This is a duplicate of #312.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants