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: {
     31:   ISInitializePackage();

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

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

     41:   Collective on IS

     43:   Input Parameters:
     44: + is    - The index set object
     45: - method - The name of the index set type

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

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

     53:   Use ISDuplicate() to make a duplicate

     55:   Level: intermediate

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

     65:   PetscObjectTypeCompare((PetscObject) is, method, &match);
     66:   if (match) return 0;

     68:   ISRegisterAll();
     69:   PetscFunctionListFind(ISList,method,&r);
     71:   if (is->ops->destroy) {
     72:     (*is->ops->destroy)(is);
     73:     is->ops->destroy = NULL;
     74:   }
     75:   (*r)(is);
     76:   PetscObjectChangeTypeName((PetscObject)is,method);
     77:   return 0;
     78: }

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

     83:   Not Collective

     85:   Input Parameter:
     86: . is  - The index set

     88:   Output Parameter:
     89: . type - The index set type name

     91:   Level: intermediate

     93: .seealso: ISSetType(), ISCreate()
     94: @*/
     95: PetscErrorCode  ISGetType(IS is, ISType *type)
     96: {
     99:   if (!ISRegisterAllCalled) {
    100:     ISRegisterAll();
    101:   }
    102:   *type = ((PetscObject)is)->type_name;
    103:   return 0;
    104: }

    106: /*--------------------------------------------------------------------------------------------------------------------*/

    108: /*@C
    109:   ISRegister - Adds a new index set implementation

    111:   Not Collective

    113:   Input Parameters:
    114: + name        - The name of a new user-defined creation routine
    115: - create_func - The creation routine itself

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

    120:   Sample usage:
    121: .vb
    122:     ISRegister("my_is_name",  MyISCreate);
    123: .ve

    125:   Then, your vector type can be chosen with the procedural interface via
    126: .vb
    127:     ISCreate(MPI_Comm, IS *);
    128:     ISSetType(IS,"my_is_name");
    129: .ve
    130:    or at runtime via the option
    131: .vb
    132:     -is_type my_is_name
    133: .ve

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

    138:   Level: developer

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

    142:   Level: advanced
    143: @*/
    144: PetscErrorCode  ISRegister(const char sname[], PetscErrorCode (*function)(IS))
    145: {
    146:   ISInitializePackage();
    147:   PetscFunctionListAdd(&ISList,sname,function);
    148:   return 0;
    149: }