Actual source code: isreg.c
petsc-3.4.5 2014-06-29
2: #include <petsc-private/isimpl.h> /*I "petscis.h" I*/
4: PetscFunctionList ISList = NULL;
5: PetscBool ISRegisterAllCalled = PETSC_FALSE;
9: /*@
10: ISCreate - Creates an index set object.
12: Collective on MPI_Comm
14: Input Parameters:
15: . comm - the MPI communicator
17: Output Parameter:
18: . is - the new index set
20: Notes:
21: When the communicator is not MPI_COMM_SELF, the operations on IS are NOT
22: conceptually the same as MPI_Group operations. The IS are then
23: distributed sets of indices and thus certain operations on them are
24: collective.
26: Level: beginner
28: Concepts: index sets^creating
29: Concepts: IS^creating
31: .seealso: ISCreateGeneral(), ISCreateStride(), ISCreateBlock(), ISAllGather()
32: @*/
33: PetscErrorCode ISCreate(MPI_Comm comm,IS *is)
34: {
39: #if !defined(PETSC_USE_DYNAMIC_LIBRARIES)
40: ISInitializePackage();
41: #endif
43: PetscHeaderCreate(*is,_p_IS,struct _ISOps,IS_CLASSID,"IS","Index Set","IS",comm,ISDestroy,ISView);
44: return(0);
45: }
49: /*@C
50: ISSetType - Builds a index set, for a particular implementation.
52: Collective on IS
54: Input Parameters:
55: + is - The index set object
56: - method - The name of the index set type
58: Options Database Key:
59: . -is_type <type> - Sets the index set type; use -help for a list of available types
61: Notes:
62: See "petsc/include/petscis.h" for available istor types (for instance, ISGENERAL, ISSTRIDE, or ISBLOCK).
64: Use ISDuplicate() to make a duplicate
66: Level: intermediate
69: .seealso: ISGetType(), ISCreate()
70: @*/
71: PetscErrorCode ISSetType(IS is, ISType method)
72: {
73: PetscErrorCode (*r)(IS);
74: PetscBool match;
79: PetscObjectTypeCompare((PetscObject) is, method, &match);
80: if (match) return(0);
82: if (!ISRegisterAllCalled) {ISRegisterAll();}
83: PetscFunctionListFind(ISList,method,&r);
84: if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown IS type: %s", method);
85: if (is->ops->destroy) {
86: (*is->ops->destroy)(is);
87: is->ops->destroy = NULL;
88: }
89: (*r)(is);
90: PetscObjectChangeTypeName((PetscObject)is,method);
91: return(0);
92: }
96: /*@C
97: ISGetType - Gets the index set type name (as a string) from the IS.
99: Not Collective
101: Input Parameter:
102: . is - The index set
104: Output Parameter:
105: . type - The index set type name
107: Level: intermediate
109: .seealso: ISSetType(), ISCreate()
110: @*/
111: PetscErrorCode ISGetType(IS is, ISType *type)
112: {
118: if (!ISRegisterAllCalled) {
119: ISRegisterAll();
120: }
121: *type = ((PetscObject)is)->type_name;
122: return(0);
123: }
126: /*--------------------------------------------------------------------------------------------------------------------*/
130: /*@C
131: ISRegister - Adds a new index set implementation
133: Not Collective
135: Input Parameters:
136: + name - The name of a new user-defined creation routine
137: - create_func - The creation routine itself
139: Notes:
140: ISRegister() may be called multiple times to add several user-defined vectors
142: Sample usage:
143: .vb
144: ISRegister("my_is_name", MyISCreate);
145: .ve
147: Then, your vector type can be chosen with the procedural interface via
148: .vb
149: ISCreate(MPI_Comm, IS *);
150: ISSetType(IS,"my_is_name");
151: .ve
152: or at runtime via the option
153: .vb
154: -is_type my_is_name
155: .ve
157: This is no ISSetFromOptions() and the current implementations do not have a way to dynamically determine type, so
158: dynamic registration of custom IS types will be of limited use to users.
160: Level: developer
162: .keywords: IS, register
163: .seealso: ISRegisterAll(), ISRegisterDestroy(), ISRegister()
165: Level: advanced
166: @*/
167: PetscErrorCode ISRegister(const char sname[], PetscErrorCode (*function)(IS))
168: {
172: PetscFunctionListAdd(&ISList,sname,function);
173: return(0);
174: }