enrichedfem.gains package
Submodules
enrichedfem.gains.compare module
- class enrichedfem.gains.compare.CompareGainsMethods(gains_enhanced_fem: GainsEnhancedFEM)[source]
Bases:
objectCompare gains of enhanced FEM methods.
This class compares the gains achieved by enhanced FEM methods (additive and multiplicative corrections) over standard FEM and PINNs. It reads error data from CSV files, computes gains, creates dataframes for errors and gains, and saves statistics about the gains.
- Parameters:
gains_enhanced_fem (GainsEnhancedFEM) – An instance of the GainsEnhancedFEM class, containing the error data.
- __compute_gains(df_errors)
Compute gains of enhanced methods over FEM and PINNs.
This method computes the gains of additive (“Corr”) and multiplicative (“Mult”) correction methods over standard FEM and PINNs, based on the errors provided in the input DataFrame.
- Parameters:
df_errors (pandas.DataFrame) – A DataFrame containing the errors for each method, with “method” as a level in the columns MultiIndex.
- Returns:
- A tuple containing two dictionaries: tab_gains_overFEM
with gains over FEM, and tab_gains_overPINNs with gains over PINNs.
- Return type:
tuple
- __read_errors(degree, tab_M=None)
Read error data for different methods.
This method reads error data from CSV files for FEM, PINNs, additive correction (“Corr”), and multiplicative correction (“Mult”) methods for a given degree and a list of M values. It raises FileNotFoundError if any of the required files are not found.
- Parameters:
degree (int) – The degree of the finite element solution.
tab_M (list, optional) – A list of M values to consider for the “Mult” methods. Defaults to None.
- Returns:
- A tuple containing a dictionary of error arrays for each
method and a list of mesh sizes (h).
- Return type:
tuple
- Raises:
FileNotFoundError – If any of the required error files are not found.
- create_dataframes_alldeg_allM(tab_M=None)[source]
Create DataFrames of errors and gains for all degrees and all M values.
This method creates and saves DataFrames of errors and gains for all degrees specified in self.gef.tab_degree and all specified M values. It calls the create_dataframes_deg_allM method for each degree.
- Parameters:
tab_M (list, optional) – A list of M values to consider for the “Mult” methods. Defaults to None.
Returns: None
- create_dataframes_deg_allM(degree, tab_M=None)[source]
Create DataFrames of errors and gains for a given degree and all M values.
This method creates two pandas DataFrames: one for errors and one for gains, for a given degree and all specified M values. The error DataFrame contains the L2 errors for each method (FEM, PINNs, Corr, Mult, Mult_weak), while the gains DataFrame contains the gains of enhanced methods over FEM and PINNs. Both DataFrames are saved to CSV files.
- Parameters:
degree (int) – The degree of the finite element solution.
tab_M (list, optional) – A list of M values to consider for the “Mult” methods. Defaults to None.
- Returns:
The DataFrame of gains.
- Return type:
pandas.DataFrame
- create_dferrors_deg_allM(degree, tab_M=None)[source]
Create a DataFrame of errors for a given degree and all M values.
This method reads error data for different methods (FEM, PINNs, Corr, Mult, Mult_weak) from CSV files, and constructs a pandas DataFrame where each row represents a parameter sample and each column represents a method, mesh size, and mesh size (h). The DataFrame is then saved to a CSV file.
- Parameters:
degree (int) – The degree of the finite element solution.
tab_M (list, optional) – A list of M values to consider for the “Mult” methods. Defaults to None.
- Returns:
The DataFrame of errors.
- Return type:
pandas.DataFrame
- create_params_str()[source]
Create string representations of parameter sets.
This method generates a list of strings, where each string represents a set of parameters used in the problem. The parameters are rounded to two decimal places and separated by commas within each string.
- Returns:
A list of strings, each representing a parameter set.
- Return type:
list
- save_stats_alldeg_allM(tab_M=None)[source]
Save statistics of gains for all degrees and all M values.
This method computes and saves statistics (min, max, mean, std) of the gains of enhanced methods over FEM and PINNs for all degrees specified in self.gef.tab_degree and all specified M values. It calls the save_stats_deg_allM method for each degree.
- Parameters:
tab_M (list, optional) – A list of M values to consider for the “Mult” methods. Defaults to None.
Returns: None
- save_stats_deg_allM(degree, tab_M=None)[source]
Save statistics of gains for a given degree and all M values.
This method computes and saves statistics (min, max, mean, std) of the gains of enhanced methods (Corr, Mult, Mult_weak) over FEM and PINNs for a given degree and all specified M values. The statistics are saved as a CSV file and a PNG image.
- Parameters:
degree (int) – The degree of the finite element solution.
tab_M (list, optional) – A list of M values to consider for the “Mult” methods. Defaults to None.
- Returns:
The DataFrame containing the rounded statistics.
- Return type:
pandas.DataFrame
enrichedfem.gains.gains module
- class enrichedfem.gains.gains.GainsEnhancedFEM(n_params, pb_considered, **kwargs)[source]
Bases:
objectCalculate and analyze the gains of enhanced FEM methods.
This class calculates and analyzes the gains obtained by using enhanced FEM methods (additive and multiplicative corrections) compared to standard FEM and PINNs. It computes errors for different methods, degrees, and mesh sizes, and provides functionalities to save and analyze the results.
- Parameters:
n_params (int) – The number of parameter samples to consider.
pb_considered – The problem being considered.
repo_dir (str) – The repository directory. Defaults to “./”.
high_degree (int) – The highest degree of the finite element solution. Defaults to 10.
error_degree (int) – The degree of the error space. Defaults to 4.
tab_nb_vert (list) – A list of number of vertices to consider. Defaults to [20, 40].
tab_degree (list) – A list of degrees to consider. Defaults to [1, 2, 3].
- __infos_from_problem()
Extract problem information.
This method extracts information about the problem, such as dimension, testcase, version, parameters, and solver type, from the pb_considered attribute and stores them as attributes of the class. It also generates random parameters within the problem’s parameter domain.
- read_csv(csv_file)[source]
Read error data from a CSV file.
This method reads error data from a CSV file generated by the run_errors_deg method. It extracts the mesh sizes (h), errors for each parameter sample, and number of vertices.
- Parameters:
csv_file (str) – The path to the CSV file.
- Returns:
- A tuple containing the DataFrame, a list of mesh sizes (h),
and a NumPy array of errors for each parameter sample.
- Return type:
tuple
- run_corr_alldeg(u_theta, new_run=False)[source]
Run additive correction error calculations for all degrees.
This method runs the error calculations for the additive correction method (“Corr”) for all degrees specified in self.tab_degree, using the run_errors_alldeg method.
- Parameters:
u_theta – The predicted solution from the PINNs model.
new_run (bool, optional) – Whether to force a new run. Defaults to False.
Returns: None
- run_corr_deg(degree, u_theta, new_run=False)[source]
Run additive correction error calculations for a given degree.
This method runs the error calculations for the additive correction method (“Corr”) for a given degree, using the run_errors_deg method.
- Parameters:
degree (int) – The degree of the finite element solution.
u_theta – The predicted solution from the PINNs model.
new_run (bool, optional) – Whether to force a new run. Defaults to False.
- Returns:
A tuple containing the DataFrame, a list of mesh sizes (h), and a NumPy array of errors for each parameter sample.
- Return type:
tuple
- run_errors_alldeg(method, **kwargs)[source]
Run error calculations for a given method and all degrees.
This method calculates the L2 errors for a given method (FEM, PINNs, “Corr”, or “Mult”) and all degrees specified in self.tab_degree, for multiple parameter samples and mesh sizes. It calls the run_errors_deg method for each degree.
- Parameters:
method (str) – The error estimation method. Should be one of “FEM”, “PINNs”, “Corr”, or “Mult”.
**kwargs – Additional keyword arguments. These may include: new_run (bool): Whether to force a new run even if a CSV file exists. Defaults to False. u_theta: The predicted solution (required for “Corr” and “Mult”). M (float): Lifting constant (required for “Mult”). impose_bc (bool): Whether to impose boundary conditions (required for “Mult”).
Returns: None
- run_errors_deg(method, degree, **kwargs)[source]
Run error calculations for a given method and degree.
This method calculates the L2 errors for a given method (FEM, PINNs, additive correction “Corr”, or multiplicative correction “Mult”) and degree, for sets of parameter and given mesh sizes. The results are saved to a CSV file.
- Parameters:
method (str) – The error estimation method. Should be one of “FEM”, “PINNs”, “Corr”, or “Mult”.
degree (int) – The degree of the finite element solution.
**kwargs – Additional keyword arguments. These may include: new_run (bool): Whether to force a new run even if a CSV file exists. Defaults to False. u_theta: The predicted solution (required for “Corr” and “Mult”). M (float): Lifting constant (required for “Mult”). impose_bc (bool): Whether to impose boundary conditions (required for “Mult”).
- Returns:
- A tuple containing the DataFrame of errors, a list of mesh
sizes (h), and a NumPy array of errors for each parameter sample.
- Return type:
tuple
- run_fem_alldeg(new_run=False)[source]
Run FEM error calculations for all degrees.
This method runs the error calculations for the standard FEM for all degrees specified in self.tab_degree, using the run_errors_alldeg method.
- Parameters:
new_run (bool, optional) – Whether to force a new run. Defaults to False.
Returns: None
- run_fem_deg(degree, new_run=False)[source]
Run FEM error calculations for a given degree.
This method runs the error calculations for the standard FEM for a given degree, using the run_errors_deg method.
- Parameters:
degree (int) – The degree of the finite element solution.
new_run (bool, optional) – Whether to force a new run. Defaults to False.
- Returns:
A tuple containing the DataFrame, a list of mesh sizes (h), and a NumPy array of errors for each parameter sample.
- Return type:
tuple
- run_mult_alldeg_M(u_theta, M=0.0, impose_bc=True, new_run=False)[source]
Run multiplicative correction error calculations for all degrees and a given M value.
This method runs the error calculations for the multiplicative correction method (“Mult”) for all degrees specified in self.tab_degree and a given M value, using the run_errors_alldeg method.
- Parameters:
u_theta – The predicted solution from the PINNs model.
M (float, optional) – Lifting constant. Defaults to 0.0.
impose_bc (bool, optional) – Whether to impose boundary conditions. Defaults to True.
new_run (bool, optional) – Whether to force a new run. Defaults to False.
Returns: None
- run_mult_alldeg_allM(u_theta, tab_M, impose_bc=True, new_run=False)[source]
Run multiplicative correction error calculations for all degrees and multiple M values.
This method runs the error calculations for the multiplicative correction method (“Mult”) for all degrees specified in self.tab_degree and a list of M values. It calls the run_mult_alldeg_M method for each M value.
- Parameters:
u_theta – The predicted solution from the PINNs model.
tab_M (list) – A list of M values to consider.
impose_bc (bool, optional) – Whether to impose boundary conditions. Defaults to True.
new_run (bool, optional) – Whether to force a new run. Defaults to False.
Returns: None
- run_mult_deg_M(degree, u_theta, M=0.0, impose_bc=True, new_run=False)[source]
Run multiplicative correction error calculations for a given degree and M value.
This method runs the error calculations for the multiplicative correction method (“Mult”) for a given degree and M value, using the run_errors_deg method.
- Parameters:
degree (int) – The degree of the finite element solution.
u_theta – The predicted solution from the PINNs model.
M (float, optional) – Lifting constant. Defaults to 0.0.
impose_bc (bool, optional) – Whether to impose boundary conditions. Defaults to True.
new_run (bool, optional) – Whether to force a new run. Defaults to False.
- Returns:
A tuple containing the DataFrame, a list of mesh sizes (h), and a NumPy array of errors for each parameter sample.
- Return type:
tuple
- run_mult_deg_allM(degree, u_theta, tab_M, impose_bc=True, new_run=False)[source]
Run multiplicative correction error calculations for a given degree and multiple M values.
This method runs the error calculations for the multiplicative correction method (“Mult”) for a given degree and a list of M values. It calls the run_mult_deg_M method for each M value.
- Parameters:
degree (int) – The degree of the finite element solution.
u_theta – The predicted solution from the PINNs model.
tab_M (list) – A list of M values to consider.
impose_bc (bool, optional) – Whether to impose boundary conditions. Defaults to True.
new_run (bool, optional) – Whether to force a new run. Defaults to False.
Returns: None
- run_pinns_alldeg(u_theta, new_run=False)[source]
Run PINNs error calculations for all degrees.
This method runs the error calculations for the PINNs method for all degrees specified in self.tab_degree, using the run_errors_alldeg method.
- Parameters:
u_theta – The predicted solution from the PINNs model.
new_run (bool, optional) – Whether to force a new run. Defaults to False.
Returns: None
- run_pinns_deg(degree, u_theta, new_run=False)[source]
Run PINNs error calculations for a given degree.
This method runs the error calculations for the PINNs method for a given degree, using the run_errors_deg method.
- Parameters:
degree (int) – The degree of the finite element solution.
u_theta – The predicted solution from the PINNs model.
new_run (bool, optional) – Whether to force a new run. Defaults to False.
- Returns:
A tuple containing the DataFrame, a list of mesh sizes (h), and a NumPy array of errors for each parameter sample.
- Return type:
tuple