utils.visualization.generate_vtk

utils.visualization.generate_vtk

VTK export utilities.

This module provides functions for: - plotting a 2D field on a scikit-fem basis - writing one displacement vector to a VTK file, with mesh translation - exporting paired full-order and reduced-order solutions to VTK - exporting a displacement time series to VTK with a PVD collection file - exporting a point-data time series to VTK on an undeformed mesh

Notes

Authors: Suparno Bhattacharyya

Functions

Name Description
generate_vtk Export paired full-order and reduced-order solutions to VTK.
save_vtk_solution Write one solution vector to a VTK file.
save_vtk_time_series Write one VTK per saved time step and write a PVD collection file.
save_vtk_time_series_point Write point-data frames to VTK on an undeformed mesh.
save_vtu_time_series_point Write point-data frames to VTK on an undeformed mesh.
save_vtu_time_series_point_vertexsample U: (n_steps, ndofs_P2)
visualize2D Plot a scalar field on a 2D scikit-fem basis.

generate_vtk

utils.visualization.generate_vtk.generate_vtk(
    LS_test,
    LS_rom,
    mesh,
    basis,
    scale=1.0,
    num_test=5,
    out_dir='sol_vtk_files',
    split_dim=False,
    clean_out_dir=False,
)

Export paired full-order and reduced-order solutions to VTK.

The function selects num_test random indices and writes one full-order and one reduced-order VTK file in a subfolder Test_i.

Parameters

Name Type Description Default
LS_test sequence of array_like Full-order solution vectors. required
LS_rom sequence of array_like Reduced-order solution vectors aligned with LS_test by index. required
mesh object Mesh object passed to save_vtk_solution. required
basis object Basis object passed to save_vtk_solution. required
scale float Scale factor for nodal values. Default is 1.0. 1.0
num_test int Number of cases to export. Default is 5. 5
out_dir str Output directory. Subfolders Test_1, Test_2, … are created. Default is “sol_vtk_files”. 'sol_vtk_files'
split_dim bool Passed to save_vtk_solution. Default is False. False
clean_out_dir bool If True, remove out_dir before writing. Default is False. False

Returns

Name Type Description
None

Notes

Authors: Suparno Bhattacharyya

save_vtk_solution

utils.visualization.generate_vtk.save_vtk_solution(
    u,
    mesh,
    basis,
    scale,
    run_dir,
    prefix,
    split_dim=False,
)

Write one solution vector to a VTK file.

The function extracts nodal degrees of freedom from u using basis.nodal_dofs, scales the nodal values by scale, translates the mesh, and writes one .vtk file. If split_dim is True, the nodal displacement components are stored as scalar point-data fields.

Parameters

Name Type Description Default
u array_like Global solution vector that contains nodal degrees of freedom indexed by basis.nodal_dofs. required
mesh object Mesh object that provides: - translated(u_node) returning a new mesh - save(path, point_data=...) writing a VTK file required
basis object Basis object that provides nodal_dofs. required
scale float Scale factor applied to nodal values before translation. required
run_dir str or pathlib.Path Output directory. required
prefix str Output file prefix. The file name is {prefix}.vtk. required
split_dim bool If True, write scalar fields u_x, u_y, u_z (up to the mesh dimension). If False, write only the displaced mesh. Default is False. False

Returns

Name Type Description
None

Notes

Authors: Suparno Bhattacharyya

save_vtk_time_series

utils.visualization.generate_vtk.save_vtk_time_series(
    U,
    times,
    mesh,
    basis,
    scale,
    run_dir,
    prefix,
    interval=10,
)

Write one VTK per saved time step and write a PVD collection file.

The function saves frames named {prefix}_{k:04d}.vtk and writes a PVD file named {prefix}.pvd that references the frames and their times.

Parameters

Name Type Description Default
U numpy.ndarray Displacement history with shape (ndofs, n_steps). required
times numpy.ndarray Time values with shape (n_steps,). required
mesh object Mesh object passed to save_vtk_solution. required
basis object Basis object passed to save_vtk_solution. required
scale float Scale factor for nodal values before translation. required
run_dir pathlib.Path Output directory. required
prefix str Base name used for VTK frames and the PVD file. required
interval int Save every interval steps. Default is 10. 10

Returns

Name Type Description
None

Notes

Authors: Suparno Bhattacharyya

save_vtk_time_series_point

utils.visualization.generate_vtk.save_vtk_time_series_point(
    U,
    mesh,
    run_dir,
    prefix,
    interval=10,
    point_data_name='Temperature',
)

Write point-data frames to VTK on an undeformed mesh.

The function writes frames named {prefix}_{k:04d}.vtk with a point-data array stored under point_data_name.

The time axis handling is: - if U.shape[0] == n_points: treat U as (n_points, n_steps) and save columns - else: treat U as (n_steps, n_points) and save rows

Parameters

Name Type Description Default
U numpy.ndarray Point-data history with shape (n_steps, n_points) or (n_points, n_steps). required
mesh object Mesh object that provides save(path, point_data=...). required
run_dir pathlib.Path Output directory. required
prefix str Base name used for VTK frames. required
interval int Save every interval steps. Default is 10. 10
point_data_name str Key used in VTK point_data. Default is “Temperature”. 'Temperature'

Returns

Name Type Description
None

Notes

Authors: Suparno Bhattacharyya

save_vtu_time_series_point

utils.visualization.generate_vtk.save_vtu_time_series_point(
    U,
    mesh,
    run_dir,
    prefix,
    interval=10,
    point_data_name='Temperature',
)

Write point-data frames to VTK on an undeformed mesh.

The function writes frames named {prefix}_{k:04d}.vtk with a point-data array stored under point_data_name.

The time axis handling is: - if U.shape[0] == n_points: treat U as (n_points, n_steps) and save columns - else: treat U as (n_steps, n_points) and save rows

Parameters

Name Type Description Default
U numpy.ndarray Point-data history with shape (n_steps, n_points) or (n_points, n_steps). required
mesh object Mesh object that provides save(path, point_data=...). required
run_dir pathlib.Path Output directory. required
prefix str Base name used for VTU frames. required
interval int Save every interval steps. Default is 10. 10
point_data_name str Key used in VTK point_data. Default is “Temperature”. 'Temperature'

Returns

Name Type Description
None

Notes

Authors: Suparno Bhattacharyya

save_vtu_time_series_point_vertexsample

utils.visualization.generate_vtk.save_vtu_time_series_point_vertexsample(
    U,
    mesh,
    basis,
    run_dir,
    prefix,
    interval=8,
    point_data_name='Temperature',
)

U: (n_steps, ndofs_P2) Saves vertex-sampled field (n_vertices,) on the original mesh.

visualize2D

utils.visualization.generate_vtk.visualize2D(u, basis)

Plot a scalar field on a 2D scikit-fem basis.

Parameters

Name Type Description Default
u array_like Field values compatible with the given basis. required
basis object scikit-fem basis. required

Returns

Name Type Description
out Return value from the backend plot/show call.