Actual source code: view.c
1: #define PETSC_DLL
3: #include "private/viewerimpl.h" /*I "petscsys.h" I*/
5: PetscCookie PETSC_VIEWER_COOKIE;
7: static PetscTruth PetscViewerPackageInitialized = PETSC_FALSE;
10: /*@C
11: PetscViewerFinalizePackage - This function destroys everything in the Petsc interface to Mathematica. It is
12: called from PetscFinalize().
14: Level: developer
16: .keywords: Petsc, destroy, package, mathematica
17: .seealso: PetscFinalize()
18: @*/
19: PetscErrorCode PetscViewerFinalizePackage(void)
20: {
22: PetscViewerPackageInitialized = PETSC_FALSE;
23: PetscViewerList = 0;
24: return(0);
25: }
29: /*@C
30: PetscViewerInitializePackage - This function initializes everything in the main PetscViewer package.
32: Input Parameter:
33: path - The dynamic library path, or PETSC_NULL
35: Level: developer
37: .keywords: Petsc, initialize, package
38: .seealso: PetscInitialize()
39: @*/
40: PetscErrorCode PetscViewerInitializePackage(const char path[])
41: {
42: char logList[256];
43: char *className;
44: PetscTruth opt;
45: PetscErrorCode ierr;
48: if (PetscViewerPackageInitialized) return(0);
49: PetscViewerPackageInitialized = PETSC_TRUE;
50: /* Register Classes */
51: PetscCookieRegister("Viewer",&PETSC_VIEWER_COOKIE);
53: /* Register Constructors */
54: PetscViewerRegisterAll(path);
56: /* Process info exclusions */
57: PetscOptionsGetString(PETSC_NULL, "-info_exclude", logList, 256, &opt);
58: if (opt) {
59: PetscStrstr(logList, "viewer", &className);
60: if (className) {
61: PetscInfoDeactivateClass(0);
62: }
63: }
64: /* Process summary exclusions */
65: PetscOptionsGetString(PETSC_NULL, "-log_summary_exclude", logList, 256, &opt);
66: if (opt) {
67: PetscStrstr(logList, "viewer", &className);
68: if (className) {
69: PetscLogEventDeactivateClass(0);
70: }
71: }
72: #if defined(PETSC_HAVE_MATHEMATICA)
73: PetscViewerMathematicaInitializePackage(PETSC_NULL);
74: #endif
75: PetscRegisterFinalize(PetscViewerFinalizePackage);
76: return(0);
77: }
81: /*@
82: PetscViewerDestroy - Destroys a PetscViewer.
84: Collective on PetscViewer
86: Input Parameters:
87: . viewer - the PetscViewer to be destroyed.
89: Level: beginner
91: .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen()
93: @*/
94: PetscErrorCode PetscViewerDestroy(PetscViewer viewer)
95: {
100: PetscViewerFlush(viewer);
101: if (--((PetscObject)viewer)->refct > 0) return(0);
103: PetscObjectDepublish(viewer);
105: if (viewer->ops->destroy) {
106: (*viewer->ops->destroy)(viewer);
107: }
108: PetscHeaderDestroy(viewer);
109: return(0);
110: }
114: /*@C
115: PetscViewerGetType - Returns the type of a PetscViewer.
117: Not Collective
119: Input Parameter:
120: . viewer - the PetscViewer
122: Output Parameter:
123: . type - PetscViewer type (see below)
125: Available Types Include:
126: . PETSC_VIEWER_SOCKET - Socket PetscViewer
127: . PETSC_VIEWER_ASCII - ASCII PetscViewer
128: . PETSC_VIEWER_BINARY - binary file PetscViewer
129: . PETSC_VIEWER_STRING - string PetscViewer
130: . PETSC_VIEWER_DRAW - drawing PetscViewer
132: Level: intermediate
134: Note:
135: See include/petscviewer.h for a complete list of PetscViewers.
137: PetscViewerType is actually a string
139: .seealso: PetscViewerCreate(), PetscViewerSetType()
141: @*/
142: PetscErrorCode PetscViewerGetType(PetscViewer viewer,const PetscViewerType *type)
143: {
147: *type = ((PetscObject)viewer)->type_name;
148: return(0);
149: }
153: /*@C
154: PetscViewerSetOptionsPrefix - Sets the prefix used for searching for all
155: PetscViewer options in the database.
157: Collective on PetscViewer
159: Input Parameter:
160: + viewer - the PetscViewer context
161: - prefix - the prefix to prepend to all option names
163: Notes:
164: A hyphen (-) must NOT be given at the beginning of the prefix name.
165: The first character of all runtime options is AUTOMATICALLY the hyphen.
167: Level: advanced
169: .keywords: PetscViewer, set, options, prefix, database
171: .seealso: PetscViewerSetFromOptions()
172: @*/
173: PetscErrorCode PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[])
174: {
179: PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix);
180: return(0);
181: }
185: /*@C
186: PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all
187: PetscViewer options in the database.
189: Collective on PetscViewer
191: Input Parameters:
192: + viewer - the PetscViewer context
193: - prefix - the prefix to prepend to all option names
195: Notes:
196: A hyphen (-) must NOT be given at the beginning of the prefix name.
197: The first character of all runtime options is AUTOMATICALLY the hyphen.
199: Level: advanced
201: .keywords: PetscViewer, append, options, prefix, database
203: .seealso: PetscViewerGetOptionsPrefix()
204: @*/
205: PetscErrorCode PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[])
206: {
208:
211: PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix);
212: return(0);
213: }
217: /*@C
218: PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all
219: PetscViewer options in the database.
221: Not Collective
223: Input Parameter:
224: . viewer - the PetscViewer context
226: Output Parameter:
227: . prefix - pointer to the prefix string used
229: Notes: On the fortran side, the user should pass in a string 'prefix' of
230: sufficient length to hold the prefix.
232: Level: advanced
234: .keywords: PetscViewer, get, options, prefix, database
236: .seealso: PetscViewerAppendOptionsPrefix()
237: @*/
238: PetscErrorCode PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[])
239: {
244: PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix);
245: return(0);
246: }
250: /*@
251: PetscViewerSetUp - Sets up the internal viewer data structures for the later use.
253: Collective on PetscViewer
255: Input Parameters:
256: . viewer - the PetscViewer context
258: Notes:
259: For basic use of the PetscViewer classes the user need not explicitly call
260: PetscViewerSetUp(), since these actions will happen automatically.
262: Level: advanced
264: .keywords: PetscViewer, setup
266: .seealso: PetscViewerCreate(), PetscViewerDestroy()
267: @*/
268: PetscErrorCode PetscViewerSetUp(PetscViewer viewer)
269: {
272: return(0);
273: }
277: /*@C
278: PetscViewerView - Visualizes a viewer object.
280: Collective on PetscViewer
282: Input Parameters:
283: + v - the viewer
284: - viewer - visualization context
286: Notes:
287: The available visualization contexts include
288: + PETSC_VIEWER_STDOUT_SELF - standard output (default)
289: . PETSC_VIEWER_STDOUT_WORLD - synchronized standard
290: output where only the first processor opens
291: the file. All other processors send their
292: data to the first processor to print.
293: - PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure
295: Level: beginner
297: .seealso: PetscViewerSetFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(),
298: PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad()
299: @*/
300: PetscErrorCode PetscViewerView(PetscViewer v,PetscViewer viewer)
301: {
302: PetscErrorCode ierr;
303: PetscTruth iascii;
304: const PetscViewerType cstr;
305: PetscViewerFormat format;
310: if (!viewer) {
311: PetscViewerASCIIGetStdout(((PetscObject)v)->comm,&viewer);
312: }
316: PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
317: if (iascii) {
318: PetscViewerGetFormat(viewer,&format);
319: if (format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
320: if (((PetscObject)v)->prefix) {
321: PetscViewerASCIIPrintf(viewer,"PetscViewer Object:(%s)\n",((PetscObject)v)->prefix);
322: } else {
323: PetscViewerASCIIPrintf(viewer,"PetscViewer Object:\n");
324: }
325: PetscViewerASCIIPushTab(viewer);
326: PetscViewerGetType(v,&cstr);
327: PetscViewerASCIIPrintf(viewer,"type=%s\n",cstr);
328: }
329: }
330: if (!iascii) {
331: SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported",((PetscObject)viewer)->type_name);
332: } else {
333: PetscViewerGetFormat(viewer,&format);
334: if (format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
335: PetscViewerASCIIPopTab(viewer);
336: }
337: }
338: return(0);
339: }