Partial Differential Equations
This module contains class for solving Partial Differential Equations (PDE) with Dirichlet, Neumann and Robin Boundary Conditions.
- class findiff.pde.BoundaryConditions(shape)
Represents boundary conditions for a PDE.
Supports Dirichlet, Neumann and Robin (mixed) boundary conditions.
- Dirichlet:
bc[index] = value- Neumann:
bc[index] = (diff_operator, value)- Robin (\(\alpha u + \beta \partial u / \partial n = g\)):
bc[index] = (alpha, diff_operator, beta, value)
Alternatively, Robin BCs can be specified using the operator-tuple form
bc[index] = (alpha * Identity() + beta * diff_operator, value).Initializes the BoundaryCondition object.
The BoundaryCondition objects needs information about the grid on which to solve the PDE, specifically the shape of the (equidistant) grid.
Parameters
- shape: tuple of ints
the number of grid points in each dimension
- class findiff.pde.PDE(lhs, rhs, bcs)
Representation of a partial differential equation.
Initializes the PDE.
You need to specify the left hand side (lhs) in terms of derivatives as well as the right hand side in terms of an array.
Parameters
- lhs: FinDiff object or combination of FinDiff objects
the left hand side of the PDE
- rhs: numpy.ndarray
the right hand side of the PDE
- bcs: BoundaryConditions
the boundary conditions for the PDE
- solve(solver=None, **solver_options)
Solves the PDE.
Parameters
- solverstr, callable, or None
Which linear solver to use.
Noneor'direct': usescipy.sparse.linalg.spsolve(default, backward compatible).'cg': Conjugate Gradient (requires symmetric positive definite system).'gmres': Generalized Minimal Residual (general systems).'bicgstab': BiConjugate Gradient Stabilized (general non-symmetric systems).'lgmres': LGMRES variant of GMRES.'minres': Minimal Residual (symmetric indefinite systems).A callable with signature
f(A, b, **kw) -> xorf(A, b, **kw) -> (x, info). If the callable returns a 2-tuple the second element is treated as a convergence flag (0 = success).
- **solver_options
Additional keyword arguments passed to the iterative solver. Common options include:
rtol(float): Relative convergence tolerance.maxiter(int): Maximum number of iterations.x0(ndarray): Initial guess for the solution.preconditioner(str or LinearOperator): If'ilu', an incomplete LU preconditioner is built automatically. Otherwise pass ascipy.sparse.linalg.LinearOperatorto use as the preconditionerM.
Returns
- outnumpy.ndarray
Array with the solution of the PDE.
Raises
- RuntimeError
If an iterative solver fails to converge.
- ValueError
If an unknown solver name is given or if solver_options are passed with the direct solver.