Writer for VTX files, using ADIOS2 to create the files. VTX supports arbitrary order Lagrange finite elements for the geometry description and arbitrary order (discontinuous) Lagrange finite elements for Functions. The files can be viewed using Paraview.
| 32 | __all__ = [*__all__, "VTXWriter", "VTXMeshPolicy"] |
| 33 | |
| 34 | class VTXWriter: |
| 35 | """Writer for VTX files, using ADIOS2 to create the files. |
| 36 | |
| 37 | VTX supports arbitrary order Lagrange finite elements for the |
| 38 | geometry description and arbitrary order (discontinuous) |
| 39 | Lagrange finite elements for Functions. |
| 40 | |
| 41 | The files can be viewed using Paraview. |
| 42 | """ |
| 43 | |
| 44 | _cpp_object: _cpp.io.VTXWriter_float32 | _cpp.io.VTXWriter_float64 |
| 45 | |
| 46 | def __init__( |
| 47 | self, |
| 48 | comm: _MPI.Comm, |
| 49 | filename: str | Path, |
| 50 | output: Mesh | Function | list[Function] | tuple[Function], |
| 51 | engine: str = "BPFile", |
| 52 | mesh_policy: VTXMeshPolicy = VTXMeshPolicy.update, |
| 53 | ): |
| 54 | """Initialize a writer for outputting data in the VTX format. |
| 55 | |
| 56 | Args: |
| 57 | comm: The MPI communicator |
| 58 | filename: The output filename |
| 59 | output: The data to output. Either a mesh, a single |
| 60 | (discontinuous) Lagrange Function or list of |
| 61 | (discontinuous) Lagrange Functions. |
| 62 | engine: ADIOS2 engine to use for output. See |
| 63 | ADIOS2 documentation for options. |
| 64 | mesh_policy: Controls if the mesh is written to file at |
| 65 | the first time step only when a ``Function`` is |
| 66 | written to file, or is re-written (updated) at each |
| 67 | time step. Has an effect only for ``Function`` |
| 68 | output. |
| 69 | |
| 70 | Note: |
| 71 | All Functions for output must share the same mesh and |
| 72 | have the same element type. |
| 73 | """ |
| 74 | # Get geometry type |
| 75 | if isinstance(output, Mesh): |
| 76 | dtype = output.geometry.x.dtype |
| 77 | elif isinstance(output, Function): |
| 78 | dtype = output.function_space.mesh.geometry.x.dtype |
| 79 | else: |
| 80 | dtype = output[0].function_space.mesh.geometry.x.dtype |
| 81 | |
| 82 | if np.issubdtype(dtype, np.float32): |
| 83 | _vtxwriter = _cpp.io.VTXWriter_float32 |
| 84 | elif np.issubdtype(dtype, np.float64): |
| 85 | _vtxwriter = _cpp.io.VTXWriter_float64 |
| 86 | else: |
| 87 | raise RuntimeError(f"VTXWriter does not support dtype={dtype}.") |
| 88 | |
| 89 | if isinstance(output, Mesh): |
| 90 | self._cpp_object = _vtxwriter(comm, filename, output._cpp_object, engine) # type: ignore[union-attr] |
| 91 | else: |
no outgoing calls