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. `IS` are objects used to do efficient indexing into other data structures such as `Vec` and `Mat`
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: [](sec_scatter), `IS`, `ISType()`, `ISSetType()`, `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 `ISType`
41: Collective
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: [](sec_scatter), `IS`, `ISGENERAL`, `ISBLOCK`, `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, `ISType`, (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: [](sec_scatter), `IS`, `ISType`, `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: Sample usage:
115: .vb
116: ISRegister("my_is_name", MyISCreate);
117: .ve
119: Then, your vector type can be chosen with the procedural interface via
120: .vb
121: ISCreate(MPI_Comm, IS *);
122: ISSetType(IS,"my_is_name");
123: .ve
124: or at runtime via the option
125: .vb
126: -is_type my_is_name
127: .ve
129: Level: developer
131: Notes:
132: `ISRegister()` may be called multiple times to add several user-defined vectors
134: This is no `ISSetFromOptions()` and the current implementations do not have a way to dynamically determine type, so
135: dynamic registration of custom `IS` types will be of limited use to users.
137: .seealso: [](sec_scatter), `IS`, `ISType`, `ISSetType()`, `ISRegisterAll()`, `ISRegisterDestroy()`, `ISRegister()`
138: @*/
139: PetscErrorCode ISRegister(const char sname[], PetscErrorCode (*function)(IS))
140: {
141: ISInitializePackage();
142: PetscFunctionListAdd(&ISList, sname, function);
143: return 0;
144: }