xref: /petsc/src/sys/classes/viewer/interface/viewa.c (revision 9371c9d470a9602b6d10a8bf50c9b2280a79e45a)
15c6c1daeSBarry Smith 
2af0996ceSBarry Smith #include <petsc/private/viewerimpl.h> /*I "petscsys.h" I*/
35c6c1daeSBarry Smith 
4*9371c9d4SSatish Balay const char *const PetscViewerFormats[] = {"DEFAULT", "ASCII_MATLAB", "ASCII_MATHEMATICA", "ASCII_IMPL", "ASCII_INFO", "ASCII_INFO_DETAIL", "ASCII_COMMON", "ASCII_SYMMODU", "ASCII_INDEX", "ASCII_DENSE", "ASCII_MATRIXMARKET", "ASCII_VTK", "ASCII_VTK_CELL", "ASCII_VTK_COORDS", "ASCII_PCICE", "ASCII_PYTHON", "ASCII_FACTOR_INFO", "ASCII_LATEX", "ASCII_XML", "ASCII_FLAMEGRAPH", "ASCII_GLVIS", "ASCII_CSV", "DRAW_BASIC", "DRAW_LG", "DRAW_LG_XRANGE", "DRAW_CONTOUR", "DRAW_PORTS", "VTK_VTS", "VTK_VTR", "VTK_VTU", "BINARY_MATLAB", "NATIVE", "HDF5_PETSC", "HDF5_VIZ", "HDF5_XDMF", "HDF5_MAT", "NOFORMAT", "LOAD_BALANCE", "FAILED", "ALL", "PetscViewerFormat", "PETSC_VIEWER_", NULL};
55c6c1daeSBarry Smith 
65c6c1daeSBarry Smith /*@C
75c6c1daeSBarry Smith    PetscViewerSetFormat - Sets the format for PetscViewers.
85c6c1daeSBarry Smith 
95c6c1daeSBarry Smith    Logically Collective on PetscViewer
105c6c1daeSBarry Smith 
116a9046bcSBarry Smith    This routine is deprecated, you should use PetscViewerPushFormat()/PetscViewerPopFormat()
126a9046bcSBarry Smith 
135c6c1daeSBarry Smith    Input Parameters:
145c6c1daeSBarry Smith +  viewer - the PetscViewer
155c6c1daeSBarry Smith -  format - the format
165c6c1daeSBarry Smith 
175c6c1daeSBarry Smith    Level: intermediate
185c6c1daeSBarry Smith 
195c6c1daeSBarry Smith    Notes:
205c6c1daeSBarry Smith    Available formats include
215c6c1daeSBarry Smith +    PETSC_VIEWER_DEFAULT - default format
225c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_MATLAB - MATLAB format
235c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_DENSE - print matrix as dense
245c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_IMPL - implementation-specific format
255c6c1daeSBarry Smith       (which is in many cases the same as the default)
265c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_INFO - basic information about object
275c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_INFO_DETAIL - more detailed info
285c6c1daeSBarry Smith        about object
295c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_COMMON - identical output format for
305c6c1daeSBarry Smith        all objects of a particular type
315c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_INDEX - (for vectors) prints the vector
325c6c1daeSBarry Smith        element number next to each vector entry
335c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_SYMMODU - print parallel vectors without
345c6c1daeSBarry Smith        indicating the processor ranges
358ec8862eSJed Brown .    PETSC_VIEWER_ASCII_VTK - outputs the object to a VTK file (deprecated since v3.14)
365c6c1daeSBarry Smith .    PETSC_VIEWER_NATIVE - store the object to the binary
375c6c1daeSBarry Smith        file in its native format (for example, dense
385c6c1daeSBarry Smith        matrices are stored as dense), DMDA vectors are dumped directly to the
395c6c1daeSBarry Smith        file instead of being first put in the natural ordering
405c6c1daeSBarry Smith .    PETSC_VIEWER_DRAW_BASIC - views the vector with a simple 1d plot
415c6c1daeSBarry Smith .    PETSC_VIEWER_DRAW_LG - views the vector with a line graph
425c6c1daeSBarry Smith -    PETSC_VIEWER_DRAW_CONTOUR - views the vector with a contour plot
435c6c1daeSBarry Smith 
445c6c1daeSBarry Smith    These formats are most often used for viewing matrices and vectors.
455c6c1daeSBarry Smith 
465c6c1daeSBarry Smith    If a format (for example PETSC_VIEWER_DRAW_CONTOUR) was applied to a viewer
475c6c1daeSBarry Smith   where it didn't apply (PETSC_VIEWER_STDOUT_WORLD) it cause the default behavior
485c6c1daeSBarry Smith   for that viewer to be used.
495c6c1daeSBarry Smith 
50f55353a2SBarry Smith     Note: This supports passing in a NULL for the viewer for use in the debugger, but it should never be called in the code with a NULL viewer
51f55353a2SBarry Smith 
52db781477SPatrick Sanan .seealso: `PetscViewerGetFormat()`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`, `PetscViewerType`,
53c2e3fba1SPatrick Sanan           `PetscViewerPushFormat()`, `PetscViewerPopFormat()`, `PetscViewerDrawOpen()`, `PetscViewerSocketOpen()`
545c6c1daeSBarry Smith @*/
55*9371c9d4SSatish Balay PetscErrorCode PetscViewerSetFormat(PetscViewer viewer, PetscViewerFormat format) {
565c6c1daeSBarry Smith   PetscFunctionBegin;
575c6c1daeSBarry Smith   if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
585c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
595c6c1daeSBarry Smith   PetscValidLogicalCollectiveEnum(viewer, format, 2);
605c6c1daeSBarry Smith   viewer->format = format;
615c6c1daeSBarry Smith   PetscFunctionReturn(0);
625c6c1daeSBarry Smith }
635c6c1daeSBarry Smith 
645c6c1daeSBarry Smith /*@C
655c6c1daeSBarry Smith    PetscViewerPushFormat - Sets the format for file PetscViewers.
665c6c1daeSBarry Smith 
675c6c1daeSBarry Smith    Logically Collective on PetscViewer
685c6c1daeSBarry Smith 
695c6c1daeSBarry Smith    Input Parameters:
705c6c1daeSBarry Smith +  viewer - the PetscViewer
715c6c1daeSBarry Smith -  format - the format
725c6c1daeSBarry Smith 
735c6c1daeSBarry Smith    Level: intermediate
745c6c1daeSBarry Smith 
755c6c1daeSBarry Smith    Notes:
765c6c1daeSBarry Smith    Available formats include
775c6c1daeSBarry Smith +    PETSC_VIEWER_DEFAULT - default format
785c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_MATLAB - MATLAB format
795c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_IMPL - implementation-specific format
805c6c1daeSBarry Smith       (which is in many cases the same as the default)
815c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_INFO - basic information about object
825c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_INFO_DETAIL - more detailed info
835c6c1daeSBarry Smith        about object
845c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_COMMON - identical output format for
855c6c1daeSBarry Smith        all objects of a particular type
865c6c1daeSBarry Smith .    PETSC_VIEWER_ASCII_INDEX - (for vectors) prints the vector
875c6c1daeSBarry Smith        element number next to each vector entry
885c6c1daeSBarry Smith .    PETSC_VIEWER_NATIVE - store the object to the binary
895c6c1daeSBarry Smith        file in its native format (for example, dense
905c6c1daeSBarry Smith        matrices are stored as dense), for DMDA vectors displays vectors in DMDA ordering, not natural
915c6c1daeSBarry Smith .    PETSC_VIEWER_DRAW_BASIC - views the vector with a simple 1d plot
925c6c1daeSBarry Smith .    PETSC_VIEWER_DRAW_LG - views the vector with a line graph
93fe866b2dSBarry Smith .    PETSC_VIEWER_DRAW_CONTOUR - views the vector with a contour plot
94fe866b2dSBarry Smith -    PETSC_VIEWER_ASCII_XML - saves the data in XML format, needed for PetscLogView() when viewing with PetscLogNestedBegin()
955c6c1daeSBarry Smith 
965c6c1daeSBarry Smith    These formats are most often used for viewing matrices and vectors.
975c6c1daeSBarry Smith    Currently, the object name is used only in the MATLAB format.
985c6c1daeSBarry Smith 
99db781477SPatrick Sanan .seealso: `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`,
100db781477SPatrick Sanan           `PetscViewerSetFormat()`, `PetscViewerPopFormat()`
1015c6c1daeSBarry Smith @*/
102*9371c9d4SSatish Balay PetscErrorCode PetscViewerPushFormat(PetscViewer viewer, PetscViewerFormat format) {
1035c6c1daeSBarry Smith   PetscFunctionBegin;
1045c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
1055c6c1daeSBarry Smith   PetscValidLogicalCollectiveEnum(viewer, format, 2);
10608401ef6SPierre Jolivet   PetscCheck(viewer->iformat <= PETSCVIEWERFORMATPUSHESMAX - 1, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Too many PetscViewerPushFormat(), perhaps you forgot PetscViewerPopFormat()?");
1075c6c1daeSBarry Smith 
1085c6c1daeSBarry Smith   viewer->formats[viewer->iformat++] = viewer->format;
1095c6c1daeSBarry Smith   viewer->format                     = format;
1105c6c1daeSBarry Smith   PetscFunctionReturn(0);
1115c6c1daeSBarry Smith }
1125c6c1daeSBarry Smith 
1135c6c1daeSBarry Smith /*@C
1145c6c1daeSBarry Smith    PetscViewerPopFormat - Resets the format for file PetscViewers.
1155c6c1daeSBarry Smith 
1165c6c1daeSBarry Smith    Logically Collective on PetscViewer
1175c6c1daeSBarry Smith 
1185c6c1daeSBarry Smith    Input Parameters:
1195c6c1daeSBarry Smith .  viewer - the PetscViewer
1205c6c1daeSBarry Smith 
1215c6c1daeSBarry Smith    Level: intermediate
1225c6c1daeSBarry Smith 
123db781477SPatrick Sanan .seealso: `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`,
124db781477SPatrick Sanan           `PetscViewerSetFormat()`, `PetscViewerPushFormat()`
1255c6c1daeSBarry Smith @*/
126*9371c9d4SSatish Balay PetscErrorCode PetscViewerPopFormat(PetscViewer viewer) {
1275c6c1daeSBarry Smith   PetscFunctionBegin;
1285c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
1295c6c1daeSBarry Smith   if (viewer->iformat <= 0) PetscFunctionReturn(0);
1305c6c1daeSBarry Smith 
1315c6c1daeSBarry Smith   viewer->format = viewer->formats[--viewer->iformat];
1325c6c1daeSBarry Smith   PetscFunctionReturn(0);
1335c6c1daeSBarry Smith }
1345c6c1daeSBarry Smith 
135569e28a7SMatthew G. Knepley /*@C
136569e28a7SMatthew G. Knepley    PetscViewerGetFormat - Gets the format for PetscViewers.
137569e28a7SMatthew G. Knepley 
138569e28a7SMatthew G. Knepley    Not collective
139569e28a7SMatthew G. Knepley 
140569e28a7SMatthew G. Knepley    Input Parameter:
141569e28a7SMatthew G. Knepley .  viewer - the PetscViewer
142569e28a7SMatthew G. Knepley 
143569e28a7SMatthew G. Knepley    Output Parameter:
144d8d19677SJose E. Roman .  format - the format
145569e28a7SMatthew G. Knepley 
146569e28a7SMatthew G. Knepley    Level: intermediate
147569e28a7SMatthew G. Knepley 
148569e28a7SMatthew G. Knepley    Notes:
149569e28a7SMatthew G. Knepley    Available formats include
150569e28a7SMatthew G. Knepley +    PETSC_VIEWER_DEFAULT - default format
151569e28a7SMatthew G. Knepley .    PETSC_VIEWER_ASCII_MATLAB - MATLAB format
152569e28a7SMatthew G. Knepley .    PETSC_VIEWER_ASCII_DENSE - print matrix as dense
153569e28a7SMatthew G. Knepley .    PETSC_VIEWER_ASCII_IMPL - implementation-specific format
154569e28a7SMatthew G. Knepley       (which is in many cases the same as the default)
155569e28a7SMatthew G. Knepley .    PETSC_VIEWER_ASCII_INFO - basic information about object
156569e28a7SMatthew G. Knepley .    PETSC_VIEWER_ASCII_INFO_DETAIL - more detailed info
157569e28a7SMatthew G. Knepley        about object
158569e28a7SMatthew G. Knepley .    PETSC_VIEWER_ASCII_COMMON - identical output format for
159569e28a7SMatthew G. Knepley        all objects of a particular type
160569e28a7SMatthew G. Knepley .    PETSC_VIEWER_ASCII_INDEX - (for vectors) prints the vector
161569e28a7SMatthew G. Knepley        element number next to each vector entry
162569e28a7SMatthew G. Knepley .    PETSC_VIEWER_ASCII_SYMMODU - print parallel vectors without
163569e28a7SMatthew G. Knepley        indicating the processor ranges
164569e28a7SMatthew G. Knepley .    PETSC_VIEWER_ASCII_VTK - outputs the object to a VTK file (deprecated since v3.14)
165569e28a7SMatthew G. Knepley .    PETSC_VIEWER_NATIVE - store the object to the binary
166569e28a7SMatthew G. Knepley        file in its native format (for example, dense
167569e28a7SMatthew G. Knepley        matrices are stored as dense), DMDA vectors are dumped directly to the
168569e28a7SMatthew G. Knepley        file instead of being first put in the natural ordering
169569e28a7SMatthew G. Knepley .    PETSC_VIEWER_DRAW_BASIC - views the vector with a simple 1d plot
170569e28a7SMatthew G. Knepley .    PETSC_VIEWER_DRAW_LG - views the vector with a line graph
171569e28a7SMatthew G. Knepley -    PETSC_VIEWER_DRAW_CONTOUR - views the vector with a contour plot
172569e28a7SMatthew G. Knepley 
173569e28a7SMatthew G. Knepley    These formats are most often used for viewing matrices and vectors.
174569e28a7SMatthew G. Knepley 
175569e28a7SMatthew G. Knepley    If a format (for example PETSC_VIEWER_DRAW_CONTOUR) was applied to a viewer
176569e28a7SMatthew G. Knepley   where it didn't apply (PETSC_VIEWER_STDOUT_WORLD) it cause the default behavior
177569e28a7SMatthew G. Knepley   for that viewer to be used.
178569e28a7SMatthew G. Knepley 
179db781477SPatrick Sanan .seealso: `PetscViewerSetFormat()`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`, `PetscViewerType`,
180c2e3fba1SPatrick Sanan           `PetscViewerPushFormat()`, `PetscViewerPopFormat()`, `PetscViewerDrawOpen()`, `PetscViewerSocketOpen()`
181569e28a7SMatthew G. Knepley @*/
182*9371c9d4SSatish Balay PetscErrorCode PetscViewerGetFormat(PetscViewer viewer, PetscViewerFormat *format) {
1835c6c1daeSBarry Smith   PetscFunctionBegin;
1845c6c1daeSBarry Smith   *format = viewer->format;
1855c6c1daeSBarry Smith   PetscFunctionReturn(0);
1865c6c1daeSBarry Smith }
187