# M50. Solutions for other tools **Package:** K7, its second part: a solution is handed to xarray, with its coordinates and its times as labels, and written as VTK files that ParaView opens. ## What was built - **`solution.to_xarray()`** returns an `xarray.Dataset`: one variable for each unknown, over the coordinates of the domain by their names and over the time, with the points of the grid and the recorded times as labels. The plan and the diagnostics are attributes, as JSON. - **`solution.to_vtk(path)`** writes XML files of VTK, with no library: - a grid in Cartesian coordinates as a rectilinear grid (`.vtr`), which keeps the points of each axis as they are, also Chebyshev points; - a disk, a ball and a cylinder as a structured grid (`.vts`), with the points where they lie in space and the circle around the axis closed; - a solution in time as one file for each recorded time and a collection (`.pvd`) that lists them with their times; - a complex unknown as its real and its imaginary part. - **Both in a new file of the frontend**, `python/pdemagic/_export.py`. ## What was checked The files were read back with VTK itself (version 9.7.2, in an environment beside the project): a box between walls, a ball, and a series in time. The values at the points and the places of the points agree exactly with the solution, and the collection lists every recorded time. The tests of the project read the files as XML and decode their arrays, without VTK. ## Decisions ### D50.1. xarray is an optional dependency *Developer, 2026-11-19.* `to_xarray` needs xarray, which brings pandas. Both are under permissive licenses (Apache-2.0 and BSD-3-Clause). It is an extra, `pdemagic[xarray]`, as matplotlib is for plots (decision D45): the plain installation stays numpy and sympy. It is imported when the method is called, and the method says how to install it if it is missing. ### D50.2. VTK files are written by hand *Developer, 2026-11-19.* The XML files of VTK are a few lines of text around arrays in base64. A library for them would be a dependency for forty lines of code. The arrays are written in binary, each after its size as an integer of 64 bits that is encoded by itself, which is what VTK reads without compression. That they are read was checked with VTK, once, by hand: the project does not depend on it, also not for its tests. ### D50.3. The grid as it is *Developer, 2026-11-19.* A file holds the values on the grid of the solution, as `solution[u]` does: nothing is interpolated for it. On a region of the plane that is the grid over the rectangle around it, with no number outside the shape, which ParaView shows in the colour it has for that. The elements themselves, as an unstructured grid that follows the boundary, would be the better picture, and are left. ## What is left - VTK files that hold the elements of a region, and the surfaces of bodies. - A saved problem that can be solved again (B5).