Actual source code: networkview.c
1: #include <petscconf.h>
2: // We need to define this ahead of any other includes to make sure mkstemp is actually defined
3: #if defined(PETSC_HAVE_MKSTEMP)
4: #if !defined(_XOPEN_SOURCE)
5: #define _XOPEN_SOURCE 600
6: #endif
7: #endif
8: #include <petsc/private/dmnetworkimpl.h>
9: #include <petscdraw.h>
11: static PetscErrorCode DMView_Network_CSV(DM dm, PetscViewer viewer)
12: {
13: DM dmcoords;
14: PetscInt nsubnets, i, subnet, nvertices, nedges, vertex, edge, gidx, ncomp;
15: PetscInt vertexOffsets[2], globalEdgeVertices[2];
16: PetscScalar vertexCoords[2], *color_ptr, color;
17: const PetscInt *vertices, *edges, *edgeVertices;
18: Vec allVertexCoords;
19: PetscMPIInt rank;
20: MPI_Comm comm;
22: PetscFunctionBegin;
23: // Get the coordinate information from dmcoords
24: PetscCheck(dm->coordinates[0].dm, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_NULL, "CoordinateDM not created");
25: PetscCall(DMGetCoordinateDM(dm, &dmcoords));
27: PetscCall(DMGetCoordinateDim(dmcoords, &i));
28: PetscCheck(i == 2, PETSC_COMM_WORLD, PETSC_ERR_SUP, "dim %" PetscInt_FMT " != 2 is not supported yet", i);
30: // Get the coordinate vector from dm
31: PetscCall(DMGetCoordinatesLocal(dm, &allVertexCoords));
33: // Get the MPI communicator and this process' rank
34: PetscCall(PetscObjectGetComm((PetscObject)dmcoords, &comm));
35: PetscCallMPI(MPI_Comm_rank(comm, &rank));
37: // Start synchronized printing
38: PetscCall(PetscViewerASCIIPushSynchronized(viewer));
40: // Write the header
41: PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "Type,Rank,ID,X,Y,Z,Name,Color\n"));
43: // Iterate each subnetwork (Note: We need to get the global number of subnets apparently)
44: PetscCall(DMNetworkGetNumSubNetworks(dmcoords, NULL, &nsubnets));
45: for (subnet = 0; subnet < nsubnets; subnet++) {
46: // Get the subnetwork's vertices and edges
47: PetscCall(DMNetworkGetSubnetwork(dmcoords, subnet, &nvertices, &nedges, &vertices, &edges));
49: // Write out each vertex
50: for (i = 0; i < nvertices; i++) {
51: vertex = vertices[i];
53: // Get the offset into the coordinate vector for the vertex
54: PetscCall(DMNetworkGetLocalVecOffset(dmcoords, vertex, ALL_COMPONENTS, vertexOffsets));
55: vertexOffsets[1] = vertexOffsets[0] + 1;
56: // Remap vertex to the global value
57: PetscCall(DMNetworkGetGlobalVertexIndex(dmcoords, vertex, &gidx));
58: // Get the vertex position from the coordinate vector
59: PetscCall(VecGetValues(allVertexCoords, 2, vertexOffsets, vertexCoords));
61: // Get vertex color; TODO: name
62: PetscCall(DMNetworkGetNumComponents(dmcoords, vertex, &ncomp));
63: PetscCheck(ncomp <= 1, PETSC_COMM_WORLD, PETSC_ERR_SUP, "num of components %" PetscInt_FMT " must be <= 1", ncomp);
64: color = 0.0;
65: if (ncomp == 1) {
66: PetscCall(DMNetworkGetComponent(dmcoords, vertex, 0, NULL, (void **)&color_ptr, NULL));
67: color = *color_ptr;
68: }
69: PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "Node,%d,%" PetscInt_FMT ",%lf,%lf,0,%" PetscInt_FMT ",%lf\n", rank, gidx, (double)PetscRealPart(vertexCoords[0]), (double)PetscRealPart(vertexCoords[1]), gidx, (double)PetscRealPart(color)));
70: }
72: // Write out each edge
73: for (i = 0; i < nedges; i++) {
74: edge = edges[i];
75: PetscCall(DMNetworkGetConnectedVertices(dmcoords, edge, &edgeVertices));
76: PetscCall(DMNetworkGetGlobalVertexIndex(dmcoords, edgeVertices[0], &globalEdgeVertices[0]));
77: PetscCall(DMNetworkGetGlobalVertexIndex(dmcoords, edgeVertices[1], &globalEdgeVertices[1]));
78: PetscCall(DMNetworkGetGlobalEdgeIndex(dmcoords, edge, &edge));
80: // TODO: Determine edge color/name
81: PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "Edge,%d,%" PetscInt_FMT ",%" PetscInt_FMT ",%" PetscInt_FMT ",0,%" PetscInt_FMT "\n", rank, edge, globalEdgeVertices[0], globalEdgeVertices[1], edge));
82: }
83: }
84: // End synchronized printing
85: PetscCall(PetscViewerFlush(viewer));
86: PetscCall(PetscViewerASCIIPopSynchronized(viewer));
87: PetscFunctionReturn(PETSC_SUCCESS);
88: }
90: static PetscErrorCode DMView_Network_Matplotlib(DM dm, PetscViewer viewer)
91: {
92: PetscMPIInt rank, size;
93: MPI_Comm comm;
94: char filename[PETSC_MAX_PATH_LEN + 1], options[512], proccall[PETSC_MAX_PATH_LEN + 512], scriptFile[PETSC_MAX_PATH_LEN + 1], buffer[256], buffer2[256];
95: PetscViewer csvViewer;
96: FILE *processFile = NULL;
97: PetscBool isnull, optionShowRanks = PETSC_FALSE, optionRankIsSet = PETSC_FALSE, showNoNodes = PETSC_FALSE, showNoNumbering = PETSC_FALSE, optionShowVertices = PETSC_FALSE, optionViewPadding = PETSC_FALSE;
98: PetscDraw draw;
99: DM_Network *network = (DM_Network *)dm->data;
100: PetscReal drawPause, viewPadding = 1.0;
101: #if defined(PETSC_HAVE_MKSTEMP)
102: PetscBool isSharedTmp;
103: #endif
105: PetscFunctionBegin;
106: // Deal with the PetscDraw we are given
107: PetscCall(PetscViewerDrawGetDraw(viewer, 1, &draw));
108: PetscCall(PetscDrawIsNull(draw, &isnull));
109: PetscCall(PetscDrawSetVisible(draw, PETSC_FALSE));
111: // Clear the file name buffer so all communicated bytes are well-defined
112: PetscCall(PetscMemzero(filename, sizeof(filename)));
114: // Get the MPI communicator and this process' rank
115: PetscCall(PetscObjectGetComm((PetscObject)dm, &comm));
116: PetscCallMPI(MPI_Comm_rank(comm, &rank));
117: PetscCallMPI(MPI_Comm_size(comm, &size));
119: #if defined(PETSC_HAVE_MKSTEMP)
120: // Get if the temporary directory is shared
121: // Note: This must be done collectively on every rank, it cannot be done on a single rank
122: PetscCall(PetscSharedTmp(comm, &isSharedTmp));
123: #endif
125: /* Process Options */
126: optionShowRanks = network->vieweroptions.showallranks;
127: showNoNodes = network->vieweroptions.shownovertices;
128: showNoNumbering = network->vieweroptions.shownonumbering;
130: /*
131: TODO: if the option -dmnetwork_view_tmpdir can be moved up here that would be good as well.
132: */
133: PetscOptionsBegin(PetscObjectComm((PetscObject)dm), ((PetscObject)dm)->prefix, "MatPlotLib PetscViewer DMNetwork Options", "PetscViewer");
134: PetscCall(PetscOptionsBool("-dmnetwork_view_all_ranks", "View all ranks in the DMNetwork", NULL, optionShowRanks, &optionShowRanks, NULL));
135: PetscCall(PetscOptionsString("-dmnetwork_view_rank_range", "Set of ranks to view the DMNetwork on", NULL, NULL, buffer, sizeof(buffer), &optionRankIsSet));
136: PetscCall(PetscOptionsBool("-dmnetwork_view_no_vertices", "Do not view vertices", NULL, showNoNodes, &showNoNodes, NULL));
137: PetscCall(PetscOptionsBool("-dmnetwork_view_no_numbering", "Do not view edge and vertex numbering", NULL, showNoNumbering, &showNoNumbering, NULL));
138: PetscCall(PetscOptionsString("-dmnetwork_view_zoomin_vertices", "Focus the view on the given set of vertices", NULL, NULL, buffer2, sizeof(buffer2), &optionShowVertices));
139: PetscCall(PetscOptionsReal("-dmnetwork_view_zoomin_vertices_padding", "Set the padding when viewing specific vertices", NULL, viewPadding, &viewPadding, &optionViewPadding));
140: PetscOptionsEnd();
142: // Generate and broadcast the temporary file name from rank 0
143: if (rank == 0) {
144: #if defined(PETSC_HAVE_TMPNAM_S)
145: // Acquire a temporary file to write to and open an ASCII/CSV viewer
146: PetscCheck(tmpnam_s(filename, sizeof(filename)) == 0, comm, PETSC_ERR_SYS, "Could not acquire temporary file");
147: #elif defined(PETSC_HAVE_MKSTEMP)
148: PetscBool isTmpOverridden;
149: size_t numChars;
150: // Same thing, but for POSIX systems on which tmpnam is deprecated
151: // Note: Configure may detect mkstemp but it will not be defined if compiling for C99, so check additional defines to see if we can use it
152: // Mkstemp requires us to explicitly specify part of the path, but some systems may not like putting files in /tmp/ so have an option for it
153: PetscCall(PetscOptionsGetString(NULL, NULL, "-dmnetwork_view_tmpdir", filename, sizeof(filename), &isTmpOverridden));
154: // If not specified by option try using a shared tmp on the system
155: if (!isTmpOverridden) {
156: // Validate that if tmp is not overridden it is at least shared
157: PetscCheck(isSharedTmp, comm, PETSC_ERR_SUP_SYS, "Temporary file directory is not shared between ranks, try using -dmnetwork_view_tmpdir to specify a shared directory");
158: PetscCall(PetscGetTmp(PETSC_COMM_SELF, filename, sizeof(filename)));
159: }
160: // Make sure the filename ends with a '/'
161: PetscCall(PetscStrlen(filename, &numChars));
162: if (filename[numChars - 1] != '/') {
163: filename[numChars] = '/';
164: filename[numChars + 1] = 0;
165: }
166: // Perform the actual temporary file creation
167: PetscCall(PetscStrlcat(filename, "XXXXXX", sizeof(filename)));
168: PetscCheck(mkstemp(filename) != -1, comm, PETSC_ERR_SYS, "Could not acquire temporary file");
169: #else
170: // Same thing, but for older C versions which don't have the safe form
171: PetscCheck(tmpnam(filename) != NULL, comm, PETSC_ERR_SYS, "Could not acquire temporary file");
172: #endif
173: }
175: // Broadcast the filename to all other MPI ranks
176: PetscCallMPI(MPI_Bcast(filename, PETSC_MAX_PATH_LEN, MPI_BYTE, 0, comm));
178: PetscCall(PetscViewerASCIIOpen(comm, filename, &csvViewer));
179: PetscCall(PetscViewerPushFormat(csvViewer, PETSC_VIEWER_ASCII_CSV));
181: // Use the CSV viewer to write out the local network
182: PetscCall(DMView_Network_CSV(dm, csvViewer));
184: // Close the viewer
185: PetscCall(PetscViewerDestroy(&csvViewer));
187: // Generate options string
188: PetscCall(PetscMemzero(options, sizeof(options)));
189: // If the draw is null run as a "test execute" ie. do nothing just test that the script was called correctly
190: PetscCall(PetscStrlcat(options, isnull ? " -tx " : " ", sizeof(options)));
191: PetscCall(PetscDrawGetPause(draw, &drawPause));
192: if (drawPause > 0) {
193: char pausebuffer[64];
194: PetscCall(PetscSNPrintf(pausebuffer, sizeof(pausebuffer), "%f", (double)drawPause));
195: PetscCall(PetscStrlcat(options, " -dt ", sizeof(options)));
196: PetscCall(PetscStrlcat(options, pausebuffer, sizeof(options)));
197: }
198: if (optionShowRanks || optionRankIsSet) {
199: // Show all ranks only if the option is set in code or by the user AND not showing specific ranks AND there is more than one process
200: if (optionShowRanks && !optionRankIsSet && size != 1) PetscCall(PetscStrlcat(options, " -dar ", sizeof(options)));
201: // Do not show the global plot if the user requests it OR if one specific rank is requested
202: if (network->vieweroptions.dontshowglobal || optionRankIsSet) PetscCall(PetscStrlcat(options, " -ncp ", sizeof(options)));
204: if (optionRankIsSet) {
205: // If a range of ranks to draw is specified append it
206: PetscCall(PetscStrlcat(options, " -drr ", sizeof(options)));
207: PetscCall(PetscStrlcat(options, buffer, sizeof(options)));
208: } else {
209: // Otherwise, use the options provided in code
210: if (network->vieweroptions.viewranks) {
211: const PetscInt *viewranks;
212: PetscInt viewrankssize;
213: char rankbuffer[64];
214: PetscCall(ISGetTotalIndices(network->vieweroptions.viewranks, &viewranks));
215: PetscCall(ISGetSize(network->vieweroptions.viewranks, &viewrankssize));
216: PetscCall(PetscStrlcat(options, " -drr ", sizeof(options)));
217: for (PetscInt i = 0; i < viewrankssize; i++) {
218: PetscCall(PetscSNPrintf(rankbuffer, sizeof(rankbuffer), "%" PetscInt_FMT, viewranks[i]));
219: PetscCall(PetscStrlcat(options, rankbuffer, sizeof(options)));
220: }
221: PetscCall(ISRestoreTotalIndices(network->vieweroptions.viewranks, &viewranks));
222: } // if not provided an IS of viewing ranks, skip viewing
223: }
224: }
225: if (optionShowVertices) {
226: // Pass vertices to focus on if defined
227: PetscCall(PetscStrlcat(options, " -vsv ", sizeof(options)));
228: PetscCall(PetscStrlcat(options, buffer2, sizeof(options)));
229: optionViewPadding = PETSC_TRUE;
230: // Pass padding if set
231: if (optionViewPadding) {
232: PetscCall(PetscSNPrintf(buffer2, sizeof(buffer2), "%f", (double)viewPadding));
233: PetscCall(PetscStrlcat(options, " -vp ", sizeof(options)));
234: PetscCall(PetscStrlcat(options, buffer2, sizeof(options)));
235: }
236: }
238: // Check for options for visibility...
239: if (showNoNodes) PetscCall(PetscStrlcat(options, " -nn ", sizeof(options)));
240: if (showNoNumbering) PetscCall(PetscStrlcat(options, " -nnl -nel ", sizeof(options)));
242: // Get the value of $PETSC_DIR
243: PetscCall(PetscStrreplace(comm, "${PETSC_DIR}/share/petsc/bin/dmnetwork_view.py", scriptFile, sizeof(scriptFile)));
244: PetscCall(PetscFixFilename(scriptFile, scriptFile));
245: // Generate the system call for 'python3 $PETSC_DIR/share/petsc/dmnetwork_view.py '
246: PetscCall(PetscArrayzero(proccall, sizeof(proccall)));
247: PetscCall(PetscSNPrintf(proccall, sizeof(proccall), "%s %s %s %s", PETSC_PYTHON_EXE, scriptFile, options, filename));
249: #if defined(PETSC_HAVE_POPEN)
250: // Perform the call to run the python script (Note: while this is called on all ranks POpen will only run on rank 0)
251: PetscCall(PetscPOpen(comm, NULL, proccall, "r", &processFile));
252: if (processFile != NULL) {
253: while (fgets(buffer, sizeof(buffer), processFile) != NULL) PetscCall(PetscPrintf(comm, "%s", buffer));
254: }
255: PetscCall(PetscPClose(comm, processFile));
256: #else
257: // Same thing, but using the standard library for systems that don't have POpen/PClose (only run on rank 0)
258: if (rank == 0) PetscCheck(system(proccall) == 0, PETSC_COMM_SELF, PETSC_ERR_SYS, "Failed to call viewer script");
259: // Barrier so that all ranks wait until the call completes
260: PetscCallMPI(MPI_Barrier(comm));
261: #endif
262: // Clean up the temporary file we used using rank 0
263: if (rank == 0) PetscCheck(remove(filename) == 0, PETSC_COMM_SELF, PETSC_ERR_SYS, "Failed to delete temporary file");
264: PetscFunctionReturn(PETSC_SUCCESS);
265: }
267: PetscErrorCode DMView_Network(DM dm, PetscViewer viewer)
268: {
269: PetscBool isascii, isdraw;
270: PetscViewerFormat format;
272: PetscFunctionBegin;
275: PetscCall(PetscViewerGetFormat(viewer, &format));
277: PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERDRAW, &isdraw));
278: if (isdraw) {
279: PetscCall(DMView_Network_Matplotlib(dm, viewer));
280: PetscFunctionReturn(PETSC_SUCCESS);
281: }
283: PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii));
284: if (isascii) {
285: const PetscInt *cone, *vtx, *edges;
286: PetscInt vfrom, vto, i, j, nv, ne, nsv, p, nsubnet;
287: DM_Network *network = (DM_Network *)dm->data;
288: PetscMPIInt rank;
290: PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)dm), &rank));
291: if (format == PETSC_VIEWER_ASCII_CSV) {
292: PetscCall(DMView_Network_CSV(dm, viewer));
293: PetscFunctionReturn(PETSC_SUCCESS);
294: }
296: nsubnet = network->cloneshared->Nsubnet; /* num of subnetworks */
297: if (!rank) {
298: PetscCall(PetscPrintf(PETSC_COMM_SELF, " NSubnets: %" PetscInt_FMT "; NEdges: %" PetscInt_FMT "; NVertices: %" PetscInt_FMT "; NSharedVertices: %" PetscInt_FMT ".\n", nsubnet, network->cloneshared->NEdges, network->cloneshared->NVertices,
299: network->cloneshared->Nsvtx));
300: }
302: PetscCall(DMNetworkGetSharedVertices(dm, &nsv, NULL));
303: PetscCall(PetscViewerASCIIPushSynchronized(viewer));
304: PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " [%d] nEdges: %" PetscInt_FMT "; nVertices: %" PetscInt_FMT "; nSharedVertices: %" PetscInt_FMT "\n", rank, network->cloneshared->nEdges, network->cloneshared->nVertices, nsv));
306: for (i = 0; i < nsubnet; i++) {
307: PetscCall(DMNetworkGetSubnetwork(dm, i, &nv, &ne, &vtx, &edges));
308: if (ne) {
309: PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " Subnet %" PetscInt_FMT ": nEdges %" PetscInt_FMT ", nVertices(include shared vertices) %" PetscInt_FMT "\n", i, ne, nv));
310: for (j = 0; j < ne; j++) {
311: p = edges[j];
312: PetscCall(DMNetworkGetConnectedVertices(dm, p, &cone));
313: PetscCall(DMNetworkGetGlobalVertexIndex(dm, cone[0], &vfrom));
314: PetscCall(DMNetworkGetGlobalVertexIndex(dm, cone[1], &vto));
315: PetscCall(DMNetworkGetGlobalEdgeIndex(dm, edges[j], &p));
316: PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " edge %" PetscInt_FMT ": %" PetscInt_FMT " ----> %" PetscInt_FMT "\n", p, vfrom, vto));
317: }
318: }
319: }
321: /* Shared vertices */
322: PetscCall(DMNetworkGetSharedVertices(dm, NULL, &vtx));
323: if (nsv) {
324: PetscInt gidx;
325: PetscBool ghost;
326: const PetscInt *sv = NULL;
328: PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " SharedVertices:\n"));
329: for (i = 0; i < nsv; i++) {
330: PetscCall(DMNetworkIsGhostVertex(dm, vtx[i], &ghost));
331: if (ghost) continue;
333: PetscCall(DMNetworkSharedVertexGetInfo(dm, vtx[i], &gidx, &nv, &sv));
334: PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " svtx %" PetscInt_FMT ": global index %" PetscInt_FMT ", subnet[%" PetscInt_FMT "].%" PetscInt_FMT " ---->\n", i, gidx, sv[0], sv[1]));
335: for (j = 1; j < nv; j++) PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " ----> subnet[%" PetscInt_FMT "].%" PetscInt_FMT "\n", sv[2 * j], sv[2 * j + 1]));
336: }
337: }
338: PetscCall(PetscViewerFlush(viewer));
339: PetscCall(PetscViewerASCIIPopSynchronized(viewer));
340: } else PetscCheck(isascii, PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Viewer type %s not yet supported for DMNetwork writing", ((PetscObject)viewer)->type_name);
341: PetscFunctionReturn(PETSC_SUCCESS);
342: }
344: /*@
345: DMNetworkViewSetShowRanks - Sets viewing the `DMETNWORK` on each rank individually.
347: Logically Collective
349: Input Parameter:
350: . dm - the `DMNETWORK` object
352: Output Parameter:
353: . showranks - `PETSC_TRUE` if viewing each rank's sub network individually
355: Level: beginner
357: .seealso: `DM`, `DMNETWORK`, `DMNetworkViewSetShowGlobal()`, `DMNetworkViewSetShowVertices()`, `DMNetworkViewSetShowNumbering()`, `DMNetworkViewSetViewRanks()`
358: @*/
359: PetscErrorCode DMNetworkViewSetShowRanks(DM dm, PetscBool showranks)
360: {
361: DM_Network *network = (DM_Network *)dm->data;
363: PetscFunctionBegin;
365: network->vieweroptions.showallranks = showranks;
366: PetscFunctionReturn(PETSC_SUCCESS);
367: }
369: /*@
370: DMNetworkViewSetShowGlobal - Set viewing the global network.
372: Logically Collective
374: Input Parameter:
375: . dm - the `DMNETWORK` object
377: Output Parameter:
378: . showglobal - `PETSC_TRUE` if viewing the global network
380: Level: beginner
382: .seealso: `DM`, `DMNETWORK`, `DMNetworkViewSetShowRanks()`, `DMNetworkViewSetShowVertices()`, `DMNetworkViewSetShowNumbering()`, `DMNetworkViewSetViewRanks()`
383: @*/
384: PetscErrorCode DMNetworkViewSetShowGlobal(DM dm, PetscBool showglobal)
385: {
386: DM_Network *network = (DM_Network *)dm->data;
388: PetscFunctionBegin;
390: network->vieweroptions.dontshowglobal = (PetscBool)(!showglobal);
391: PetscFunctionReturn(PETSC_SUCCESS);
392: }
394: /*@
395: DMNetworkViewSetShowVertices - Sets whether to display the vertices in viewing routines.
397: Logically Collective
399: Input Parameter:
400: . dm - the `DMNETWORK` object
402: Output Parameter:
403: . showvertices - `PETSC_TRUE` if visualizing the vertices
405: Level: beginner
407: .seealso: `DM`, `DMNETWORK`, `DMNetworkViewSetShowRanks()`, `DMNetworkViewSetShowGlobal()`, `DMNetworkViewSetShowNumbering()`, `DMNetworkViewSetViewRanks()`
408: @*/
409: PetscErrorCode DMNetworkViewSetShowVertices(DM dm, PetscBool showvertices)
410: {
411: DM_Network *network = (DM_Network *)dm->data;
413: PetscFunctionBegin;
415: network->vieweroptions.shownovertices = (PetscBool)(!showvertices);
416: PetscFunctionReturn(PETSC_SUCCESS);
417: }
419: /*@
420: DMNetworkViewSetShowNumbering - Set displaying the numbering of edges and vertices in viewing routines.
422: Logically Collective
424: Input Parameter:
425: . dm - the `DMNETWORK` object
427: Output Parameter:
428: . shownumbering - `PETSC_TRUE` if displaying the numbering of edges and vertices
430: Level: beginner
432: .seealso: `DM`, `DMNETWORK`, `DMNetworkViewSetShowRanks()`, `DMNetworkViewSetShowGlobal()`, `DMNetworkViewSetShowVertices()`, `DMNetworkViewSetViewRanks()`
433: @*/
434: PetscErrorCode DMNetworkViewSetShowNumbering(DM dm, PetscBool shownumbering)
435: {
436: DM_Network *network = (DM_Network *)dm->data;
438: PetscFunctionBegin;
440: network->vieweroptions.shownonumbering = (PetscBool)(!shownumbering);
441: PetscFunctionReturn(PETSC_SUCCESS);
442: }
444: /*@
445: DMNetworkViewSetViewRanks - View the `DMNETWORK` on each of the specified ranks individually.
447: Collective
449: Input Parameter:
450: . dm - the `DMNETWORK` object
452: Output Parameter:
453: . viewranks - set of ranks to view the `DMNETWORK` on individually
455: Level: beginner
457: Note:
458: `DMNetwork` takes ownership of the input viewranks `IS`, it should be destroyed by the caller.
460: .seealso: `DM`, `DMNETWORK`, `DMNetworkViewSetShowRanks()`, `DMNetworkViewSetShowGlobal()`, `DMNetworkViewSetShowVertices()`, `DMNetworkViewSetShowNumbering()`
461: @*/
462: PetscErrorCode DMNetworkViewSetViewRanks(DM dm, IS viewranks)
463: {
464: DM_Network *network = (DM_Network *)dm->data;
466: PetscFunctionBegin;
469: PetscCheckSameComm(dm, 1, viewranks, 2);
470: PetscCall(ISDestroy(&network->vieweroptions.viewranks));
471: PetscCall(PetscObjectReference((PetscObject)viewranks));
472: network->vieweroptions.viewranks = viewranks;
473: PetscFunctionReturn(PETSC_SUCCESS);
474: }