Debian Codegraph @

docs/default_backend.md

raw
1 # Setting a Global Default Backend
2
3 By default, `io4dolfinx` uses the `adios2` backend for all read and write operations. It is possible to pass in the `backend` argument to individual function calls to override this default. For example the following code snippet will use the `h5py` backend for writing the first mesh, and use the default `adios2` backend for writing the second mesh.
4
5 ```python
6 import dolfinx
7 from mpi4py import MPI
8 import io4dolfinx
9
10 mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
11
12 # Write the mesh using the h5py backend
13 io4dolfinx.write_mesh("first_mesh.h5", mesh, backend="h5py")
14 io4dolfinx.write_mesh("second_mesh.bp", mesh) # Uses the default adios2 backend
15 ```
16 If you want to more explicit you could also pass in the `backend` argument to the second write operation, i.e
17
18 ```python
19 io4dolfinx.write_mesh("second_mesh.bp", mesh, backend="adios2")
20 ```
21 but it is not necessary since `adios2` is the default backend.
22
23 If you prefer to use a different backend (such as `h5py`) across your entire application without having to pass the `backend` argument to every individual function call, you can configure a global default.
24
25 ## Usage
26
27 Use the `io4dolfinx.set_default_backend` function at the start of your script to change the backend globally.
28
29 ```python
30 import dolfinx
31 from mpi4py import MPI
32 import io4dolfinx
33
34 # Set the global default backend to h5py
35 io4dolfinx.set_default_backend("h5py")
36
37 mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
38
39 # The following write operation will automatically use the "h5py" backend
40 io4dolfinx.write_mesh("my_mesh.h5", mesh)
41 ```