Actual source code: prefix.c
petsc-3.7.7 2017-09-25
2: /*
3: Provides utility routines for manulating any type of PETSc object.
4: */
5: #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/
9: /*@C
10: PetscObjectSetOptions - Sets the options database used by the object
12: Collective on PetscObject
14: Input Parameters:
15: + obj - any PETSc object, for example a Vec, Mat or KSP.
16: - options - the options database, use NULL for default
18: Notes: if this is not called the object will use the default options database
20: Level: advanced
22: .seealso: PetscOptionsCreate(), PetscOptionsDestroy()
24: @*/
25: PetscErrorCode PetscObjectSetOptions(PetscObject obj,PetscOptions options)
26: {
29: obj->options = options;
30: return(0);
31: }
35: /*
36: PetscObjectSetOptionsPrefix - Sets the prefix used for searching for all
37: options of PetscObjectType in the database.
39: Collective on Object
41: Input Parameters:
42: . obj - any PETSc object, for example a Vec, Mat or KSP.
43: . prefix - the prefix string to prepend to option requests of the object.
45: Notes:
46: A hyphen (-) must NOT be given at the beginning of the prefix name.
47: The first character of all runtime options is AUTOMATICALLY the
48: hyphen.
50: Concepts: prefix^setting
52: */
53: PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject obj,const char prefix[])
54: {
59: if (!prefix) {
60: PetscFree(obj->prefix);
61: } else {
62: if (prefix[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
63: if (prefix != obj->prefix) {
64: PetscFree(obj->prefix);
65: PetscStrallocpy(prefix,&obj->prefix);
66: }
67: }
68: return(0);
69: }
73: /*
74: PetscObjectAppendOptionsPrefix - Sets the prefix used for searching for all
75: options of PetscObjectType in the database.
77: Input Parameters:
78: . obj - any PETSc object, for example a Vec, Mat or KSP.
79: . prefix - the prefix string to prepend to option requests of the object.
81: Notes:
82: A hyphen (-) must NOT be given at the beginning of the prefix name.
83: The first character of all runtime options is AUTOMATICALLY the
84: hyphen.
86: Concepts: prefix^setting
88: */
89: PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject obj,const char prefix[])
90: {
91: char *buf = obj->prefix;
93: size_t len1,len2;
97: if (!prefix) return(0);
98: if (!buf) {
99: PetscObjectSetOptionsPrefix(obj,prefix);
100: return(0);
101: }
102: if (prefix[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
104: PetscStrlen(prefix,&len1);
105: PetscStrlen(buf,&len2);
106: PetscMalloc1(1+len1+len2,&obj->prefix);
107: PetscStrcpy(obj->prefix,buf);
108: PetscStrcat(obj->prefix,prefix);
109: PetscFree(buf);
110: return(0);
111: }
115: /*
116: PetscObjectGetOptionsPrefix - Gets the prefix of the PetscObject.
118: Input Parameters:
119: . obj - any PETSc object, for example a Vec, Mat or KSP.
121: Output Parameters:
122: . prefix - pointer to the prefix string used is returned
124: Concepts: prefix^getting
126: */
127: PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject obj,const char *prefix[])
128: {
132: *prefix = obj->prefix;
133: return(0);
134: }
138: /*
139: PetscObjectPrependOptionsPrefix - Sets the prefix used for searching for all
140: options of PetscObjectType in the database.
142: Input Parameters:
143: . obj - any PETSc object, for example a Vec, Mat or KSP.
144: . prefix - the prefix string to prepend to option requests of the object.
146: Notes:
147: A hyphen (-) must NOT be given at the beginning of the prefix name.
148: The first character of all runtime options is AUTOMATICALLY the
149: hyphen.
151: Concepts: prefix^setting
153: */
154: PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject obj,const char prefix[])
155: {
156: char *buf;
157: size_t len1,len2;
162: buf = obj->prefix;
163: if (!prefix) return(0);
164: if (!buf) {
165: PetscObjectSetOptionsPrefix(obj,prefix);
166: return(0);
167: }
168: if (prefix[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
170: PetscStrlen(prefix,&len1);
171: PetscStrlen(buf,&len2);
172: PetscMalloc1(1+len1+len2,&obj->prefix);
173: PetscStrcpy(obj->prefix,prefix);
174: PetscStrcat(obj->prefix,buf);
175: PetscFree(buf);
176: return(0);
177: }