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: PetscTryTypeMethod(is, destroy);
72: is->ops->destroy = NULL;
74: (*r)(is);
75: PetscObjectChangeTypeName((PetscObject)is, method);
76: return 0;
77: }
79: /*@C
80: ISGetType - Gets the index set type name (as a string) from the IS.
82: Not Collective
84: Input Parameter:
85: . is - The index set
87: Output Parameter:
88: . type - The index set type name
90: Level: intermediate
92: .seealso: `ISSetType()`, `ISCreate()`
93: @*/
94: PetscErrorCode ISGetType(IS is, ISType *type)
95: {
98: if (!ISRegisterAllCalled) ISRegisterAll();
99: *type = ((PetscObject)is)->type_name;
100: return 0;
101: }
103: /*--------------------------------------------------------------------------------------------------------------------*/
105: /*@C
106: ISRegister - Adds a new index set implementation
108: Not Collective
110: Input Parameters:
111: + name - The name of a new user-defined creation routine
112: - create_func - The creation routine itself
114: Notes:
115: ISRegister() may be called multiple times to add several user-defined vectors
117: Sample usage:
118: .vb
119: ISRegister("my_is_name", MyISCreate);
120: .ve
122: Then, your vector type can be chosen with the procedural interface via
123: .vb
124: ISCreate(MPI_Comm, IS *);
125: ISSetType(IS,"my_is_name");
126: .ve
127: or at runtime via the option
128: .vb
129: -is_type my_is_name
130: .ve
132: This is no ISSetFromOptions() and the current implementations do not have a way to dynamically determine type, so
133: dynamic registration of custom IS types will be of limited use to users.
135: Level: developer
137: .seealso: `ISRegisterAll()`, `ISRegisterDestroy()`, `ISRegister()`
139: Level: advanced
140: @*/
141: PetscErrorCode ISRegister(const char sname[], PetscErrorCode (*function)(IS))
142: {
143: ISInitializePackage();
144: PetscFunctionListAdd(&ISList, sname, function);
145: return 0;
146: }