xref: /petsc/src/sys/classes/viewer/interface/viewa.c (revision c3339decea92175325d9368fa13196bcd0e0e58b)
15c6c1daeSBarry Smith 
2af0996ceSBarry Smith #include <petsc/private/viewerimpl.h> /*I "petscsys.h" I*/
35c6c1daeSBarry Smith 
49371c9d4SSatish 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
7811af0c4SBarry Smith    PetscViewerSetFormat - Sets the format for a `PetscViewer`.
85c6c1daeSBarry Smith 
9*c3339decSBarry Smith    Logically Collective
105c6c1daeSBarry Smith 
11811af0c4SBarry Smith    This routine is deprecated, you should use `PetscViewerPushFormat()`/`PetscViewerPopFormat()`
126a9046bcSBarry Smith 
135c6c1daeSBarry Smith    Input Parameters:
14811af0c4SBarry 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
21811af0c4SBarry Smith +    `PETSC_VIEWER_DEFAULT` - default format
22811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_MATLAB` - MATLAB format
23811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_DENSE` - print matrix as dense
24811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_IMPL` - implementation-specific format
255c6c1daeSBarry Smith       (which is in many cases the same as the default)
26811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO` - basic information about object
27811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO_DETAIL` - more detailed info
285c6c1daeSBarry Smith        about object
29811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_COMMON` - identical output format for
305c6c1daeSBarry Smith        all objects of a particular type
31811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INDEX` - (for vectors) prints the vector
325c6c1daeSBarry Smith        element number next to each vector entry
33811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_SYMMODU` - print parallel vectors without
345c6c1daeSBarry Smith        indicating the processor ranges
35811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_VTK` - outputs the object to a VTK file (deprecated since v3.14)
36811af0c4SBarry Smith .    `PETSC_VIEWER_NATIVE` - store the object to the binary
375c6c1daeSBarry Smith        file in its native format (for example, dense
38811af0c4SBarry 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
40811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_BASIC` - views the vector with a simple 1d plot
41811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_LG` - views the vector with a line graph
42811af0c4SBarry 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 
46811af0c4SBarry Smith    If a format (for example `PETSC_VIEWER_DRAW_CONTOUR`) was applied to a viewer
47811af0c4SBarry 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 
50811af0c4SBarry Smith     Note:
51811af0c4SBarry Smith     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
52f55353a2SBarry Smith 
53db781477SPatrick Sanan .seealso: `PetscViewerGetFormat()`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`, `PetscViewerType`,
54c2e3fba1SPatrick Sanan           `PetscViewerPushFormat()`, `PetscViewerPopFormat()`, `PetscViewerDrawOpen()`, `PetscViewerSocketOpen()`
555c6c1daeSBarry Smith @*/
56d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscViewerSetFormat(PetscViewer viewer, PetscViewerFormat format)
57d71ae5a4SJacob Faibussowitsch {
585c6c1daeSBarry Smith   PetscFunctionBegin;
595c6c1daeSBarry Smith   if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
605c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
615c6c1daeSBarry Smith   PetscValidLogicalCollectiveEnum(viewer, format, 2);
625c6c1daeSBarry Smith   viewer->format = format;
635c6c1daeSBarry Smith   PetscFunctionReturn(0);
645c6c1daeSBarry Smith }
655c6c1daeSBarry Smith 
665c6c1daeSBarry Smith /*@C
67811af0c4SBarry Smith    PetscViewerPushFormat - Sets the format for a `PetscViewer`.
685c6c1daeSBarry Smith 
69*c3339decSBarry Smith    Logically Collective
705c6c1daeSBarry Smith 
715c6c1daeSBarry Smith    Input Parameters:
72811af0c4SBarry Smith +  viewer - the `PetscViewer`
735c6c1daeSBarry Smith -  format - the format
745c6c1daeSBarry Smith 
755c6c1daeSBarry Smith    Level: intermediate
765c6c1daeSBarry Smith 
775c6c1daeSBarry Smith    Notes:
785c6c1daeSBarry Smith    Available formats include
79811af0c4SBarry Smith +    `PETSC_VIEWER_DEFAULT` - default format
80811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_MATLAB` - MATLAB format
81811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_IMPL` - implementation-specific format
825c6c1daeSBarry Smith       (which is in many cases the same as the default)
83811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO` - basic information about object
84811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO_DETAIL` - more detailed info
855c6c1daeSBarry Smith        about object
86811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_COMMON` - identical output format for
875c6c1daeSBarry Smith        all objects of a particular type
88811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INDEX` - (for vectors) prints the vector
895c6c1daeSBarry Smith        element number next to each vector entry
90811af0c4SBarry Smith .    `PETSC_VIEWER_NATIVE` - store the object to the binary
915c6c1daeSBarry Smith        file in its native format (for example, dense
92811af0c4SBarry Smith        matrices are stored as dense), for `DMDA` vectors displays vectors in `DMDA` ordering, not natural
93811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_BASIC` - views the vector with a simple 1d plot
94811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_LG` - views the vector with a line graph
95811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_CONTOUR` - views the vector with a contour plot
96811af0c4SBarry Smith -    `PETSC_VIEWER_ASCII_XML` - saves the data in XML format, needed for `PetscLogView()` when viewing with `PetscLogNestedBegin()`
975c6c1daeSBarry Smith 
985c6c1daeSBarry Smith    These formats are most often used for viewing matrices and vectors.
995c6c1daeSBarry Smith    Currently, the object name is used only in the MATLAB format.
1005c6c1daeSBarry Smith 
101811af0c4SBarry Smith .seealso: `PetscViewer`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`,
102db781477SPatrick Sanan           `PetscViewerSetFormat()`, `PetscViewerPopFormat()`
1035c6c1daeSBarry Smith @*/
104d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscViewerPushFormat(PetscViewer viewer, PetscViewerFormat format)
105d71ae5a4SJacob Faibussowitsch {
1065c6c1daeSBarry Smith   PetscFunctionBegin;
1075c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
1085c6c1daeSBarry Smith   PetscValidLogicalCollectiveEnum(viewer, format, 2);
10908401ef6SPierre Jolivet   PetscCheck(viewer->iformat <= PETSCVIEWERFORMATPUSHESMAX - 1, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Too many PetscViewerPushFormat(), perhaps you forgot PetscViewerPopFormat()?");
1105c6c1daeSBarry Smith 
1115c6c1daeSBarry Smith   viewer->formats[viewer->iformat++] = viewer->format;
1125c6c1daeSBarry Smith   viewer->format                     = format;
1135c6c1daeSBarry Smith   PetscFunctionReturn(0);
1145c6c1daeSBarry Smith }
1155c6c1daeSBarry Smith 
1165c6c1daeSBarry Smith /*@C
117811af0c4SBarry Smith    PetscViewerPopFormat - Resets the format for a `PetscViewer`.
1185c6c1daeSBarry Smith 
119*c3339decSBarry Smith    Logically Collective
1205c6c1daeSBarry Smith 
1215c6c1daeSBarry Smith    Input Parameters:
122811af0c4SBarry Smith .  viewer - the `PetscViewer`
1235c6c1daeSBarry Smith 
1245c6c1daeSBarry Smith    Level: intermediate
1255c6c1daeSBarry Smith 
126811af0c4SBarry Smith .seealso: `PetscViewer`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`,
127db781477SPatrick Sanan           `PetscViewerSetFormat()`, `PetscViewerPushFormat()`
1285c6c1daeSBarry Smith @*/
129d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscViewerPopFormat(PetscViewer viewer)
130d71ae5a4SJacob Faibussowitsch {
1315c6c1daeSBarry Smith   PetscFunctionBegin;
1325c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
1335c6c1daeSBarry Smith   if (viewer->iformat <= 0) PetscFunctionReturn(0);
1345c6c1daeSBarry Smith 
1355c6c1daeSBarry Smith   viewer->format = viewer->formats[--viewer->iformat];
1365c6c1daeSBarry Smith   PetscFunctionReturn(0);
1375c6c1daeSBarry Smith }
1385c6c1daeSBarry Smith 
139569e28a7SMatthew G. Knepley /*@C
140811af0c4SBarry Smith    PetscViewerGetFormat - Gets the current format for `PetscViewer`.
141569e28a7SMatthew G. Knepley 
142569e28a7SMatthew G. Knepley    Not collective
143569e28a7SMatthew G. Knepley 
144569e28a7SMatthew G. Knepley    Input Parameter:
145811af0c4SBarry Smith .  viewer - the `PetscViewer`
146569e28a7SMatthew G. Knepley 
147569e28a7SMatthew G. Knepley    Output Parameter:
148d8d19677SJose E. Roman .  format - the format
149569e28a7SMatthew G. Knepley 
150569e28a7SMatthew G. Knepley    Level: intermediate
151569e28a7SMatthew G. Knepley 
152569e28a7SMatthew G. Knepley    Notes:
153569e28a7SMatthew G. Knepley    Available formats include
154811af0c4SBarry Smith +    `PETSC_VIEWER_DEFAULT` - default format
155811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_MATLAB` - MATLAB format
156811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_DENSE` - print matrix as dense
157811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_IMPL` - implementation-specific format
158569e28a7SMatthew G. Knepley       (which is in many cases the same as the default)
159811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO` - basic information about object
160811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO_DETAIL` - more detailed info
161569e28a7SMatthew G. Knepley        about object
162811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_COMMON` - identical output format for
163569e28a7SMatthew G. Knepley        all objects of a particular type
164811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INDEX` - (for vectors) prints the vector
165569e28a7SMatthew G. Knepley        element number next to each vector entry
166811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_SYMMODU` - print parallel vectors without
167569e28a7SMatthew G. Knepley        indicating the processor ranges
168811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_VTK` - outputs the object to a VTK file (deprecated since v3.14)
169811af0c4SBarry Smith .    `PETSC_VIEWER_NATIVE` - store the object to the binary
170569e28a7SMatthew G. Knepley        file in its native format (for example, dense
171569e28a7SMatthew G. Knepley        matrices are stored as dense), DMDA vectors are dumped directly to the
172569e28a7SMatthew G. Knepley        file instead of being first put in the natural ordering
173811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_BASIC` - views the vector with a simple 1d plot
174811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_LG` - views the vector with a line graph
175811af0c4SBarry Smith -    `PETSC_VIEWER_DRAW_CONTOUR` - views the vector with a contour plot
176569e28a7SMatthew G. Knepley 
177569e28a7SMatthew G. Knepley    These formats are most often used for viewing matrices and vectors.
178569e28a7SMatthew G. Knepley 
179811af0c4SBarry Smith    If a format (for example `PETSC_VIEWER_DRAW_CONTOUR`) was applied to a viewer
180811af0c4SBarry Smith   where it didn't apply (`PETSC_VIEWER_STDOUT_WORLD`) it cause the default behavior
181569e28a7SMatthew G. Knepley   for that viewer to be used.
182569e28a7SMatthew G. Knepley 
183811af0c4SBarry Smith .seealso: `PetscViewer`, `PetscViewerSetFormat()`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`, `PetscViewerType`,
184c2e3fba1SPatrick Sanan           `PetscViewerPushFormat()`, `PetscViewerPopFormat()`, `PetscViewerDrawOpen()`, `PetscViewerSocketOpen()`
185569e28a7SMatthew G. Knepley @*/
186d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscViewerGetFormat(PetscViewer viewer, PetscViewerFormat *format)
187d71ae5a4SJacob Faibussowitsch {
1885c6c1daeSBarry Smith   PetscFunctionBegin;
1895c6c1daeSBarry Smith   *format = viewer->format;
1905c6c1daeSBarry Smith   PetscFunctionReturn(0);
1915c6c1daeSBarry Smith }
192