Actual source code: isreg.c

  2: #include <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:   PetscTypeCompare((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:   }
 88:   (*r)(is);
 89:   PetscObjectChangeTypeName((PetscObject)is,method);
 90:   return(0);
 91: }

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

 98:   Not Collective

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

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

106:   Level: intermediate

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

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


125: /*--------------------------------------------------------------------------------------------------------------------*/

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

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

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


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

154:    Not Collective

156:    Level: advanced

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

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