MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / __init__

Method __init__

python/dolfinx/io/utils.py:46–97  ·  view source on GitHub ↗

Initialize a writer for outputting data in the VTX format. Args: comm: The MPI communicator filename: The output filename output: The data to output. Either a mesh, a single (discontinuous) Lagrange Function or list of

(
            self,
            comm: _MPI.Comm,
            filename: str | Path,
            output: Mesh | Function | list[Function] | tuple[Function],
            engine: str = "BPFile",
            mesh_policy: VTXMeshPolicy = VTXMeshPolicy.update,
        )

Source from the content-addressed store, hash-verified

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:
92 cpp_objects = (
93 [output._cpp_object]
94 if isinstance(output, Function)
95 else [o._cpp_object for o in output]
96 )
97 self._cpp_object = _vtxwriter(comm, filename, cpp_objects, engine, mesh_policy)
98
99 def __enter__(self):
100 """Enter context manager."""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected