Solver

The Solver class is the core component of the fast_poisson_solver package, designed to efficiently solve Poisson’s equation with numerous configurations.

from fast_poisson_solver import Solver
solver = Solver(device='cuda:0', precision=torch.float32, verbose=False,
                use_weights=True, compile_model=True, lambdas_pde=None, seed=0)

The Solver class is initialized with parameters to specify the computational device (‘cpu’ or ‘cuda’), precision of computation (torch.float32 or torch.float64), verbosity of logs, usage of pre-trained or random weights, compilation of the network model for faster inference, weights for the PDE part in the loss term, and seed for generating random numbers.

The precompute method is then used to prepare the data for the solver based on provided coordinates. This step can be performed once for multiple different source functions and boundary condition values.

solver.precompute(x_pde, y_pde, x_bc, y_bc)

The solve method solves the Poisson equation with the provided source function and boundary condition.

u_ml, u_ml_pde, u_ml_bc, f_ml, t_ml = solver.solve(f, u_bc)

For more complex usage scenarios, such as managing computation resources or integrating with other PyTorch-based workflows, the Solver class offers advanced customization options. For instance, the precompute method includes save and load parameters to control the storage and retrieval of precomputed data.

solver.precompute(x_pde, y_pde, x_bc, y_bc, name='my_precomputation', save=True, load=False)

For a detailed understanding of the Solver class, its methods, and their parameters, please refer to the detailed documentation below.

class fast_poisson_solver.Solver(device='cuda', precision=torch.float32, verbose=False, use_weights=True, compile_model=True, lambdas_pde=None, seed=0)

This class represents the main solver used for fast Poisson equation solving. It is a key component of the fast_poisson_solver package.

Parameters:
devicestr, optional

Specifies the device where the computations will be performed. This should be a valid PyTorch device string such as ‘cuda’ for GPU processing or ‘cpu’ for CPU processing. Default is ‘cuda’.

precisiontorch.dtype, optional

This determines the precision of the computation. This should be a valid PyTorch data type such as torch.float32 or torch.float64. Default is torch.float32.

verbosebool, optional

When set to True, enables the printing of detailed logs during computation. Default is False.

use_weightsbool, optional

Determines whether the network uses pre-trained weights or random weights. If True, the network uses pre-trained weights. Default is True.

compile_modelbool, optional

Specifies whether the network model is compiled for faster inference. If False, the model won’t be compiled. Default is True.

lambdas_pdelist of float, optional

A list that weights the influence of the PDE part in the loss term. If None, default weight 1e-12 will be used. Default is None.

seedint, optional

This parameter sets the seed for generating random numbers, which helps in achieving deterministic results. Default is 0.

Methods

precompute(x_pde, y_pde, x_bc, y_bc[, name, ...])

This method is used for precomputing of the data based on the given coordinates.

solve(f, bc)

This method is used to solve the PDE with the provided source function and boundary condition.

precompute(x_pde, y_pde, x_bc, y_bc, name=None, save=False, load=False)

This method is used for precomputing of the data based on the given coordinates.

Parameters:
x_pdetensor/array/list

Coordinates that lie inside the domain and define the behavior of the partial differential equation (PDE).

y_pdetensor/array/list

Coordinates that lie inside the domain and define the behavior of the partial differential equation (PDE).

x_bctensor/array/list

Coordinates of the boundary condition.

y_bctensor/array/list

Coordinates of the boundary condition.

namestr, optional

Name used for saving or loading the precomputed data. If no name is provided, the default name will be used. Default is None.

savebool, optional

Specifies whether the precomputed data should be saved. If True, the data will be saved using the provided name. Default is True.

loadbool, optional

Specifies whether the precomputed data with the provided name should be loaded. If True, the method will attempt to load the data with the given name. Default is True.

solve(f, bc)

This method is used to solve the PDE with the provided source function and boundary condition.

Parameters:
ftensor/array/list

The source function for the PDE.

bctensor/array/list

The boundary condition for the PDE.

Returns:
tuple

The tuple contains the following elements:

u_predtensor

The complete solution of the PDE.

u_pde_predtensor

The solution of the PDE inside the domain.

u_bc_predtensor

The solution for the boundary condition.

f_predtensor

The predicted source function.

runtimefloat

The time it took the method to run in seconds.