Actual source code: isreg.c
 
   petsc-3.6.2 2015-10-02
   
  2: #include <petsc/private/isimpl.h>    /*I "petscis.h"  I*/
  4: PetscFunctionList ISList              = 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:   ISInitializePackage();
 41:   PetscHeaderCreate(*is,IS_CLASSID,"IS","Index Set","IS",comm,ISDestroy,ISView);
 42:   PetscLayoutCreate(comm, &(*is)->map);
 43:   return(0);
 44: }
 48: /*@C
 49:   ISSetType - Builds a index set, for a particular implementation.
 51:   Collective on IS
 53:   Input Parameters:
 54: + is    - The index set object
 55: - method - The name of the index set type
 57:   Options Database Key:
 58: . -is_type <type> - Sets the index set type; use -help for a list of available types
 60:   Notes:
 61:   See "petsc/include/petscis.h" for available istor types (for instance, ISGENERAL, ISSTRIDE, or ISBLOCK).
 63:   Use ISDuplicate() to make a duplicate
 65:   Level: intermediate
 68: .seealso: ISGetType(), ISCreate()
 69: @*/
 70: PetscErrorCode  ISSetType(IS is, ISType method)
 71: {
 72:   PetscErrorCode (*r)(IS);
 73:   PetscBool      match;
 78:   PetscObjectTypeCompare((PetscObject) is, method, &match);
 79:   if (match) return(0);
 81:   ISRegisterAll();
 82:   PetscFunctionListFind(ISList,method,&r);
 83:   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown IS type: %s", method);
 84:   if (is->ops->destroy) {
 85:     (*is->ops->destroy)(is);
 86:     is->ops->destroy = NULL;
 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, ISType *type)
111: {
117:   if (!ISRegisterAllCalled) {
118:     ISRegisterAll();
119:   }
120:   *type = ((PetscObject)is)->type_name;
121:   return(0);
122: }
125: /*--------------------------------------------------------------------------------------------------------------------*/
129: /*@C
130:   ISRegister - Adds a new index set implementation
132:   Not Collective
134:   Input Parameters:
135: + name        - The name of a new user-defined creation routine
136: - create_func - The creation routine itself
138:   Notes:
139:   ISRegister() may be called multiple times to add several user-defined vectors
141:   Sample usage:
142: .vb
143:     ISRegister("my_is_name",  MyISCreate);
144: .ve
146:   Then, your vector type can be chosen with the procedural interface via
147: .vb
148:     ISCreate(MPI_Comm, IS *);
149:     ISSetType(IS,"my_is_name");
150: .ve
151:    or at runtime via the option
152: .vb
153:     -is_type my_is_name
154: .ve
156:   This is no ISSetFromOptions() and the current implementations do not have a way to dynamically determine type, so
157:   dynamic registration of custom IS types will be of limited use to users.
159:   Level: developer
161: .keywords: IS, register
162: .seealso: ISRegisterAll(), ISRegisterDestroy(), ISRegister()
164:   Level: advanced
165: @*/
166: PetscErrorCode  ISRegister(const char sname[], PetscErrorCode (*function)(IS))
167: {
171:   PetscFunctionListAdd(&ISList,sname,function);
172:   return(0);
173: }