Closed amine-aboufirass closed 4 years ago
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?
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()
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?:
pyvista
project into fipy
's Viewer
architecture. pyvista
looks like a healthy project with excellent VTK plotting capabilities.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...
.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.
Matplotlib2DGridViewer
is optimized to display variables defined on grid meshes. Matplotlib2DViewer
is a general tool that can display variables defined on arbitrary 2D meshes.
A contribution of a PyVista viewer class would be most welcome
We are open to using pygmsh, but according to its author, it doesn't handle parallel partitioning, which limits its utility for FiPy.
@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 https://github.com/pyvista/pyvista-support/issues/108 might be necessary.
This is a duplicate of #312.
I tried to replicate the circle diffusion example as follows. I used
pygmsh
to generate the geometry string thatfipy
required:The above returns a warning (in jupyter) and the mesh fails to plot:
I also found a related issue https://github.com/usnistgov/fipy/issues/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 theplotMesh
method currently working?