Actual source code: ao.c

  1: #define PETSCDM_DLL

  3: /*  
  4:    Defines the abstract operations on AO (application orderings) 
  5: */
 6:  #include src/dm/ao/aoimpl.h

  8: /* Logging support */
  9: PetscCookie  AO_COOKIE = 0;
 10: PetscEvent  AO_PetscToApplication = 0, AO_ApplicationToPetsc = 0;

 14: /*@C
 15:    AOView - Displays an application ordering.

 17:    Collective on AO and PetscViewer

 19:    Input Parameters:
 20: +  ao - the application ordering context
 21: -  viewer - viewer used for display

 23:    Level: intermediate

 25:    Note:
 26:    The available visualization contexts include
 27: +     PETSC_VIEWER_STDOUT_SELF - standard output (default)
 28: -     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
 29:          output where only the first processor opens
 30:          the file.  All other processors send their 
 31:          data to the first processor to print. 

 33:    The user can open an alternative visualization context with
 34:    PetscViewerASCIIOpen() - output to a specified file.

 36: .keywords: application ordering

 38: .seealso: PetscViewerASCIIOpen()
 39: @*/
 40: PetscErrorCode  AOView(AO ao,PetscViewer viewer)
 41: {

 46:   if (!viewer) viewer = PETSC_VIEWER_STDOUT_(((PetscObject)ao)->comm);
 48:   (*ao->ops->view)(ao,viewer);
 49:   return(0);
 50: }

 54: /*@
 55:    AODestroy - Destroys an application ordering set.

 57:    Collective on AO

 59:    Input Parameters:
 60: .  ao - the application ordering context

 62:    Level: beginner

 64: .keywords: destroy, application ordering

 66: .seealso: AOCreateBasic()
 67: @*/
 68: PetscErrorCode  AODestroy(AO ao)
 69: {

 74:   if (--((PetscObject)ao)->refct > 0) return(0);
 75:   /* if memory was published with AMS then destroy it */
 76:   PetscObjectDepublish(ao);
 77:   /* destroy the internal part */
 78:   if (ao->ops->destroy) {
 79:     (*ao->ops->destroy)(ao);
 80:   }
 81:   PetscHeaderDestroy(ao);
 82:   return(0);
 83: }


 86: /* ---------------------------------------------------------------------*/
 89: /*@
 90:    AOPetscToApplicationIS - Maps an index set in the PETSc ordering to 
 91:    the application-defined ordering.

 93:    Collective on AO and IS

 95:    Input Parameters:
 96: +  ao - the application ordering context
 97: -  is - the index set

 99:    Level: intermediate

101:    Notes:
102:    The index set cannot be of type stride or block
103:    
104:    Any integers in ia[] that are negative are left unchanged. This 
105:          allows one to convert, for example, neighbor lists that use negative
106:          entries to indicate nonexistent neighbors due to boundary conditions
107:          etc.

109: .keywords: application ordering, mapping

111: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(),
112:           AOApplicationToPetscIS(),AOPetscToApplication()
113: @*/
114: PetscErrorCode  AOPetscToApplicationIS(AO ao,IS is)
115: {
117:   PetscInt       n,*ia;
118:   PetscTruth     flag;

123:   ISBlock(is,&flag);
124:   if (flag) SETERRQ(PETSC_ERR_SUP,"Cannot translate block index sets");
125:   ISStride(is,&flag);
126:   if (flag) {
127:     ISStrideToGeneral(is);
128:   }

130:   ISGetLocalSize(is,&n);
131:   ISGetIndices(is,&ia);
132:   (*ao->ops->petsctoapplication)(ao,n,ia);
133:   ISRestoreIndices(is,&ia);
134:   return(0);
135: }

139: /*@
140:    AOApplicationToPetscIS - Maps an index set in the application-defined
141:    ordering to the PETSc ordering.

143:    Collective on AO and IS

145:    Input Parameters:
146: +  ao - the application ordering context
147: -  is - the index set

149:    Level: beginner

151:    Note:
152:    The index set cannot be of type stride or block
153:    
154:    Any integers in ia[] that are negative are left unchanged. This 
155:    allows one to convert, for example, neighbor lists that use negative
156:    entries to indicate nonexistent neighbors due to boundary conditions, etc.

158: .keywords: application ordering, mapping

160: .seealso: AOCreateBasic(), AOView(), AOPetscToApplication(),
161:           AOPetscToApplicationIS(), AOApplicationToPetsc()
162: @*/
163: PetscErrorCode  AOApplicationToPetscIS(AO ao,IS is)
164: {
166:   PetscInt       n,*ia;
167:   PetscTruth     flag;

172:   ISBlock(is,&flag);
173:   if (flag) SETERRQ(PETSC_ERR_SUP,"Cannot translate block index sets");
174:   ISStride(is,&flag);
175:   if (flag) {
176:     ISStrideToGeneral(is);
177:   }

179:   ISGetLocalSize(is,&n);
180:   ISGetIndices(is,&ia);
181:   (*ao->ops->applicationtopetsc)(ao,n,ia);
182:   ISRestoreIndices(is,&ia);
183:   return(0);
184: }

188: /*@
189:    AOPetscToApplication - Maps a set of integers in the PETSc ordering to 
190:    the application-defined ordering.

192:    Collective on AO

194:    Input Parameters:
195: +  ao - the application ordering context
196: .  n - the number of integers
197: -  ia - the integers

199:    Level: beginner

201:    Note:
202:    Any integers in ia[] that are negative are left unchanged. This 
203:    allows one to convert, for example, neighbor lists that use negative
204:    entries to indicate nonexistent neighbors due to boundary conditions, etc.

206: .keywords: application ordering, mapping

208: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(),
209:           AOPetscToApplicationIS(), AOApplicationToPetsc()
210: @*/
211: PetscErrorCode  AOPetscToApplication(AO ao,PetscInt n,PetscInt ia[])
212: {

218:   (*ao->ops->petsctoapplication)(ao,n,ia);
219:   return(0);
220: }

224: /*@
225:    AOApplicationToPetsc - Maps a set of integers in the application-defined
226:    ordering to the PETSc ordering.

228:    Collective on AO

230:    Input Parameters:
231: +  ao - the application ordering context
232: .  n - the number of integers
233: -  ia - the integers; these are replaced with their mapped value

235:    Level: beginner

237:    Note:
238:    Any integers in ia[] that are negative are left unchanged. This 
239:    allows one to convert, for example, neighbor lists that use negative
240:    entries to indicate nonexistent neighbors due to boundary conditions, etc.

242: .keywords: application ordering, mapping

244: .seealso: AOCreateBasic(), AOView(), AOPetscToApplication(),
245:           AOPetscToApplicationIS(), AOApplicationToPetsc()
246: @*/
247: PetscErrorCode  AOApplicationToPetsc(AO ao,PetscInt n,PetscInt ia[])
248: {

254:   (*ao->ops->applicationtopetsc)(ao,n,ia);
255:   return(0);
256: }

260: /*@
261:   AOPetscToApplicationPermuteInt - Permutes an array of blocks of integers
262:   in the PETSc ordering to the application-defined ordering.

264:   Collective on AO

266:   Input Parameters:
267: + ao    - The application ordering context
268: . block - The block size
269: - array - The integer array

271:   Note: The length of the array should be block*N, where N is length
272:   provided to the AOCreate*() method that created the AO.

274:   The permutation takes array[i_pet] --> array[i_app], where i_app is
275:   the index of 'i' in the application ordering and i_pet is the index
276:   of 'i' in the petsc ordering.

278:   Level: beginner

280: .keywords: application ordering, mapping
281: .seealso: AOCreateBasic(), AOView(), AOApplicationToPetsc(), AOPetscToApplicationIS()
282: @*/
283: PetscErrorCode  AOPetscToApplicationPermuteInt(AO ao, PetscInt block, PetscInt array[])
284: {

290:   (*ao->ops->petsctoapplicationpermuteint)(ao, block, array);
291:   return(0);
292: }

296: /*@
297:   AOApplicationToPetscPermuteInt - Permutes an array of blocks of integers
298:   in the application-defined ordering to the PETSc ordering.

300:   Collective on AO

302:   Input Parameters:
303: + ao    - The application ordering context
304: . block - The block size
305: - array - The integer array

307:   Note: The length of the array should be block*N, where N is length
308:   provided to the AOCreate*() method that created the AO.

310:   The permutation takes array[i_app] --> array[i_pet], where i_app is
311:   the index of 'i' in the application ordering and i_pet is the index
312:   of 'i' in the petsc ordering.

314:   Level: beginner

316: .keywords: application ordering, mapping

318: .seealso: AOCreateBasic(), AOView(), AOPetscToApplicationIS(), AOApplicationToPetsc()
319: @*/
320: PetscErrorCode  AOApplicationToPetscPermuteInt(AO ao, PetscInt block, PetscInt array[])
321: {

327:   (*ao->ops->applicationtopetscpermuteint)(ao, block, array);
328:   return(0);
329: }

333: /*@
334:   AOPetscToApplicationPermuteReal - Permutes an array of blocks of reals
335:   in the PETSc ordering to the application-defined ordering.

337:   Collective on AO

339:   Input Parameters:
340: + ao    - The application ordering context
341: . block - The block size
342: - array - The integer array

344:   Note: The length of the array should be block*N, where N is length
345:   provided to the AOCreate*() method that created the AO.

347:   The permutation takes array[i_pet] --> array[i_app], where i_app is
348:   the index of 'i' in the application ordering and i_pet is the index
349:   of 'i' in the petsc ordering.

351:   Level: beginner

353: .keywords: application ordering, mapping

355: .seealso: AOCreateBasic(), AOView(), AOApplicationToPetsc(), AOPetscToApplicationIS()
356: @*/
357: PetscErrorCode  AOPetscToApplicationPermuteReal(AO ao, PetscInt block, PetscReal array[])
358: {

364:   (*ao->ops->petsctoapplicationpermutereal)(ao, block, array);
365:   return(0);
366: }

370: /*@
371:   AOApplicationToPetscPermuteReal - Permutes an array of blocks of reals
372:   in the application-defined ordering to the PETSc ordering.

374:   Collective on AO

376:   Input Parameters:
377: + ao    - The application ordering context
378: . block - The block size
379: - array - The integer array

381:   Note: The length of the array should be block*N, where N is length
382:   provided to the AOCreate*() method that created the AO.

384:   The permutation takes array[i_app] --> array[i_pet], where i_app is
385:   the index of 'i' in the application ordering and i_pet is the index
386:   of 'i' in the petsc ordering.

388:   Level: beginner

390: .keywords: application ordering, mapping

392: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(), AOPetscToApplicationIS()
393: @*/
394: PetscErrorCode  AOApplicationToPetscPermuteReal(AO ao, PetscInt block, PetscReal array[])
395: {

401:   (*ao->ops->applicationtopetscpermutereal)(ao, block, array);
402:   return(0);
403: }