Actual source code: pyvistaviewer.c

  1: #include "petscviewer.h"
  2: #include <petsc/private/viewerimpl.h>

  4: /*@C
  5:      PETSC_VIEWER_PYVISTA_ - Creates a PyVista `PetscViewer` shared by all MPI processes in a communicator.

  7:      Collective

  9:      Input Parameter:
 10: .    comm - the MPI communicator to share the `PetscViewer`

 12:      Level: developer

 14:      Note:
 15:      Unlike almost all other PETSc routines, `PETSC_VIEWER_PYVISTA_()` does not return
 16:      an error code.  It is usually used in the form
 17:    .vb
 18:           XXXView(XXX object, PETSC_VIEWER_PYVISTA_(comm));
 19:    .ve

 21: .seealso: [](sec_viewers), `PetscViewer`
 22: @*/
 23: PetscViewer PETSC_VIEWER_PYVISTA_(MPI_Comm comm)
 24: {
 25:   PetscViewer viewer;

 27:   PetscFunctionBegin;
 28:   PetscCallNull(PetscViewerCreate(comm, &viewer));
 29:   PetscCallNull(PetscViewerSetType(viewer, PETSCVIEWERPYVISTA));
 30:   PetscCallNull(PetscViewerSetFromOptions(viewer));
 31:   PetscCallNull(PetscObjectRegisterDestroy((PetscObject)viewer));
 32:   PetscFunctionReturn(viewer);
 33: }

 35: /*MC
 36:    PETSCVIEWERPYVISTA - A PyVista viewer implemented using Python code

 38:   Level: beginner

 40:   Notes:
 41:   Currently the `DM` viewer only supports `DMPLEX` meshes.

 43: .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerCreate()`, `VecView()`, `DMView()`, `DMPLEX`
 44: M*/
 45: PETSC_EXTERN PetscErrorCode PetscViewerCreate_PyVista(PetscViewer viewer)
 46: {
 47:   PetscFunctionBegin;
 48:   PetscCall(PetscPythonInitialize(NULL, NULL));
 49:   PetscCall(PetscViewerSetType(viewer, PETSCVIEWERPYTHON));
 50:   PetscCall(PetscObjectChangeTypeName((PetscObject)viewer, PETSCVIEWERPYVISTA));
 51:   PetscCall(PetscViewerPythonSetType(viewer, "petsc4py.lib._pytypes.viewer.petscpyvista.PetscPyVista"));
 52:   PetscFunctionReturn(PETSC_SUCCESS);
 53: }