Actual source code: isreg.c

petsc-3.3-p7 2013-05-11
  2: #include <petsc-private/isimpl.h>    /*I "petscis.h"  I*/

  4: PetscFList ISList                       = PETSC_NULL;
  5: PetscBool  ISRegisterAllCalled          = PETSC_FALSE;

  9: /*@
 10:    ISCreate - Creates an index set object.

 12:    Collective on MPI_Comm

 14:    Input Parameters:
 15: .  comm - the MPI communicator

 17:    Output Parameter:
 18: .  is - the new index set

 20:    Notes:
 21:    When the communicator is not MPI_COMM_SELF, the operations on IS are NOT
 22:    conceptually the same as MPI_Group operations. The IS are then
 23:    distributed sets of indices and thus certain operations on them are
 24:    collective.

 26:    Level: beginner

 28:   Concepts: index sets^creating
 29:   Concepts: IS^creating

 31: .seealso: ISCreateGeneral(), ISCreateStride(), ISCreateBlock(), ISAllGather()
 32: @*/
 33: PetscErrorCode  ISCreate(MPI_Comm comm,IS *is)
 34: {

 39: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
 40:   ISInitializePackage(PETSC_NULL);
 41: #endif

 43:   PetscHeaderCreate(*is,_p_IS,struct _ISOps,IS_CLASSID,-1,"IS","Index Set","IS",comm,ISDestroy,ISView);
 44:   return(0);
 45: }

 49: /*@C
 50:   ISSetType - Builds a index set, for a particular implementation.

 52:   Collective on IS

 54:   Input Parameters:
 55: + is    - The index set object
 56: - method - The name of the index set type

 58:   Options Database Key:
 59: . -is_type <type> - Sets the index set type; use -help for a list of available types

 61:   Notes:
 62:   See "petsc/include/petscis.h" for available istor types (for instance, ISGENERAL, ISSTRIDE, or ISBLOCK).

 64:   Use ISDuplicate() to make a duplicate

 66:   Level: intermediate


 69: .seealso: ISGetType(), ISCreate()
 70: @*/
 71: PetscErrorCode  ISSetType(IS is, const ISType method)
 72: {
 73:   PetscErrorCode (*r)(IS);
 74:   PetscBool      match;

 79:   PetscObjectTypeCompare((PetscObject) is, method, &match);
 80:   if (match) return(0);

 82:   if (!ISRegisterAllCalled) {ISRegisterAll(PETSC_NULL);}
 83:   PetscFListFind(ISList, ((PetscObject)is)->comm, method,PETSC_TRUE,(void (**)(void)) &r);
 84:   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown IS type: %s", method);
 85:   if (is->ops->destroy) {
 86:     (*is->ops->destroy)(is);
 87:     is->ops->destroy = PETSC_NULL;
 88:   }
 89:   (*r)(is);
 90:   PetscObjectChangeTypeName((PetscObject)is,method);
 91:   return(0);
 92: }

 96: /*@C
 97:   ISGetType - Gets the index set type name (as a string) from the IS.

 99:   Not Collective

101:   Input Parameter:
102: . is  - The index set

104:   Output Parameter:
105: . type - The index set type name

107:   Level: intermediate

109: .seealso: ISSetType(), ISCreate()
110: @*/
111: PetscErrorCode  ISGetType(IS is, const ISType *type)
112: {

118:   if (!ISRegisterAllCalled) {
119:     ISRegisterAll(PETSC_NULL);
120:   }
121:   *type = ((PetscObject)is)->type_name;
122:   return(0);
123: }


126: /*--------------------------------------------------------------------------------------------------------------------*/

130: /*@C
131:   ISRegister - See ISRegisterDynamic()

133:   Level: advanced
134: @*/
135: PetscErrorCode  ISRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(IS))
136: {
137:   char           fullname[PETSC_MAX_PATH_LEN];

141:   PetscStrcpy(fullname, path);
142:   PetscStrcat(fullname, ":");
143:   PetscStrcat(fullname, name);
144:   PetscFListAdd(&ISList, sname, fullname, (void (*)(void)) function);
145:   return(0);
146: }


149: /*--------------------------------------------------------------------------------------------------------------------*/
152: /*@C
153:    ISRegisterDestroy - Frees the list of IS methods that were registered by ISRegister()/ISRegisterDynamic().

155:    Not Collective

157:    Level: advanced

159: .keywords: IS, register, destroy
160: .seealso: ISRegister(), ISRegisterAll(), ISRegisterDynamic()
161: @*/
162: PetscErrorCode  ISRegisterDestroy(void)
163: {

167:   PetscFListDestroy(&ISList);
168:   ISRegisterAllCalled = PETSC_FALSE;
169:   return(0);
170: }