xref: /petsc/src/sys/classes/viewer/interface/viewa.c (revision 862e4a309d45a165aaa4da0d704ba733429d833a)
1 
2 #include <petsc/private/viewerimpl.h> /*I "petscsys.h" I*/
3 
4 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};
5 
6 /*@C
7    PetscViewerSetFormat - Sets the format for a `PetscViewer`.
8 
9    Logically Collective on viewer
10 
11    This routine is deprecated, you should use `PetscViewerPushFormat()`/`PetscViewerPopFormat()`
12 
13    Input Parameters:
14 +  viewer - the `PetscViewer`
15 -  format - the format
16 
17    Level: intermediate
18 
19    Notes:
20    Available formats include
21 +    `PETSC_VIEWER_DEFAULT` - default format
22 .    `PETSC_VIEWER_ASCII_MATLAB` - MATLAB format
23 .    `PETSC_VIEWER_ASCII_DENSE` - print matrix as dense
24 .    `PETSC_VIEWER_ASCII_IMPL` - implementation-specific format
25       (which is in many cases the same as the default)
26 .    `PETSC_VIEWER_ASCII_INFO` - basic information about object
27 .    `PETSC_VIEWER_ASCII_INFO_DETAIL` - more detailed info
28        about object
29 .    `PETSC_VIEWER_ASCII_COMMON` - identical output format for
30        all objects of a particular type
31 .    `PETSC_VIEWER_ASCII_INDEX` - (for vectors) prints the vector
32        element number next to each vector entry
33 .    `PETSC_VIEWER_ASCII_SYMMODU` - print parallel vectors without
34        indicating the processor ranges
35 .    `PETSC_VIEWER_ASCII_VTK` - outputs the object to a VTK file (deprecated since v3.14)
36 .    `PETSC_VIEWER_NATIVE` - store the object to the binary
37        file in its native format (for example, dense
38        matrices are stored as dense), `DMDA` vectors are dumped directly to the
39        file instead of being first put in the natural ordering
40 .    `PETSC_VIEWER_DRAW_BASIC` - views the vector with a simple 1d plot
41 .    `PETSC_VIEWER_DRAW_LG` - views the vector with a line graph
42 -    `PETSC_VIEWER_DRAW_CONTOUR` - views the vector with a contour plot
43 
44    These formats are most often used for viewing matrices and vectors.
45 
46    If a format (for example `PETSC_VIEWER_DRAW_CONTOUR`) was applied to a viewer
47   where it didn't apply (`PETSC_VIEWER_STDOUT_WORLD`) it cause the default behavior
48   for that viewer to be used.
49 
50     Note:
51     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
52 
53 .seealso: `PetscViewerGetFormat()`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`, `PetscViewerType`,
54           `PetscViewerPushFormat()`, `PetscViewerPopFormat()`, `PetscViewerDrawOpen()`, `PetscViewerSocketOpen()`
55 @*/
56 PetscErrorCode PetscViewerSetFormat(PetscViewer viewer, PetscViewerFormat format)
57 {
58   PetscFunctionBegin;
59   if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
60   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
61   PetscValidLogicalCollectiveEnum(viewer, format, 2);
62   viewer->format = format;
63   PetscFunctionReturn(0);
64 }
65 
66 /*@C
67    PetscViewerPushFormat - Sets the format for a `PetscViewer`.
68 
69    Logically Collective on viewer
70 
71    Input Parameters:
72 +  viewer - the `PetscViewer`
73 -  format - the format
74 
75    Level: intermediate
76 
77    Notes:
78    Available formats include
79 +    `PETSC_VIEWER_DEFAULT` - default format
80 .    `PETSC_VIEWER_ASCII_MATLAB` - MATLAB format
81 .    `PETSC_VIEWER_ASCII_IMPL` - implementation-specific format
82       (which is in many cases the same as the default)
83 .    `PETSC_VIEWER_ASCII_INFO` - basic information about object
84 .    `PETSC_VIEWER_ASCII_INFO_DETAIL` - more detailed info
85        about object
86 .    `PETSC_VIEWER_ASCII_COMMON` - identical output format for
87        all objects of a particular type
88 .    `PETSC_VIEWER_ASCII_INDEX` - (for vectors) prints the vector
89        element number next to each vector entry
90 .    `PETSC_VIEWER_NATIVE` - store the object to the binary
91        file in its native format (for example, dense
92        matrices are stored as dense), for `DMDA` vectors displays vectors in `DMDA` ordering, not natural
93 .    `PETSC_VIEWER_DRAW_BASIC` - views the vector with a simple 1d plot
94 .    `PETSC_VIEWER_DRAW_LG` - views the vector with a line graph
95 .    `PETSC_VIEWER_DRAW_CONTOUR` - views the vector with a contour plot
96 -    `PETSC_VIEWER_ASCII_XML` - saves the data in XML format, needed for `PetscLogView()` when viewing with `PetscLogNestedBegin()`
97 
98    These formats are most often used for viewing matrices and vectors.
99    Currently, the object name is used only in the MATLAB format.
100 
101 .seealso: `PetscViewer`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`,
102           `PetscViewerSetFormat()`, `PetscViewerPopFormat()`
103 @*/
104 PetscErrorCode PetscViewerPushFormat(PetscViewer viewer, PetscViewerFormat format)
105 {
106   PetscFunctionBegin;
107   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
108   PetscValidLogicalCollectiveEnum(viewer, format, 2);
109   PetscCheck(viewer->iformat <= PETSCVIEWERFORMATPUSHESMAX - 1, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Too many PetscViewerPushFormat(), perhaps you forgot PetscViewerPopFormat()?");
110 
111   viewer->formats[viewer->iformat++] = viewer->format;
112   viewer->format                     = format;
113   PetscFunctionReturn(0);
114 }
115 
116 /*@C
117    PetscViewerPopFormat - Resets the format for a `PetscViewer`.
118 
119    Logically Collective on viewer
120 
121    Input Parameters:
122 .  viewer - the `PetscViewer`
123 
124    Level: intermediate
125 
126 .seealso: `PetscViewer`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`,
127           `PetscViewerSetFormat()`, `PetscViewerPushFormat()`
128 @*/
129 PetscErrorCode PetscViewerPopFormat(PetscViewer viewer)
130 {
131   PetscFunctionBegin;
132   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
133   if (viewer->iformat <= 0) PetscFunctionReturn(0);
134 
135   viewer->format = viewer->formats[--viewer->iformat];
136   PetscFunctionReturn(0);
137 }
138 
139 /*@C
140    PetscViewerGetFormat - Gets the current format for `PetscViewer`.
141 
142    Not collective
143 
144    Input Parameter:
145 .  viewer - the `PetscViewer`
146 
147    Output Parameter:
148 .  format - the format
149 
150    Level: intermediate
151 
152    Notes:
153    Available formats include
154 +    `PETSC_VIEWER_DEFAULT` - default format
155 .    `PETSC_VIEWER_ASCII_MATLAB` - MATLAB format
156 .    `PETSC_VIEWER_ASCII_DENSE` - print matrix as dense
157 .    `PETSC_VIEWER_ASCII_IMPL` - implementation-specific format
158       (which is in many cases the same as the default)
159 .    `PETSC_VIEWER_ASCII_INFO` - basic information about object
160 .    `PETSC_VIEWER_ASCII_INFO_DETAIL` - more detailed info
161        about object
162 .    `PETSC_VIEWER_ASCII_COMMON` - identical output format for
163        all objects of a particular type
164 .    `PETSC_VIEWER_ASCII_INDEX` - (for vectors) prints the vector
165        element number next to each vector entry
166 .    `PETSC_VIEWER_ASCII_SYMMODU` - print parallel vectors without
167        indicating the processor ranges
168 .    `PETSC_VIEWER_ASCII_VTK` - outputs the object to a VTK file (deprecated since v3.14)
169 .    `PETSC_VIEWER_NATIVE` - store the object to the binary
170        file in its native format (for example, dense
171        matrices are stored as dense), DMDA vectors are dumped directly to the
172        file instead of being first put in the natural ordering
173 .    `PETSC_VIEWER_DRAW_BASIC` - views the vector with a simple 1d plot
174 .    `PETSC_VIEWER_DRAW_LG` - views the vector with a line graph
175 -    `PETSC_VIEWER_DRAW_CONTOUR` - views the vector with a contour plot
176 
177    These formats are most often used for viewing matrices and vectors.
178 
179    If a format (for example `PETSC_VIEWER_DRAW_CONTOUR`) was applied to a viewer
180   where it didn't apply (`PETSC_VIEWER_STDOUT_WORLD`) it cause the default behavior
181   for that viewer to be used.
182 
183 .seealso: `PetscViewer`, `PetscViewerSetFormat()`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`, `PetscViewerType`,
184           `PetscViewerPushFormat()`, `PetscViewerPopFormat()`, `PetscViewerDrawOpen()`, `PetscViewerSocketOpen()`
185 @*/
186 PetscErrorCode PetscViewerGetFormat(PetscViewer viewer, PetscViewerFormat *format)
187 {
188   PetscFunctionBegin;
189   *format = viewer->format;
190   PetscFunctionReturn(0);
191 }
192