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