Actual source code: pythonviewer.c
1: #include "petscsystypes.h"
2: #include <petsc/private/viewerimpl.h>
4: /*@
5: PetscViewerPythonSetType - Initialize a `PetscViewer` object implemented in Python.
7: Collective
9: Input Parameters:
10: + viewer - the viewer object.
11: - pyname - full dotted Python name [package].module[.{class|function}]
13: Options Database Key:
14: . -viewer_python_type <pyname> - python class
16: Level: intermediate
18: .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerType`, `PetscViewerCreate()`, `PetscViewerSetType()`, `PETSCVIEWERPYTHON`, `PetscPythonInitialize()`
19: @*/
20: PetscErrorCode PetscViewerPythonSetType(PetscViewer viewer, const char pyname[])
21: {
22: PetscFunctionBegin;
24: PetscAssertPointer(pyname, 2);
25: PetscTryMethod(viewer, "PetscViewerPythonSetType_C", (PetscViewer, const char[]), (viewer, pyname));
26: PetscFunctionReturn(PETSC_SUCCESS);
27: }
29: /*@
30: PetscViewerPythonGetType - Get the Python name of a `PetscViewer` object implemented in Python.
32: Not Collective
34: Input Parameter:
35: . viewer - the viewer
37: Output Parameter:
38: . pyname - full dotted Python name [package].module[.{class|function}]
40: Level: intermediate
42: .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerType`, `PetscViewerCreate()`, `PetscViewerSetType()`, `PETSCVIEWERPYTHON`, `PetscPythonInitialize()`, `PetscViewerPythonSetType()`
43: @*/
44: PetscErrorCode PetscViewerPythonGetType(PetscViewer viewer, const char *pyname[])
45: {
46: PetscFunctionBegin;
48: PetscAssertPointer(pyname, 2);
49: PetscUseMethod(viewer, "PetscViewerPythonGetType_C", (PetscViewer, const char *[]), (viewer, pyname));
50: PetscFunctionReturn(PETSC_SUCCESS);
51: }
53: /*@
54: PetscViewerPythonViewObject - View a `PetscObject`.
56: Collective
58: Input Parameters:
59: + viewer - the viewer object.
60: - obj - the object to be viewed.
62: Level: intermediate
64: .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerPythonCreate()`
65: @*/
66: PetscErrorCode PetscViewerPythonViewObject(PetscViewer viewer, PetscObject obj)
67: {
68: PetscFunctionBegin;
71: PetscTryMethod(viewer, "PetscViewerPythonViewObject_C", (PetscViewer, PetscObject), (viewer, obj));
72: PetscFunctionReturn(PETSC_SUCCESS);
73: }
75: /*@
76: PetscViewerPythonCreate - Create a `PetscViewer` object implemented in Python.
78: Collective
80: Input Parameters:
81: + comm - MPI communicator
82: - pyname - full dotted Python name [package].module[.{class|function}]
84: Output Parameter:
85: . viewer - the viewer
87: Level: intermediate
89: .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerType`, `PETSCVIEWERPYTHON`, `PetscViewerPythonSetType()`, `PetscPythonInitialize()`, `PetscViewerPythonViewObject()`
90: @*/
91: PetscErrorCode PetscViewerPythonCreate(MPI_Comm comm, const char pyname[], PetscViewer *viewer)
92: {
93: PetscFunctionBegin;
94: PetscAssertPointer(pyname, 2);
95: PetscAssertPointer(viewer, 3);
96: PetscCall(PetscViewerCreate(comm, viewer));
97: PetscCall(PetscViewerSetType(*viewer, PETSCVIEWERPYTHON));
98: PetscCall(PetscViewerPythonSetType(*viewer, pyname));
99: PetscFunctionReturn(PETSC_SUCCESS);
100: }
102: /*@C
103: PETSC_VIEWER_PYTHON_ - Creates a Python `PetscViewer` shared by all MPI processes in a communicator.
105: Collective
107: Input Parameter:
108: . comm - the MPI communicator to share the `PetscViewer`
110: Level: developer
112: Note:
113: Unlike almost all other PETSc routines, `PETSC_VIEWER_PYTHON_()` does not return
114: an error code. It is usually used in the form
115: .vb
116: XXXView(XXX object, PETSC_VIEWER_PYTHON_(comm));
117: .ve
119: .seealso: [](sec_viewers), `PetscViewer`
120: @*/
121: PetscViewer PETSC_VIEWER_PYTHON_(MPI_Comm comm)
122: {
123: PetscViewer viewer;
125: PetscFunctionBegin;
126: PetscCallNull(PetscViewerCreate(comm, &viewer));
127: PetscCallNull(PetscViewerSetType(viewer, PETSCVIEWERPYTHON));
128: PetscCallNull(PetscObjectRegisterDestroy((PetscObject)viewer));
129: PetscFunctionReturn(viewer);
130: }
132: /*MC
133: PETSCVIEWERPYTHON - A viewer implemented using Python code
135: Level: beginner
137: Notes:
138: This is the parent viewer for any implemented in Python.
140: .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerCreate()`, `VecView()`, `DMView()`, `DMPLEX`, `PETSCVIEWERPYVISTA`
141: M*/