Actual source code: view.c

  1: #define PETSC_DLL

  3: #include "src/sys/viewer/viewerimpl.h"  /*I "petsc.h" I*/  

  5: PetscCookie PETSC_VIEWER_COOKIE = 0;

  9: /*@C
 10:   PetscViewerInitializePackage - This function initializes everything in the main PetscViewer package.

 12:   Input Parameter:
 13:   path - The dynamic library path, or PETSC_NULL

 15:   Level: developer

 17: .keywords: Petsc, initialize, package
 18: .seealso: PetscInitialize()
 19: @*/
 20: PetscErrorCode  PetscViewerInitializePackage(const char path[])
 21: {
 22:   static PetscTruth initialized = PETSC_FALSE;
 23:   char              logList[256];
 24:   char              *className;
 25:   PetscTruth        opt;
 26:   PetscErrorCode    ierr;

 29:   if (initialized) return(0);
 30:   initialized = PETSC_TRUE;
 31:   /* Register Classes */
 32:   PetscLogClassRegister(&PETSC_VIEWER_COOKIE, "Viewer");

 34:   /* Register Constructors */
 35:   PetscViewerRegisterAll(path);

 37:   /* Process info exclusions */
 38:   PetscOptionsGetString(PETSC_NULL, "-info_exclude", logList, 256, &opt);
 39:   if (opt) {
 40:     PetscStrstr(logList, "viewer", &className);
 41:     if (className) {
 42:       PetscInfoDeactivateClass(0);
 43:     }
 44:   }
 45:   /* Process summary exclusions */
 46:   PetscOptionsGetString(PETSC_NULL, "-log_summary_exclude", logList, 256, &opt);
 47:   if (opt) {
 48:     PetscStrstr(logList, "viewer", &className);
 49:     if (className) {
 51:     }
 52:   }
 53:   return(0);
 54: }

 58: /*@
 59:    PetscViewerDestroy - Destroys a PetscViewer.

 61:    Collective on PetscViewer

 63:    Input Parameters:
 64: .  viewer - the PetscViewer to be destroyed.

 66:    Level: beginner

 68: .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen()

 70: @*/
 71: PetscErrorCode  PetscViewerDestroy(PetscViewer viewer)
 72: {

 77:   PetscViewerFlush(viewer);
 78:   if (--viewer->refct > 0) return(0);

 80:   PetscObjectDepublish(viewer);

 82:   if (viewer->ops->destroy) {
 83:     (*viewer->ops->destroy)(viewer);
 84:   }
 85:   PetscHeaderDestroy(viewer);
 86:   return(0);
 87: }

 91: /*@C
 92:    PetscViewerGetType - Returns the type of a PetscViewer.

 94:    Not Collective

 96:    Input Parameter:
 97: .   viewer - the PetscViewer

 99:    Output Parameter:
100: .  type - PetscViewer type (see below)

102:    Available Types Include:
103: .  PETSC_VIEWER_SOCKET - Socket PetscViewer
104: .  PETSC_VIEWER_ASCII - ASCII PetscViewer
105: .  PETSC_VIEWER_BINARY - binary file PetscViewer
106: .  PETSC_VIEWER_STRING - string PetscViewer
107: .  PETSC_VIEWER_DRAW - drawing PetscViewer

109:    Level: intermediate

111:    Note:
112:    See include/petscviewer.h for a complete list of PetscViewers.

114:    PetscViewerType is actually a string

116: .seealso: PetscViewerCreate(), PetscViewerSetType()

118: @*/
119: PetscErrorCode  PetscViewerGetType(PetscViewer viewer,PetscViewerType *type)
120: {
123:   *type = (PetscViewerType) viewer->type_name;
124:   return(0);
125: }

129: /*@C
130:    PetscViewerSetOptionsPrefix - Sets the prefix used for searching for all 
131:    PetscViewer options in the database.

133:    Collective on PetscViewer

135:    Input Parameter:
136: +  viewer - the PetscViewer context
137: -  prefix - the prefix to prepend to all option names

139:    Notes:
140:    A hyphen (-) must NOT be given at the beginning of the prefix name.
141:    The first character of all runtime options is AUTOMATICALLY the hyphen.

143:    Level: advanced

145: .keywords: PetscViewer, set, options, prefix, database

147: .seealso: PetscViewerSetFromOptions()
148: @*/
149: PetscErrorCode  PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[])
150: {

155:   PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix);
156:   return(0);
157: }

161: /*@C
162:    PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all 
163:    PetscViewer options in the database.

165:    Collective on PetscViewer

167:    Input Parameters:
168: +  viewer - the PetscViewer context
169: -  prefix - the prefix to prepend to all option names

171:    Notes:
172:    A hyphen (-) must NOT be given at the beginning of the prefix name.
173:    The first character of all runtime options is AUTOMATICALLY the hyphen.

175:    Level: advanced

177: .keywords: PetscViewer, append, options, prefix, database

179: .seealso: PetscViewerGetOptionsPrefix()
180: @*/
181: PetscErrorCode  PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[])
182: {
184: 
187:   PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix);
188:   return(0);
189: }

193: /*@C
194:    PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all 
195:    PetscViewer options in the database.

197:    Not Collective

199:    Input Parameter:
200: .  viewer - the PetscViewer context

202:    Output Parameter:
203: .  prefix - pointer to the prefix string used

205:    Notes: On the fortran side, the user should pass in a string 'prefix' of
206:    sufficient length to hold the prefix.

208:    Level: advanced

210: .keywords: PetscViewer, get, options, prefix, database

212: .seealso: PetscViewerAppendOptionsPrefix()
213: @*/
214: PetscErrorCode  PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[])
215: {

220:   PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix);
221:   return(0);
222: }

226: /*@
227:    PetscViewerSetUp - Sets up the internal viewer data structures for the later use.

229:    Collective on PetscViewer

231:    Input Parameters:
232: .  viewer - the PetscViewer context

234:    Notes:
235:    For basic use of the PetscViewer classes the user need not explicitly call
236:    PetscViewerSetUp(), since these actions will happen automatically.

238:    Level: advanced

240: .keywords: PetscViewer, setup

242: .seealso: PetscViewerCreate(), PetscViewerDestroy()
243: @*/
244: PetscErrorCode  PetscViewerSetUp(PetscViewer viewer)
245: {
248:   return(0);
249: }

253: /*@C
254:    PetscViewerView - Visualizes a viewer object.

256:    Collective on PetscViewer

258:    Input Parameters:
259: +  v - the viewer
260: -  viewer - visualization context

262:   Notes:
263:   The available visualization contexts include
264: +    PETSC_VIEWER_STDOUT_SELF - standard output (default)
265: .    PETSC_VIEWER_STDOUT_WORLD - synchronized standard
266:         output where only the first processor opens
267:         the file.  All other processors send their 
268:         data to the first processor to print. 
269: -     PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure

271:    Level: beginner

273: .seealso: PetscViewerSetFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), 
274:           PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad()
275: @*/
276: PetscErrorCode  PetscViewerView(PetscViewer v,PetscViewer viewer)
277: {
278:   PetscErrorCode    ierr;
279:   PetscTruth        iascii;
280:   const char        *cstr;
281:   PetscViewerFormat format;

286:   if (!viewer) {
287:     PetscViewerASCIIGetStdout(v->comm,&viewer);
288:   }

292:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
293:   if (iascii) {
294:     PetscViewerGetFormat(viewer,&format);
295:     if (format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
296:       if (v->prefix) {
297:         PetscViewerASCIIPrintf(viewer,"PetscViewer Object:(%s)\n",v->prefix);
298:       } else {
299:         PetscViewerASCIIPrintf(viewer,"PetscViewer Object:\n");
300:       }
301:       PetscViewerASCIIPushTab(viewer);
302:       PetscViewerGetType(v,&cstr);
303:       PetscViewerASCIIPrintf(viewer,"type=%s\n",cstr);
304:     }
305:   }
306:   if (!iascii) {
307:     SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported",((PetscObject)viewer)->type_name);
308:   } else {
309:     PetscViewerGetFormat(viewer,&format);
310:     if (format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
311:       PetscViewerASCIIPopTab(viewer);
312:     }
313:   }
314:   return(0);
315: }