4.5.2 pde.solvers.base module

Package that contains base classes for solvers.

Beside the abstract base class SolverBase defining the interfaces, we also provide AdaptiveSolverBase, which contains methods for adaptive solvers.

SolverBase

Base class for persistent PDE solver strategy objects.

AdaptiveSolverBase

Base class for solvers that can produce adaptive stepping functions.

ConvergenceError

Indicates that an implicit step did not converge.

class AdaptiveSolverBase(pde, *, backend='auto', adaptive=False, tolerance=0.0001)[source]

Bases: SolverBase

Base class for solvers that can produce adaptive stepping functions.

Parameters:
  • pde (PDEBase) – The partial differential equation that should be solved

  • backend (str) – The backend used for numerical operations

  • adaptive (bool) – Whether to use adaptive time stepping

  • tolerance (float) – Error tolerance for adaptive time stepping

dt_max: float = 10000000000.0

maximal time step that the adaptive solver will use

Type:

float

dt_min: float = 1e-10

minimal time step that the adaptive solver will use

Type:

float

make_stepper(state, dt=None)[source]

Create the executable stepping function produced by this solver.

Parameters:
  • state (FieldBase) – An example for the state from which the grid and other information can be extracted

  • dt (float) – Time step used (Uses SolverBase.dt_default if None). This sets the initial time step for adaptive solvers.

Returns:

Function that can be called to advance the state from time t_start to time t_end. The function call signature is (state: numpy.ndarray, t_start: float, t_end: float)

Return type:

StepperType

exception ConvergenceError[source]

Bases: RuntimeError

Indicates that an implicit step did not converge.

class SolverBase(pde, *, backend='auto')[source]

Bases: object

Base class for persistent PDE solver strategy objects.

Parameters:
  • pde (PDEBase) – The partial differential equation that should be solved

  • backend (str or BackendBase) – The backend used for numerical operations

property backend: BackendBase

The backend for this solver.

Type:

BackendBase

property backend_name: str

The name of the backend used for this solver.

Type:

str

dt_default: float = 0.001

default time step used when no initial value was specified

Type:

float

classmethod from_name(name, pde, **kwargs)[source]

Create a solver object from its registered name.

Solver classes are automatically registered when they inherit from SolverBase. Note that this also requires that the respective python module containing the solver has been loaded before it is attempted to be used.

Parameters:
  • name (str) – The name of the solver to construct

  • pde (PDEBase) – The partial differential equation that should be solved

  • **kwargs – Additional arguments for the constructor of the solver

Returns:

An instance of a subclass of SolverBase

Return type:

SolverBase

info: dict[str, Any]
make_stepper(state, dt=None)[source]

Create the executable stepping function produced by this solver.

Parameters:
  • state (FieldBase) – An example for the state from which the grid and other information can be extracted

  • dt (float) – Initial time step used (Uses SolverBase.dt_default if None)

Returns:

Function that can be called to advance the state from time t_start to time t_end. The function call signature is (state: numpy.ndarray, t_start: float, t_end: float)

Return type:

StepperType

mpi_run: bool = False

Whether this solver runs using MPI

Type:

bool

registered_solvers()[source]

Returns all solvers that are currently registered.

Returns:

a dictionary with the names of the solvers and the associated class

Return type:

dict