Actual source code: isreg.c
petsc-3.10.5 2019-03-28
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 on MPI_Comm
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: Concepts: index sets^creating
27: Concepts: IS^creating
29: .seealso: ISCreateGeneral(), ISCreateStride(), ISCreateBlock(), ISAllGather()
30: @*/
31: PetscErrorCode ISCreate(MPI_Comm comm,IS *is)
32: {
37: ISInitializePackage();
39: PetscHeaderCreate(*is,IS_CLASSID,"IS","Index Set","IS",comm,ISDestroy,ISView);
40: PetscLayoutCreate(comm, &(*is)->map);
41: return(0);
42: }
44: /*@C
45: ISSetType - Builds a index set, for a particular implementation.
47: Collective on IS
49: Input Parameters:
50: + is - The index set object
51: - method - The name of the index set type
53: Options Database Key:
54: . -is_type <type> - Sets the index set type; use -help for a list of available types
56: Notes:
57: See "petsc/include/petscis.h" for available istor types (for instance, ISGENERAL, ISSTRIDE, or ISBLOCK).
59: Use ISDuplicate() to make a duplicate
61: Level: intermediate
64: .seealso: ISGetType(), ISCreate()
65: @*/
66: PetscErrorCode ISSetType(IS is, ISType method)
67: {
68: PetscErrorCode (*r)(IS);
69: PetscBool match;
74: PetscObjectTypeCompare((PetscObject) is, method, &match);
75: if (match) return(0);
77: ISRegisterAll();
78: PetscFunctionListFind(ISList,method,&r);
79: if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown IS type: %s", method);
80: if (is->ops->destroy) {
81: (*is->ops->destroy)(is);
82: is->ops->destroy = NULL;
83: }
84: (*r)(is);
85: PetscObjectChangeTypeName((PetscObject)is,method);
86: return(0);
87: }
89: /*@C
90: ISGetType - Gets the index set type name (as a string) from the IS.
92: Not Collective
94: Input Parameter:
95: . is - The index set
97: Output Parameter:
98: . type - The index set type name
100: Level: intermediate
102: .seealso: ISSetType(), ISCreate()
103: @*/
104: PetscErrorCode ISGetType(IS is, ISType *type)
105: {
111: if (!ISRegisterAllCalled) {
112: ISRegisterAll();
113: }
114: *type = ((PetscObject)is)->type_name;
115: return(0);
116: }
119: /*--------------------------------------------------------------------------------------------------------------------*/
121: /*@C
122: ISRegister - Adds a new index set implementation
124: Not Collective
126: Input Parameters:
127: + name - The name of a new user-defined creation routine
128: - create_func - The creation routine itself
130: Notes:
131: ISRegister() may be called multiple times to add several user-defined vectors
133: Sample usage:
134: .vb
135: ISRegister("my_is_name", MyISCreate);
136: .ve
138: Then, your vector type can be chosen with the procedural interface via
139: .vb
140: ISCreate(MPI_Comm, IS *);
141: ISSetType(IS,"my_is_name");
142: .ve
143: or at runtime via the option
144: .vb
145: -is_type my_is_name
146: .ve
148: This is no ISSetFromOptions() and the current implementations do not have a way to dynamically determine type, so
149: dynamic registration of custom IS types will be of limited use to users.
151: Level: developer
153: .keywords: IS, register
154: .seealso: ISRegisterAll(), ISRegisterDestroy(), ISRegister()
156: Level: advanced
157: @*/
158: PetscErrorCode ISRegister(const char sname[], PetscErrorCode (*function)(IS))
159: {
163: ISInitializePackage();
164: PetscFunctionListAdd(&ISList,sname,function);
165: return(0);
166: }