xref: /petsc/src/sys/classes/viewer/interface/viewa.c (revision 811af0c4b09a35de4306c442f88bd09fdc09897d)
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
7*811af0c4SBarry Smith    PetscViewerSetFormat - Sets the format for a `PetscViewer`.
85c6c1daeSBarry Smith 
9*811af0c4SBarry Smith    Logically Collective on viewer
105c6c1daeSBarry Smith 
11*811af0c4SBarry Smith    This routine is deprecated, you should use `PetscViewerPushFormat()`/`PetscViewerPopFormat()`
126a9046bcSBarry Smith 
135c6c1daeSBarry Smith    Input Parameters:
14*811af0c4SBarry 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
21*811af0c4SBarry Smith +    `PETSC_VIEWER_DEFAULT` - default format
22*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_MATLAB` - MATLAB format
23*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_DENSE` - print matrix as dense
24*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_IMPL` - implementation-specific format
255c6c1daeSBarry Smith       (which is in many cases the same as the default)
26*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO` - basic information about object
27*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO_DETAIL` - more detailed info
285c6c1daeSBarry Smith        about object
29*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_COMMON` - identical output format for
305c6c1daeSBarry Smith        all objects of a particular type
31*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INDEX` - (for vectors) prints the vector
325c6c1daeSBarry Smith        element number next to each vector entry
33*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_SYMMODU` - print parallel vectors without
345c6c1daeSBarry Smith        indicating the processor ranges
35*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_VTK` - outputs the object to a VTK file (deprecated since v3.14)
36*811af0c4SBarry Smith .    `PETSC_VIEWER_NATIVE` - store the object to the binary
375c6c1daeSBarry Smith        file in its native format (for example, dense
38*811af0c4SBarry 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
40*811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_BASIC` - views the vector with a simple 1d plot
41*811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_LG` - views the vector with a line graph
42*811af0c4SBarry 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 
46*811af0c4SBarry Smith    If a format (for example `PETSC_VIEWER_DRAW_CONTOUR`) was applied to a viewer
47*811af0c4SBarry 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 
50*811af0c4SBarry Smith     Note:
51*811af0c4SBarry 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 @*/
569371c9d4SSatish Balay PetscErrorCode PetscViewerSetFormat(PetscViewer viewer, PetscViewerFormat format) {
575c6c1daeSBarry Smith   PetscFunctionBegin;
585c6c1daeSBarry Smith   if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
595c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
605c6c1daeSBarry Smith   PetscValidLogicalCollectiveEnum(viewer, format, 2);
615c6c1daeSBarry Smith   viewer->format = format;
625c6c1daeSBarry Smith   PetscFunctionReturn(0);
635c6c1daeSBarry Smith }
645c6c1daeSBarry Smith 
655c6c1daeSBarry Smith /*@C
66*811af0c4SBarry Smith    PetscViewerPushFormat - Sets the format for a `PetscViewer`.
675c6c1daeSBarry Smith 
68*811af0c4SBarry Smith    Logically Collective on viewer
695c6c1daeSBarry Smith 
705c6c1daeSBarry Smith    Input Parameters:
71*811af0c4SBarry Smith +  viewer - the `PetscViewer`
725c6c1daeSBarry Smith -  format - the format
735c6c1daeSBarry Smith 
745c6c1daeSBarry Smith    Level: intermediate
755c6c1daeSBarry Smith 
765c6c1daeSBarry Smith    Notes:
775c6c1daeSBarry Smith    Available formats include
78*811af0c4SBarry Smith +    `PETSC_VIEWER_DEFAULT` - default format
79*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_MATLAB` - MATLAB format
80*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_IMPL` - implementation-specific format
815c6c1daeSBarry Smith       (which is in many cases the same as the default)
82*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO` - basic information about object
83*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO_DETAIL` - more detailed info
845c6c1daeSBarry Smith        about object
85*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_COMMON` - identical output format for
865c6c1daeSBarry Smith        all objects of a particular type
87*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INDEX` - (for vectors) prints the vector
885c6c1daeSBarry Smith        element number next to each vector entry
89*811af0c4SBarry Smith .    `PETSC_VIEWER_NATIVE` - store the object to the binary
905c6c1daeSBarry Smith        file in its native format (for example, dense
91*811af0c4SBarry Smith        matrices are stored as dense), for `DMDA` vectors displays vectors in `DMDA` ordering, not natural
92*811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_BASIC` - views the vector with a simple 1d plot
93*811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_LG` - views the vector with a line graph
94*811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_CONTOUR` - views the vector with a contour plot
95*811af0c4SBarry Smith -    `PETSC_VIEWER_ASCII_XML` - saves the data in XML format, needed for `PetscLogView()` when viewing with `PetscLogNestedBegin()`
965c6c1daeSBarry Smith 
975c6c1daeSBarry Smith    These formats are most often used for viewing matrices and vectors.
985c6c1daeSBarry Smith    Currently, the object name is used only in the MATLAB format.
995c6c1daeSBarry Smith 
100*811af0c4SBarry Smith .seealso: `PetscViewer`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`,
101db781477SPatrick Sanan           `PetscViewerSetFormat()`, `PetscViewerPopFormat()`
1025c6c1daeSBarry Smith @*/
1039371c9d4SSatish Balay PetscErrorCode PetscViewerPushFormat(PetscViewer viewer, PetscViewerFormat format) {
1045c6c1daeSBarry Smith   PetscFunctionBegin;
1055c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
1065c6c1daeSBarry Smith   PetscValidLogicalCollectiveEnum(viewer, format, 2);
10708401ef6SPierre Jolivet   PetscCheck(viewer->iformat <= PETSCVIEWERFORMATPUSHESMAX - 1, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Too many PetscViewerPushFormat(), perhaps you forgot PetscViewerPopFormat()?");
1085c6c1daeSBarry Smith 
1095c6c1daeSBarry Smith   viewer->formats[viewer->iformat++] = viewer->format;
1105c6c1daeSBarry Smith   viewer->format                     = format;
1115c6c1daeSBarry Smith   PetscFunctionReturn(0);
1125c6c1daeSBarry Smith }
1135c6c1daeSBarry Smith 
1145c6c1daeSBarry Smith /*@C
115*811af0c4SBarry Smith    PetscViewerPopFormat - Resets the format for a `PetscViewer`.
1165c6c1daeSBarry Smith 
117*811af0c4SBarry Smith    Logically Collective on viewer
1185c6c1daeSBarry Smith 
1195c6c1daeSBarry Smith    Input Parameters:
120*811af0c4SBarry Smith .  viewer - the `PetscViewer`
1215c6c1daeSBarry Smith 
1225c6c1daeSBarry Smith    Level: intermediate
1235c6c1daeSBarry Smith 
124*811af0c4SBarry Smith .seealso: `PetscViewer`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`,
125db781477SPatrick Sanan           `PetscViewerSetFormat()`, `PetscViewerPushFormat()`
1265c6c1daeSBarry Smith @*/
1279371c9d4SSatish Balay PetscErrorCode PetscViewerPopFormat(PetscViewer viewer) {
1285c6c1daeSBarry Smith   PetscFunctionBegin;
1295c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
1305c6c1daeSBarry Smith   if (viewer->iformat <= 0) PetscFunctionReturn(0);
1315c6c1daeSBarry Smith 
1325c6c1daeSBarry Smith   viewer->format = viewer->formats[--viewer->iformat];
1335c6c1daeSBarry Smith   PetscFunctionReturn(0);
1345c6c1daeSBarry Smith }
1355c6c1daeSBarry Smith 
136569e28a7SMatthew G. Knepley /*@C
137*811af0c4SBarry Smith    PetscViewerGetFormat - Gets the current format for `PetscViewer`.
138569e28a7SMatthew G. Knepley 
139569e28a7SMatthew G. Knepley    Not collective
140569e28a7SMatthew G. Knepley 
141569e28a7SMatthew G. Knepley    Input Parameter:
142*811af0c4SBarry Smith .  viewer - the `PetscViewer`
143569e28a7SMatthew G. Knepley 
144569e28a7SMatthew G. Knepley    Output Parameter:
145d8d19677SJose E. Roman .  format - the format
146569e28a7SMatthew G. Knepley 
147569e28a7SMatthew G. Knepley    Level: intermediate
148569e28a7SMatthew G. Knepley 
149569e28a7SMatthew G. Knepley    Notes:
150569e28a7SMatthew G. Knepley    Available formats include
151*811af0c4SBarry Smith +    `PETSC_VIEWER_DEFAULT` - default format
152*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_MATLAB` - MATLAB format
153*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_DENSE` - print matrix as dense
154*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_IMPL` - implementation-specific format
155569e28a7SMatthew G. Knepley       (which is in many cases the same as the default)
156*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO` - basic information about object
157*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO_DETAIL` - more detailed info
158569e28a7SMatthew G. Knepley        about object
159*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_COMMON` - identical output format for
160569e28a7SMatthew G. Knepley        all objects of a particular type
161*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INDEX` - (for vectors) prints the vector
162569e28a7SMatthew G. Knepley        element number next to each vector entry
163*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_SYMMODU` - print parallel vectors without
164569e28a7SMatthew G. Knepley        indicating the processor ranges
165*811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_VTK` - outputs the object to a VTK file (deprecated since v3.14)
166*811af0c4SBarry Smith .    `PETSC_VIEWER_NATIVE` - store the object to the binary
167569e28a7SMatthew G. Knepley        file in its native format (for example, dense
168569e28a7SMatthew G. Knepley        matrices are stored as dense), DMDA vectors are dumped directly to the
169569e28a7SMatthew G. Knepley        file instead of being first put in the natural ordering
170*811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_BASIC` - views the vector with a simple 1d plot
171*811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_LG` - views the vector with a line graph
172*811af0c4SBarry Smith -    `PETSC_VIEWER_DRAW_CONTOUR` - views the vector with a contour plot
173569e28a7SMatthew G. Knepley 
174569e28a7SMatthew G. Knepley    These formats are most often used for viewing matrices and vectors.
175569e28a7SMatthew G. Knepley 
176*811af0c4SBarry Smith    If a format (for example `PETSC_VIEWER_DRAW_CONTOUR`) was applied to a viewer
177*811af0c4SBarry Smith   where it didn't apply (`PETSC_VIEWER_STDOUT_WORLD`) it cause the default behavior
178569e28a7SMatthew G. Knepley   for that viewer to be used.
179569e28a7SMatthew G. Knepley 
180*811af0c4SBarry Smith .seealso: `PetscViewer`, `PetscViewerSetFormat()`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`, `PetscViewerType`,
181c2e3fba1SPatrick Sanan           `PetscViewerPushFormat()`, `PetscViewerPopFormat()`, `PetscViewerDrawOpen()`, `PetscViewerSocketOpen()`
182569e28a7SMatthew G. Knepley @*/
1839371c9d4SSatish Balay PetscErrorCode PetscViewerGetFormat(PetscViewer viewer, PetscViewerFormat *format) {
1845c6c1daeSBarry Smith   PetscFunctionBegin;
1855c6c1daeSBarry Smith   *format = viewer->format;
1865c6c1daeSBarry Smith   PetscFunctionReturn(0);
1875c6c1daeSBarry Smith }
188