Actual source code: isreg.c


  2: #include <petsc/private/isimpl.h>

  4: PetscFunctionList ISList              = NULL;
  5: PetscBool         ISRegisterAllCalled = PETSC_FALSE;

  7: /*@
  8:    ISCreate - Creates an index set object.

 10:    Collective

 12:    Input Parameters:
 13: .  comm - the MPI communicator

 15:    Output Parameter:
 16: .  is - the new index set

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

 24:    Level: beginner

 26: .seealso: ISCreateGeneral(), ISCreateStride(), ISCreateBlock(), ISAllGather()
 27: @*/
 28: PetscErrorCode  ISCreate(MPI_Comm comm,IS *is)
 29: {

 34:   ISInitializePackage();

 36:   PetscHeaderCreate(*is,IS_CLASSID,"IS","Index Set","IS",comm,ISDestroy,ISView);
 37:   PetscLayoutCreate(comm, &(*is)->map);
 38:   return(0);
 39: }

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

 44:   Collective on IS

 46:   Input Parameters:
 47: + is    - The index set object
 48: - method - The name of the index set type

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

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

 56:   Use ISDuplicate() to make a duplicate

 58:   Level: intermediate

 60: .seealso: ISGetType(), ISCreate()
 61: @*/
 62: PetscErrorCode  ISSetType(IS is, ISType method)
 63: {
 64:   PetscErrorCode (*r)(IS);
 65:   PetscBool      match;

 70:   PetscObjectTypeCompare((PetscObject) is, method, &match);
 71:   if (match) return(0);

 73:   ISRegisterAll();
 74:   PetscFunctionListFind(ISList,method,&r);
 75:   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown IS type: %s", method);
 76:   if (is->ops->destroy) {
 77:     (*is->ops->destroy)(is);
 78:     is->ops->destroy = NULL;
 79:   }
 80:   (*r)(is);
 81:   PetscObjectChangeTypeName((PetscObject)is,method);
 82:   return(0);
 83: }

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

 88:   Not Collective

 90:   Input Parameter:
 91: . is  - The index set

 93:   Output Parameter:
 94: . type - The index set type name

 96:   Level: intermediate

 98: .seealso: ISSetType(), ISCreate()
 99: @*/
100: PetscErrorCode  ISGetType(IS is, ISType *type)
101: {

107:   if (!ISRegisterAllCalled) {
108:     ISRegisterAll();
109:   }
110:   *type = ((PetscObject)is)->type_name;
111:   return(0);
112: }

114: /*--------------------------------------------------------------------------------------------------------------------*/

116: /*@C
117:   ISRegister - Adds a new index set implementation

119:   Not Collective

121:   Input Parameters:
122: + name        - The name of a new user-defined creation routine
123: - create_func - The creation routine itself

125:   Notes:
126:   ISRegister() may be called multiple times to add several user-defined vectors

128:   Sample usage:
129: .vb
130:     ISRegister("my_is_name",  MyISCreate);
131: .ve

133:   Then, your vector type can be chosen with the procedural interface via
134: .vb
135:     ISCreate(MPI_Comm, IS *);
136:     ISSetType(IS,"my_is_name");
137: .ve
138:    or at runtime via the option
139: .vb
140:     -is_type my_is_name
141: .ve

143:   This is no ISSetFromOptions() and the current implementations do not have a way to dynamically determine type, so
144:   dynamic registration of custom IS types will be of limited use to users.

146:   Level: developer

148: .seealso: ISRegisterAll(), ISRegisterDestroy(), ISRegister()

150:   Level: advanced
151: @*/
152: PetscErrorCode  ISRegister(const char sname[], PetscErrorCode (*function)(IS))
153: {

157:   ISInitializePackage();
158:   PetscFunctionListAdd(&ISList,sname,function);
159:   return(0);
160: }