Actual source code: view.c

petsc-3.3-p7 2013-05-11
  2: #include <petsc-private/viewerimpl.h>  /*I "petscsys.h" I*/  

  4: PetscClassId PETSC_VIEWER_CLASSID;

  6: static PetscBool  PetscViewerPackageInitialized = PETSC_FALSE;
  9: /*@C
 10:   PetscViewerFinalizePackage - This function destroys everything in the Petsc interface to Mathematica. It is
 11:   called from PetscFinalize().

 13:   Level: developer

 15: .keywords: Petsc, destroy, package, mathematica
 16: .seealso: PetscFinalize()
 17: @*/
 18: PetscErrorCode  PetscViewerFinalizePackage(void)
 19: {
 21:   PetscViewerPackageInitialized = PETSC_FALSE;
 22:   PetscViewerList               = 0;
 23:   return(0);
 24: }

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

 31:   Input Parameter:
 32:   path - The dynamic library path, or PETSC_NULL

 34:   Level: developer

 36: .keywords: Petsc, initialize, package
 37: .seealso: PetscInitialize()
 38: @*/
 39: PetscErrorCode  PetscViewerInitializePackage(const char path[])
 40: {
 41:   char              logList[256];
 42:   char              *className;
 43:   PetscBool         opt;
 44:   PetscErrorCode    ierr;

 47:   if (PetscViewerPackageInitialized) return(0);
 48:   PetscViewerPackageInitialized = PETSC_TRUE;
 49:   /* Register Classes */
 50:   PetscClassIdRegister("Viewer",&PETSC_VIEWER_CLASSID);

 52:   /* Register Constructors */
 53:   PetscViewerRegisterAll(path);

 55:   /* Process info exclusions */
 56:   PetscOptionsGetString(PETSC_NULL, "-info_exclude", logList, 256, &opt);
 57:   if (opt) {
 58:     PetscStrstr(logList, "viewer", &className);
 59:     if (className) {
 60:       PetscInfoDeactivateClass(0);
 61:     }
 62:   }
 63:   /* Process summary exclusions */
 64:   PetscOptionsGetString(PETSC_NULL, "-log_summary_exclude", logList, 256, &opt);
 65:   if (opt) {
 66:     PetscStrstr(logList, "viewer", &className);
 67:     if (className) {
 68:       PetscLogEventDeactivateClass(0);
 69:     }
 70:   }
 71: #if defined(PETSC_HAVE_MATHEMATICA)
 72:   PetscViewerMathematicaInitializePackage(PETSC_NULL);
 73: #endif
 74:   PetscRegisterFinalize(PetscViewerFinalizePackage);
 75:   return(0);
 76: }

 80: /*@
 81:    PetscViewerDestroy - Destroys a PetscViewer.

 83:    Collective on PetscViewer

 85:    Input Parameters:
 86: .  viewer - the PetscViewer to be destroyed.

 88:    Level: beginner

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

 92: @*/
 93: PetscErrorCode  PetscViewerDestroy(PetscViewer *viewer)
 94: {

 98:   if (!*viewer) return(0);

101:   PetscViewerFlush(*viewer);
102:   if (--((PetscObject)(*viewer))->refct > 0) {*viewer = 0; return(0);}

104:   PetscObjectDepublish(*viewer);

106:   if ((*viewer)->ops->destroy) {
107:     (*(*viewer)->ops->destroy)(*viewer);
108:   }
109:   PetscHeaderDestroy(viewer);
110:   return(0);
111: }

115: /*@C
116:    PetscViewerGetType - Returns the type of a PetscViewer.

118:    Not Collective

120:    Input Parameter:
121: .   viewer - the PetscViewer

123:    Output Parameter:
124: .  type - PetscViewer type (see below)

126:    Available Types Include:
127: .  PETSCVIEWERSOCKET - Socket PetscViewer
128: .  PETSCVIEWERASCII - ASCII PetscViewer
129: .  PETSCVIEWERBINARY - binary file PetscViewer
130: .  PETSCVIEWERSTRING - string PetscViewer
131: .  PETSCVIEWERDRAW - drawing PetscViewer

133:    Level: intermediate

135:    Note:
136:    See include/petscviewer.h for a complete list of PetscViewers.

138:    PetscViewerType is actually a string

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

142: @*/
143: PetscErrorCode  PetscViewerGetType(PetscViewer viewer,const PetscViewerType *type)
144: {
148:   *type = ((PetscObject)viewer)->type_name;
149:   return(0);
150: }

154: /*@C
155:    PetscViewerSetOptionsPrefix - Sets the prefix used for searching for all 
156:    PetscViewer options in the database.

158:    Logically Collective on PetscViewer

160:    Input Parameter:
161: +  viewer - the PetscViewer context
162: -  prefix - the prefix to prepend to all option names

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

168:    Level: advanced

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

172: .seealso: PetscViewerSetFromOptions()
173: @*/
174: PetscErrorCode  PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[])
175: {

180:   PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix);
181:   return(0);
182: }

186: /*@C
187:    PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all 
188:    PetscViewer options in the database.

190:    Logically Collective on PetscViewer

192:    Input Parameters:
193: +  viewer - the PetscViewer context
194: -  prefix - the prefix to prepend to all option names

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

200:    Level: advanced

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

204: .seealso: PetscViewerGetOptionsPrefix()
205: @*/
206: PetscErrorCode  PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[])
207: {
209: 
212:   PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix);
213:   return(0);
214: }

218: /*@C
219:    PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all 
220:    PetscViewer options in the database.

222:    Not Collective

224:    Input Parameter:
225: .  viewer - the PetscViewer context

227:    Output Parameter:
228: .  prefix - pointer to the prefix string used

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

233:    Level: advanced

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

237: .seealso: PetscViewerAppendOptionsPrefix()
238: @*/
239: PetscErrorCode  PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[])
240: {

245:   PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix);
246:   return(0);
247: }

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

254:    Collective on PetscViewer

256:    Input Parameters:
257: .  viewer - the PetscViewer context

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

263:    Level: advanced

265: .keywords: PetscViewer, setup

267: .seealso: PetscViewerCreate(), PetscViewerDestroy()
268: @*/
269: PetscErrorCode  PetscViewerSetUp(PetscViewer viewer)
270: {
273:   return(0);
274: }

278: /*@C
279:    PetscViewerView - Visualizes a viewer object.

281:    Collective on PetscViewer

283:    Input Parameters:
284: +  v - the viewer
285: -  viewer - visualization context

287:   Notes:
288:   The available visualization contexts include
289: +    PETSC_VIEWER_STDOUT_SELF - standard output (default)
290: .    PETSC_VIEWER_STDOUT_WORLD - synchronized standard
291:         output where only the first processor opens
292:         the file.  All other processors send their 
293:         data to the first processor to print. 
294: -     PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure

296:    Level: beginner

298: .seealso: PetscViewerSetFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), 
299:           PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad()
300: @*/
301: PetscErrorCode  PetscViewerView(PetscViewer v,PetscViewer viewer)
302: {
303:   PetscErrorCode        ierr;
304:   PetscBool             iascii;
305:   const PetscViewerType cstr;
306:   PetscViewerFormat     format;

311:   if (!viewer) {
312:     PetscViewerASCIIGetStdout(((PetscObject)v)->comm,&viewer);
313:   }

317:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);
318:   if (iascii) {
319:     PetscViewerGetFormat(viewer,&format);
320:     if (format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
321:       PetscObjectPrintClassNamePrefixType((PetscObject)v,viewer,"PetscViewer Object");
322:       PetscViewerASCIIPushTab(viewer);
323:       PetscViewerGetType(v,&cstr);
324:       PetscViewerASCIIPrintf(viewer,"type=%s\n",cstr);
325:     }
326:   }
327:   if (!iascii) {
328:     SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Viewer type %s not supported",((PetscObject)viewer)->type_name);
329:   } else {
330:     PetscViewerGetFormat(viewer,&format);
331:     if (format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
332:       PetscViewerASCIIPopTab(viewer);
333:     }
334:   }
335:   return(0);
336: }