xref: /petsc/src/sys/classes/viewer/interface/viewa.c (revision 01311c95a4eb0c722f7a49062585955469f8d6c4)
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 
9c3339decSBarry 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 
50*01311c95SBarry 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
51f55353a2SBarry Smith 
52d1f92df0SBarry Smith .seealso: [](sec_viewers), `PetscViewerGetFormat()`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`, `PetscViewerType`,
53c2e3fba1SPatrick Sanan           `PetscViewerPushFormat()`, `PetscViewerPopFormat()`, `PetscViewerDrawOpen()`, `PetscViewerSocketOpen()`
545c6c1daeSBarry Smith @*/
55d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscViewerSetFormat(PetscViewer viewer, PetscViewerFormat format)
56d71ae5a4SJacob Faibussowitsch {
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;
623ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
635c6c1daeSBarry Smith }
645c6c1daeSBarry Smith 
655c6c1daeSBarry Smith /*@C
66811af0c4SBarry Smith    PetscViewerPushFormat - Sets the format for a `PetscViewer`.
675c6c1daeSBarry Smith 
68c3339decSBarry Smith    Logically Collective
695c6c1daeSBarry Smith 
705c6c1daeSBarry Smith    Input Parameters:
71811af0c4SBarry 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
78811af0c4SBarry Smith +    `PETSC_VIEWER_DEFAULT` - default format
79811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_MATLAB` - MATLAB format
80811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_IMPL` - implementation-specific format
815c6c1daeSBarry Smith       (which is in many cases the same as the default)
82811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO` - basic information about object
83811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO_DETAIL` - more detailed info
845c6c1daeSBarry Smith        about object
85811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_COMMON` - identical output format for
865c6c1daeSBarry Smith        all objects of a particular type
87811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INDEX` - (for vectors) prints the vector
885c6c1daeSBarry Smith        element number next to each vector entry
89811af0c4SBarry Smith .    `PETSC_VIEWER_NATIVE` - store the object to the binary
905c6c1daeSBarry Smith        file in its native format (for example, dense
91811af0c4SBarry Smith        matrices are stored as dense), for `DMDA` vectors displays vectors in `DMDA` ordering, not natural
92811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_BASIC` - views the vector with a simple 1d plot
93811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_LG` - views the vector with a line graph
94811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_CONTOUR` - views the vector with a contour plot
95811af0c4SBarry 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*01311c95SBarry Smith .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerFormat`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`,
101db781477SPatrick Sanan           `PetscViewerSetFormat()`, `PetscViewerPopFormat()`
1025c6c1daeSBarry Smith @*/
103d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscViewerPushFormat(PetscViewer viewer, PetscViewerFormat format)
104d71ae5a4SJacob Faibussowitsch {
1055c6c1daeSBarry Smith   PetscFunctionBegin;
1065c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
1075c6c1daeSBarry Smith   PetscValidLogicalCollectiveEnum(viewer, format, 2);
10808401ef6SPierre Jolivet   PetscCheck(viewer->iformat <= PETSCVIEWERFORMATPUSHESMAX - 1, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Too many PetscViewerPushFormat(), perhaps you forgot PetscViewerPopFormat()?");
1095c6c1daeSBarry Smith 
1105c6c1daeSBarry Smith   viewer->formats[viewer->iformat++] = viewer->format;
1115c6c1daeSBarry Smith   viewer->format                     = format;
1123ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1135c6c1daeSBarry Smith }
1145c6c1daeSBarry Smith 
1155c6c1daeSBarry Smith /*@C
116811af0c4SBarry Smith    PetscViewerPopFormat - Resets the format for a `PetscViewer`.
1175c6c1daeSBarry Smith 
118c3339decSBarry Smith    Logically Collective
1195c6c1daeSBarry Smith 
1205c6c1daeSBarry Smith    Input Parameters:
121811af0c4SBarry Smith .  viewer - the `PetscViewer`
1225c6c1daeSBarry Smith 
1235c6c1daeSBarry Smith    Level: intermediate
1245c6c1daeSBarry Smith 
125*01311c95SBarry Smith .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerFormat`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`,
126db781477SPatrick Sanan           `PetscViewerSetFormat()`, `PetscViewerPushFormat()`
1275c6c1daeSBarry Smith @*/
128d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscViewerPopFormat(PetscViewer viewer)
129d71ae5a4SJacob Faibussowitsch {
1305c6c1daeSBarry Smith   PetscFunctionBegin;
1315c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
1323ba16761SJacob Faibussowitsch   if (viewer->iformat <= 0) PetscFunctionReturn(PETSC_SUCCESS);
1335c6c1daeSBarry Smith 
1345c6c1daeSBarry Smith   viewer->format = viewer->formats[--viewer->iformat];
1353ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1365c6c1daeSBarry Smith }
1375c6c1daeSBarry Smith 
138569e28a7SMatthew G. Knepley /*@C
139811af0c4SBarry Smith    PetscViewerGetFormat - Gets the current format for `PetscViewer`.
140569e28a7SMatthew G. Knepley 
141569e28a7SMatthew G. Knepley    Not collective
142569e28a7SMatthew G. Knepley 
143569e28a7SMatthew G. Knepley    Input Parameter:
144811af0c4SBarry Smith .  viewer - the `PetscViewer`
145569e28a7SMatthew G. Knepley 
146569e28a7SMatthew G. Knepley    Output Parameter:
147d8d19677SJose E. Roman .  format - the format
148569e28a7SMatthew G. Knepley 
149569e28a7SMatthew G. Knepley    Level: intermediate
150569e28a7SMatthew G. Knepley 
151569e28a7SMatthew G. Knepley    Notes:
152569e28a7SMatthew G. Knepley    Available formats include
153811af0c4SBarry Smith +    `PETSC_VIEWER_DEFAULT` - default format
154811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_MATLAB` - MATLAB format
155811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_DENSE` - print matrix as dense
156811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_IMPL` - implementation-specific format
157569e28a7SMatthew G. Knepley       (which is in many cases the same as the default)
158811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO` - basic information about object
159811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INFO_DETAIL` - more detailed info
160569e28a7SMatthew G. Knepley        about object
161811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_COMMON` - identical output format for
162569e28a7SMatthew G. Knepley        all objects of a particular type
163811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_INDEX` - (for vectors) prints the vector
164569e28a7SMatthew G. Knepley        element number next to each vector entry
165811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_SYMMODU` - print parallel vectors without
166569e28a7SMatthew G. Knepley        indicating the processor ranges
167811af0c4SBarry Smith .    `PETSC_VIEWER_ASCII_VTK` - outputs the object to a VTK file (deprecated since v3.14)
168811af0c4SBarry Smith .    `PETSC_VIEWER_NATIVE` - store the object to the binary
169569e28a7SMatthew G. Knepley        file in its native format (for example, dense
170569e28a7SMatthew G. Knepley        matrices are stored as dense), DMDA vectors are dumped directly to the
171569e28a7SMatthew G. Knepley        file instead of being first put in the natural ordering
172811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_BASIC` - views the vector with a simple 1d plot
173811af0c4SBarry Smith .    `PETSC_VIEWER_DRAW_LG` - views the vector with a line graph
174811af0c4SBarry Smith -    `PETSC_VIEWER_DRAW_CONTOUR` - views the vector with a contour plot
175569e28a7SMatthew G. Knepley 
176569e28a7SMatthew G. Knepley    These formats are most often used for viewing matrices and vectors.
177569e28a7SMatthew G. Knepley 
178811af0c4SBarry Smith    If a format (for example `PETSC_VIEWER_DRAW_CONTOUR`) was applied to a viewer
179811af0c4SBarry Smith   where it didn't apply (`PETSC_VIEWER_STDOUT_WORLD`) it cause the default behavior
180569e28a7SMatthew G. Knepley   for that viewer to be used.
181569e28a7SMatthew G. Knepley 
182d1f92df0SBarry Smith .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerSetFormat()`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`, `PetscViewerType`,
183c2e3fba1SPatrick Sanan           `PetscViewerPushFormat()`, `PetscViewerPopFormat()`, `PetscViewerDrawOpen()`, `PetscViewerSocketOpen()`
184569e28a7SMatthew G. Knepley @*/
185d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscViewerGetFormat(PetscViewer viewer, PetscViewerFormat *format)
186d71ae5a4SJacob Faibussowitsch {
1875c6c1daeSBarry Smith   PetscFunctionBegin;
1885c6c1daeSBarry Smith   *format = viewer->format;
1893ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1905c6c1daeSBarry Smith }
191