HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
Functions | Variables
convergence_analysis Namespace Reference

Functions

 get_available_error_types ()
 
 validate_error_selection (selected_errors)
 
 parse_timehistory_file (filename)
 
 compute_energy_error (file_data)
 
 extract_error_arrays (parsed_files)
 
 calculate_convergence_rate (mesh_sizes, errors)
 
 extract_simulation_info (parsed_files)
 
 create_convergence_plot (error_arrays, sim_info, selected_error_types, output_file='convergence_plot.png')
 
 generate_latex_plot (error_arrays, sim_info, selected_error_types, output_file='convergence_plot.tex')
 
 generate_latex_table (error_arrays, sim_info, selected_error_types, output_file='convergence_table.tex')
 
 main ()
 

Variables

dict ALL_ERROR_TYPES
 

Detailed Description

Convergence Analysis Script for HHO-NSA Simulation Data - Enhanced Version with Error Selection
Focus: Read files, extract error quantities, and generate plots/tables for k=0 simulations
Only considers energy-related errors: Energy, L2density, L2velocity, UPWdensity, H1velocity

NEW FEATURE: Ability to select which error types to include in plots and tables

Output options:
- PNG/PDF plots (matplotlib)
- LaTeX table (for inclusion in documents)
- LaTeX plot (pgfplots, can be compiled standalone or included)

Function Documentation

◆ calculate_convergence_rate()

convergence_analysis.calculate_convergence_rate (   mesh_sizes,
  errors 
)
Calculate convergence rate using least squares fit on log-log data.

Parameters:
mesh_sizes (array): Array of mesh sizes
errors (array): Array of corresponding errors

Returns:
tuple: (rate, constant) where rate is the convergence rate and constant is the fitting constant

◆ compute_energy_error()

convergence_analysis.compute_energy_error (   file_data)
Compute the energy error norm and its components for a single simulation file.

Energy = sqrt(L2density + L2velocity + UPWdensity + H1velocity)
where:
- L2density = max(L2_density_errors^2) over all time steps
- L2velocity = max(L2_velocity_errors^2) over all time steps  
- UPWdensity = sum over time steps of dt * upwind_density_errors^2
- H1velocity = sum over time steps of dt * viscosity * h1_velocity_errors^2

Parameters:
file_data (dict): Dictionary from parse_timehistory_file containing all_data

Returns:
dict: Dictionary containing all energy components and total energy

◆ create_convergence_plot()

convergence_analysis.create_convergence_plot (   error_arrays,
  sim_info,
  selected_error_types,
  output_file = 'convergence_plot.png' 
)
Create convergence plot with selected energy error types only.

Parameters:
error_arrays (dict): Dictionary containing error arrays
sim_info (dict): Simulation info for title
selected_error_types (dict): Dictionary of selected error types to plot
output_file (str): Output filename for the plot

◆ extract_error_arrays()

convergence_analysis.extract_error_arrays (   parsed_files)
Extract arrays of relevant errors from multiple parsed files.
Since we only work with k=0, no need to group by degree.
Only extracts energy-related errors.

Parameters:
parsed_files (list): List of dictionaries from parse_timehistory_file

Returns:
dict: Dictionary containing error arrays

◆ extract_simulation_info()

convergence_analysis.extract_simulation_info (   parsed_files)
Extract simulation info for titles (mesh type and time step).

Parameters:
parsed_files (list): List of parsed file data

Returns:
dict: Dictionary with mesh_type and time_step

◆ generate_latex_plot()

convergence_analysis.generate_latex_plot (   error_arrays,
  sim_info,
  selected_error_types,
  output_file = 'convergence_plot.tex' 
)
Generate LaTeX document with pgfplots for the convergence plot.

Parameters:
error_arrays (dict): Dictionary containing error arrays
sim_info (dict): Simulation info for title
selected_error_types (dict): Dictionary of selected error types to plot
output_file (str): Output filename for the LaTeX plot

◆ generate_latex_table()

convergence_analysis.generate_latex_table (   error_arrays,
  sim_info,
  selected_error_types,
  output_file = 'convergence_table.tex' 
)
Generate LaTeX table with convergence rates and error values.
Only includes selected energy-related errors.

Parameters:
error_arrays (dict): Dictionary containing error arrays
sim_info (dict): Simulation info for title
selected_error_types (dict): Dictionary of selected error types to include
output_file (str): Output filename for the LaTeX table

◆ get_available_error_types()

convergence_analysis.get_available_error_types ( )
Return list of available error type names for user selection.

◆ main()

convergence_analysis.main ( )
Main function with post-treatment options for k=0 simulations.

◆ parse_timehistory_file()

convergence_analysis.parse_timehistory_file (   filename)
Parse a single timehistory file and extract relevant quantities.

Parameters:
filename (str): Path to the timehistory file

Returns:
dict: Dictionary containing extracted data

◆ validate_error_selection()

convergence_analysis.validate_error_selection (   selected_errors)
Validate user's error type selection.

Parameters:
selected_errors (list or None): List of user-selected error type names, or None if not specified

Returns:
dict: Dictionary of valid error types to use

Variable Documentation

◆ ALL_ERROR_TYPES

dict convergence_analysis.ALL_ERROR_TYPES
Initial value:
1= {
2 'energy': {'key': 'energy_errors', 'name': 'Energy Norm', 'color': '#1f77b4', 'marker': 'o'},
3 'l2density': {'key': 'energy_l2density', 'name': 'Energy L2 Density', 'color': '#ff7f0e', 'marker': 's'},
4 'l2velocity': {'key': 'energy_l2velocity', 'name': 'Energy L2 Velocity', 'color': '#2ca02c', 'marker': '^'},
5 'upwdensity': {'key': 'energy_upwdensity', 'name': 'Energy UPW Density', 'color': '#d62728', 'marker': 'v'},
6 'h1velocity': {'key': 'energy_h1velocity', 'name': 'Energy H1 Velocity', 'color': '#9467bd', 'marker': 'D'}
7}