1 2 #include <petsc-private/viewerimpl.h> /*I "petscviewer.h" I*/ 3 4 PetscClassId PETSC_VIEWER_CLASSID; 5 6 static PetscBool PetscViewerPackageInitialized = PETSC_FALSE; 7 #undef __FUNCT__ 8 #define __FUNCT__ "PetscViewerFinalizePackage" 9 /*@C 10 PetscViewerFinalizePackage - This function destroys everything in the Petsc interface to Mathematica. It is 11 called from PetscFinalize(). 12 13 Level: developer 14 15 .keywords: Petsc, destroy, package, mathematica 16 .seealso: PetscFinalize() 17 @*/ 18 PetscErrorCode PetscViewerFinalizePackage(void) 19 { 20 PetscFunctionBegin; 21 PetscViewerPackageInitialized = PETSC_FALSE; 22 PetscViewerList = 0; 23 PetscFunctionReturn(0); 24 } 25 26 #undef __FUNCT__ 27 #define __FUNCT__ "PetscViewerInitializePackage" 28 /*@C 29 PetscViewerInitializePackage - This function initializes everything in the main PetscViewer package. 30 31 Level: developer 32 33 .keywords: Petsc, initialize, package 34 .seealso: PetscInitialize() 35 @*/ 36 PetscErrorCode PetscViewerInitializePackage(void) 37 { 38 char logList[256]; 39 char *className; 40 PetscBool opt; 41 PetscErrorCode ierr; 42 43 PetscFunctionBegin; 44 if (PetscViewerPackageInitialized) PetscFunctionReturn(0); 45 PetscViewerPackageInitialized = PETSC_TRUE; 46 /* Register Classes */ 47 ierr = PetscClassIdRegister("Viewer",&PETSC_VIEWER_CLASSID);CHKERRQ(ierr); 48 49 /* Register Constructors */ 50 ierr = PetscViewerRegisterAll();CHKERRQ(ierr); 51 52 /* Process info exclusions */ 53 ierr = PetscOptionsGetString(NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr); 54 if (opt) { 55 ierr = PetscStrstr(logList, "viewer", &className);CHKERRQ(ierr); 56 if (className) { 57 ierr = PetscInfoDeactivateClass(0);CHKERRQ(ierr); 58 } 59 } 60 /* Process summary exclusions */ 61 ierr = PetscOptionsGetString(NULL, "-log_summary_exclude", logList, 256, &opt);CHKERRQ(ierr); 62 if (opt) { 63 ierr = PetscStrstr(logList, "viewer", &className);CHKERRQ(ierr); 64 if (className) { 65 ierr = PetscLogEventDeactivateClass(0);CHKERRQ(ierr); 66 } 67 } 68 #if defined(PETSC_HAVE_MATHEMATICA) 69 ierr = PetscViewerMathematicaInitializePackage();CHKERRQ(ierr); 70 #endif 71 ierr = PetscRegisterFinalize(PetscViewerFinalizePackage);CHKERRQ(ierr); 72 PetscFunctionReturn(0); 73 } 74 75 #undef __FUNCT__ 76 #define __FUNCT__ "PetscViewerDestroy" 77 /*@ 78 PetscViewerDestroy - Destroys a PetscViewer. 79 80 Collective on PetscViewer 81 82 Input Parameters: 83 . viewer - the PetscViewer to be destroyed. 84 85 Level: beginner 86 87 .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen() 88 89 @*/ 90 PetscErrorCode PetscViewerDestroy(PetscViewer *viewer) 91 { 92 PetscErrorCode ierr; 93 94 PetscFunctionBegin; 95 if (!*viewer) PetscFunctionReturn(0); 96 PetscValidHeaderSpecific(*viewer,PETSC_VIEWER_CLASSID,1); 97 98 ierr = PetscViewerFlush(*viewer);CHKERRQ(ierr); 99 if (--((PetscObject)(*viewer))->refct > 0) {*viewer = 0; PetscFunctionReturn(0);} 100 101 ierr = PetscObjectAMSViewOff((PetscObject)*viewer);CHKERRQ(ierr); 102 if ((*viewer)->ops->destroy) { 103 ierr = (*(*viewer)->ops->destroy)(*viewer);CHKERRQ(ierr); 104 } 105 ierr = PetscHeaderDestroy(viewer);CHKERRQ(ierr); 106 PetscFunctionReturn(0); 107 } 108 109 #undef __FUNCT__ 110 #define __FUNCT__ "PetscViewerGetType" 111 /*@C 112 PetscViewerGetType - Returns the type of a PetscViewer. 113 114 Not Collective 115 116 Input Parameter: 117 . viewer - the PetscViewer 118 119 Output Parameter: 120 . type - PetscViewer type (see below) 121 122 Available Types Include: 123 . PETSCVIEWERSOCKET - Socket PetscViewer 124 . PETSCVIEWERASCII - ASCII PetscViewer 125 . PETSCVIEWERBINARY - binary file PetscViewer 126 . PETSCVIEWERSTRING - string PetscViewer 127 . PETSCVIEWERDRAW - drawing PetscViewer 128 129 Level: intermediate 130 131 Note: 132 See include/petscviewer.h for a complete list of PetscViewers. 133 134 PetscViewerType is actually a string 135 136 .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType 137 138 @*/ 139 PetscErrorCode PetscViewerGetType(PetscViewer viewer,PetscViewerType *type) 140 { 141 PetscFunctionBegin; 142 PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 143 PetscValidPointer(type,2); 144 *type = ((PetscObject)viewer)->type_name; 145 PetscFunctionReturn(0); 146 } 147 148 #undef __FUNCT__ 149 #define __FUNCT__ "PetscViewerSetOptionsPrefix" 150 /*@C 151 PetscViewerSetOptionsPrefix - Sets the prefix used for searching for all 152 PetscViewer options in the database. 153 154 Logically Collective on PetscViewer 155 156 Input Parameter: 157 + viewer - the PetscViewer context 158 - prefix - the prefix to prepend to all option names 159 160 Notes: 161 A hyphen (-) must NOT be given at the beginning of the prefix name. 162 The first character of all runtime options is AUTOMATICALLY the hyphen. 163 164 Level: advanced 165 166 .keywords: PetscViewer, set, options, prefix, database 167 168 .seealso: PetscViewerSetFromOptions() 169 @*/ 170 PetscErrorCode PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[]) 171 { 172 PetscErrorCode ierr; 173 174 PetscFunctionBegin; 175 PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 176 ierr = PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 177 PetscFunctionReturn(0); 178 } 179 180 #undef __FUNCT__ 181 #define __FUNCT__ "PetscViewerAppendOptionsPrefix" 182 /*@C 183 PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all 184 PetscViewer options in the database. 185 186 Logically Collective on PetscViewer 187 188 Input Parameters: 189 + viewer - the PetscViewer context 190 - prefix - the prefix to prepend to all option names 191 192 Notes: 193 A hyphen (-) must NOT be given at the beginning of the prefix name. 194 The first character of all runtime options is AUTOMATICALLY the hyphen. 195 196 Level: advanced 197 198 .keywords: PetscViewer, append, options, prefix, database 199 200 .seealso: PetscViewerGetOptionsPrefix() 201 @*/ 202 PetscErrorCode PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[]) 203 { 204 PetscErrorCode ierr; 205 206 PetscFunctionBegin; 207 PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 208 ierr = PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 209 PetscFunctionReturn(0); 210 } 211 212 #undef __FUNCT__ 213 #define __FUNCT__ "PetscViewerGetOptionsPrefix" 214 /*@C 215 PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all 216 PetscViewer options in the database. 217 218 Not Collective 219 220 Input Parameter: 221 . viewer - the PetscViewer context 222 223 Output Parameter: 224 . prefix - pointer to the prefix string used 225 226 Notes: On the fortran side, the user should pass in a string 'prefix' of 227 sufficient length to hold the prefix. 228 229 Level: advanced 230 231 .keywords: PetscViewer, get, options, prefix, database 232 233 .seealso: PetscViewerAppendOptionsPrefix() 234 @*/ 235 PetscErrorCode PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[]) 236 { 237 PetscErrorCode ierr; 238 239 PetscFunctionBegin; 240 PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 241 ierr = PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 242 PetscFunctionReturn(0); 243 } 244 245 #undef __FUNCT__ 246 #define __FUNCT__ "PetscViewerSetUp" 247 /*@ 248 PetscViewerSetUp - Sets up the internal viewer data structures for the later use. 249 250 Collective on PetscViewer 251 252 Input Parameters: 253 . viewer - the PetscViewer context 254 255 Notes: 256 For basic use of the PetscViewer classes the user need not explicitly call 257 PetscViewerSetUp(), since these actions will happen automatically. 258 259 Level: advanced 260 261 .keywords: PetscViewer, setup 262 263 .seealso: PetscViewerCreate(), PetscViewerDestroy() 264 @*/ 265 PetscErrorCode PetscViewerSetUp(PetscViewer viewer) 266 { 267 PetscFunctionBegin; 268 PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 269 PetscFunctionReturn(0); 270 } 271 272 #undef __FUNCT__ 273 #define __FUNCT__ "PetscViewerView" 274 /*@C 275 PetscViewerView - Visualizes a viewer object. 276 277 Collective on PetscViewer 278 279 Input Parameters: 280 + v - the viewer 281 - viewer - visualization context 282 283 Notes: 284 The available visualization contexts include 285 + PETSC_VIEWER_STDOUT_SELF - standard output (default) 286 . PETSC_VIEWER_STDOUT_WORLD - synchronized standard 287 output where only the first processor opens 288 the file. All other processors send their 289 data to the first processor to print. 290 - PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure 291 292 Level: beginner 293 294 .seealso: PetscViewerSetFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), 295 PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad() 296 @*/ 297 PetscErrorCode PetscViewerView(PetscViewer v,PetscViewer viewer) 298 { 299 PetscErrorCode ierr; 300 PetscBool iascii; 301 PetscViewerFormat format; 302 303 PetscFunctionBegin; 304 PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1); 305 PetscValidType(v,1); 306 if (!viewer) { 307 ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)v),&viewer);CHKERRQ(ierr); 308 } 309 PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 310 PetscCheckSameComm(v,1,viewer,2); 311 312 ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 313 if (iascii) { 314 ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 315 if (format == PETSC_VIEWER_DEFAULT || format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) { 316 ierr = PetscObjectPrintClassNamePrefixType((PetscObject)v,viewer,"PetscViewer Object");CHKERRQ(ierr); 317 if (v->format) { 318 ierr = PetscViewerASCIIPrintf(viewer," Viewer format = %s\n",PetscViewerFormats[v->format]);CHKERRQ(ierr); 319 } 320 ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 321 if (v->ops->view) { 322 ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr); 323 } 324 ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 325 } 326 } 327 PetscFunctionReturn(0); 328 } 329