On Fri, Nov 21, 2008 at 5:38 PM, Angus Hendrick
<[EMAIL PROTECTED]> wrote:
> Hello,
>
> I'm using fipy to model heat transport on 2D meshes.  I'd like to be able to
> save the mesh into a standard hdf5 file, so that it can be easily read by
> non-fipy users to check my simulations, and I'd also like to be able to
> directly read the saved file back in and create the appropriate fipy mesh.

Sounds reasonable.

> From reviewing the code, it looks like the core class is the Mesh class, and
> that the key variables for recreating the original mesh are the vertex
> coordinates, the FaceVertexIDs, and the CellFaceIDs.

Correct.

> Which I can easily
> retrieve from the mesh I generate and then and store in my hdf5 file.
> However I have a couple of problems making this happen.
>
> First, I can't seem to figure out how to import the Mesh class so that I can
> pass it this information to re-instance the mesh (assuming this is the right
> approach).

If it's a 3D mesh then use "from fipy.meshes.numMesh.mesh import
Mesh", for a 2D mesh then use "from fipy.meshes.numMesh.mesh 2Dimport
Mesh2D" and for a 1D mesh use "from fipy.meshes.numMesh.mesh1D import
Mesh1D". You could write a factory function to return the right object
based on the dimension to make it easier. I hope that helps.

> Second, while I understand what the vertex coordinates are, the
> relationships between the coordinates and the face vertex and cell face IDs
> is opaque to me, and I'm hoping someone would explain these to me.

The "vertexCoords" is a (d, nv) shaped float array of coordinates
where "d" is the dimension and "nv" is the number of coordinates.

The "faceVertexIDs" is a (p, nf) shaped integer masked array of the
vertex IDs that correspond to a given face. "p" is the maximum number
of vertices making up a face and "nf" is the total number of faces in
the mesh. The values held in this array index "vertexCoords". The
array is masked because the number of vertices used to define two
given faces in a mesh can be different.

The "cellFaceIDs" s a (q, nc) shaped integer masked array of the face
IDs that correspond to a given cell. "q" is the maximum number of
faces making up a cell and "nc" is the total number of cells in the
mesh. The values held in this array index "faceVertexIDs".

For example if I take cell 2 in a mesh "m" and I want to know some of
it's vertex coords, I could do,

from fipy import *
m = Grid2D(nx=2, ny=2)

for faceID in m._getCellFaceIDs()[:,2]:
    for vertexID in m._getFaceVertexIDs()[:,faceID]:
        print vertexID, m.getVertexCoords()[:,vertexID]

3 [ 0.  1.]
4 [ 1.  1.]
4 [ 1.  1.]
7 [ 1.  2.]
6 [ 0.  2.]
7 [ 1.  2.]
3 [ 0.  1.]
6 [ 0.  2.]

The output is non-unique.

> Finally,
> if this representation is not a standard, generally recognized method of
> depicting a mesh, I should probably convert from these to something more
> standard for storage, so that my data will be more comprehensible to
> non-fipy users.

I am not sure there is a standard, but there are not that many
sensible choices for a finite volume mesh. What is good about this
choice is that there is no need to specify handedness. The other
sensible choice is to do away with faces and just have vertices and
cells. You then need to know something else that defines the structure
of each element. Using the vtk element definitions may be a good
standard, which uses just the cell and faces. See
<http://matforge.org/fipy/browser/trunk/fipy/viewers/mayaviViewer/mayaviViewer.py?rev=2811#L101>
as an example of where we have tried to do this with the mayavi
viewer. The method "_getOrderedCellVertexIDs()" should return an
ordered list of vertex ids for a given mesh. I am not certain that it
always works, check it for your mesh.
For more information on vtk you can go through the mayavi website
<http://mayavi.sourceforge.net/>.

> Any advice/help/insights on how to best store the mesh info is appreciated.

Hope this helps

Cheers.



-- 
Daniel Wheeler

Reply via email to