
NAO Interface Class NARegularGrid
The NARegularGrid class is a base class representing all regular
grids. Regular grids seem to be one of those things that everyone
knows when they see one, but for which good precise definitions don't
exist. The definition of a NARegularGrid includes tensor products of
stretched one-dimensional grids, but the interface also supports grids
with cells missing, or with extra cells. So both of the grids below are
covered by the class:
I don't know what you call the second (but its regular under this definition
8-)} The green edges are to be identifed with each other, as are the
magenta edges.
In addition to the interface to the general celluar complex that a discrete
manifold presents, a NARegularGrid provides information about neighboring
vertices in each of the coordinate directions, and mesh spacings in the
same directions. In two dimensions this means that the cells are
quadrilaterals, and except for edge cells where there are no neighbors
in one direction, there are four immediate neighbors of each vertex,
and functions which define the mesh spacing in the "x" and "y" directions.
To use this class, include the header file
NAO/RegGrid.h
and link against library
libNAOBase.a
The following member functions are available when classes are derived from this
interface class, in addition to those provided by the parent class
NARegion.
Pure Virtual Member Functions, which must be provided by derived classes:
-
| NAFunction* getMeshSpacingFn(dir
) const; |
| Returns the mesh spacing function of the grid.
|
| const int | dir
; | The direction the mesh spacing is wanted. (Specified by user).
|
|
-
| long getNextNeighboringVertex(v
,axis
) const; |
| Returns the next neighboring vertex.
|
| const long | v
; | Vertex. (Specified by user).
|
| const int | axis
; | Direction. (Specified by user).
|
|
-
| long getPreviousNeighboringVertex(v
,axis
) const; |
| Returns the previous neighboring vertex.
|
| const long | v
; | Vertex. (Specified by user).
|
| const int | axis
; | Direction. (Specified by user).
|
|
-
-
| NABoolean isitinChart(pt
) const; |
| Returns TRUE if the given point is in the domain of the chart mapping.
|
|
-
-
| void getVertex(i
,pt
) const; |
| get a vertex.
|
| const long | i
; | Vertex number. (Specified by user).
|
| NAPointOnManifold* | pt
; | NAPointOnManifold in which to return the vertex. User is responsible for allocating storage. (Specified by user).
|
|
-
-
-
| long getCellNumber(pt
,dimension
) const; |
| Given the dimension of the cell, returns the cell in which the given point lies.
|
| const NAPointOnManifold* | pt
; | Point. (Specified by user).
|
| int | dimension
; | Dimension of cell. (Specified by user).
|
|
-
| long getNumberOfCells(dimension
) const; |
| return the number of cells of a given dimension.
|
| const int | dimension
; | Dimension of cell. (Specified by user).
|
|
-
| int getMaxNumberOfCellFaces(dimension
) const; |
| return the largest number of faces of cells of a given dimension.
|
| const int | dimension
; | Dimension of cell. (Specified by user).
|
|
-
| int getMinNumberOfCellFaces(dimension
) const; |
| return the smallest number of faces of cells of a given dimension.
|
| const int | dimension
; | Dimension of cell. (Specified by user).
|
|
-
| int getNumberOfCellFaces(dimension
,cell
) const; |
| return the number of faces of a cell of a given dimension.
|
| const int | dimension
; | Dimension of cell. (Specified by user).
|
| const long | cell
; | Cell number. (Specified by user).
|
|
-
| int getCellFaces(dimension
,cell
,faces
) const; |
| Get a list of all the faces of a cell of a given dimension. Returns the number of faces in the array.
|
| const int | dimension
; | Dimension of cell. (Specified by user).
|
| const long | cell
; | Cell number. (Specified by user).
|
| long* | faces
; | Array to receive the list of faces. User is responsible for allocating space. (Specified by user).
|
|
-
| long getCellFace(dimension
,cell
,face
) const; |
| Returns the index of a face of a cell of a given dimension.
|
| const int | dimension
; | Dimension of cell. (Specified by user).
|
| const long | cell
; | Cell number. (Specified by user).
|
| const int | face
; | Face number. (Specified by user).
|
|
-
| int getMaxNumberOfFaceCells(dimension
) const; |
| Returns the largest number of cells adjacent to a face of a given dimension.
|
| const int | dimension
; | Dimension of face. (Specified by user).
|
|
-
| int getMinNumberOfFaceCells(dimension
) const; |
| Returns the smallest number of cells adjacent to a face of a given dimension.
|
| const int | dimension
; | Dimension of face. (Specified by user).
|
|
-
| int getNumberOfFaceCells(dimension
,face
) const; |
| Returns the number of cells adjacent to a face of a given dimension.
|
| const int | dimension
; | Dimension of face. (Specified by user).
|
| const long | face
; | index of Face. (Specified by user).
|
|
-
| int getFaceCells(dimension
,face
,cells
) const; |
| Get a list of all the cells adjacent to a face of a given dimension. Returns the number of faces in the array.
|
| const int | dimension
; | Dimension of face. (Specified by user).
|
| const long | face
; | index of Face. (Specified by user).
|
| long* | cells
; | Array to receive the list of cells. User is responsible for allocating space. (Specified by user).
|
|
-
| long getFaceCell(dimension
,face
,cell
) const; |
| Returns the index of a cell adjacent to a face of a given dimension.
|
| const int | dimension
; | Dimension of face. (Specified by user).
|
| const long | face
; | index of Face. (Specified by user).
|
| const int | cell
; | Cell number. (Specified by user).
|
|
-
| float getBoundingBoxMin(chart
,direction
) const; |
| Returns the minimum value of the bounding box for a chart, in the given direction.
|
| const int | chart
; | The chart number. (Specified by user).
|
| const int | direction
; | The coordinate direction. (Specified by user).
|
|
-
| float getBoundingBoxMax(chart
,direction
) const; |
| Returns the maximum value of the bounding box for a chart, in the given direction.
|
| const int | chart
; | The chart number. (Specified by user).
|
| const int | direction
; | The coordinate direction. (Specified by user).
|
|
-
| float getBoundingBoxScale(chart
,direction
) const; |
| Returns a typical scale of the chart within the bounding box, in the given direction.
|
| const int | chart
; | The chart number. (Specified by user).
|
| const int | direction
; | The coordinate direction. (Specified by user).
|
|
Virtual Member Functions, which may or may not be provided by derived classes:
-
| long getNextNeighboringVertex(c
,v
,axis
) const; |
| Returns the next neighboring vertex.
|
| const int | c
; | Component. (Specified by user).
|
| const long | v
; | Vertex. (Specified by user).
|
| const int | axis
; | Direction. (Specified by user).
|
|
-
| long getPreviousNeighboringVertex(c
,v
,axis
) const; |
| Returns the previous neighboring vertex.
|
| const int | c
; | Component. (Specified by user).
|
| const long | v
; | Vertex. (Specified by user).
|
| const int | axis
; | Direction. (Specified by user).
|
|
-
-
| long getNumberOfVertices(c
) const; |
| Returns the number of vertices in a component mesh.
|
| const int | c
; | Component. (Specified by user).
|
|
-
| void getVertex(c
,i
,pt
) const; |
| get a vertex from a component mesh.
|
| const int | c
; | Component. (Specified by user).
|
| const long | i
; | Vertex number. (Specified by user).
|
| NAPointOnManifold* | pt
; | NAPointOnManifold in which to return the vertex. User is responsible for allocating storage. (Specified by user).
|
|
-
| long getVertexNumber(c
,v
) const; |
| Returns the vertex number of a vertex on a component mesh.
|
| const int | c
; | Component. (Specified by user).
|
| const NAPointOnManifold* | v
; | Vertex. (Specified by user).
|
|
-
| long getCellNumber(c
,pt
,dimension
) const; |
| Given the dimension of the cell, returns the cell in which the given point lies.
|
| const int | c
; | Component. (Specified by user).
|
| const NAPointOnManifold* | pt
; | Point. (Specified by user).
|
| int | dimension
; | Dimension of cell. (Specified by user).
|
|
-
| long getNumberOfCells(c
,dimension
) const; |
| Returns the number of cells of a given dimension on a component mesh.
|
| const int | c
; | Component. (Specified by user).
|
| const int | dimension
; | Dimension of cell. (Specified by user).
|
|
-
| int getMaxNumberOfCellFaces(c
,dimension
) const; |
| Returns the largest number of faces of cells of a given dimension on a component mesh.
|
| const int | c
; | Component. (Specified by user).
|
| const int | dimension
; | Dimension of cell. (Specified by user).
|
|
-
| int getMinNumberOfCellFaces(c
,dimension
) const; |
| Returns the smallest number of faces of cells of a given dimension on a component mesh.
|
| const int | c
; | Component. (Specified by user).
|
| const int | dimension
; | Dimension of cell. (Specified by user).
|
|
-
| int getNumberOfCellFaces(c
,dimension
,cell
) const; |
| Returns the number of faces of a cell of a given dimension on a component mesh.
|
| const int | c
; | Component. (Specified by user).
|
| const int | dimension
; | Dimension of cell. (Specified by user).
|
| const long | cell
; | Cell number. (Specified by user).
|
|
-
| int getCellFaces(c
,dimension
,cell
,faces
) const; |
| Get a list of all the faces of a cell of a given dimension of a given component. Returns the number of faces in the array.
|
| const int | c
; | Component. (Specified by user).
|
| const int | dimension
; | Dimension of cell. (Specified by user).
|
| const long | cell
; | Cell number. (Specified by user).
|
| long* | faces
; | Array to receive the list of faces. User is responsible for allocating space. (Specified by user).
|
|
-
| long getCellFace(c
,dimension
,cell
,face
) const; |
| Returns the index of a face of a cell of a given dimension on a component mesh.
|
| const int | c
; | Component. (Specified by user).
|
| const int | dimension
; | Dimension of cell. (Specified by user).
|
| const long | cell
; | Cell number. (Specified by user).
|
| const int | face
; | Face number. (Specified by user).
|
|
-
| int getMaxNumberOfFaceCells(c
,dimension
) const; |
| Returns the largest number of cells adjacent to a face of a given dimension on a component mesh.
|
| const int | c
; | Component. (Specified by user).
|
| const int | dimension
; | Dimension of face. (Specified by user).
|
|
-
| int getMinNumberOfFaceCells(c
,dimension
) const; |
| Returns the smallest number of cells adjacent to a face of a given dimension on a component mesh.
|
| const int | c
; | Component. (Specified by user).
|
| const int | dimension
; | Dimension of face. (Specified by user).
|
|
-
| int getNumberOfFaceCells(c
,dimension
,face
) const; |
| Returns the number of cells adjacent to a face of a given dimension on a component mesh.
|
| const int | c
; | Component. (Specified by user).
|
| const int | dimension
; | Dimension of face. (Specified by user).
|
| const long | face
; | index of Face. (Specified by user).
|
|
-
| int getFaceCells(c
,dimension
,face
,cells
) const; |
| Get a list of all the cells adjacent to a face of a given dimension of a given component. Returns the number of faces in the array.
|
| const int | c
; | Component. (Specified by user).
|
| const int | dimension
; | Dimension of face. (Specified by user).
|
| const long | face
; | index of Face. (Specified by user).
|
| long* | cells
; | Array to receive the list of cells. User is responsible for allocating space. (Specified by user).
|
|
-
| long getFaceCell(c
,dimension
,face
,cell
) const; |
| Returns the index of a cell adjacent to a face of a given dimension on a component mesh.
|
| const int | c
; | Component. (Specified by user).
|
| const int | dimension
; | Dimension of face. (Specified by user).
|
| const long | face
; | index of Face. (Specified by user).
|
| const int | cell
; | Cell number. (Specified by user).
|
|
-
| NABoolean canBeCastTo(type
) const; |
| returns TRUE if this NAAlgorithm can be cast to the type given.
|
| const char* | type
; | The string corresponding to the class (Specified by user).
|
|
non Virtual Member Functions, which are provided by this base class and may not be replaced by a derived class:
-
| NABoolean isitDiscrete() const; |
| Returns TRUE if this class implements the member functions associated with meshes.
|
The following classes are children of this base class:
There is no additional data associated with the NARegularGrid base class,
only the additional interfaces that it defines.
The first set of interfaces
provide information about the neighbors of
a vertex. For each coordinate direction, there are two neighbors, one in
the positive direction (the next vertex), and the other in the
other direction (the previous vertex). The figure below shows
this for a three dimensional mesh:

Vertices on the boundaries of the grid may be missing one or mor of these
neighbors. In that case, the convention is that the neighbor queries
return an invalid vertex number, -1.
For a regular three dimensional grid, indexed by (i,j,k), each running
bewteen (0,0,0) and (nx,ny,nz), we have that the index of
a vertex is
The neighors are easily found
| next(I,0) = I+1 |
| prev(I,0) = I-1 |
| next(I,1) = I+nx |
| prev(I,1) = I-nx |
| next(I,2) = I+nx*ny |
| prev(I,2) = I-nx*ny |
Boundaries can be dealt with in a couple of ways. Notice that
| i=mod(I,nx) |
| j=mod(floor(I/nx),ny) |
| k=floor(I/nx/ny) |
I have found that these interfaces are easy to implement, much more so than
the routines that ask for a global numbering of the edges and faces in a three
dimensional regular grid.
The second set of new interfaces
provides information about the mesh spacing, as a function of position in
the grid. Notice that we have separated the topological information
about the grid to which the first set of interfaces allows access, from this
spacing information.
Each coordinate direction has a spacing. For "rectangular" meshes,
where the spacing between grid points is constant, the meaning of the spacing
is clear. I'm not sure how those who implement regular grids with variable
mesh spacings will choose to interpret these functions.
Particular examples can be found in documentation for the child classes
of this base class. As an example of the base class, let me show how they
can be used to implement a finite difference stencil, since that was the
main motivation for the interfaces.
Consider the difference scheme
| (L f)_{i+1/2,j+1/2,k+1/2}
= (f_{i+1,j,k}-f_{i,j,k})/|x_{i+1,j,k}-x_{i,j,k}| |
|
+ (f_{i,j+1,k}-f_{i,j,k})/|x_{i,j+1,k}-x_{i,j,k}| |
|
+ (f_{i,j,k+1}-f_{i,j,k})/|x_{i,j,k+1}-x_{i,j,k}| |
This might be done in the following way:
NAFunction *Fhx=grid->getMeshSpacingFn(0);
NAFunction *Fhy=grid->getMeshSpacingFn(1);
NAFunction *Fhz=grid->getMeshSpacingFn(2);
int n=grid->getNumberOfVertices();
for(i=0;i<n;i++)
{
g[i]=0;
i1=grid->getNextNeighboringVertex(i,0);
grid->getVertex(i1,v1);
Fhx->evaluate(v1,hx1);
grid->getVertex(i,v);
Fhx->evaluate(v,hx);
h=.5*(hx1->getDoubleCoordinate(0)+hx->getDoubleCoordinate(0));
g[i]+=(f[i1]-f[i])/h;
i1=grid->getNextNeighboringVertex(i,1);
grid->getVertex(i1,v1);
Fhy->evaluate(v1,hy1);
grid->getVertex(i,v);
Fhy->evaluate(v,hy);
h=.5*(hy1->getDoubleCoordinate(0)+hy->getDoubleCoordinate(0));
g[i]+=(f[i1]-f[i])/h;
i1=grid->getNextNeighboringVertex(i,2);
grid->getVertex(i1,v1);
Fhz->evaluate(v1,hz1);
grid->getVertex(i,v);
Fhz->evaluate(v,hz);
h=.5*(hz1->getDoubleCoordinate(0)+hz->getDoubleCoordinate(0));
g[i]+=(f[i1]-f[i])/h;
}
I've left out a couple of things, and haven't done other things I might to
speed this up a bit, or to handle boundaries, but I think the main idea
is clear.
The parent of this Interface class:
Siblings of this Interface class:
Children of this Interface class:
The Finite Difference classes are based on functions defined on
regular grids. See for example, the classes:
Created: Fri Oct 9 14:44:21 EDT 1998
[Comments |
NAO home page ]
[Research home page]
[ IBM home page |
Order |
Privacy |
ContactIBM |
Legal ]