dragonfly_sim.utils.filewriter
Attributes
Classes
Writes dolfinx Functions to VTX (.bp) files for ParaView. |
|
One named field of a FileWriter: its parent space and output function. |
Functions
|
(len(cells), dofs_per_cell * bs) dof-array indices of cells, cell-major. |
|
Owned geometry nodes of all ranks on rank 0, in global node order. Collective. |
|
Gather the (n_local, k) arrays of all ranks to rank 0, stacked in rank order. |
|
Return the ghost-free serial copy of mesh on rank 0 (None elsewhere). |
Module Contents
- class dragonfly_sim.utils.filewriter.FileWriter(filename, comm_obj, func_space, mesh_deformation=False, time_dependent=False)
Writes dolfinx Functions to VTX (.bp) files for ParaView.
One writer holds one or more named fields on the same mesh, written to a single file:
func_spaceis either a function space (one field, named “solution”) or a dict{name: function space}, e.g. density, momentum (a vector field), energy and pressure. All fields of a writer must share the mesh and be either all gathered or all per-rank (see below); the mesh is then stored once per frame for all of them.ParaView’s VTX reader concatenates the per-rank blocks of a parallel write without merging the points the blocks share. Where neighbouring cells share points within a rank – DG0 fields, written as cell data on the mesh geometry, and continuous fields – the MPI partition boundaries then show up as cracks (exterior faces, boundary edges, jumps in point-interpolated cell data). Those spaces are gathered to rank 0 and written as a single block on a serial copy of the mesh.
Note on the DG0 gather: rank 0 holds the whole mesh (built once per parent mesh and shared by the writers on it) plus one frame of the fields, and every frame passes through rank 0. Per-frame data is small (one value per cell and component); the serial mesh is what bounds the mesh size. Past that point, the parallel alternatives are writing DG0 as per-cell-node DG data of the geometry degree (flat cells, no smoothing across cells) or dolfinx’s XDMFFile.
Discontinuous spaces with more than one dof per cell (DG p >= 1) are written by VTX with separate points for every cell, so every cell face is a crack in serial as well and partition boundaries add none. Each rank writes its own owned cells in parallel; ghost cells are left out because they would be written twice.
Keywords, set per writer to match the simulation and the fields:
- mesh_deformation
False: frames are written on the geometry the mesh had when the writer was created. True: each frame is written on the mesh geometry at the time of the write (e.g. a shape-optimisation design evaluation, or a moving mesh).
- time_dependent
False: frames are labelled by a counter (
write_counter, e.g. the design-evaluation index). True: frames are labelled by the physical time passed astime=, which must increase from frame to frame.
- _check_dof_mapping()
Verify that mapped dofs sit at the same coordinates on both meshes.
The cell-local dof order is assumed equal on the parent and output meshes; this holds for the Lagrange/DG spaces written here but would break for spaces whose entity dofs depend on cell orientation. Collective.
- _copy_cell_values(array, field=None)
Copy a parent dof array into a field’s output function. Collective.
- _parent_array(field, u_interp)
- _sync_geometry()
Copy the current parent node coordinates onto the output mesh. Collective.
- construct_function_and_writer()
- interpolate_and_write(u_interp, write_counter=None, time=None)
Write one frame.
u_interpis, for a single-field writer, a Function on the writer’s space or a UFL expression; for a multi-field writer, a dict{name: Function or UFL expression}with one entry per field.A counter-labelled writer (time_dependent=False) takes an optional
write_counter; a time-dependent writer requirestime. Collective.
- comm
- property field_names
- fields
- filename
- property function
- functionspace
- mesh_deformation = False
- property parent_idx
- single_field
- property target_funcspace
- time_dependent = False
- class dragonfly_sim.utils.filewriter._Field(name, V)
One named field of a FileWriter: its parent space and output function.
- V
- function = None
- gather
- name
- parent_function
- parent_idx
- target_funcspace = None
- target_idx = None
- dragonfly_sim.utils.filewriter._cell_dof_indices(V, cells)
(len(cells), dofs_per_cell * bs) dof-array indices of cells, cell-major.
- dragonfly_sim.utils.filewriter._gather_geometry(mesh)
Owned geometry nodes of all ranks on rank 0, in global node order. Collective.
- dragonfly_sim.utils.filewriter._gather_rows(comm, rows)
Gather the (n_local, k) arrays of all ranks to rank 0, stacked in rank order.
- dragonfly_sim.utils.filewriter._serial_mesh(mesh, mesh_deformation)
Return the ghost-free serial copy of mesh on rank 0 (None elsewhere).
Owned cells and owned geometry nodes are numbered contiguously per rank in global numbering, so gathering them in rank order yields the cells and nodes in global order, each exactly once. Collective.
- dragonfly_sim.utils.filewriter._serial_meshes