Actual source code: isreg.c
petsc-dev 2014-02-02
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: ISInitializePackage();
41: PetscHeaderCreate(*is,_p_IS,struct _ISOps,IS_CLASSID,"IS","Index Set","IS",comm,ISDestroy,ISView);
42: return(0);
43: }
47: /*@C
48: ISSetType - Builds a index set, for a particular implementation.
50: Collective on IS
52: Input Parameters:
53: + is - The index set object
54: - method - The name of the index set type
56: Options Database Key:
57: . -is_type <type> - Sets the index set type; use -help for a list of available types
59: Notes:
60: See "petsc/include/petscis.h" for available istor types (for instance, ISGENERAL, ISSTRIDE, or ISBLOCK).
62: Use ISDuplicate() to make a duplicate
64: Level: intermediate
67: .seealso: ISGetType(), ISCreate()
68: @*/
69: PetscErrorCode ISSetType(IS is, ISType method)
70: {
71: PetscErrorCode (*r)(IS);
72: PetscBool match;
77: PetscObjectTypeCompare((PetscObject) is, method, &match);
78: if (match) return(0);
80: if (!ISRegisterAllCalled) {ISRegisterAll();}
81: PetscFunctionListFind(ISList,method,&r);
82: if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown IS type: %s", method);
83: if (is->ops->destroy) {
84: (*is->ops->destroy)(is);
85: is->ops->destroy = NULL;
86: }
87: (*r)(is);
88: PetscObjectChangeTypeName((PetscObject)is,method);
89: return(0);
90: }
94: /*@C
95: ISGetType - Gets the index set type name (as a string) from the IS.
97: Not Collective
99: Input Parameter:
100: . is - The index set
102: Output Parameter:
103: . type - The index set type name
105: Level: intermediate
107: .seealso: ISSetType(), ISCreate()
108: @*/
109: PetscErrorCode ISGetType(IS is, ISType *type)
110: {
116: if (!ISRegisterAllCalled) {
117: ISRegisterAll();
118: }
119: *type = ((PetscObject)is)->type_name;
120: return(0);
121: }
124: /*--------------------------------------------------------------------------------------------------------------------*/
128: /*@C
129: ISRegister - Adds a new index set implementation
131: Not Collective
133: Input Parameters:
134: + name - The name of a new user-defined creation routine
135: - create_func - The creation routine itself
137: Notes:
138: ISRegister() may be called multiple times to add several user-defined vectors
140: Sample usage:
141: .vb
142: ISRegister("my_is_name", MyISCreate);
143: .ve
145: Then, your vector type can be chosen with the procedural interface via
146: .vb
147: ISCreate(MPI_Comm, IS *);
148: ISSetType(IS,"my_is_name");
149: .ve
150: or at runtime via the option
151: .vb
152: -is_type my_is_name
153: .ve
155: This is no ISSetFromOptions() and the current implementations do not have a way to dynamically determine type, so
156: dynamic registration of custom IS types will be of limited use to users.
158: Level: developer
160: .keywords: IS, register
161: .seealso: ISRegisterAll(), ISRegisterDestroy(), ISRegister()
163: Level: advanced
164: @*/
165: PetscErrorCode ISRegister(const char sname[], PetscErrorCode (*function)(IS))
166: {
170: PetscFunctionListAdd(&ISList,sname,function);
171: return(0);
172: }