pyserep.io
pyserep.io — matrix loading, export, and mesh output.
- pyserep.io.enforce_symmetry(mat: spmatrix) csc_matrix[source]
Enforce symmetry:
A ← 0.5 * (A + Aᵀ).- Parameters:
mat (scipy.sparse matrix)
- Returns:
Symmetric version of mat.
- Return type:
- pyserep.io.load_frf_npz(path: str) Dict[str, ndarray][source]
Load a saved FRF
.npzfile.- Returns:
freqs_hz— evaluation frequencies (Hz)rom_*— ROM FRF arrays (complex)ref_*— reference FRF arrays (complex)- Return type:
dict with keys
- pyserep.io.load_matrices(stiffness_path: str, mass_path: str, verbose: bool = True, symmetry_tol: float = 1e-08) Tuple[csc_matrix, csc_matrix][source]
Load stiffness and mass matrices from disk.
- Parameters:
stiffness_path (str) – Path to the stiffness matrix file.
mass_path (str) – Path to the mass matrix file.
verbose (bool) – Print loading progress, matrix statistics, and memory usage.
symmetry_tol (float) – Symmetry tolerance forwarded to
load_matrix().
- Returns:
K (scipy.sparse.csc_matrix) – Stiffness matrix.
M (scipy.sparse.csc_matrix) – Mass matrix.
- Raises:
FileNotFoundError – If either file does not exist.
ValueError – If K and M have incompatible shapes or are not square.
Examples
>>> K, M = load_matrices("K.mtx", "M.mtx") >>> K.shape == M.shape True
- pyserep.io.load_matrix(path: str, symmetry_tol: float = 1e-08) csc_matrix[source]
Load a single sparse or dense matrix from disk, returning a CSC matrix.
- Parameters:
- Returns:
The loaded matrix in CSC format.
- Return type:
- Raises:
FileNotFoundError – If the file does not exist.
ValueError – If the format is unrecognised or the file cannot be parsed.
Examples
>>> K = load_matrix("StiffMatrixmm.mtx") >>> K.shape (66525, 66525)
- pyserep.io.load_metrics(folder: str, prefix: str = 'SEREP') Dict[str, Any][source]
Load a saved metrics JSON file.
- pyserep.io.load_reduced_matrices(folder: str, prefix: str = 'SEREP') tuple[ndarray, ndarray, ndarray][source]
Load saved Ka, Ma, and T matrices.
- Returns:
Ka, Ma, T
- Return type:
np.ndarray
- pyserep.io.save_results(results: PipelineResults, folder: str, prefix: str = 'SEREP', save_matrices: bool = True, verbose: bool = True) Dict[str, str][source]
Save all pipeline results to folder.
- Parameters:
results (PipelineResults)
folder (str) – Output directory (created if it does not exist).
prefix (str) – Filename prefix for all output files.
save_matrices (bool) – If True, save Ka, Ma, and T matrices. These can be large; set to False to save only indices, FRF, and metrics.
verbose (bool)
- Returns:
Mapping of result type → absolute file path.
- Return type:
- pyserep.io.write_ansys_node_list(master_dofs: ndarray, path: str, component_name: str = 'MASTER_NODES', verbose: bool = True) None[source]
Write an Ansys APDL input file that selects the master DOF nodes.
Usage in Ansys: /INPUT, master_nodes.inp
- pyserep.io.write_master_dofs_csv(master_dofs: ndarray, path: str, node_coords: ndarray | None = None, verbose: bool = True) None[source]
Write master DOF indices to a CSV file.
Columns: dof_index, node_number, direction, [x, y, z]
- Parameters:
master_dofs (np.ndarray of int — 0-based DOF indices)
path (str — output .csv path)
node_coords (np.ndarray, shape (N_nodes, 3), optional) – Node coordinate array (indexed by node_number − 1). If provided, x, y, z columns are written.
verbose (bool)
- pyserep.io.write_master_dofs_vtk(master_dofs: ndarray, node_coords: ndarray, path: str, scalar_data: ndarray | None = None, scalar_name: str = 'eid_score', verbose: bool = True) None[source]
Write master DOF locations as a VTK unstructured point cloud.
Opens in ParaView, MayaVi, VisIt, etc.
- pyserep.io.write_uff58_mode_shapes(phi: ndarray, freqs_hz: ndarray, selected_modes: ndarray, master_dofs: ndarray, node_coords: ndarray | None, path: str, zeta: float = 0.001, verbose: bool = True) None[source]
Write mode shapes to a UFF (Universal File Format) dataset 58 file.
Compatible with SDyPy, pyFRF, ME’scopeVES, nModal, and other EMA/OMA post-processors.
- Parameters:
phi (np.ndarray, shape (N, n_all_modes))
freqs_hz (np.ndarray)
selected_modes (np.ndarray of int)
master_dofs (np.ndarray of int — only these DOFs are exported)
node_coords (np.ndarray, shape (N_nodes, 3), optional)
path (str — output .uff path)
zeta (float — damping ratio for all modes)
verbose (bool)