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.h5on 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
axesis 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),ReandIm(real and imaginary parts),abs2(the density \(\lvert\psi\rvert^2\)),SplineDegreeandnfuncs(lists, one entry per axis) andknots(the open knot vectors).- Return type:
dict
- Raises:
KeyError – If the file has no
wavefunctiondataset or aknots_*dataset is missing.ValueError – If the dimensionality is not 1, 2 or 3, the coefficient shape does not match the
nfuncsattributes, or a grid inaxeslies 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-levelknots_x(andknots_y,knots_z) datasets carrying theSplineDegreeandnfuncsattributes. The spatial dimension is the number ofknots_*datasets present. Evaluation followsreconstruct_wfs().- Parameters:
path (str or pathlib.Path) – Path to
static/<name>_eigen.h5.istate (int, optional) – Index of the eigenstate (the
<i>inpsi_<i>).npoints (int, optional) – Grid points per axis when
axesis 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(), withistatein place ofstep.- Return type:
dict
- Raises:
KeyError – If the dataset
psi_<istate>does not exist.ValueError – If the coefficient shape is incompatible with
nfuncsor 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()orreconstruct_static_wfs().out_path (str or pathlib.Path) – Destination file. Unless
fmtis given, the extension selects the format:.vtsfor a VTK structured grid,.vtufor an unstructured grid (the structured grid cast to unstructured) and.vtkfor 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 fromres["abs2"]) andpsi_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(thevizextra).
- 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
nqpoints per knot span on each axis. Within a span the density is a polynomial of degree2pper axis, so the rule is exact (up to round-off) whenever2p <= 2*nq - 1; the defaultnq=5is exact for splines of degreep <= 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
wavefunctionor aknots_*dataset is missing.ValueError – If the coefficient shape does not match the
nfuncsattributes.