Actual source code: ao.c

  1: /*$Id: ao.c,v 1.39 2001/03/23 23:24:50 balay Exp $*/
  2: /*  
  3:    Defines the abstract operations on AO (application orderings) 
  4: */
  5: #include "src/dm/ao/aoimpl.h"      /*I "petscao.h" I*/

  7: /*@C
  8:    AOView - Displays an application ordering.

 10:    Collective on AO and PetscViewer

 12:    Input Parameters:
 13: +  ao - the application ordering context
 14: -  viewer - viewer used for display

 16:    Level: intermediate

 18:    Note:
 19:    The available visualization contexts include
 20: +     PETSC_VIEWER_STDOUT_SELF - standard output (default)
 21: -     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
 22:          output where only the first processor opens
 23:          the file.  All other processors send their 
 24:          data to the first processor to print. 

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

 29: .keywords: application ordering

 31: .seealso: PetscViewerASCIIOpen()
 32: @*/
 33: int AOView(AO ao,PetscViewer viewer)
 34: {

 39:   if (!viewer) viewer = PETSC_VIEWER_STDOUT_(ao->comm);
 41:   (*ao->ops->view)(ao,viewer);
 42:   return(0);
 43: }

 45: /*@
 46:    AODestroy - Destroys an application ordering set.

 48:    Collective on AO

 50:    Input Parameters:
 51: .  ao - the application ordering context

 53:    Level: beginner

 55: .keywords: destroy, application ordering

 57: .seealso: AOCreateBasic()
 58: @*/
 59: int AODestroy(AO ao)
 60: {

 64:   if (!ao) return(0);
 66:   if (--ao->refct > 0) return(0);

 68:   /* if memory was published with AMS then destroy it */
 69:   PetscObjectDepublish(ao);

 71:   (*ao->ops->destroy)(ao);
 72:   return(0);
 73: }


 76: /* ---------------------------------------------------------------------*/
 77: /*@
 78:    AOPetscToApplicationIS - Maps an index set in the PETSc ordering to 
 79:    the application-defined ordering.

 81:    Collective on AO and IS

 83:    Input Parameters:
 84: +  ao - the application ordering context
 85: -  is - the index set

 87:    Level: intermediate

 89:    Notes:
 90:    The index set cannot be of type stride or block
 91:    
 92:    Any integers in ia[] that are negative are left unchanged. This 
 93:          allows one to convert, for example, neighbor lists that use negative
 94:          entries to indicate nonexistent neighbors due to boundary conditions
 95:          etc.

 97: .keywords: application ordering, mapping

 99: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(),
100:           AOApplicationToPetscIS(),AOPetscToApplication()
101: @*/
102: int AOPetscToApplicationIS(AO ao,IS is)
103: {
104:   int        n,*ia,ierr;
105:   PetscTruth flag;

109:   ISBlock(is,&flag);
110:   if (flag) SETERRQ(1,"Cannot translate block index sets");
111:   ISStride(is,&flag);
112:   if (flag) {
113:     ISStrideToGeneral(is);
114:   }

116:   ISGetLocalSize(is,&n);
117:   ISGetIndices(is,&ia);
118:   (*ao->ops->petsctoapplication)(ao,n,ia);
119:   ISRestoreIndices(is,&ia);
120:   return(0);
121: }

123: /*@
124:    AOApplicationToPetscIS - Maps an index set in the application-defined
125:    ordering to the PETSc ordering.

127:    Collective on AO and IS

129:    Input Parameters:
130: +  ao - the application ordering context
131: -  is - the index set

133:    Level: beginner

135:    Note:
136:    The index set cannot be of type stride or block
137:    
138:    Any integers in ia[] that are negative are left unchanged. This 
139:    allows one to convert, for example, neighbor lists that use negative
140:    entries to indicate nonexistent neighbors due to boundary conditions, etc.

142: .keywords: application ordering, mapping

144: .seealso: AOCreateBasic(), AOView(), AOPetscToApplication(),
145:           AOPetscToApplicationIS(), AOApplicationToPetsc()
146: @*/
147: int AOApplicationToPetscIS(AO ao,IS is)
148: {
149:   int        n,*ia,ierr;
150:   PetscTruth flag;

154:   ISBlock(is,&flag);
155:   if (flag) SETERRQ(1,"Cannot translate block index sets");
156:   ISStride(is,&flag);
157:   if (flag) {
158:     ISStrideToGeneral(is);
159:   }

161:   ISGetLocalSize(is,&n);
162:   ISGetIndices(is,&ia);
163:   (*ao->ops->applicationtopetsc)(ao,n,ia);
164:   ISRestoreIndices(is,&ia);
165:   return(0);
166: }

168: /*@
169:    AOPetscToApplication - Maps a set of integers in the PETSc ordering to 
170:    the application-defined ordering.

172:    Collective on AO

174:    Input Parameters:
175: +  ao - the application ordering context
176: .  n - the number of integers
177: -  ia - the integers

179:    Level: beginner

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

186: .keywords: application ordering, mapping

188: .seealso: AOCreateBasic(), AOView(),AOApplicationToPetsc(),
189:           AOPetscToApplicationIS(), AOApplicationToPetsc()
190: @*/
191: int AOPetscToApplication(AO ao,int n,int *ia)
192: {

197:   (*ao->ops->petsctoapplication)(ao,n,ia);
198:   return(0);
199: }

201: /*@
202:    AOApplicationToPetsc - Maps a set of integers in the application-defined
203:    ordering to the PETSc ordering.

205:    Collective on AO

207:    Input Parameters:
208: +  ao - the application ordering context
209: .  n - the number of integers
210: -  ia - the integers

212:    Level: beginner

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

219: .keywords: application ordering, mapping

221: .seealso: AOCreateBasic(), AOView(), AOPetscToApplication(),
222:           AOPetscToApplicationIS(), AOApplicationToPetsc()
223: @*/
224: int AOApplicationToPetsc(AO ao,int n,int *ia)
225: {

230:   (*ao->ops->applicationtopetsc)(ao,n,ia);
231:   return(0);
232: }