zkit.io.wfs_field

Reconstruct TDSE-Z wavefunctions from their B-spline coefficients.

TDSE-Z stores the wavefunction as B-spline coefficients (the IGA degrees of freedom), not as values on a grid. The time-dependent snapshots are written to td/<name>_wfs.h5 with the PETSc HDF5 viewer:

/wavefunction   (n_snap, n_x[, n_y[, n_z]], 2)   trailing axis = [Re, Im]
/knots_x        (1-D) PetIGA compact knot vector of the x axis
/knots_y        (1-D) same for y (2-D and 3-D runs)
/knots_z        (1-D) same for z (3-D runs)

Each knots_* dataset carries the integer attributes SplineDegree (the degree p) and nfuncs (the number of basis functions on that axis), which are the attributes this module reads.

The coefficients are stored in tensor (i, j, k) index order, so the per-axis shape of a snapshot equals nfuncs and the coefficients are the control points of a tensor-product B-spline.

The open knot vector expected by igakit is obtained by appending one copy of the last knot to PetIGA’s compact vector. The field is then evaluated with igakit’s compiled evaluators igakit.igalib.bsp.Evaluate1, Evaluate2 and Evaluate3.

zkit.io.wfs_field.reconstruct_wfs(path, step=0, npoints=200, axes=None)

Evaluate one wavefunction snapshot of td/<name>_wfs.h5 on a grid.

Parameters:
  • path (str or pathlib.Path) – Path to td/<name>_wfs.h5.

  • step (int, optional) – Snapshot index along the leading (time) axis of wavefunction.

  • npoints (int, optional) – Number of grid points per axis when axes is not given. The default grid spans the whole knot span of each axis.

  • axes (list of array_like, optional) – Explicit 1-D coordinate grids, one per spatial axis. Each must lie inside the knot span [open_kv[p], open_kv[nfuncs]] of its axis.

Returns:

dim (int, spatial dimension), step (int), axes (list of 1-D coordinate arrays), psi (complex array on the tensor grid), Re and Im (real and imaginary parts), abs2 (the density \(\lvert\psi\rvert^2\)), SplineDegree and nfuncs (lists, one entry per axis) and knots (the open knot vectors).

Return type:

dict

Raises:
  • KeyError – If the file has no wavefunction dataset or a knots_* dataset is missing.

  • ValueError – If the dimensionality is not 1, 2 or 3, the coefficient shape does not match the nfuncs attributes, or a grid in axes lies outside the knot span.

zkit.io.wfs_field.reconstruct_static_wfs(path, istate=0, npoints=200, axes=None)

Evaluate the static eigenstate psi_<istate> of an EigenData file on a grid.

The static solver of TDSE-Z stores each converged eigenstate as a top-level dataset psi_<i> of B-spline coefficients with a trailing [Re, Im] axis, either in tensor shape (*nfuncs, 2) or flattened to (prod(nfuncs), 2) in tensor order, together with top-level knots_x (and knots_y, knots_z) datasets carrying the SplineDegree and nfuncs attributes. The spatial dimension is the number of knots_* datasets present. Evaluation follows reconstruct_wfs().

Parameters:
  • path (str or pathlib.Path) – Path to static/<name>_eigen.h5.

  • istate (int, optional) – Index of the eigenstate (the <i> in psi_<i>).

  • npoints (int, optional) – Grid points per axis when axes is not given.

  • axes (list of array_like, optional) – Explicit 1-D coordinate grids, one per spatial axis, each inside the knot span [open_kv[p], open_kv[nfuncs]].

Returns:

The same keys as reconstruct_wfs(), with istate in place of step.

Return type:

dict

Raises:
  • KeyError – If the dataset psi_<istate> does not exist.

  • ValueError – If the coefficient shape is incompatible with nfuncs or a grid lies outside the knot span.

zkit.io.wfs_field.wfs_to_vtk(res, out_path, fmt=None)

Export an evaluated wavefunction to a VTK file for ParaView.

Parameters:
  • res (dict) – Output of reconstruct_wfs() or reconstruct_static_wfs().

  • out_path (str or pathlib.Path) – Destination file. Unless fmt is given, the extension selects the format: .vts for a VTK structured grid, .vtu for an unstructured grid (the structured grid cast to unstructured) and .vtk for the legacy VTK format. Any other extension is written as a structured grid.

  • fmt ({"vts", "vtu", "vtk"}, optional) – Explicit format, overriding the extension.

Returns:

out_path.

Return type:

str

Notes

The grid carries the point-data arrays psi_re (Re psi), psi_im (Im psi), psi_mag (the density |psi|^2, taken from res["abs2"]) and psi_phase (arg psi, in radians). 1-D and 2-D fields are written as structured grids with singleton extents in the missing directions.

Requires pyvista (the viz extra).

zkit.io.wfs_field.compute_wfs_norm(path, step=0, nq=5)

Norm of a wavefunction snapshot by Gauss quadrature over the knot spans.

Computes \(\langle\psi\vert\psi\rangle = \int \lvert\psi\rvert^2\,d^dr\) over the whole spline domain with a tensor-product Gauss-Legendre rule of nq points per knot span on each axis. Within a span the density is a polynomial of degree 2p per axis, so the rule is exact (up to round-off) whenever 2p <= 2*nq - 1; the default nq=5 is exact for splines of degree p <= 4.

Parameters:
  • path (str or pathlib.Path) – Path to td/<name>_wfs.h5.

  • step (int, optional) – Snapshot index.

  • nq (int, optional) – Gauss points per knot span and axis.

Returns:

The integral of \(\lvert\psi\rvert^2\) over the domain.

Return type:

float

Raises:
  • KeyError – If wavefunction or a knots_* dataset is missing.

  • ValueError – If the coefficient shape does not match the nfuncs attributes.