Numeric

To make validating this module for your use case, the module is shiped with a numeric solver that takes the same input format. The numeric solver is based on Finite Difference Matrix Operators.

The code for the numeric solver is from this Github repository by M.A. Zaman.

See his publication for more details:

Zaman, M.A. “Numerical Solution of the Poisson Equation Using Finite Difference Matrix Operators”, Electronics 2022, 11, 2365. https://doi.org/10.3390/electronics11152365

Usage of numeric_solve function is as follows:

from fast_poisson_solver import Solver, numeric_solve, analyze

u_num = numeric_solve(f, x_pde, y_pde, u_bc, x_bc, y_bc)

The function accepts lists, numpy arrays, or PyTorch tensors as input data. It explicitly accepts the same input as the Solver. However, the coordinates have to form a grid but the order is not important, as the function sorts them anyway.

For more details and further input variables see the full documentation below.

fast_poisson_solver.numeric_solve(f, x_pde, y_pde, u_bc, x_bc, y_bc, precision=torch.float32, verbose=0)

This function numerically solves the partial differential equation (PDE) using the provided source function, PDE coordinates, boundary condition, and boundary condition coordinates. It uses the precision specified, measures the time taken for the operation if requested, and controls the verbosity of the output.

Parameters:
ftensor/array/list

The source function for the PDE.

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.

u_bctensor/array/list

The boundary condition for the PDE.

x_bctensor/array/list

Coordinates of the boundary condition.

y_bctensor/array/list

Coordinates of the boundary condition.

precisiontorch.dtype, optional

The precision to be used for the numeric solver. Default is torch.float32.

verboseint, optional

Controls the verbosity of the output. If 0, only the solution ‘u’ is returned. If greater than 0, both the solution ‘u’ and runtime ‘delta t’ are returned. Default is 1.

Returns:
tuple
utensor

The complete numeric solution of the PDE.

tfloat

The runtime, i.e., the time it took the method to run in seconds.

References

Zaman, M.A. “Numerical Solution of the Poisson Equation Using Finite Difference Matrix Operators”, Electronics 2022, 11, 2365. https://doi.org/10.3390/electronics11152365

See also: https://github.com/zaman13/Poisson-solver-2D