API Reference#
Pre-processing scripts#
- vasp.automatedPreprocessing.automated_preprocessing.read_command_line(input_path=None)[source]#
Read arguments from commandline and return all values in a dictionary. If input_path is not None, then do not parse command line, but only return default values.
- Args:
input_path (str): Input file path, positional argument with default None.
- vasp.automatedPreprocessing.automated_preprocessing.run_pre_processing(input_model, verbose_print, smoothing_method, smoothing_factor, smoothing_iterations, meshing_method, refine_region, has_multiple_inlets, add_flow_extensions, visualize, config_path, coarsening_factor, inlet_flow_extension_length, outlet_flow_extension_length, number_of_sublayers_fluid, number_of_sublayers_solid, edge_length, region_points, compress_mesh, scale_factor, scale_factor_h5, resampling_step, meshing_parameters, remove_all, solid_thickness, solid_thickness_parameters, mesh_format, flow_rate_factor, solid_side_wall_id, interface_fsi_id, solid_outer_wall_id, fluid_volume_id, solid_volume_id, mesh_generation_retries, no_solid, extract_branch, branch_group_ids, branch_ids_offset, distance_method)[source]#
Automatically generate mesh of surface model in .vtu and .xml format, including prescribed flow rates at inlet and outlet based on flow network model.
Runs simulation of meshed case on a remote ssh server if server configuration is provided.
- Parameters:
input_model (str) – Name of case
verbose_print (bool) – Toggles verbose mode
smoothing_method (str) – Method for surface smoothing
smoothing_factor (float) – Smoothing factor of Voronoi smoothing
smoothing_iterations (int) – Number of smoothing iterations for Taubin and Laplace smoothing
meshing_method (str) – Determines what the density of the volumetric mesh depends upon
refine_region (bool) – Refines selected region of input if True
has_multiple_inlets (bool) – Specifies whether the input model has multiple inlets
add_flow_extensions (bool) – Adds flow extensions to mesh if True
visualize (bool) – Visualize resulting surface model with flow rates
config_path (str) – Path to configuration file for remote simulation
coarsening_factor (float) – Refine or coarsen the standard mesh size with given factor
inlet_flow_extension_length (float) – Factor defining length of flow extensions at the inlet(s)
outlet_flow_extension_length (float) – Factor defining length of flow extensions at the outlet(s)
number_of_sublayers_fluid (int) – Number of sublayers for fluid
number_of_sublayers_solid (int) – Number of sublayers for solid
edge_length (float) – Edge length used for meshing with constant element size
region_points (list) – User defined points to define which region to refine
compress_mesh (bool) – Compresses finalized mesh if True
scale_factor (float) – Scale input model by this factor
resampling_step (float) – Float value determining the resampling step for centerline computations, in [m]
meshing_parameters (list) – Parameters for meshing method ‘distancetospheres’
remove_all (bool) – Remove mesh and all pre-processing files
solid_thickness (str) – Constant or variable mesh thickness
solid_thickness_parameters (list) – Specify parameters for solid thickness
mesh_format (str) – Specify the format for the generated mesh
flow_rate_factor (float) – Flow rate factor
solid_side_wall_id (int) – ID for solid side wall
interface_fsi_id (int) – ID for the FSI interface
solid_outer_wall_id (int) – ID for the solid outer wall
fluid_volume_id (int) – ID for the fluid volume
solid_volume_id (int) – ID for the solid volume
mesh_generation_retries (int) – Number of mesh generation retries before trying alternative method
no_solid (bool) – Generate mesh without solid
extract_branch (bool) – Enable extraction of a specific branch, marking solid mesh IDs with an offset.
branch_group_ids (list) – Specify group IDs to extract for the branch.
branch_ids_offset (int) – Set offset for marking solid mesh IDs when extracting a branch.
distance_method (str) – Change between ‘euclidean’ and ‘geodesic’ distance measure
- vasp.automatedPreprocessing.automated_preprocessing.save_command_to_file(file_path)[source]#
Save the command-line arguments to a file.
- Parameters:
file_path (str) – Path to the file where the command-line arguments should be saved.
- vasp.automatedPreprocessing.preprocessing_common.check_flatten_boundary(num_inlets_outlets: int, mesh_path: str | Path, threshold_stdev: float = 0.001) None [source]#
Check whether inlets and outlets are flat, then flatten them if necessary
- Parameters:
num_inlets_outlets (int) – Number of inlets and outlets in the mesh
mesh_path (Union[str, Path]) – Path to the mesh file
threshold_stdev (float) – Threshold for standard deviation of facet unit normals
- Returns:
None
- vasp.automatedPreprocessing.preprocessing_common.convert_vtu_mesh_to_xdmf(file_name_vtu_mesh: str | Path, file_name_xdmf_mesh: str | Path) None [source]#
Convert a VTU mesh to XDMF format using meshio. This function is intended to run in serial.
- Parameters:
file_name_vtu_mesh (Union[str, Path]) – Path to the input VTU mesh file.
file_name_xdmf_mesh (Union[str, Path]) – Path to the output XDMF file.
- vasp.automatedPreprocessing.preprocessing_common.convert_xml_mesh_to_hdf5(file_name_xml_mesh: str | Path, scaling_factor: float = 1) None [source]#
Converts an XML mesh to an HDF5 mesh.
- Parameters:
file_name_xml_mesh (Union[str, Path]) – The name of the XML mesh file.
scaling_factor (float, optional) – A scaling factor to apply to the mesh coordinates. The default value is 1 (no scaling). Note that probes and parameters inside _info.json file will not be scaled if you only scale HDF5 file.
- Returns:
None
- Raises:
FileNotFoundError – If the XML mesh file does not exist.
- vasp.automatedPreprocessing.preprocessing_common.dist_sphere_spheres(surface: vtkPolyData, save_path: str | Path, distance_offset: float, distance_scale: float, min_distance: float, max_distance: float, distance_method: str = 'geodesic') vtkPolyData [source]#
Determines the target edge length for each cell on the surface, including potential refinement or coarsening of certain user specified areas. Level of refinement/coarseness is determined based on the distance to the spheres. The distance computation can be either ‘euclidean’ or ‘geodesic’ (default).
- Parameters:
surface (vtkPolyData) – Input surface model
save_path (Union[str, Path]) – Location to store processed surface
distance_offset (float) – Offset added to the distances
distance_scale (float) – Scale applied to the distances
min_distance (float) – Minimum value for the distances
max_distance (float) – Maximum value for the distances
distance_method (str) – Method to compute distances (‘euclidean’ or ‘geodesic’)
- Returns:
Processed surface model with info on cell specific target edge length
- Return type:
surface (vtkPolyData)
- vasp.automatedPreprocessing.preprocessing_common.distance_to_spheres_solid_thickness(surface: vtkPolyData, save_path: str | Path, distance_offset: float = 0, distance_scale: float = 0.1, min_distance: float = 0.25, max_distance: float = 0.3) vtkPolyData [source]#
Determines the solid thickness using vmtkdistancetospheres. Write the distance data to save_path.
- Parameters:
surface (vtkPolyData) – Input surface model
save_path (Union[str, Path]) – Location to store processed surface
distance_offset (float) – Offset added to the distances
distance_scale (float) – Scale applied to the distances
min_distance (float) – Minimum value for the distances
max_distance (float) – Maximum value for the distances
- Returns:
Processed surface model with info on solid thickness
- Return type:
surface (vtkPolyData)
- vasp.automatedPreprocessing.preprocessing_common.edge_length_evaluator(file_name_mesh: str | Path, file_name_edge_length_xdmf: str | Path) None [source]#
Evaluates the edge length of a mesh.
- Parameters:
file_name_mesh (Union[str, Path]) – Path to the XML mesh file.
file_name_edge_length_xdmf (Union[str, Path]) – Path to the output XDMF file.
- vasp.automatedPreprocessing.preprocessing_common.generate_mesh(surface: vtkPolyData, number_of_sublayers_fluid: int, number_of_sublayers_solid: int, solid_thickness: str, solid_thickness_parameters: list, centerlines: vtkPolyData, solid_side_wall_id: int = 11, interface_fsi_id: int = 22, solid_outer_wall_id: int = 33, fluid_volume_id: int = 0, solid_volume_id: int = 1, no_solid: bool = False, extract_branch: bool = False, branch_group_ids: list = [], branch_ids_offset: int = 1000) tuple [source]#
Generates a mesh suitable for FSI from an input surface model.
- Parameters:
surface (vtkPolyData) – Surface model to be meshed.
number_of_sublayers_fluid (int) – Number of sublayers for fluid.
number_of_sublayers_solid (int) – Number of sublayers for solid.
solid_thickness (str) – Type of solid thickness (‘variable’ or ‘constant’).
solid_thickness_parameters (list) – List of parameters for solid thickness.
centerlines (vtkPolyData) – Centerlines of input model.
solid_side_wall_id (int, optional) – ID for solid side wall. Default is 11.
interface_fsi_id (int, optional) – ID for the FSI interface. Default is 22.
solid_outer_wall_id (int, optional) – ID for solid outer wall. Default is 33.
fluid_volume_id (int, optional) – ID for the fluid volume. Default is 0.
solid_volume_id (int, optional) – ID for the solid volume. Default is 1.
no_solid (bool, optional) – Generate mesh without solid.
extract_branch (bool, optional) – Enable extraction of a specific branch, marking solid mesh IDs with an offset.
branch_group_ids (list, optional) – Specify group IDs to extract for the branch.
branch_ids_offset (int) – Set offset for marking solid mesh IDs when extracting a branch.
- Returns:
A tuple containing the generated mesh (vtkUnstructuredGrid) and the remeshed surface (vtkPolyData).
- Return type:
tuple
Post-processing scripts#
This script is a versatile Python script for parsing and visualizing simulation log files. It extracts data from log files, offers flexible plotting options, and helps users gain insights from simulation results.
Example:
vasp-log-plotter simulation.log –plot-all –save –output-directory Results –figure-size 12,8
- vasp.automatedPostprocessing.log_plotter.compute_average_over_cycles(data: ndarray, time_steps_per_cycle: int) ndarray [source]#
Compute the average over cycles in a numpy array.
- Parameters:
data (np.ndarray) – The input data array.
time_steps_per_cycle (int) – The number of time steps in each cycle.
- Returns:
A numpy array containing the average data over cycles.
- Return type:
np.ndarray
- vasp.automatedPostprocessing.log_plotter.compute_tke(probe_points: Dict[int, Dict[str, Any]], time_steps_per_cycle: int, start_cycle: int | None = None, end_cycle: int | None = None) Dict[int, Tuple[ndarray, ndarray, ndarray]] [source]#
Compute the mean velocity, fluctuating velocity, and turbulent kinetic energy for each point within the specified cycle range in the probe points data using phase-averaging.
- Parameters:
probe_points (dict) – Probe points data as returned by parse_log_file.
time_steps_per_cycle (int) – Number of time steps per cycle.
start_cycle (int, optional) – The cycle to start computing from (inclusive). Default is the first cycle.
end_cycle (int, optional) – The cycle to end computing at (inclusive). Default is the last cycle.
- Returns:
- A dictionary containing the mean velocity, fluctuating velocity, and TKE for each point within the
specified cycle range. Each entry is a tuple of (mean_velocity, fluctuating_velocity, tke_array).
- Return type:
dict
- vasp.automatedPostprocessing.log_plotter.parse_command_line_args() Namespace [source]#
Parse command-line arguments.
- Returns:
Parsed command-line arguments.
- Return type:
argparse.Namespace
- vasp.automatedPostprocessing.log_plotter.parse_dictionary_from_log(log_file: str) dict [source]#
Parse a dictionary-like content from a log file and return it as a dictionary.
- Parameters:
log_file (str) – Path to the log file.
- Returns:
Parsed dictionary.
- Return type:
dict
- vasp.automatedPostprocessing.log_plotter.parse_log_file(log_file: str) Dict[str, Any] [source]#
Parse a log file and store data in a structured dictionary with numpy arrays.
- Parameters:
log_file (str) – Path to the log file.
- Returns:
A dictionary containing the parsed data.
- Return type:
dict
- vasp.automatedPostprocessing.log_plotter.plot_multiple_variables_comparison(variable_mean: ndarray, variable_min: ndarray, variable_max: ndarray, variable_name: str, time_steps_per_cycle: int, save_to_file: bool = False, output_directory: str | None = None, figure_size: Tuple[int, int] = (10, 6), start_cycle: int | None = 1, end_cycle: int | None = None) None [source]#
Plot mean, min, and max variables against time on the same figure.
- Parameters:
variable_mean (numpy.ndarray) – Array containing the mean variable values.
variable_min (numpy.ndarray) – Array containing the min variable values.
variable_max (numpy.ndarray) – Array containing the max variable values.
variable_name (str) – Names of the variables for labeling the plot (mean, min, max).
time_steps_per_cycle (int) – The number of time steps in each cycle.
save_to_file (bool, optional) – Whether to save the figure to a file (default is False).
output_directory (str, optional) – The directory where the figure will be saved when save_to_file is True.
figure_size (tuple, optional) – Figure size in inches (width, height). Default is (10, 6).
start_cycle (int, optional) – The cycle to start comparing from. Default is 1 (start from first cycle).
end_cycle (int, optional) – The cycle to end comparing at. Default is None (end at last cycle).
- vasp.automatedPostprocessing.log_plotter.plot_multiple_variables_vs_time(time: ndarray, variable_mean: ndarray, variable_min: ndarray, variable_max: ndarray, variable_name: str, save_to_file: bool = False, output_directory: str | None = None, figure_size: Tuple[int, int] = (10, 6), start: int | None = None, end: int | None = None) None [source]#
Plot mean, min, and max variables against time on the same figure.
- Parameters:
time (numpy.ndarray) – Array containing time values.
variable_mean (numpy.ndarray) – Array containing the mean variable values.
variable_min (numpy.ndarray) – Array containing the min variable values.
variable_max (numpy.ndarray) – Array containing the max variable values.
variable_name (str) – Names of the variables for labeling the plot (mean, min, max).
save_to_file (bool, optional) – Whether to save the figure to a file (default is False).
output_directory (str, optional) – The directory where the figure will be saved when save_to_file is True.
figure_size (tuple, optional) – Figure size in inches (width, height). Default is (10, 6).
start (int, optional) – Index to start plotting data from. Default is None (start from the beginning).
end (int, optional) – Index to end plotting data at. Default is None (end at the last data point).
- vasp.automatedPostprocessing.log_plotter.plot_newton_iteration(variable: ndarray, variable_name: str, save_to_file: bool = False, output_directory: str | None = None, figure_size: Tuple[int, int] = (10, 6)) None [source]#
Plot Newton iteration (atol or rtol).
- Parameters:
variable (numpy.ndarray) – Array containing the variable values.
variable_name (str) – Name of the variable for labeling the plot.
save_to_file (bool, optional) – Whether to save the figure to a file (default is False).
output_directory (str, optional) – The directory where the figure will be saved when save_to_file is True.
figure_size (tuple, optional) – Figure size in inches (width, height). Default is (10, 6).
- vasp.automatedPostprocessing.log_plotter.plot_probe_points(time: ndarray, probe_points: Dict[int, Dict[str, ndarray]], selected_probe_points: List[int] | None = None, save_to_file: bool = False, output_directory: str | None = None, figure_size: Tuple[int, int] = (12, 6), start: int | None = None, end: int | None = None) None [source]#
Plot velocity magnitude and pressure for probe points against time.
- Parameters:
time (numpy.ndarray) – Time array.
probe_points (dict) – Probe point data containing velocity magnitude and pressure arrays.
selected_probe_points (list, optional) – List of probe points to plot. Plot all probe points if not provided.
save_to_file (bool, optional) – Whether to save the figures to files (default is False).
output_directory (str, optional) – The directory where the figure will be saved when save_to_file is True.
figure_size (tuple, optional) – Figure size in inches (width, height). Default is (12, 8).
start (int, optional) – Index to start plotting data from. Default is None (start from the beginning).
end (int, optional) – Index to end plotting data at. Default is None (end at the last data point).
- vasp.automatedPostprocessing.log_plotter.plot_probe_points_comparison(probe_points: Dict[int, Dict[str, ndarray]], time_steps_per_cycle: int, selected_probe_points: List[int] | None = None, save_to_file: bool = False, output_directory: str | None = None, figure_size: Tuple[int, int] = (12, 6), start_cycle: int | None = 0, end_cycle: int | None = None) None [source]#
Plot comparison of velocity magnitude and pressure for probe points across multiple cycles.
- Parameters:
probe_points (dict) – Probe point data containing velocity magnitude and pressure arrays.
selected_probe_points (list, optional) – List of probe points to plot. Plot all probe points if not provided.
time_steps_per_cycle (int) – The number of time steps in each cycle.
save_to_file (bool, optional) – Whether to save the figures to files (default is False).
output_directory (str, optional) – The directory where the figure will be saved when save_to_file is True.
figure_size (tuple, optional) – Figure size in inches (width, height). Default is (12, 8).
start_cycle (int, optional) – The cycle to start comparing from. Default is 1 (start from first cycle).
end_cycle (int, optional) – The cycle to end comparing at. Default is None (end at last cycle).
- vasp.automatedPostprocessing.log_plotter.plot_probe_points_displacement(time: ndarray, probe_points: Dict[int, Dict[str, ndarray]], selected_probe_points: List[int] | None = None, save_to_file: bool = False, output_directory: str | None = None, figure_size: Tuple[int, int] = (12, 6), start: int | None = None, end: int | None = None) None [source]#
Plot displacement magnitude for probe points against time.
- Parameters:
time (numpy.ndarray) – Time array.
probe_points (dict) – Probe point data containing displacement magnitude arrays.
selected_probe_points (list, optional) – List of probe points to plot. Plot all probe points if not provided.
save_to_file (bool, optional) – Whether to save the figures to files (default is False).
output_directory (str, optional) – The directory where the figure will be saved when save_to_file is True.
figure_size (tuple, optional) – Figure size in inches (width, height). Default is (12, 8).
start (int, optional) – Index to start plotting data from. Default is None (start from the beginning).
end (int, optional) – Index to end plotting data at. Default is None (end at the last data point).
- vasp.automatedPostprocessing.log_plotter.plot_probe_points_displacement_comparison(probe_points: Dict[int, Dict[str, ndarray]], time_steps_per_cycle: int, selected_probe_points: List[int] | None = None, save_to_file: bool = False, output_directory: str | None = None, figure_size: Tuple[int, int] = (12, 6), start_cycle: int | None = 0, end_cycle: int | None = None) None [source]#
Plot comparison of displacement magnitude for probe points across multiple cycles.
- Parameters:
probe_points (dict) – Probe point data containing displacement magnitude arrays.
selected_probe_points (list, optional) – List of probe points to plot. Plot all probe points if not provided.
time_steps_per_cycle (int) – The number of time steps in each cycle.
save_to_file (bool, optional) – Whether to save the figures to files (default is False).
output_directory (str, optional) – The directory where the figure will be saved when save_to_file is True.
figure_size (tuple, optional) – Figure size in inches (width, height). Default is (12, 8).
start_cycle (int, optional) – The cycle to start comparing from. Default is 1 (start from first cycle).
end_cycle (int, optional) – The cycle to end comparing at. Default is None (end at last cycle).
- vasp.automatedPostprocessing.log_plotter.plot_probe_points_tke(tke_data: Dict[int, Tuple[ndarray, ndarray, ndarray]], selected_probe_points: List[int] | None = None, save_to_file: bool = False, output_directory: str | None = None, figure_size: Tuple[int, int] = (12, 6), start: int | None = None, end: int | None = None)[source]#
Plot the turbulent kinetic energy (TKE) for each probe point in separate subplots.
- Parameters:
tke_data (dict) – A dictionary containing TKE data for each probe point. This should be in the format returned by compute_mean_fluctuating_and_tke_velocity.
save_to_file (bool, optional) – Whether to save the figures to files (default is False).
output_directory (str, optional) – The directory where the figure will be saved when save_to_file is True.
figure_size (tuple, optional) – Figure size in inches (width, height). Default is (12, 8).
start (int, optional) – Index to start plotting data from. Default is None (start from the beginning).
end (int, optional) – Index to end plotting data at. Default is None (end at the last data point).
- vasp.automatedPostprocessing.log_plotter.plot_probe_points_tke_comparison(tke_data: Dict[int, Tuple[ndarray, ndarray, ndarray]], time_steps_per_cycle: int, selected_probe_points: List[int] | None = None, save_to_file: bool = False, output_directory: str | None = None, figure_size: Tuple[int, int] = (12, 6))[source]#
Plot the turbulent kinetic energy (TKE) per cycle for selected probe points in separate figures.
- Parameters:
tke_data (dict) – A dictionary containing TKE data for each probe point. This should be in the format returned by compute_tke.
time_steps_per_cycle (int) – Number of time steps per cycle.
selected_probe_points (list, optional) – List of probe points to plot. If not provided, all probe points will be plotted.
save_to_file (bool, optional) – Whether to save the figures to files (default is False).
output_directory (str, optional) – The directory where the figure will be saved when save_to_file is True.
figure_size (tuple, optional) – Figure size in inches (width, height). Default is (12, 8).
- vasp.automatedPostprocessing.log_plotter.plot_variable_comparison(variable: ndarray, variable_name: str, time_steps_per_cycle: int, save_to_file: bool = False, output_directory: str | None = None, figure_size: Tuple[int, int] = (10, 6), start_cycle: int | None = 1, end_cycle: int | None = None) None [source]#
Plot comparison of a variable across multiple cycles.
- Parameters:
variable (numpy.ndarray) – Array containing the variable values.
variable_name (str) – Name of the variable for labeling the plot.
time_steps_per_cycle (int) – The number of time steps in each cycle.
save_to_file (bool, optional) – Whether to save the figure to a file (default is False).
output_directory (str, optional) – The directory where the figure will be saved when save_to_file is True.
figure_size (tuple, optional) – Figure size in inches (width, height). Default is (10, 6).
start_cycle (int, optional) – The cycle to start comparing from. Default is 1 (start at first cycle).
end_cycle (int, optional) – The cycle to end comparing at. Default is None (end at last cycle).
- vasp.automatedPostprocessing.log_plotter.plot_variable_vs_time(time: ndarray, variable: ndarray, variable_name: str, save_to_file: bool = False, output_directory: str | None = None, figure_size: Tuple[int, int] = (10, 6), start: int | None = None, end: int | None = None) None [source]#
Plot a variable against time.
- Parameters:
time (numpy.ndarray) – Array containing time values.
variable (numpy.ndarray) – Array containing the variable values.
variable_name (str) – Name of the variable for labeling the plot.
save_to_file (bool, optional) – Whether to save the figure to a file (default is False).
output_directory (str, optional) – The directory where the figure will be saved when save_to_file is True.
figure_size (tuple, optional) – Figure size in inches (width, height). Default is (10, 6).
start (int, optional) – Index to start plotting data from. Default is None (start from the beginning).
end (int, optional) – Index to end plotting data at. Default is None (end at the last data point).
- vasp.automatedPostprocessing.log_plotter.save_plot_to_file(variable_name: str, output_directory: str | None) None [source]#
Save a plot to a file.
- Parameters:
variable_name (str) – Name of the variable for generating the filename.
output_directory (str, optional) – The directory where the figure will be saved.
- vasp.automatedPostprocessing.log_plotter.save_probe_points_data_to_file(probe_points: Dict[int, Dict[str, ndarray]], output_directory: str | None, time: ndarray, start: int | None = None, end: int | None = None) None [source]#
Save probe points data to files.
- Parameters:
probe_points (dict) – Probe point data containing velocity magnitude and pressure arrays.
output_directory (str, optional) – The directory where the files will be saved when save_to_file is True.
time (numpy.ndarray) – Time array.
start (int, optional) – Index to start saving data from. Default is None (start from the beginning).
end (int, optional) – Index to end saving data at. Default is None (end at the last data point).
- vasp.automatedPostprocessing.log_plotter.save_probe_points_displacement_data_to_file(probe_points: Dict[int, Dict[str, ndarray]], output_directory: str | None, time: ndarray, start: int | None = None, end: int | None = None) None [source]#
Save probe points displacement data to files.
- Parameters:
probe_points (dict) – Probe point data containing displacement magnitude arrays.
output_directory (str, optional) – The directory where the files will be saved when save_to_file is True.
time (numpy.ndarray) – Time array.
start (int, optional) – Index to start saving data from. Default is None (start from the beginning).
end (int, optional) – Index to end saving data at. Default is None (end at the last data point).
This script is used to predeform the mesh for an FSI simulation. It assumes that the simulation has already been executed, and the displacement information is available in the ‘displacement.h5’ file. By applying the reverse of the displacement to the original mesh, this script generates a predeformed mesh for subsequent simulation steps.
- vasp.automatedPostprocessing.predeform_mesh.main() None [source]#
Main function for parsing arguments and predeforming the mesh.
- Returns:
None
- vasp.automatedPostprocessing.predeform_mesh.parse_arguments() Namespace [source]#
Parse command line arguments.
- Returns:
Parsed command-line arguments.
- Return type:
argparse.Namespace
- vasp.automatedPostprocessing.predeform_mesh.predeform_mesh(folder_path: Path, mesh_path: Path, scale_factor: float) None [source]#
Predeform the mesh for FSI simulation.
- Parameters:
folder_path (Path) – Path to the simulation results folder.
mesh_path (Path) – Path to the mesh file.
scale_factor (float) – Scale factor for mesh deformation.
- Returns:
None
- vasp.automatedPostprocessing.postprocessing_common.get_domain_ids(mesh_path: Path, fluid_domain_id: int | List[int], solid_domain_id: int | List[int]) Tuple[ndarray[Any, dtype[integer]], ndarray[Any, dtype[integer]], ndarray[Any, dtype[integer]]] [source]#
Given a mesh file, this function returns the IDs of the fluid and solid domains. The IDs is a list of integers that correspond to the index of the coordinates (nodes) in the mesh file.
- Parameters:
mesh_path (Path) – Path to the mesh file that contains the fluid and solid domains
fluid_domain_id (int) – ID of the fluid domain
solid_domain_id (int) – ID of the solid domain
- Returns:
List of IDs of the fluid domain solid_ids (list): List of IDs of the solid domain all_ids (list): List of IDs of the whole mesh
- Return type:
fluid_ids (list)
- vasp.automatedPostprocessing.postprocessing_common.output_file_lists(xdmf_file: Path) Tuple[List[str], List[float], List[int]] [source]#
If the simulation has been restarted, the output is stored in multiple files and may not have even temporal spacing This loop determines the file names from the xdmf output file
- Parameters:
xdmf_file (Path) – Path to xdmf file
- Returns:
- A tuple containing:
List of names of h5 files associated with each timestep
List of time values in xdmf file
List of indices of each timestep in the corresponding h5 file
- Return type:
Tuple[List[str], List[float], List[int]]
- vasp.automatedPostprocessing.postprocessing_common.read_parameters_from_file(folder: str | Path) Dict | None [source]#
Reads parameters from a JSON file located in the specified folder.
- Parameters:
folder (str) – The folder containing simulation results
- Returns:
The loaded parameters as a Python dictionary, or None if an error occurs.
- Return type:
dict or None
This script reads the displacement and velocity data from turtleFSI output and reformats the data so that it can be read in fenics. The output files are saved in the Visualization_separate_domain folder.
- vasp.automatedPostprocessing.postprocessing_fenics.create_hdf5.create_hdf5(visualization_path, mesh_path, save_time_step, stride, start_time, end_time, extract_solid_only, fluid_domain_id, solid_domain_id)[source]#
Loads displacement/velocity data from turtleFSI output and reformats the data so that it can be read in fenics.
- Parameters:
visualization_path (Path) – Path to the folder containing the visualization files (displacement/velocity.h5)
mesh_path (Path) – Path to the mesh file (mesh.h5 or mesh_refined.h5 depending on save_deg)
stride – stride of the time steps to be saved
start_t (float) – desired start time for the output file
end_t (float) – desired end time for the output file
extract_solid_only (bool) – If True, only the solid domain is extracted for displacement. If False, both the fluid and solid domains are extracted.
fluid_domain_id (int or list) – ID of the fluid domain
solid_domain_id (int or list) – ID of the solid domain
- vasp.automatedPostprocessing.postprocessing_fenics.create_hdf5.parse_arguments() Namespace [source]#
Parse command line arguments.
- Returns:
Parsed command-line arguments.
- Return type:
argparse.Namespace
This script loads displacement and velocity from .h5 file given by create_hdf5.py, converts and saves to .xdmf format for visualization (in e.g. ParaView).
- vasp.automatedPostprocessing.postprocessing_fenics.create_separate_domain_visualization.create_separate_domain_visualization(visualization_separate_domain_folder, mesh_path, stride=1)[source]#
Loads displacement and velocity from .h5 file given by create_hdf5.py, converts and saves to .xdmf format for visualization (in e.g. ParaView). This function works with MPI. If the displacement was saved for the entire domain, no additional xdmf file will be created for the displacement. :param visualization_separate_domain_folder: Path to the folder containing the .h5 files :type visualization_separate_domain_folder: Path :param mesh_path: Path to the mesh that contains both fluid and solid domain :type mesh_path: Path :param stride: Save frequency of visualization output (default: 1) :type stride: int
- vasp.automatedPostprocessing.postprocessing_fenics.create_separate_domain_visualization.main() None [source]#
- vasp.automatedPostprocessing.postprocessing_fenics.create_separate_domain_visualization.parse_arguments() Namespace [source]#
Parse command line arguments.
- Returns:
Parsed command-line arguments.
- Return type:
argparse.Namespace
common functions for postprocessing-fenics scripts
- vasp.automatedPostprocessing.postprocessing_fenics.postprocessing_fenics_common.parse_arguments() Namespace [source]#
Parse command line arguments.
- Returns:
Parsed command-line arguments.
- Return type:
argparse.Namespace
- vasp.automatedPostprocessing.postprocessing_fenics.postprocessing_fenics_common.project_dg(f: Function, V: FunctionSpace) Function [source]#
Project a function v into a DG space V. It perfomrs the same operation as dolfin.project, but it is more efficient since we use local_solver which is possible since we use DG spaces.
- Parameters:
v (Function) – Function to be projected
V (FunctionSpace) – DG space
- Returns:
Projected function
- Return type:
Function
- exception vasp.automatedPostprocessing.postprocessing_h5py.chroma_filters.ParameterError[source]#
Exception class for mal-formed inputs
- vasp.automatedPostprocessing.postprocessing_h5py.chroma_filters.chroma_filterbank(sr, n_fft, n_chroma=12, tuning=0.0, ctroct=5.0, octwidth=2, norm=2, base_c=True, dtype=<class 'numpy.float32'>)[source]#
Create a chroma filter bank.
This creates a linear transformation matrix to project FFT bins onto chroma bins (i.e. pitch classes).
- Parameters:
sr (number > 0 [scalar]) – audio sampling rate
n_fft (int > 0 [scalar]) – number of FFT bins
n_chroma (int > 0 [scalar]) – number of chroma bins
tuning (float) – Tuning deviation from A440 in fractions of a chroma bin.
ctroct (float > 0 [scalar])
octwidth (float > 0 or None [scalar]) –
ctroct
andoctwidth
specify a dominance window: a Gaussian weighting centered onctroct
(in octs, A0 = 27.5Hz) and with a gaussian half-width ofoctwidth
.Set
octwidth
to None to use a flat weighting.norm (float > 0 or np.inf) – Normalization factor for each filter
base_c (bool) – If True, the filter bank will start at ‘C’. If False, the filter bank will start at ‘A’.
dtype (np.dtype) – The data type of the output basis. By default, uses 32-bit (single-precision) floating point.
- Returns:
wts – Chroma filter matrix
- Return type:
ndarray [shape=(n_chroma, 1 + n_fft / 2)]
See also
librosa.util.normalize
,librosa.feature.chroma_stft
Notes
This function caches at level 10.
Examples
Build a simple chroma filter bank
>>> chromafb = librosa.filters.chroma(22050, 4096) array([[ 1.689e-05, 3.024e-04, ..., 4.639e-17, 5.327e-17], [ 1.716e-05, 2.652e-04, ..., 2.674e-25, 3.176e-25], ..., [ 1.578e-05, 3.619e-04, ..., 8.577e-06, 9.205e-06], [ 1.643e-05, 3.355e-04, ..., 1.474e-10, 1.636e-10]])
Use quarter-tones instead of semitones
>>> librosa.filters.chroma(22050, 4096, n_chroma=24) array([[ 1.194e-05, 2.138e-04, ..., 6.297e-64, 1.115e-63], [ 1.206e-05, 2.009e-04, ..., 1.546e-79, 2.929e-79], ..., [ 1.162e-05, 2.372e-04, ..., 6.417e-38, 9.923e-38], [ 1.180e-05, 2.260e-04, ..., 4.697e-50, 7.772e-50]])
Equally weight all octaves
>>> librosa.filters.chroma(22050, 4096, octwidth=None) array([[ 3.036e-01, 2.604e-01, ..., 2.445e-16, 2.809e-16], [ 3.084e-01, 2.283e-01, ..., 1.409e-24, 1.675e-24], ..., [ 2.836e-01, 3.116e-01, ..., 4.520e-05, 4.854e-05], [ 2.953e-01, 2.888e-01, ..., 7.768e-10, 8.629e-10]])
>>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots() >>> img = librosa.display.specshow(chromafb, x_axis='linear', ax=ax) >>> ax.set(ylabel='Chroma filter', title='Chroma filter bank') >>> fig.colorbar(img, ax=ax)
- vasp.automatedPostprocessing.postprocessing_h5py.chroma_filters.hz_to_octs(frequencies, tuning=0.0, bins_per_octave=12)[source]#
Convert frequencies (Hz) to (fractional) octave numbers.
Examples
>>> librosa.hz_to_octs(440.0) 4. >>> librosa.hz_to_octs([32, 64, 128, 256]) array([ 0.219, 1.219, 2.219, 3.219])
- Parameters:
frequencies (number >0 or np.ndarray [shape=(n,)] or float) – scalar or vector of frequencies
tuning (float) – Tuning deviation from A440 in (fractional) bins per octave.
bins_per_octave (int > 0) – Number of bins per octave.
- Returns:
octaves – octave number for each frequency
- Return type:
number or np.ndarray [shape=(n,)]
See also
- vasp.automatedPostprocessing.postprocessing_h5py.chroma_filters.normalize(S, norm=inf, axis=0, threshold=None, fill=None)[source]#
Normalize an array along a chosen axis.
Given a norm (described below) and a target axis, the input array is scaled so that:
norm(S, axis=axis) == 1
For example,
axis=0
normalizes each column of a 2-d array by aggregating over the rows (0-axis). Similarly,axis=1
normalizes each row of a 2-d array.This function also supports thresholding small-norm slices: any slice (i.e., row or column) with norm below a specified
threshold
can be left un-normalized, set to all-zeros, or filled with uniform non-zero values that normalize to 1.Note: the semantics of this function differ from scipy.linalg.norm in two ways: multi-dimensional arrays are supported, but matrix-norms are not.
- Parameters:
S (np.ndarray) – The matrix to normalize
norm ({np.inf, -np.inf, 0, float > 0, None}) –
np.inf : maximum absolute value
-np.inf : mininum absolute value
0 : number of non-zeros (the support)
- floatcorresponding l_p norm
See scipy.linalg.norm for details.
None : no normalization is performed
axis (int [scalar]) – Axis along which to compute the norm.
threshold (number > 0 [optional]) –
Only the columns (or rows) with norm at least
threshold
are normalized.By default, the threshold is determined from the numerical precision of
S.dtype
.fill (None or bool) –
If None, then columns (or rows) with norm below
threshold
are left as is.If False, then columns (rows) with norm below
threshold
are set to 0.If True, then columns (rows) with norm below
threshold
are filled uniformly such that the corresponding norm is 1.Note
fill=True
is incompatible withnorm=0
because no uniform vector exists with l0 “norm” equal to 1.
- Returns:
S_norm – Normalized array
- Return type:
np.ndarray [shape=S.shape]
- Raises:
ParameterError – If
norm
is not among the valid types defined above IfS
is not finite Iffill=True
andnorm=0
See also
scipy.linalg.norm
Notes
This function caches at level 40.
Examples
>>> # Construct an example matrix >>> S = np.vander(np.arange(-2.0, 2.0)) >>> S array([[-8., 4., -2., 1.], [-1., 1., -1., 1.], [ 0., 0., 0., 1.], [ 1., 1., 1., 1.]]) >>> # Max (l-infinity)-normalize the columns >>> librosa.util.normalize(S) array([[-1. , 1. , -1. , 1. ], [-0.125, 0.25 , -0.5 , 1. ], [ 0. , 0. , 0. , 1. ], [ 0.125, 0.25 , 0.5 , 1. ]]) >>> # Max (l-infinity)-normalize the rows >>> librosa.util.normalize(S, axis=1) array([[-1. , 0.5 , -0.25 , 0.125], [-1. , 1. , -1. , 1. ], [ 0. , 0. , 0. , 1. ], [ 1. , 1. , 1. , 1. ]]) >>> # l1-normalize the columns >>> librosa.util.normalize(S, norm=1) array([[-0.8 , 0.667, -0.5 , 0.25 ], [-0.1 , 0.167, -0.25 , 0.25 ], [ 0. , 0. , 0. , 0.25 ], [ 0.1 , 0.167, 0.25 , 0.25 ]]) >>> # l2-normalize the columns >>> librosa.util.normalize(S, norm=2) array([[-0.985, 0.943, -0.816, 0.5 ], [-0.123, 0.236, -0.408, 0.5 ], [ 0. , 0. , 0. , 0.5 ], [ 0.123, 0.236, 0.408, 0.5 ]])
>>> # Thresholding and filling >>> S[:, -1] = 1e-308 >>> S array([[ -8.000e+000, 4.000e+000, -2.000e+000, 1.000e-308], [ -1.000e+000, 1.000e+000, -1.000e+000, 1.000e-308], [ 0.000e+000, 0.000e+000, 0.000e+000, 1.000e-308], [ 1.000e+000, 1.000e+000, 1.000e+000, 1.000e-308]])
>>> # By default, small-norm columns are left untouched >>> librosa.util.normalize(S) array([[ -1.000e+000, 1.000e+000, -1.000e+000, 1.000e-308], [ -1.250e-001, 2.500e-001, -5.000e-001, 1.000e-308], [ 0.000e+000, 0.000e+000, 0.000e+000, 1.000e-308], [ 1.250e-001, 2.500e-001, 5.000e-001, 1.000e-308]]) >>> # Small-norm columns can be zeroed out >>> librosa.util.normalize(S, fill=False) array([[-1. , 1. , -1. , 0. ], [-0.125, 0.25 , -0.5 , 0. ], [ 0. , 0. , 0. , 0. ], [ 0.125, 0.25 , 0.5 , 0. ]]) >>> # Or set to constant with unit-norm >>> librosa.util.normalize(S, fill=True) array([[-1. , 1. , -1. , 1. ], [-0.125, 0.25 , -0.5 , 1. ], [ 0. , 0. , 0. , 1. ], [ 0.125, 0.25 , 0.5 , 1. ]]) >>> # With an l1 norm instead of max-norm >>> librosa.util.normalize(S, norm=1, fill=True) array([[-0.8 , 0.667, -0.5 , 0.25 ], [-0.1 , 0.167, -0.25 , 0.25 ], [ 0. , 0. , 0. , 0.25 ], [ 0.1 , 0.167, 0.25 , 0.25 ]])
- vasp.automatedPostprocessing.postprocessing_h5py.chroma_filters.octs_to_hz(octs, tuning=0.0, bins_per_octave=12)[source]#
Convert octaves numbers to frequencies.
Octaves are counted relative to A.
Examples
>>> librosa.octs_to_hz(1) 55. >>> librosa.octs_to_hz([-2, -1, 0, 1, 2]) array([ 6.875, 13.75 , 27.5 , 55. , 110. ])
- Parameters:
octaves (np.ndarray [shape=(n,)] or float) – octave number for each frequency
tuning (float) – Tuning deviation from A440 in (fractional) bins per octave.
bins_per_octave (int > 0) – Number of bins per octave.
- Returns:
frequencies – scalar or vector of frequencies
- Return type:
number or np.ndarray [shape=(n,)]
See also
- vasp.automatedPostprocessing.postprocessing_h5py.chroma_filters.tiny(x)[source]#
Compute the tiny-value corresponding to an input’s data type.
This is the smallest “usable” number representable in
x.dtype
(e.g., float32).This is primarily useful for determining a threshold for numerical underflow in division or multiplication operations.
- Parameters:
x (number or np.ndarray) – The array to compute the tiny-value for. All that matters here is
x.dtype
- Returns:
tiny_value – The smallest positive usable number for the type of
x
. Ifx
is integer-typed, then the tiny value fornp.float32
is returned instead.- Return type:
float
See also
numpy.finfo
Examples
For a standard double-precision floating point number:
>>> librosa.util.tiny(1.0) 2.2250738585072014e-308
Or explicitly as double-precision
>>> librosa.util.tiny(np.asarray(1e-5, dtype=np.float64)) 2.2250738585072014e-308
Or complex numbers
>>> librosa.util.tiny(1j) 2.2250738585072014e-308
Single-precision floating point:
>>> librosa.util.tiny(np.asarray(1e-5, dtype=np.float32)) 1.1754944e-38
Integer
>>> librosa.util.tiny(5) 1.1754944e-38
This script creates spectrograms, power spectral density and chromagrams from formatted matrices (.npz files)”
- vasp.automatedPostprocessing.postprocessing_h5py.create_spectrograms_chromagrams.create_spectrogram_composite(case_name: str, quantity: str, df: DataFrame, start_t: float, end_t: float, num_windows_per_sec: float, overlap_frac: float, window: str, lowcut: float, min_color: float, max_color: float, image_folder: str | Path, flow_rate_file: str | Path | None = None, amplitude_file: str | Path | None = None, power_scaled: bool = False, ylim: float | None = None) None [source]#
Create a composite spectrogram figure.
- Parameters:
case_name (str) – Path to simulation results.
quantity (str) – Quantity to postprocess.
df (pd.DataFrame) – Input dataframe.
start_t (float) – Start time for analysis.
end_t (float) – End time for analysis.
num_windows_per_sec (float) – Number of windows per second.
overlap_frac (float) – Overlap fraction for windows.
window (str) – Type of window for spectrogram.
lowcut (float) – Lowcut frequency for high-pass filter.
min_color (float) – Minimum value for the color range.
max_color (float) – Maximum value for the color range.
image_folder (str or Path) – Folder to save the images.
flow_rate_file (str or Path, optional) – File containing flow rate data.
amplitude_file (str or Path, optional) – File containing amplitude data.
power_scaled (bool, optional) – Whether to scale the power.
ylim (float, optional) – Y-axis limit for the plot.
This script creates a power spectrum plot.
- vasp.automatedPostprocessing.postprocessing_h5py.create_spectrum.create_spectrum(case_name: str, quantity: str, df, start_t: float, end_t: float, num_windows_per_sec: float, overlap_frac: float, window: str, lowcut: float, min_color: float, max_color: float, image_folder: str | Path, flow_rate_file: str | None = None, amplitude_file: str | None = None, power_scaled: bool = False) None [source]#
Create a power spectrum plot and save the results as an image and CSV file.
- Parameters:
case_name (str) – Name of the case.
quantity (str) – Type of data to be processed.
df – Input DataFrame containing relevant data.
start_t (float) – Desired start time of the output files.
end_t (float) – Desired end time of the output files.
num_windows_per_sec (float) – Number of windows per second.
overlap_frac (float) – Fraction of overlap between consecutive windows.
window (str) – Type of window function to use.
lowcut (float) – Cutoff frequency for the high-pass filter.
min_color (float) – Minimum value for the color range.
max_color (float) – Maximum value for the color range.
image_folder (str or Path) – Folder to save the spectrum image and CSV file.
flow_rate_file (str) – File name for flow rate data.
amplitude_file (str) – File name for amplitude data.
power_scaled (bool) – Whether to use power scaling in the PSD calculation.
- Returns:
Saves the spectrum plot as an image and CSV file.
- Return type:
None
This file contains helper functions for creating visualizations outside of FEniCS.
- vasp.automatedPostprocessing.postprocessing_h5py.postprocessing_common_h5py.calculate_windowed_rms(signal_array: ndarray, window_size: int, window_type: str = 'flat') ndarray [source]#
Calculate the windowed root mean squared (RMS) amplitude of a signal.
- Parameters:
signal_array (numpy.ndarray) – Input signal.
window_size (int) – Size of the window in number of timesteps.
window_type (str, optional) – Type of window function to use. Default is “flat”. Supported window types: “flat”, “tukey”, “hann”, “blackmanharris”, “flattop”.
- Returns:
Windowed RMS amplitudes.
- Return type:
numpy.ndarray
References
https://stackoverflow.com/questions/8245687/numpy-root-mean-squared-rms-smoothing-of-a-signal https://stackoverflow.com/questions/47484899/moving-average-produces-array-of-different-length
- vasp.automatedPostprocessing.postprocessing_h5py.postprocessing_common_h5py.create_checkpoint_xdmf_file(num_ts: int, time_between_files: float, start_t: float, n_elements: int, n_nodes: int, att_type: str, viz_type: str, output_folder: Path) None [source]#
Create an XDMF file for a time series visualization. This function is specifically for the data genearted by FEniCS write_checkpoint function.
- Parameters:
num_ts (int) – Number of time steps.
time_between_files (float) – Time interval between files.
start_t (float) – Starting time.
n_elements (int) – Number of elements.
n_nodes (int) – Number of nodes.
att_type (str) – Type of attribute - “Scalar”, “Vector”, or “Tensor”.
viz_type (str) – Visualization type.
output_folder (Path) – Path to the output folder.
- Returns:
None
- Raises:
ValueError – If an unsupported attribute type is provided.
Note
We assume that the function is discontinuous Galerkin and the element degree is 1.
- vasp.automatedPostprocessing.postprocessing_h5py.postprocessing_common_h5py.create_point_trace(formatted_data_folder: str, output_folder: str, point_ids: List[int], time_between_files: float, start_t: float, dvp: str) None [source]#
Create point traces for specified point IDs and save the results in CSV and PNG files.
- Parameters:
formatted_data_folder (str) – Path to the folder containing formatted data.
output_folder (str) – Path to the folder where output files will be saved.
point_ids (List[int]) – List of point IDs for which traces will be created.
time_between_files (float) – Time between files in seconds.
start_t (float) – Start time of the simulation.
dvp (str) – Type of visualization (‘v’ for velocity, ‘d’ for displacement, ‘p’ for pressure).
- Returns:
None
- vasp.automatedPostprocessing.postprocessing_h5py.postprocessing_common_h5py.create_transformed_matrix(input_path: str | Path, output_folder: str | Path, mesh_path: str | Path, case_name: str, start_t: float, end_t: float, quantity: str, fluid_domain_id: int | list[int], solid_domain_id: int | list[int], stride: int = 1) Tuple[float, dict[str, ndarray] | None, dict[str, ndarray] | None] [source]#
Create a transformed matrix from simulation data.
- Parameters:
input_path (str or Path) – Path to the input simulation data.
output_folder (str or Path) – Path to the output folder where the transformed matrix will be stored.
mesh_path (str or Path) – Path to the input mesh data.
case_name (str) – Name of the simulation case.
start_t (float) – Start time for extracting data.
end_t (float) – End time for extracting data.
quantity (str) – Quantity to extract (e.g., ‘d’ for displacement, ‘v’ for velocity).
fluid_domain_id (int or list) – ID of the fluid domain
solid_domain_id (int or list) – ID of the solid domain
stride (int) – Stride for selecting timesteps.
- Returns:
A tuple containing the time between files, dof_info_dict,
- Return type:
Tuple[float, dict[str, np.ndarray], dict[str, np.ndarray]]
- vasp.automatedPostprocessing.postprocessing_h5py.postprocessing_common_h5py.create_xdmf_file(num_ts: int, time_between_files: float, start_t: float, n_elements: int, n_nodes: int, att_type: str, viz_type: str, output_folder: Path) None [source]#
Create an XDMF file for a time series visualization.
- Parameters:
num_ts (int) – Number of time steps.
time_between_files (float) – Time interval between files.
start_t (float) – Starting time.
n_elements (int) – Number of elements.
n_nodes (int) – Number of nodes.
att_type (str) – Type of attribute - “Scalar”, “Vector”, or “Tensor”.
viz_type (str) – Visualization type.
output_folder (Path) – Path to the output folder.
- Returns:
None
- Raises:
ValueError – If an unsupported attribute type is provided.
- vasp.automatedPostprocessing.postprocessing_h5py.postprocessing_common_h5py.get_coords(mesh_path: str | Path) ndarray [source]#
Get coordinates from a mesh file.
- Parameters:
mesh_path (str or Path) – Path to the mesh file.
- Returns:
Array containing the coordinates.
- Return type:
np.ndarray
- vasp.automatedPostprocessing.postprocessing_h5py.postprocessing_common_h5py.get_domain_ids_specified_region(mesh_path: str | Path, fluid_sampling_domain_id: int, solid_sampling_domain_id: int) Tuple[ndarray, ndarray, ndarray] [source]#
Obtain node IDs for the fluid, solid, and all elements within specified regions of the input mesh.
- Parameters:
mesh_path (str or Path) – The file path of the input mesh.
fluid_sampling_domain_id (int) – Domain ID for the fluid region to be sampled.
solid_sampling_domain_id (int) – Domain ID for the solid region to be sampled.
- Returns:
Node IDs for fluid, solid, and all elements.
- Return type:
Tuple[np.ndarray, np.ndarray, np.ndarray]
- vasp.automatedPostprocessing.postprocessing_h5py.postprocessing_common_h5py.get_eig(T: ndarray) float [source]#
Analytically calculate eigenvalues for a three-dimensional tensor T with a characteristic polynomial equation of the form
lambda^3 - I1*lambda^2 + I2*lambda - I3 = 0 .
Since the characteristic polynomial is in its normal form , the eigenvalues can be determined using Cardanos formula. This algorithm is based on: “Efficient numerical diagonalization of hermitian 3 by 3 matrices” by J.Kopp, eqn 21-34, with coefficients: c2=-I1, c1 = I2, c3 = -I3).
NOTE: The method implemented here, implicitly assumes that the polynomial has only real roots, since imaginary ones should not occur in this use case.
In order to ensure eigenvalues with algebraic multiplicity of 1, the idea of numerical perturbations is adopted from “Computation of isotropic tensor functions” by C. Miehe (1993). Since direct comparisons with conditionals have proven to be very slow, not the eigenvalues but the coefficients occuring during the calculation of them are perturbated to get distinct values.
- Parameters:
T (np.ndarray) – Three-dimensional tensor.
- Returns:
First eigenvalue.
- Return type:
float
References
https://fenicsproject.discourse.group/t/hyperelastic-model-problems-on-plotting-stresses/3130/6
- vasp.automatedPostprocessing.postprocessing_h5py.postprocessing_common_h5py.get_interface_ids(mesh_path: str | Path, fluid_domain_id: int | list[int], solid_domain_id: int | list[int]) ndarray [source]#
Get the interface node ID’s between fluid and solid domains from the given mesh file.
- Parameters:
mesh_path (str or Path) – Path to the mesh file.
fluid_domain_id (int or list) – ID of the fluid domain
solid_domain_id (int or list) – ID of the solid domain
- Returns:
Array containing the interface node IDs.
- Return type:
np.ndarray
- vasp.automatedPostprocessing.postprocessing_h5py.postprocessing_common_h5py.get_sampling_constants(df: DataFrame, start_t: float, end_t: float) Tuple[float, int, float] [source]#
Calculate sampling constants from a DataFrame.
- Parameters:
df (DataFrame) – The input DataFrame.
start_t (float) – The start time of the data.
end_t (float) – The end time of the data.
- Returns:
A tuple containing the period (T), number of samples per cycle (nsamples), and sample rate (fs).
- Return type:
Tuple[float, int, float]
- Author:
Daniel Macdonald
- vasp.automatedPostprocessing.postprocessing_h5py.postprocessing_common_h5py.get_surface_topology_coords(out_file: str | Path) tuple [source]#
Get surface topology and coordinates from an output file.
- Parameters:
out_file (str or Path) – Path to the output file.
- Returns:
Tuple containing the surface topology and coordinates.
- Return type:
tuple
- vasp.automatedPostprocessing.postprocessing_h5py.postprocessing_common_h5py.read_npz_files(filepath: str | Path) DataFrame [source]#
Read data from an npz file and return it as a DataFrame.
- Parameters:
filepath (str or Path) – Path to the npz file.
- Returns:
DataFrame containing the data.
- Return type:
pd.DataFrame
This file contains helper functions for creating spectrograms.
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.butter_bandpass(lowcut: float, highcut: float, fs: float, order: int = 5, btype: str = 'band') tuple [source]#
Design a Butterworth bandpass, bandstop, highpass, or lowpass filter.
- Parameters:
lowcut (float) – Cutoff frequency for low cut.
highcut (float) – Cutoff frequency for high cut (ignored if btype is ‘highpass’).
fs (float) – Sampling frequency in samples per second.
order (int, optional) – Order of the filter. Default is 5.
btype (str, optional) – Type of filter (‘band’, ‘stop’, ‘highpass’, ‘lowpass’, or ‘bandpass’). Default is ‘band’.
- Returns:
Numerator (b) and denominator (a) coefficients of the filter.
- Return type:
tuple
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.butter_bandpass_filter(data: ndarray, lowcut: float = 25.0, highcut: float = 15000.0, fs: float = 2500.0, order: int = 5, btype: str = 'band') ndarray [source]#
Apply a Butterworth bandpass, bandstop, highpass, or lowpass filter to the input data.
- Parameters:
data (np.ndarray) – Input data to filter.
lowcut (float, optional) – Low cutoff frequency. Default is 25.0.
highcut (float, optional) – High cutoff frequency. Default is 15000.0.
fs (float, optional) – Sampling frequency. Default is 2500.0.
order (int, optional) – Order of the filter. Default is 5.
btype (str, optional) – Type of filter (‘band’, ‘stop’, ‘highpass’, ‘lowpass’). Default is ‘band’.
- Returns:
Filtered data.
- Return type:
np.ndarray
- Author:
Daniel Macdonald
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.calc_chroma_entropy(chroma: ndarray, n_chroma: int) ndarray [source]#
Calculate chroma entropy.
- Parameters:
chroma (np.ndarray) – Chromagram.
n_chroma (int) – Number of chroma bins.
- Returns:
Chroma entropy.
- Return type:
np.ndarray
- Author:
Daniel Macdonald
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.chromagram_from_spectrogram(Pxx: ndarray, fs: float, n_fft: int, n_chroma: int = 24, norm: bool | str = True) ndarray [source]#
Calculate chromagram from a spectrogram.
- Parameters:
Pxx (np.ndarray) – Input spectrogram.
fs (float) – Sampling frequency.
n_fft (int) – Number of FFT points.
n_chroma (int, optional) – Number of chroma bins. Default is 24.
norm (bool, optional) – Normalize chroma. Options are ‘max’, ‘sum’, or False for no normalization. Default is True.
- Returns:
Chromagram.
- Return type:
np.ndarray
- Author:
Daniel Macdonald
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.compute_average_spectrogram(df: DataFrame, fs: float, nWindow: int, overlapFrac: float, window: str, start_t: float, end_t: float, thresh: float, scaling: str = 'spectrum', filter_data: bool = False, thresh_method: str = 'new') tuple [source]#
Compute the average spectrogram for a DataFrame of time series data.
- Parameters:
df (pd.DataFrame) – Input DataFrame containing time series data.
fs (float) – Sampling frequency.
nWindow (int) – Number of samples per window.
overlapFrac (float) – Fraction of overlap between windows.
window (str) – Window function for spectrogram.
start_t (float) – Start time for the spectrogram.
end_t (float) – End time for the spectrogram.
thresh (float) – Threshold value for scaling.
scaling (str, optional) – Scaling for the spectrogram (‘density’ or ‘spectrum’). Default is ‘spectrum’.
filter_data (bool, optional) – Apply a Butterworth highpass filter to the data. Default is False.
thresh_method (str, optional) – Method for thresholding (‘old’, ‘log_only’, ‘new’). Default is ‘new’.
- Returns:
- Time bins (bins), frequency values (freqs), scaled Power Spectral Density matrix (Pxx_scaled),
maximum value after scaling (max_val), minimum value after scaling (min_val), and the lower threshold used for scaling.
- Return type:
tuple
- Author:
Daniel Macdonald
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.filter_time_data(df: DataFrame, fs: float, lowcut: float = 25.0, highcut: float = 15000.0, order: int = 6, btype: str = 'highpass') DataFrame [source]#
Apply a Butterworth highpass, lowpass, bandpass, or bandstop filter to the time series data in a DataFrame.
- Parameters:
df (pd.DataFrame) – Input DataFrame containing time series data.
fs (float) – Sampling frequency.
lowcut (float, optional) – Low cutoff frequency. Default is 25.0.
highcut (float, optional) – High cutoff frequency. Default is 15000.0.
order (int, optional) – Order of the filter. Default is 6.
btype (str, optional) – Type of filter (‘highpass’, ‘lowpass’, ‘bandpass’, ‘bandstop’). Default is ‘highpass’.
- Returns:
DataFrame containing filtered time series data.
- Return type:
pd.DataFrame
- Author:
Daniel Macdonald
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.find_points_in_box(x_min: float, x_max: float, y_min: float, y_max: float, z_min: float, z_max: float, coords: ndarray) ndarray [source]#
Find points within a box defined by its minimum and maximum x, y, and z coordinates.
- Parameters:
x_min (float) – Minimum x coordinate of the box.
x_max (float) – Maximum x coordinate of the box.
y_min (float) – Minimum y coordinate of the box.
y_max (float) – Maximum y coordinate of the box.
z_min (float) – Minimum z coordinate of the box.
z_max (float) – Maximum z coordinate of the box.
coords (np.ndarray) – The coordinates of mesh nodes as a 2D NumPy array with shape (n, 3).
- Returns:
Indices of points within the box.
- Return type:
np.ndarray
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.find_points_in_sphere(center: ndarray, radius: float, coords: ndarray) ndarray [source]#
Find points within a sphere defined by its center and radius.
- Parameters:
center (np.ndarray) – The center of the sphere as a 1D NumPy array with shape (3,).
radius (float) – The radius of the sphere.
coords (np.ndarray) – The coordinates of mesh nodes as a 2D NumPy array with shape (n, 3).
- Returns:
Indices of points within the sphere.
- Return type:
np.ndarray
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.get_psd(dfNearest: DataFrame, fsamp: float, scaling: str = 'density') tuple [source]#
Calculate the Power Spectral Density (PSD) of a DataFrame of signals.
- Parameters:
dfNearest (pd.DataFrame) – DataFrame containing signals in rows.
fsamp (float) – Sampling frequency of the signals.
scaling (str, optional) – Scaling applied to the PSD. Default is “density”.
- Returns:
A tuple containing the mean PSD matrix and the corresponding frequency values.
- Return type:
tuple
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.get_sampling_constants(df: DataFrame, start_t: float, end_t: float) tuple [source]#
Get sampling constants such as period, number of samples, and sample rate.
- Parameters:
df (pd.DataFrame) – Input DataFrame containing time series data.
start_t (float) – Start time of the data.
end_t (float) – End time of the data.
- Returns:
Period, number of samples, and sample rate.
- Return type:
tuple
- Author:
Daniel Macdonald
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.get_spectrogram(dfNearest: DataFrame, fsamp: float, nWindow: int, overlapFrac: float, window: str, start_t: float, end_t: float, scaling: str = 'spectrum', interpolate: bool = False) tuple [source]#
Calculates spectrogram.
- Parameters:
dfNearest (pd.DataFrame) – DataFrame of shape (num_points, num_timesteps).
fsamp (float) – Sampling frequency.
nWindow (int) – Number of samples per window.
overlapFrac (float) – Fraction of overlap between windows.
window (str) – Window function for spectrogram.
start_t (float) – Start time for the spectrogram.
end_t (float) – End time for the spectrogram.
scaling (str, optional) – Scaling for the spectrogram (‘density’ or ‘spectrum’). Default is ‘spectrum’.
interpolate (bool, optional) – Perform interpolation. Default is False.
- Returns:
Power Spectral Density matrix (Pxx_mean), frequency values (freqs), and time bins (bins).
- Return type:
tuple
- Author:
Daniel Macdonald
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.plot_chromagram(fig1: Figure, ax1: Axes, bins: ndarray, chroma: ndarray, title: str | None = None, path: str | Path | None = None, convert_a: float = 1.0, convert_b: float = 0.0, x_label: str | None = None, shading: Literal['flat', 'nearest', 'gouraud', 'auto'] | None = 'gouraud', color_range: list[float] | None = None) None [source]#
Plot a chromagram.
- Parameters:
fig1 (plt.Figure) – Matplotlib figure to plot on.
ax1 (plt.Axes) – Matplotlib axes to plot on.
bins (np.ndarray) – Time bins.
chroma (np.ndarray) – Chromagram values.
title (str, optional) – Title of the plot. Default is None.
path (str, optional) – Path to save the figure. Default is None.
convert_a (float, optional) – Conversion factor for the x-axis. Default is 1.0.
convert_b (float, optional) – Offset for the x-axis conversion. Default is 0.0.
x_label (str, optional) – Label for the x-axis. Default is None.
shading (str, optional) – Shading style for the plot. Default is ‘gouraud’.
color_range (list[float], optional) – Range for the color scale. Default is None.
- Returns:
None
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.plot_spectrogram(fig1: Figure, ax1: Axes, bins: ndarray, freqs: ndarray, Pxx: ndarray, ylim: float | None = None, title: str | None = None, convert_a: float = 0.0, convert_b: float = 0.0, x_label: str | None = None, color_range: list[float] | None = None) None [source]#
Plot a spectrogram.
- Parameters:
fig1 (plt.Figure) – Matplotlib figure to plot on.
ax1 (plt.Axes) – Matplotlib axes to plot on.
bins (np.ndarray) – Time bins.
freqs (np.ndarray) – Frequency values.
Pxx (np.ndarray) – Power spectral density values.
ylim (float, optional) – Maximum frequency to display on the y-axis.
title (str, optional) – Title of the plot. Default is None.
convert_a (float, optional) – Conversion factor for the x-axis. Default is 0.0.
convert_b (float, optional) – Offset for the x-axis conversion. Default is 0.0.
x_label (str, optional) – Label for the x-axis. Default is None.
color_range (list[float], optional) – Range for the color scale. Default is None.
- Returns:
None
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.read_command_line_spec() Namespace [source]#
Read arguments from the command line using ConfigArgParse.
- Returns:
Parsed command-line arguments.
- Return type:
Namespace
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.read_spectrogram_data(folder: str | Path, mesh_path: str | Path, save_deg: int, stride: int, start_t: float, end_t: float, n_samples: int, sampling_region: str, fluid_sampling_domain_id: int, solid_sampling_domain_id: int, fsi_region: list[float], quantity: str, interface_only: bool, component: str, point_ids: list[int], fluid_domain_id: int | list[int], solid_domain_id: int | list[int], sampling_method: str = 'RandomPoint')[source]#
Read spectrogram data and perform processing steps.
- Parameters:
folder (str or Path) – Path to simulation results.
mesh_path (str or Path) – Path to the mesh file.
save_deg (int) – Degree of mesh refinement.
stride (int) – Desired frequency of output data.
start_t (float) – Start time for data processing.
end_t (float) – End time for data processing.
n_samples (int) – Number of samples.
sampling_region (str) – Region for sampling data (“sphere”, “domain” or “box”).
fluid_sampling_domain_id (int) – Domain ID for fluid sampling (used when sampling_region=”domain”).
solid_sampling_domain_id (int) – Domain ID for solid sampling (used when sampling_region=”domain”).
fsi_region (list) – x, y, and z coordinates of sphere center and radius of the sphere (used when sampling_region=”sphere”). In case of sampling_region=”box”, the list should contain [x_min, x_max, y_min, y_max, z_min, z_max]. The box is defined by the minimum and maximum values of x, y, and z.
quantity (str) – Quantity to postprocess.
interface_only (bool) – Whether to include only interface ID’s.
component (str) – Component of the data to be visualized.
point_ids (int) – List of Point IDs (used when sampling_method=”PointList”).
sampling_method (str) – Method for sampling data (“RandomPoint”, “PointList”, or “Spatial”).
fluid_domain_id (int or list) – ID of the fluid domain
solid_domain_id (int or list) – ID of the solid domain
- Returns:
(Processed data type, DataFrame, Case name, Image folder, Hi-pass visualization folder).
- Return type:
tuple
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.shift_bit_length(x: int) int [source]#
Round up to the nearest power of 2.
- Parameters:
x (int) – Input integer.
- Returns:
The smallest power of 2 greater than or equal to the input.
- Return type:
int
- Author:
Daniel Macdonald
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.sonify_point(case_name: str, quantity: str, df, start_t: float, end_t: float, overlap_frac: float, lowcut: float, image_folder: str) None [source]#
Sonify a point in the dataframe and save the resulting audio as a WAV file.
- Parameters:
case_name (str) – Name of the case.
quantity (str) – Type of data to be sonified.
df (pd.DataFrame) – Input DataFrame containing relevant data.
start_t (float) – Start time for sonification.
end_t (float) – End time for sonification.
overlap_frac (float) – Fraction of overlap between consecutive segments.
lowcut (float) – Cutoff frequency for the high-pass filter.
image_folder (str) – Folder to save the sonified audio file.
- Returns:
Saves the sonified audio file in WAV format.
- Return type:
None
- vasp.automatedPostprocessing.postprocessing_h5py.spectrograms.spectrogram_scaling(Pxx_mean: ndarray, lower_thresh: float) tuple [source]#
Scale a spectrogram.
- Parameters:
Pxx_mean (np.ndarray) – Power Spectral Density matrix.
lower_thresh (float) – Threshold value for scaling.
- Returns:
- Scaled Power Spectral Density matrix (Pxx_scaled), maximum value after scaling (max_val),
minimum value after scaling (min_val), and the lower threshold used for scaling.
- Return type:
tuple
- Author:
Daniel Macdonald
common functions for postprocessing-mesh scripts
- vasp.automatedPostprocessing.postprocessing_mesh.postprocessing_mesh_common.parse_arguments() Namespace [source]#
Parse command line arguments.
- Returns:
Parsed command-line arguments.
- Return type:
argparse.Namespace
- vasp.automatedPostprocessing.postprocessing_mesh.separate_mesh.separate_mesh(mesh_path: Path, fluid_domain_id: int | list, solid_domain_id: int | list, view: bool = False) None [source]#
Given a mesh file that contains fluid and solid domains, this function separates the domains and saves them as separate mesh files. These domain specific mesh files are later used in the other postprocessing scripts.
- Parameters:
mesh_path (Path) – Path to the mesh file.
fluid_domain_id (int or list) – Domain ID for fluid domain.
solid_domain_id (int or list) – Domain ID for solid domain.
- Returns:
None
This script creates a refined mesh with domain markers from a specified mesh. However, the node numbering may not be the same as the output file with save_deg = 2, so the node numbering is corrected to match the output files. Currently, it only runs in serial (not parallel) due to the “adapt” function used in fenics. This mesh is later used in the “postprocessing_h5” and “postprocessing_fenics” scripts.
FSI problem scripts#
Problem file for tiny cylinder FSI simulation
- vasp.simulations.cylinder.create_bcs(DVP, mesh, boundaries, P_final, v_max_final, fsi_id, inlet_id, inlet_outlet_s_id, rigid_id, psi, F_solid_linear, **namespace)[source]#
- vasp.simulations.cylinder.post_solve(dvp_, dt, mesh, inlet_area, mu_f, rho_f, n, dsi, **namespace)[source]#
Problem file for offset stenosis FSI simulation
- vasp.simulations.offset_stenosis.create_bcs(t, DVP, mesh, boundaries, mu_f, fsi_id, inlet_id, inlet_outlet_s_id, rigid_id, psi, F_solid_linear, p_deg, FC_file, Q_mean, P_FC_File, P_mean, T_Cycle, **namespace)[source]#
- vasp.simulations.offset_stenosis.get_mesh_domain_and_boundaries(mesh_path, fsi_region, dx_f_id, fsi_id, rigid_id, outer_id, **namespace)[source]#
- vasp.simulations.offset_stenosis.post_solve(probe_points, solid_probe_points, dvp_, dt, mesh, inlet_area, dsi, mu_f, rho_f, n, **namespace)[source]#
Problem file for aneurysm FSI simulation
- vasp.simulations.aneurysm.create_bcs(t, DVP, mesh, boundaries, mu_f, fsi_id, inlet_id, inlet_outlet_s_id, rigid_id, psi, F_solid_linear, p_deg, FC_file, Q_mean, P_FC_File, P_mean, T_Cycle, **namespace)[source]#
- vasp.simulations.aneurysm.finished(d_mean, u_mean, p_mean, visualization_folder, save_solution_after_tstep, T, dt, **namespace)[source]#
- vasp.simulations.aneurysm.get_mesh_domain_and_boundaries(mesh_path, fsi_region, fsi_id, rigid_id, outer_id, **namespace)[source]#
- vasp.simulations.aneurysm.initiate(mesh_path, scale_probe, mesh, v_deg, p_deg, **namespace)[source]#
- vasp.simulations.aneurysm.post_solve(dvp_, n, dsi, dt, mesh, inlet_area, mu_f, rho_f, probe_points, t, save_solution_after_tstep, d_mean, u_mean, p_mean, **namespace)[source]#
Problem file for AVF FSI simulation
- class vasp.simulations.avf.VelInPara(t, dt, vel_t_ramp, n, dsi, mesh, interp_velocity, **kwargs)[source]#
- vasp.simulations.avf.create_bcs(DVP, mesh, boundaries, T, dt, fsi_id, inlet_id1, inlet_id2, rigid_id, psi, F_solid_linear, vel_t_ramp, p_t_ramp_start, p_t_ramp_end, p_deg, v_deg, patient_data_path, **namespace)[source]#
- vasp.simulations.avf.get_mesh_domain_and_boundaries(mesh_path, fsi_region, fsi_id, rigid_id, outer_id, **namespace)[source]#