Actual source code: meshCSR.c

  1: #ifdef PETSC_RCS_HEADER
  2: static char vcid[] = "$Id: meshCSR.c,v 1.19 2000/10/17 13:48:57 knepley Exp $";
  3: #endif

  5: /*
  6:      Defines the interface to the CSR mesh functions
  7: */

 9:  #include src/mesh/meshimpl.h

 11: #undef  __FUNCT__
 13: /*@
 14:   MeshCreateLocalCSR - Returns the local mesh in CSR format. All off
 15:   processor edges are ignored, and only the symmetric part of the matrix
 16:   is stored if symmetric is true.

 18:   Not collective

 20:   Input Parameters:
 21: + mesh          - The mesh
 22: . numBC         - [Optional] The number of constrained nodes to be eliminated
 23: . bcNodes       - [Optional] The numbers of constrained nodes
 24: - symmetric     - Whether to return the entire adjacency list

 26:   Output Parameters:
 27: + numVertices   - The number of vertices in the graph
 28: . numEdges      - The number of edges in the graph.
 29: . vertOffsets   - The list of offsets into the neighbor array for each vertex
 30: . vertNeighbors - The list of vertex neighbors
 31: - vertCoords    - The list of vertex coordinates

 33:   Note:
 34:   If any array, such as vertCoords, is passed as PETSC_NULL, then no return
 35:   value will be calculated.

 37:   Level: advanced

 39: .keywords: mesh, partition, CSR
 40: .seealso: MeshDestroyLocalCSR(), MeshPartition()
 41: @*/
 42: int MeshCreateLocalCSR(Mesh mesh, int *numVertices, int *numEdges, int **vertOffsets, int **vertNeighbors,
 43:                        double **vertCoords, int numBC, int *bcNodes, PetscTruth symmetric)
 44: {
 45:   int num;

 55:   if (numBC > 0) {
 57:     num = numBC;
 58:   } else {
 59:     num = 0;
 60:   }
 61:   if (!mesh->ops->createlocalcsr) {
 62:     SETERRQ(PETSC_ERR_SUP, "Not supported by this Mesh object");
 63:   }
 64:   PetscLogEventBegin(MESH_CreateLocalCSR, mesh, 0, 0, 0);
 65:   (*mesh->ops->createlocalcsr)(mesh, numVertices, numEdges, vertOffsets, vertNeighbors, vertCoords, num, bcNodes, symmetric);
 66: 
 67:   PetscLogEventEnd(MESH_CreateLocalCSR, mesh, 0, 0, 0);
 68:   return(0);
 69: }

 71: #undef  __FUNCT__
 73: /*@
 74:   MeshDestroyLocalCSR - Destroys the local mesh in CSR format

 76:   Not collective

 78:   Input Parameters:
 79: + mesh          - The mesh
 80: . vertOffsets   - The list of offsets into the neighbor array for each element
 81: . vertNeighbors - The list of element neighbors
 82: - vertCoords    - The list of vertex coordinates

 84:   Level: advanced

 86: .keywords: mesh, partition
 87: .seealso: MeshCreateLocalCSR(), MeshPartition()
 88: @*/
 89: int MeshDestroyLocalCSR(Mesh mesh, int *vertOffsets, int *vertNeighbors, double *vertCoords)
 90: {

 95:   if (vertOffsets   != PETSC_NULL) {
 96:     PetscFree(vertOffsets);
 97:   }
 98:   if (vertNeighbors != PETSC_NULL) {
 99:     PetscFree(vertNeighbors);
100:   }
101:   if (vertCoords    != PETSC_NULL) {
102:     PetscFree(vertCoords);
103:   }
104:   return(0);
105: }

107: #undef  __FUNCT__
109: /*@
110:   MeshCreateFullCSR - Returns the full mesh including all nodes in CSR format.

112:   Not collective

114:   Input Parameters:
115: + mesh          - The mesh
116: - constrain     - The flag for including connection between constrained nodes

118:   Output Parameters:
119: + numVertices   - The number of vertices in the graph
120: . numEdges      - The number of edges in the graph.
121: . vertOffsets   - List of offsets into the neighbor array for each vertex
122: - vertNeighbors - List of vertex neighbors

124:   Level: advanced

126: .keywords: mesh, partition, CSR
127: .seealso: MeshDestroyFullCSR(), MeshPartition()
128: @*/
129: int MeshCreateFullCSR(Mesh mesh, PetscTruth constrain, int *numVertices, int *numEdges, int **vertOffsets, int **vertNeighbors)
130: {

139:   if ((mesh->partitioned) && (mesh->part->numProcs > 1)) {
140:     SETERRQ(PETSC_ERR_SUP, "Not yet supported on multiple processors");
141:   }
142:   if (!mesh->ops->createfullcsr) {
143:     SETERRQ(PETSC_ERR_SUP, "Not supported by this Mesh object");
144:   }
145:   PetscLogEventBegin(MESH_CreateFullCSR, mesh, 0, 0, 0);
146:   (*mesh->ops->createfullcsr)(mesh, constrain, numVertices, numEdges, vertOffsets, vertNeighbors);
147:   PetscLogEventEnd(MESH_CreateFullCSR, mesh, 0, 0, 0);
148:   return(0);
149: }

151: #undef  __FUNCT__
153: /*@
154:   MeshDestroyFullCSR - Destroys the full mesh in CSR format

156:   Not collective

158:   Input Parameters:
159: + mesh          - The mesh
160: . vertOffsets   - List of offsets into the neighbor array for each element
161: - vertNeighbors - List of element neighbors

163:   Level: advanced

165: .keywords: mesh, partition
166: .seealso: MeshCreateFullCSR(), MeshPartition()
167: @*/
168: int MeshDestroyFullCSR(Mesh mesh, int *vertOffsets, int *vertNeighbors)
169: {

174:   PetscFree(vertOffsets);
175:   PetscFree(vertNeighbors);
176:   return(0);
177: }

179: #undef  __FUNCT__
181: /*@
182:   MeshCreateDualCSR - Returns the dual of the mesh in distributed CSR format

184:   Collective on Mesh

186:   Input Parameter:
187: . mesh          - The mesh

189:   Output Parameters:
190: + elemOffsets   - List of offsets into the neighbor array for each element
191: . elemNeighbors - List of element neighbors
192: . edgeWeights   - [Optional] List of edge weights for the dual graph
193: - weight        - [Optional] Weight for each edge

195:   Level: advanced

197: .keywords: mesh, partition, dual
198: .seealso: MeshDestroyDualCSR(), MeshPartition()
199: @*/
200: int MeshCreateDualCSR(Mesh mesh, int **elemOffsets, int **elemNeighbors, int **edgeWeights, int weight)
201: {

209:   if (!mesh->ops->createdualcsr) {
210:     SETERRQ(PETSC_ERR_SUP, "Not supported by this Mesh object");
211:   }
212:   PetscLogEventBegin(MESH_CreateDualCSR, mesh, 0, 0, 0);
213:   (*mesh->ops->createdualcsr)(mesh, elemOffsets, elemNeighbors, edgeWeights, weight);
214:   PetscLogEventEnd(MESH_CreateDualCSR, mesh, 0, 0, 0);
215:   return(0);
216: }

218: #undef  __FUNCT__
220: /*@
221:   MeshDestroyDualCSR - Destroys the dual of the mesh in distributed CSR format

223:   Not collective

225:   Input Parameters:
226: + mesh          - The mesh
227: . elemOffsets   - List of offsets into the neighbor array for each element
228: . elemNeighbors - List of element neighbors
229: - edgeWeights   - List of edge weights for the dual graph

231:   Level: advanced

233: .keywords: mesh, partition, dual
234: .seealso: MeshCreateDualCSR(), MeshPartition()
235: @*/
236: int MeshDestroyDualCSR(Mesh mesh, int *elemOffsets, int *elemNeighbors, int *edgeWeights)
237: {

242:   PetscFree(elemOffsets);
243:   PetscFree(elemNeighbors);
244:   if (edgeWeights != PETSC_NULL) {
245:     PetscFree(edgeWeights);
246:   }
247:   return(0);
248: }