Skip to content

SurfaceOfSphere

Jonathan Guyer edited this page Sep 26, 2014 · 1 revision

This example is now at source:trunk/examples/meshing/sphere.py. The procedure below is no longer valid.

An interesting problem is to solve an equation on a 2D geometry that is embedded in 3D space, such as diffusion on the surface of a sphere (with nothing either inside or outside the sphere). Without too much difficulty, you can coax gmsh to create a spherical mesh that can be imported into !FiPy. Resist the tempatation to use `GmshImporter2D`; although the topology is only two dimensional, its coordinates are three dimensional and need to be imported properly. You could import such a mesh with `GmshImporter2DIn3DSpace`, but you'll find that the math won't be done correctly when you try to solve (e.g., !FiPy won't account for the difference between a spherical Laplacian and a Cartesian Laplacian).

The key is to create a mesh on the surface of the sphere where the cells have three dimensions (polyhedra (truncated wedges)) instead of two (polygons). Another subtlety is that the naive approach to creating the mesh by sweeping latitude and longitude will generate very anisotropic cell shapes (squares on the equator and acute triangles at the poles), which causes a lot of numerical problems. We have put together two short scripts that take care of these issues, creating a mesh that occupies a thin spherical shell.

Put [attachment:sphere.gmsh?format=raw] in your working directory and, from the command-line (not in Python), type

`sphere.gmsh` is a driver file that will create a fairly isotropic 2D spherical mesh with the proper connectivity all the way around.

Now, put [attachment:extrude.py?format=raw] someplace on your `$PYTHONPATH`, launch Python, and enter

which serves to load the 2D sphere and then expand it into a spherical shell with a thicknes of 10% of the radius.

Now we can put some data on the sphere

MayaVi is the only viewer we support that can display 3D meshes. Because of bugs introduced when we shifted to NumPy, be sure that you are running !FiPy r2056 or newer (presently available only through svn).

You should see something like Image(sphere.png)

Now that we've shown you how to create a spherical mesh and how to display it, we leave doing any actual science with it as an exercise for the reader...


two notes/questions:

  1. Using the latest version of gmsh will generate the ASCII2.0 format which fipy
  doesn't yet understand.  One solution is to run gmsh interactively, generate the
  2D mesh and then use the "save as.." command to specify the file format as 1.0
  2. As per the warning:
  When I display the spherical mesh using the code snippet above, I get the following:
    [[Image(sphere_face.png)]]
  Perhaps a problem with the face ordering?
Clone this wiki locally