1 #define PETSC_DLL 2 /* 3 Provides utility routines for manulating any type of PETSc object. 4 */ 5 #include "petscsys.h" /*I "petscsys.h" I*/ 6 7 #undef __FUNCT__ 8 #define __FUNCT__ "PetscObjectSetOptionsPrefix" 9 /* 10 PetscObjectSetOptionsPrefix - Sets the prefix used for searching for all 11 options of PetscObjectType in the database. 12 13 Input Parameters: 14 . obj - any PETSc object, for example a Vec, Mat or KSP. 15 . prefix - the prefix string to prepend to option requests of the object. 16 17 Notes: 18 A hyphen (-) must NOT be given at the beginning of the prefix name. 19 The first character of all runtime options is AUTOMATICALLY the 20 hyphen. 21 22 Concepts: prefix^setting 23 24 */ 25 PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject obj,const char prefix[]) 26 { 27 PetscErrorCode ierr; 28 29 PetscFunctionBegin; 30 PetscValidHeader(obj,1); 31 if (!prefix) { 32 ierr = PetscFree(obj->prefix);CHKERRQ(ierr); 33 obj->prefix = PETSC_NULL; 34 } else { 35 if (prefix[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen"); 36 ierr = PetscFree(obj->prefix);CHKERRQ(ierr); 37 ierr = PetscStrallocpy(prefix,&obj->prefix);CHKERRQ(ierr); 38 } 39 PetscFunctionReturn(0); 40 } 41 42 #undef __FUNCT__ 43 #define __FUNCT__ "PetscObjectAppendOptionsPrefix" 44 /* 45 PetscObjectAppendOptionsPrefix - Sets the prefix used for searching for all 46 options of PetscObjectType in the database. 47 48 Input Parameters: 49 . obj - any PETSc object, for example a Vec, Mat or KSP. 50 . prefix - the prefix string to prepend to option requests of the object. 51 52 Notes: 53 A hyphen (-) must NOT be given at the beginning of the prefix name. 54 The first character of all runtime options is AUTOMATICALLY the 55 hyphen. 56 57 Concepts: prefix^setting 58 59 */ 60 PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject obj,const char prefix[]) 61 { 62 char *buf = obj->prefix; 63 PetscErrorCode ierr; 64 size_t len1,len2; 65 66 PetscFunctionBegin; 67 PetscValidHeader(obj,1); 68 if (!prefix) {PetscFunctionReturn(0);} 69 if (!buf) { 70 ierr = PetscObjectSetOptionsPrefix(obj,prefix);CHKERRQ(ierr); 71 PetscFunctionReturn(0); 72 } 73 if (prefix[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen"); 74 75 ierr = PetscStrlen(prefix,&len1);CHKERRQ(ierr); 76 ierr = PetscStrlen(buf,&len2);CHKERRQ(ierr); 77 ierr = PetscMalloc((1+len1+len2)*sizeof(char),&obj->prefix);CHKERRQ(ierr); 78 ierr = PetscStrcpy(obj->prefix,buf);CHKERRQ(ierr); 79 ierr = PetscStrcat(obj->prefix,prefix);CHKERRQ(ierr); 80 ierr = PetscFree(buf);CHKERRQ(ierr); 81 PetscFunctionReturn(0); 82 } 83 84 #undef __FUNCT__ 85 #define __FUNCT__ "PetscObjectGetOptionsPrefix" 86 /* 87 PetscObjectGetOptionsPrefix - Gets the prefix of the PetscObject. 88 89 Input Parameters: 90 . obj - any PETSc object, for example a Vec, Mat or KSP. 91 92 Output Parameters: 93 . prefix - pointer to the prefix string used is returned 94 95 Concepts: prefix^getting 96 97 */ 98 PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject obj,const char *prefix[]) 99 { 100 PetscFunctionBegin; 101 PetscValidHeader(obj,1); 102 PetscValidPointer(prefix,2); 103 *prefix = obj->prefix; 104 PetscFunctionReturn(0); 105 } 106 107 #undef __FUNCT__ 108 #define __FUNCT__ "PetscObjectPrependOptionsPrefix" 109 /* 110 PetscObjectPrependOptionsPrefix - Sets the prefix used for searching for all 111 options of PetscObjectType in the database. 112 113 Input Parameters: 114 . obj - any PETSc object, for example a Vec, Mat or KSP. 115 . prefix - the prefix string to prepend to option requests of the object. 116 117 Notes: 118 A hyphen (-) must NOT be given at the beginning of the prefix name. 119 The first character of all runtime options is AUTOMATICALLY the 120 hyphen. 121 122 Concepts: prefix^setting 123 124 */ 125 PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject obj,const char prefix[]) 126 { 127 char *buf; 128 size_t len1,len2; 129 PetscErrorCode ierr; 130 131 PetscFunctionBegin; 132 PetscValidHeader(obj,1); 133 buf = obj->prefix; 134 if (!prefix) {PetscFunctionReturn(0);} 135 if (!buf) { 136 ierr = PetscObjectSetOptionsPrefix(obj,prefix);CHKERRQ(ierr); 137 PetscFunctionReturn(0); 138 } 139 if (prefix[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen"); 140 141 ierr = PetscStrlen(prefix,&len1);CHKERRQ(ierr); 142 ierr = PetscStrlen(buf,&len2);CHKERRQ(ierr); 143 ierr = PetscMalloc((1+len1+len2)*sizeof(char),&obj->prefix);CHKERRQ(ierr); 144 ierr = PetscStrcpy(obj->prefix,prefix);CHKERRQ(ierr); 145 ierr = PetscStrcat(obj->prefix,buf);CHKERRQ(ierr); 146 ierr = PetscFree(buf);CHKERRQ(ierr); 147 PetscFunctionReturn(0); 148 } 149 150