1
2 /*
3 Provides utility routines for manulating any type of PETSc object.
4 */
5 #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/
6
7 /*@C
8 PetscObjectGetOptions - Gets the options database used by the object. Call immediately after creating the object.
9
10 Collective on PetscObject
11
12 Input Parameter:
13 . obj - any PETSc object, for example a Vec, Mat or KSP.
14
15 Output Parameter:
16 . options - the options database
17
18 Notes:
19 if this is not called the object will use the default options database
20
21 Level: advanced
22
23 .seealso: PetscOptionsCreate(), PetscOptionsDestroy(), PetscObjectSetOptionsPrefix(), PetscObjectAppendOptionsPrefix(), PetscObjectPrependOptionsPrefix(),
24 PetscObjectGetOptionsPrefix(), PetscObjectSetOptions()
25
26 @*/
PetscObjectGetOptions(PetscObject obj,PetscOptions * options)27 PetscErrorCode PetscObjectGetOptions(PetscObject obj,PetscOptions *options)
28 {
29 PetscFunctionBegin;
30 PetscValidHeader(obj,1);
31 *options = obj->options;
32 PetscFunctionReturn(0);
33 }
34
35 /*@C
36 PetscObjectSetOptions - Sets the options database used by the object. Call immediately after creating the object.
37
38 Collective on PetscObject
39
40 Input Parameters:
41 + obj - any PETSc object, for example a Vec, Mat or KSP.
42 - options - the options database, use NULL for default
43
44 Notes:
45 if this is not called the object will use the default options database
46
47 Level: advanced
48
49 .seealso: PetscOptionsCreate(), PetscOptionsDestroy(), PetscObjectSetOptionsPrefix(), PetscObjectAppendOptionsPrefix(), PetscObjectPrependOptionsPrefix(),
50 PetscObjectGetOptionsPrefix(), PetscObjectGetOptions()
51
52 @*/
PetscObjectSetOptions(PetscObject obj,PetscOptions options)53 PetscErrorCode PetscObjectSetOptions(PetscObject obj,PetscOptions options)
54 {
55 PetscFunctionBegin;
56 PetscValidHeader(obj,1);
57 obj->options = options;
58 PetscFunctionReturn(0);
59 }
60
61 /*@C
62 PetscObjectSetOptionsPrefix - Sets the prefix used for searching for all
63 options of PetscObjectType in the database.
64
65 Collective on Object
66
67 Input Parameters:
68 + obj - any PETSc object, for example a Vec, Mat or KSP.
69 - prefix - the prefix string to prepend to option requests of the object.
70
71 Notes:
72 A hyphen (-) must NOT be given at the beginning of the prefix name.
73 The first character of all runtime options is AUTOMATICALLY the
74 hyphen.
75
76 Level: advanced
77
78 .seealso: PetscOptionsCreate(), PetscOptionsDestroy(), PetscObjectAppendOptionsPrefix(), PetscObjectPrependOptionsPrefix(),
79 PetscObjectGetOptionsPrefix(), TSSetOptionsPrefix(), SNESSetOptionsPrefix(), KSPSetOptionsPrefix()
80
81 @*/
PetscObjectSetOptionsPrefix(PetscObject obj,const char prefix[])82 PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject obj,const char prefix[])
83 {
84 PetscErrorCode ierr;
85
86 PetscFunctionBegin;
87 PetscValidHeader(obj,1);
88 if (!prefix) {
89 ierr = PetscFree(obj->prefix);CHKERRQ(ierr);
90 } else {
91 if (prefix[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
92 if (prefix != obj->prefix) {
93 ierr = PetscFree(obj->prefix);CHKERRQ(ierr);
94 ierr = PetscStrallocpy(prefix,&obj->prefix);CHKERRQ(ierr);
95 }
96 }
97 PetscFunctionReturn(0);
98 }
99
100 /*@C
101 PetscObjectAppendOptionsPrefix - Sets the prefix used for searching for all
102 options of PetscObjectType in the database.
103
104 Input Parameters:
105 + obj - any PETSc object, for example a Vec, Mat or KSP.
106 - prefix - the prefix string to prepend to option requests of the object.
107
108 Notes:
109 A hyphen (-) must NOT be given at the beginning of the prefix name.
110 The first character of all runtime options is AUTOMATICALLY the
111 hyphen.
112
113 Level: advanced
114
115 .seealso: PetscOptionsCreate(), PetscOptionsDestroy(), PetscObjectSetOptionsPrefix(), PetscObjectPrependOptionsPrefix(),
116 PetscObjectGetOptionsPrefix(), TSAppendOptionsPrefix(), SNESAppendOptionsPrefix(), KSPAppendOptionsPrefix()
117
118 @*/
PetscObjectAppendOptionsPrefix(PetscObject obj,const char prefix[])119 PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject obj,const char prefix[])
120 {
121 char *buf = obj->prefix;
122 PetscErrorCode ierr;
123 size_t len1,len2;
124
125 PetscFunctionBegin;
126 PetscValidHeader(obj,1);
127 if (!prefix) PetscFunctionReturn(0);
128 if (!buf) {
129 ierr = PetscObjectSetOptionsPrefix(obj,prefix);CHKERRQ(ierr);
130 PetscFunctionReturn(0);
131 }
132 if (prefix[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
133
134 ierr = PetscStrlen(prefix,&len1);CHKERRQ(ierr);
135 ierr = PetscStrlen(buf,&len2);CHKERRQ(ierr);
136 ierr = PetscMalloc1(1+len1+len2,&obj->prefix);CHKERRQ(ierr);
137 ierr = PetscStrcpy(obj->prefix,buf);CHKERRQ(ierr);
138 ierr = PetscStrcat(obj->prefix,prefix);CHKERRQ(ierr);
139 ierr = PetscFree(buf);CHKERRQ(ierr);
140 PetscFunctionReturn(0);
141 }
142
143 /*@C
144 PetscObjectGetOptionsPrefix - Gets the prefix of the PetscObject.
145
146 Input Parameters:
147 . obj - any PETSc object, for example a Vec, Mat or KSP.
148
149 Output Parameters:
150 . prefix - pointer to the prefix string used is returned
151
152 Level: advanced
153
154 .seealso: PetscOptionsCreate(), PetscOptionsDestroy(), PetscObjectSetOptionsPrefix(), PetscObjectAppendOptionsPrefix(), PetscObjectPrependOptionsPrefix(),
155 TSGetOptionsPrefix(), SNESGetOptionsPrefix(), KSPGetOptionsPrefix()
156
157 @*/
PetscObjectGetOptionsPrefix(PetscObject obj,const char * prefix[])158 PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject obj,const char *prefix[])
159 {
160 PetscFunctionBegin;
161 PetscValidHeader(obj,1);
162 PetscValidPointer(prefix,2);
163 *prefix = obj->prefix;
164 PetscFunctionReturn(0);
165 }
166
167 /*@C
168 PetscObjectPrependOptionsPrefix - Sets the prefix used for searching for all
169 options of PetscObjectType in the database.
170
171 Input Parameters:
172 + obj - any PETSc object, for example a Vec, Mat or KSP.
173 - prefix - the prefix string to prepend to option requests of the object.
174
175 Notes:
176 A hyphen (-) must NOT be given at the beginning of the prefix name.
177 The first character of all runtime options is AUTOMATICALLY the
178 hyphen.
179
180 Level: advanced
181
182 .seealso: PetscOptionsCreate(), PetscOptionsDestroy(), PetscObjectSetOptionsPrefix(), PetscObjectAppendOptionsPrefix(),
183 PetscObjectGetOptionsPrefix(), TSPrependOptionsPrefix(), SNESPrependOptionsPrefix(), KSPPrependOptionsPrefix()
184
185 @*/
PetscObjectPrependOptionsPrefix(PetscObject obj,const char prefix[])186 PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject obj,const char prefix[])
187 {
188 char *buf;
189 size_t len1,len2;
190 PetscErrorCode ierr;
191
192 PetscFunctionBegin;
193 PetscValidHeader(obj,1);
194 buf = obj->prefix;
195 if (!prefix) PetscFunctionReturn(0);
196 if (!buf) {
197 ierr = PetscObjectSetOptionsPrefix(obj,prefix);CHKERRQ(ierr);
198 PetscFunctionReturn(0);
199 }
200 if (prefix[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
201
202 ierr = PetscStrlen(prefix,&len1);CHKERRQ(ierr);
203 ierr = PetscStrlen(buf,&len2);CHKERRQ(ierr);
204 ierr = PetscMalloc1(1+len1+len2,&obj->prefix);CHKERRQ(ierr);
205 ierr = PetscStrcpy(obj->prefix,prefix);CHKERRQ(ierr);
206 ierr = PetscStrcat(obj->prefix,buf);CHKERRQ(ierr);
207 ierr = PetscFree(buf);CHKERRQ(ierr);
208 PetscFunctionReturn(0);
209 }
210
211