enrichedfem.error_estimations package
Submodules
enrichedfem.error_estimations.compare module
- class enrichedfem.error_estimations.compare.CompareMethods(error_estimations: ErrorEstimations)[source]
Bases:
objectCompareMethods class.
This class provides methods for comparing different error estimation methods (FEM, additive correction, multiplicative correction) and visualizing the results.
- Parameters:
error_estimations (ErrorEstimations) – An instance of the ErrorEstimations class.
- plot_Corr_vs_FEM_alldeg()[source]
Plot a comparison of the additive correction method against the FEM for all degrees.
This method calls plot_method_vs_FEM_alldeg with “Corr” as the method argument, generating a log-log plot of the L2 error norm as a function of the number of vertices for both methods.
- plot_Mult_vs_Add_vs_FEM_alldeg_allM(tab_M)[source]
Plot comparison of Mult, Add, and FEM for all degrees and all M values.
This method iterates through all degrees specified in self.ee.tab_degree and calls the plot_Mult_vs_Add_vs_FEM_deg_allM method for each degree, generating a series of plots comparing the three methods for all specified M values.
- Parameters:
tab_M (list) – A list of M values to use in the multiplicative error estimation.
- plot_Mult_vs_Add_vs_FEM_deg_allM(degree, tab_M)[source]
Plot a comparison of Mult, Add, and FEM for a given degree and all M values.
This method generates a log-log plot of the L2 error norm as a function of the number of vertices for the FEM, additive correction (“Add”), and multiplicative correction (“Mult”) methods, for a given degree and all specified M values.
- Parameters:
degree (int) – The degree of the finite element solution.
tab_M (list) – A list of M values to use in the multiplicative error estimation.
- plot_Mult_vs_FEM_alldeg_M(M=0.0, impose_bc=True)[source]
Plot a comparison of the multiplicative correction method against the FEM for all degrees and a given M value.
This method calls plot_method_vs_FEM_alldeg with “Mult” as the method argument and the specified M value and boundary condition flag, generating a log-log plot of the L2 error norm as a function of the number of vertices for both methods.
- Parameters:
M (float, optional) – Lifting constant. Defaults to 0.0.
impose_bc (bool, optional) – Whether to impose boundary conditions. Defaults to True.
- plot_Mult_vs_FEM_alldeg_allM(tab_M, impose_bc=True)[source]
Plot comparison of multiplicative correction against FEM for all degrees and M values.
This method iterates through a list of M values and calls the plot_Mult_vs_FEM_alldeg_M method for each value, generating a series of plots comparing the multiplicative correction method against the FEM for all degrees.
- Parameters:
tab_M (list) – A list of M values to use in the multiplicative error estimation.
impose_bc (bool, optional) – Whether to impose boundary conditions. Defaults to True.
- plot_method_vs_FEM_alldeg(method, **kwargs)[source]
Plot a comparison of a given method against the FEM for all degrees.
This method generates a log-log plot of the L2 error norm as a function of the number of vertices for the given method and the FEM, for all degrees specified in self.ee.tab_degree.
- Parameters:
method (str) – The error estimation method (“Corr” or “Mult”).
M (float) – Lifting constant. Required for “Mult” method.
impose_bc (bool) – Whether to impose boundary conditions. Required for “Mult” method.
Returns: None
- save_tab_alldeg_allM(tab_M=None)[source]
Save tables of errors and convergence factors for all degrees and M values.
This method generates and saves tables containing the errors and convergence factors for each method (FEM, Corr, Mult) for all degrees and M values specified. The tables are saved as CSV and PNG files.
- Parameters:
tab_M (list, optional) – A list of M values to consider. Defaults to None.
- save_tab_deg_allM(degree, tab_M=None)[source]
Save a table of errors and convergence factors for a given degree and all M values.
This method generates and saves a table containing the errors and convergence factors for each method (FEM, Corr, Mult) for a given degree and all specified M values. The table is saved as a CSV and PNG file.
- Parameters:
degree (int) – The degree of the finite element solution.
tab_M (list, optional) – A list of M values to consider. Defaults to None.
- class enrichedfem.error_estimations.compare.CompareMethodsDoFs(error_estimations: ErrorEstimations)[source]
Bases:
CompareMethodsMeshSizeCompareMethodsDoFs class.
This subclass of CompareMethodsMeshSize provides methods for comparing different error estimation methods (FEM, additive correction, multiplicative correction) and visualizing the results, with a focus on mesh size and precision, in particular the number of degrees of freedom (DoFs).
- get_dofs_at_given_precision_deg_allM(given_precision, degree, tab_M=None)[source]
Get the number of degrees of freedom (DoFs) for each method at a given precision.
This method calculates the required number of vertices (N) for each method to achieve a given precision, then determines the corresponding number of DoFs for each method using the calculated N values.
- Parameters:
given_precision (float) – The target precision (L2 error norm).
degree (int) – The degree of the finite element solution.
tab_M (list, optional) – A list of M values to consider for the “Mult” method. Defaults to None.
- Returns:
- A tuple containing two dictionaries: tab_N with the
estimated number of vertices (N) for each method, and tab_nb_dofs with the corresponding number of DoFs.
- Return type:
tuple
- get_total_parameters_of_net(u_theta)[source]
Get the total number of parameters in the neural network.
This method calculates and returns the total number of trainable parameters in the neural network used for the predicted solution.
- Parameters:
u_theta – The predicted solution object, containing the neural network.
- Returns:
The total number of parameters in the network.
- Return type:
int
- save_tab_given_precisions_alldeg_allM(u_theta, tab_M=None, n_params=100)[source]
Save tables of DoFs and N for given precisions, all degrees, and all M values.
This method calculates and saves tables showing the required number of vertices (N) and degrees of freedom (DoFs) for each method (FEM, Corr, Mult, and PINNs) to achieve a set of given precisions, for all degrees and all specified M values. It also calculates DoFs with network parameters and saves them. The tables are saved as CSV and PNG images.
- Parameters:
u_theta – The predicted solution, containing the neural network.
tab_M (list, optional) – A list of M values to consider for the “Mult” method. Defaults to None.
n_params (int, optional) – Number of parameters per DoF to consider for additional DoF calculation. Defaults to 100.
Returns: None
- save_tab_given_precisions_deg_allM(u_theta, degree, tab_M=None, tab_given_precision=[0.001, 0.0001], n_params=100)[source]
Save tables of DoFs and N for given precisions, degree, and all M values.
This method calculates and saves tables of the required number of vertices (N) and degrees of freedom (DoFs) for each method (FEM, Corr, Mult, and PINNs) to achieve a set of given precisions, for a specific degree and all specified M values. It also calculates DoFs with network parameters and saves them. The tables are saved as CSV and PNG images.
- Parameters:
u_theta – The predicted solution, containing the neural network.
degree (int) – The degree of the finite element solution.
tab_M (list, optional) – A list of M values to consider for the “Mult” method. Defaults to None.
tab_given_precision (list, optional) – A list of target precisions. Defaults to [1e-3, 1e-4].
n_params (int, optional) – Number of parameters per DoF to consider for additional DoF calculation. Defaults to 100.
- Returns:
- A tuple containing two pandas DataFrames: df with N and
DoFs, and df_dofs_nparams with DoFs including network parameters.
- Return type:
tuple
- class enrichedfem.error_estimations.compare.CompareMethodsMeshSize(error_estimations: ErrorEstimations)[source]
Bases:
CompareMethodsCompareMethodsMeshSize class.
This subclass of CompareMethods provides methods for comparing different error estimation methods (FEM, additive correction, multiplicative correction) and visualizing the results, with a focus on mesh size and precision.
- __get_index(tab, val)
Get the index of the first element in ‘tab’ that is less than ‘val’.
This is a private helper method used for linear interpolation. It performs a binary search-like operation to efficiently find the appropriate index.
- Parameters:
tab (list or numpy.ndarray) – A sorted array of values.
val (float) – The target value.
- Returns:
The index of the first element in ‘tab’ less than ‘val’.
- Return type:
int
- __linear_interpolation_on_x(tab, given_y)
Perform linear interpolation to estimate x for a given y.
This method performs linear interpolation on a log-log scale to estimate the value of x for a given y, based on the provided table of x and y values.
- Parameters:
tab (numpy.ndarray) – A 2D array where the first column represents x values and the second column represents y values.
given_y (float) – The target y value for which to estimate x.
- Returns:
The estimated x value.
- Return type:
float
- get_N_at_given_precision_deg_allM(given_precision, degree, tab_M=None)[source]
Estimate the number of vertices (N) needed for each method to achieve a given precision.
This method estimates the required mesh size (number of vertices) for each method (FEM, Corr, Mult) to achieve a given precision, for a given degree and optionally a range of M values (for the “Mult” method).
- Parameters:
given_precision (float) – The target precision (L2 error norm).
degree (int) – The degree of the finite element solution.
tab_M (list, optional) – A list of M values to consider for the “Mult” method. Defaults to None.
- Returns:
- A dictionary containing the estimated number of vertices (N)
for each method.
- Return type:
dict
- get_N_deg_M(method, given_precision, degree, M=None, impose_bc=True)[source]
Estimate the number of vertices (N) needed to achieved a given precision for a given method.
This method estimates the required mesh size (number of vertices) for a given method, degree, and optionally an M value (for the “Mult” method) to achieved a given precision, using linear interpolation on a log-log scale.
- Parameters:
method (str) – The error estimation method (“FEM”, “Corr”, or “Mult”).
given_precision (float) – The target precision (L2 error norm).
degree (int) – The degree of the finite element solution.
M (float, optional) – Lifting constant. Required for “Mult” method. Defaults to None.
impose_bc (bool, optional) – Whether to impose boundary conditions. Defaults to True.
- Returns:
The estimated number of vertices (N).
- Return type:
float
- save_tab_given_precisions_alldeg_allM(tab_M=None)[source]
Save tables of required N for given precisions, all degrees, and all M values.
This method calculates and saves tables showing the required number of vertices (N) for each method (FEM, Corr, Mult) to achieve a set of given precisions, for all degrees and all specified M values. The tables are saved as both CSV and PNG images.
- Parameters:
tab_M (list, optional) – A list of M values to consider for the “Mult” method. Defaults to None.
Returns: None
- save_tab_given_precisions_deg_allM(degree, tab_M=None, tab_given_precision=[0.001, 0.0001])[source]
Save a table of required N for given precisions, degree, and all M values.
This method calculates and saves a table showing the required number of vertices (N) for each method (FEM, Corr, Mult) to achieve a set of given precisions, for a specific degree and all specified M values. The table is saved as both a CSV 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” method. Defaults to None.
tab_given_precision (list, optional) – A list of target precisions (L2 error norms). Defaults to [1e-3, 1e-4].
- Returns:
The generated DataFrame containing the required N values.
- Return type:
pandas.DataFrame
enrichedfem.error_estimations.error_estimations module
- class enrichedfem.error_estimations.error_estimations.ErrorEstimations(param_num, pb_considered, **kwargs)[source]
Bases:
objectError estimates class for the FEM method and enriched approaches.
This class allows to run the error estimates for the FEM method and enriched approaches (additive and multiplicative corrections). The L2 error is computed for different degrees and number of vertices. The results are saved in csv files and can be plotted.
- Parameters:
param_num (int) – Number of the parameter to consider
pb_considered (Problem) – Problem to consider
error_degree (int, optional) – Degree of the error space. Defaults to 4.
high_degree (int, optional) – Degree of the expression space for f. Defaults to 9.
save_fig (bool, optional) – Save flag for the figures. Defaults to False.
plot_result (bool, optional) – Plot flag for the results. Defaults to False.
plot_mesh (bool, optional) – Plot flag for the mesh. Defaults to False.
tab_nb_vert (list, optional) – List of the number of vertices. Defaults to [2**i for i in range(4,9)].
tab_degree (list, optional) – List of the degrees. 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.
- read_csv(csv_file)[source]
Read a CSV file.
- Parameters:
csv_file – CSV file to read
- Returns:
DataFrame, list of h values, list of error values
- run_corr_alldeg(u_theta, new_run=False, plot_cvg=False)[source]
Run additive correction error estimates for all degrees.
This method runs the error estimates using the additive correction method (“Corr”) for all degrees specified in self.tab_degree. It calls the run_error_estimations_alldeg method with the specified parameters.
- Parameters:
u_theta – The predicted solution.
new_run (bool, optional) – Whether to force a new run even if a CSV file exists. Defaults to False.
plot_cvg (bool, optional) – Whether to plot the convergence results. Defaults to False.
Returns: None
- run_corr_deg(degree, u_theta, new_run=False)[source]
Run additive correction error estimates for a given degree.
This method runs the error estimates using the additive correction method (“Corr”) for a given degree. It calls the run_error_estimations_deg method with the specified parameters.
- Parameters:
degree (int) – The degree of the finite element solution.
u_theta – The predicted solution.
new_run (bool, optional) – Whether to force a new run even if a CSV file exists. Defaults to False.
- Returns:
- A tuple containing the DataFrame, list of h values, and list
of error values.
- Return type:
tuple
- run_error_estimations_alldeg(method, **kwargs)[source]
Run error estimates for a given method and all degrees.
This method runs the error estimates for the given method and all degrees specified in self.tab_degree. It saves the results to a CSV file and optionally plots the convergence results.
- Parameters:
method (str) – The error estimation method (“FEM”, “Corr”, or “Mult”).
**kwargs – Additional keyword arguments. These may include: plot_cvg (bool): Whether to plot the convergence results. u_theta: Network prediction. Required for “Corr” and “Mult” methods. M (float): Lifting constant. Required for “Mult” method. impose_bc (bool): Required for “Mult” method. new_run (bool): Whether to force a new run even if a CSV file exists.
Returns: None
- run_error_estimations_deg(method, degree, **kwargs)[source]
Run error estimates for a given method and degree.
This method performs error estimates using the specified method (FEM, Corr, or Mult) for a given degree. It reads results from a CSV file if available, otherwise it runs the error estimation and saves the results to a CSV file.
- Parameters:
method (str) – The error estimation method (“FEM”, “Corr”, or “Mult”).
degree (int) – The degree of the finite element solution.
new_run (bool) – Whether to force a new run even if a CSV file exists.
u_theta – Network prediction. Required for “Corr” and “Mult” methods.
M (float) – Lifting constant. Required for “Mult” method.
impose_bc (bool) – Required for “Mult” method.
- Returns:
- A tuple containing the DataFrame, list of h values, and list
of error values.
- Return type:
tuple
- run_fem_alldeg(new_run=False, plot_cvg=False)[source]
Run FEM error estimates for all degrees.
This method runs the error estimates using the FEM method for all degrees specified in self.tab_degree. It calls the run_error_estimations_alldeg method with the specified parameters.
- Parameters:
new_run (bool, optional) – Whether to force a new run even if a CSV file exists. Defaults to False.
plot_cvg (bool, optional) – Whether to plot the convergence results. Defaults to False.
Returns: None
- run_fem_deg(degree, new_run=False)[source]
Run FEM error estimates for a given degree.
This method runs the error estimates using the FEM method for a given degree. It calls the run_error_estimations_deg method with the specified parameters.
- Parameters:
degree (int) – The degree of the finite element solution.
new_run (bool, optional) – Whether to force a new run even if a CSV file exists. Defaults to False.
- Returns:
- A tuple containing the DataFrame, list of h values, and list
of error values.
- Return type:
tuple
- run_mult_alldeg_M(u_theta, M=0.0, impose_bc=True, new_run=False, plot_cvg=False)[source]
Run multiplicative correction error estimates for all degrees and a given M value.
This method runs the error estimates using the multiplicative correction method (“Mult”) for all degrees specified in self.tab_degree and a given M value. It calls the run_error_estimations_alldeg method with the specified parameters.
- Parameters:
u_theta – The predicted solution.
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 even if a CSV file exists. Defaults to False.
plot_cvg (bool, optional) – Whether to plot the convergence results. Defaults to False.
Returns: None
- run_mult_alldeg_allM(u_theta, tab_M, impose_bc=True, new_run=False, plot_cvg=False)[source]
Run multiplicative correction error estimates for all degrees and multiple M values.
This method runs the error estimates using the multiplicative correction method (“Mult”) for all degrees specified in self.tab_degree and a range of M values.
- Parameters:
u_theta – The predicted solution.
tab_M (list) – A list of M values to use in the multiplicative error estimation.
impose_bc (bool, optional) – Whether to impose boundary conditions. Defaults to True.
new_run (bool, optional) – Whether to force a new run even if a CSV file exists. Defaults to False.
plot_cvg (bool, optional) – Whether to plot the convergence results. 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 estimates for a given degree and M value.
This method runs the error estimates using the multiplicative correction method (“Mult”) for a given degree and M value. It calls the run_error_estimations_deg method with the specified parameters.
- Parameters:
degree (int) – The degree of the finite element solution.
u_theta – The predicted solution.
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 even if a CSV file exists. Defaults to False.
- Returns:
- A tuple containing the DataFrame, list of h values, and list
of error values.
- Return type:
tuple
- run_mult_deg_allM(degree, u_theta, tab_M, impose_bc=True, new_run=False)[source]
Run multiplicative correction error estimates for a given degree and multiple M values.
This method runs the error estimates using the multiplicative correction method (“Mult”) for a given degree and a range of M values.
- Parameters:
degree (int) – The degree of the finite element solution.
u_theta – The predicted solution.
tab_M (list) – A list of M values to use in the multiplicative error estimation.
impose_bc (bool, optional) – Whether to impose boundary conditions. Defaults to True.
new_run (bool, optional) – Whether to force a new run even if a CSV file exists. Defaults to False.
Returns: None