Plotting

This module ships with two functions for plotting. One offers a visual comparison with the numeric solution and one to just display the predicted solution.

Usage of plot_comparison function for comparing the machine learning and the numeric solution is as follows:

from fast_poisson_solver import Solver, numeric_solve, plot_comparison

solver = Solver()
solver.precompute(x_pde, y_pde, x_bc, y_bc)
u_ml, u_ml_pde, u_ml_bc, f_ml, t_ml = solver.solve(f, u_bc)
u_num = numeric_solve(f, x_pde, y_pde, u_bc, x_bc, y_bc)

plot_comparison(x_pde, y_pde, x_bc, y_bc, u_pred, f, f_pred, u_num)

Usage of plot function for displaying the machine learning solution is as follows:

from fast_poisson_solver import Solver, numeric_solve, plot

solver = Solver()
solver.precompute(x_pde, y_pde, x_bc, y_bc)
u_ml, u_ml_pde, u_ml_bc, f_ml, t_ml = solver.solve(f, u_bc)
u_num = numeric_solve(f, x_pde, y_pde, u_bc, x_bc, y_bc)

plot(x_pde, y_pde, x_bc, y_bc, u_pred, f, f_pred)

Both function offer the possibility to safe the plot or turning showing the plot off.

See the detailed documentation below for more information’s.

fast_poisson_solver.plot_comparison(x_pde, y_pde, x_bc, y_bc, u_pred, f, f_pred, u_num, grid=False, save=False, save_path=None, name=None, show=True, show_points=False)

This function is used to plot and compare the numeric solution, the predicted Machine Learning solution, and the residual between the two. It also shows the true source function, the predicted source function, and the residual between these two.

Parameters:
x_pdetensor/array/list

Coordinates that lie inside the domain and define the behavior of the PDE.

y_pdetensor/array/list

Coordinates that lie inside the domain and define the behavior of the PDE.

x_bctensor/array/list

Coordinates of the boundary condition.

y_bctensor/array/list

Coordinates of the boundary condition.

u_predtensor/array/list

The predicted solution of the PDE using Machine Learning.

ftensor/array/list

The true source function for the PDE.

f_predtensor/array/list

The predicted source function for the PDE.

u_numtensor/array/list

The numeric solution of the PDE.

gridbool, optional

If True, the data is arranged into a grid and plotted as an image. If False, tricontourf is used to create a contour plot. Default is False.

savebool, optional

Whether to save the image. The image is saved in both .pdf and .png formats. Default is False.

save_pathstr, optional

Path where the image will be saved. Used only if save is True. Default is None.

namestr, optional

Name of the image file. Used only if save is True. Default is None.

showbool, optional

Whether to display the plot. Default is False.

show_points: bool, optional

Whether to show the points of the data. Default is False.

fast_poisson_solver.plot(x_pde, y_pde, x_bc, y_bc, u_pred, f, f_pred, grid=False, save=False, save_path=None, name=None, show=True, show_points=False)

This function is used to plot the predicted Machine Learning solution of the PDE, the true source function, and the predicted source function.

Parameters:
x_pdetensor/array/list

Coordinates that lie inside the domain and define the behavior of the PDE.

y_pdetensor/array/list

Coordinates that lie inside the domain and define the behavior of the PDE.

x_bctensor/array/list

Coordinates of the boundary condition.

y_bctensor/array/list

Coordinates of the boundary condition.

u_predtensor/array/list

The predicted solution of the PDE using Machine Learning.

ftensor/array/list

The true source function for the PDE.

f_predtensor/array/list

The predicted source function for the PDE.

gridbool, optional

If True, the data is arranged into a grid and plotted as an image. If False, tricontourf is used to create a contour plot. Default is False.

savebool, optional

Whether to save the image. The image is saved in both .pdf and .png formats. Default is False.

save_pathstr, optional

Path where the image will be saved. Used only if save is True. Default is None.

namestr, optional

Name of the image file. Used only if save is True. Default is None.

showbool, optional

Whether to display the plot. Default is False.

show_points: bool, optional

Whether to show the points used to train the model. Default is False.