Actual source code: isreg.c
petsc-3.12.5 2020-03-29
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
27: .seealso: ISCreateGeneral(), ISCreateStride(), ISCreateBlock(), ISAllGather()
28: @*/
29: PetscErrorCode ISCreate(MPI_Comm comm,IS *is)
30: {
35: ISInitializePackage();
37: PetscHeaderCreate(*is,IS_CLASSID,"IS","Index Set","IS",comm,ISDestroy,ISView);
38: PetscLayoutCreate(comm, &(*is)->map);
39: return(0);
40: }
42: /*@C
43: ISSetType - Builds a index set, for a particular implementation.
45: Collective on IS
47: Input Parameters:
48: + is - The index set object
49: - method - The name of the index set type
51: Options Database Key:
52: . -is_type <type> - Sets the index set type; use -help for a list of available types
54: Notes:
55: See "petsc/include/petscis.h" for available istor types (for instance, ISGENERAL, ISSTRIDE, or ISBLOCK).
57: Use ISDuplicate() to make a duplicate
59: Level: intermediate
62: .seealso: ISGetType(), ISCreate()
63: @*/
64: PetscErrorCode ISSetType(IS is, ISType method)
65: {
66: PetscErrorCode (*r)(IS);
67: PetscBool match;
72: PetscObjectTypeCompare((PetscObject) is, method, &match);
73: if (match) return(0);
75: ISRegisterAll();
76: PetscFunctionListFind(ISList,method,&r);
77: if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown IS type: %s", method);
78: if (is->ops->destroy) {
79: (*is->ops->destroy)(is);
80: is->ops->destroy = NULL;
81: }
82: (*r)(is);
83: PetscObjectChangeTypeName((PetscObject)is,method);
84: return(0);
85: }
87: /*@C
88: ISGetType - Gets the index set type name (as a string) from the IS.
90: Not Collective
92: Input Parameter:
93: . is - The index set
95: Output Parameter:
96: . type - The index set type name
98: Level: intermediate
100: .seealso: ISSetType(), ISCreate()
101: @*/
102: PetscErrorCode ISGetType(IS is, ISType *type)
103: {
109: if (!ISRegisterAllCalled) {
110: ISRegisterAll();
111: }
112: *type = ((PetscObject)is)->type_name;
113: return(0);
114: }
117: /*--------------------------------------------------------------------------------------------------------------------*/
119: /*@C
120: ISRegister - Adds a new index set implementation
122: Not Collective
124: Input Parameters:
125: + name - The name of a new user-defined creation routine
126: - create_func - The creation routine itself
128: Notes:
129: ISRegister() may be called multiple times to add several user-defined vectors
131: Sample usage:
132: .vb
133: ISRegister("my_is_name", MyISCreate);
134: .ve
136: Then, your vector type can be chosen with the procedural interface via
137: .vb
138: ISCreate(MPI_Comm, IS *);
139: ISSetType(IS,"my_is_name");
140: .ve
141: or at runtime via the option
142: .vb
143: -is_type my_is_name
144: .ve
146: This is no ISSetFromOptions() and the current implementations do not have a way to dynamically determine type, so
147: dynamic registration of custom IS types will be of limited use to users.
149: Level: developer
151: .seealso: ISRegisterAll(), ISRegisterDestroy(), ISRegister()
153: Level: advanced
154: @*/
155: PetscErrorCode ISRegister(const char sname[], PetscErrorCode (*function)(IS))
156: {
160: ISInitializePackage();
161: PetscFunctionListAdd(&ISList,sname,function);
162: return(0);
163: }