4.4 pde.solvers package

Solvers define how a PDE is solved, i.e., how the initial state is advanced in time.

Controller

Class controlling a simulation.

ExplicitSolver

Various explicit PDE solvers.

ExplicitMPISolver

Various explicit PDE solve using MPI.

ImplicitSolver

Implicit (backward) Euler PDE solver.

CrankNicolsonSolver

Crank-Nicolson solver.

AdamsBashforthSolver

Explicit Adams-Bashforth multi-step solver.

ScipySolver

PDE solver using scipy.integrate.solve_ivp().

registered_solvers

Returns all solvers that are currently registered.

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

Bases: SolverBase

Explicit Adams-Bashforth multi-step solver.

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

  • backend (str) – Determines how the function is created. Accepted values are ‘numpy` and ‘numba’. Alternatively, ‘auto’ lets the code decide for the most optimal backend.

name = 'adams–bashforth'
class Controller(solver, t_range, tracker='auto')[source]

Bases: object

Class controlling a simulation.

The controller calls a solver to advance the simulation into the future and it takes care of trackers that analyze and modify the state periodically. The controller also handles errors in the simulations and the trackers, as well as user-induced interrupts, e.g., by hitting Ctrl-C or Cmd-C to cause a KeyboardInterrupt. In case of problems, the Controller writes additional information into diagnostics, which can help to diagnose problems.

Parameters:
  • solver (SolverBase) – Solver instance that is used to advance the simulation in time

  • t_range (float or tuple) – Sets the time range for which the simulation is run. If only a single value t_end is given, the time range is assumed to be [0, t_end].

  • tracker (TrackerCollectionDataType) – Defines trackers that process the state of the simulation at specified times. A tracker is either an instance of TrackerBase or a string identifying a tracker (possible identifiers can be obtained by calling get_named_trackers()). Multiple trackers can be specified as a list. The default value auto checks the state for consistency (tracker ‘consistency’) and displays a progress bar (tracker ‘progress’) when tqdm is installed. More general trackers are defined in trackers, where all options are explained in detail. In particular, the time points where the tracker analyzes data can be chosen when creating a tracker object explicitly.

diagnostics: dict[str, Any]

diagnostic information (available after simulation finished)

Type:

dict

run(initial_state, dt=None)[source]

Run the simulation.

Diagnostic information about the solver are available in the diagnostics property after this function has been called.

Parameters:
  • initial_state (FieldBase) – The initial state of the simulation. This state will be copied and thus not modified by the simulation. Instead, the final state will be returned and trackers can be used to record intermediate states.

  • dt (float) – Time step of the chosen stepping scheme. If None, a default value based on the stepper will be chosen.

Returns:

The state at the final time point. If multiprocessing is used, only the main node will return the state. All other nodes return None.

Return type:

TState | None

property t_range: tuple[float, float]

start and end time of the simulation

Type:

tuple

class CrankNicolsonSolver(pde, *, maxiter=100, maxerror=0.0001, explicit_fraction=0, backend='auto')[source]

Bases: SolverBase

Crank-Nicolson solver.

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

  • maxiter (int) – The maximal number of iterations per step

  • maxerror (float) – The maximal error that is permitted in each step

  • explicit_fraction (float) – Hyperparameter determinig the fraction of explicit time stepping in the implicit step. explicit_fraction == 0 is the simple Crank-Nicolson scheme, while explicit_fraction == 1 reduces to the explicit Euler method. Intermediate values can improve convergence.

  • backend (str) – Determines how the function is created. Accepted values are ‘numpy` and ‘numba’. Alternatively, ‘auto’ lets the code decide for the most optimal backend.

name = 'crank-nicolson'
class ExplicitSolver(pde, scheme='euler', *, backend='auto', adaptive=False, tolerance=0.0001)[source]

Bases: AdaptiveSolverBase

Various explicit PDE solvers.

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

  • scheme (str) – Defines the explicit scheme to use. Supported values are ‘euler’ and ‘runge-kutta’ (or ‘rk’ for short).

  • backend (str) – Determines how the function is created. Accepted values are ‘numpy` and ‘numba’. Alternatively, ‘auto’ lets the code decide for the most optimal backend.

  • adaptive (bool) – When enabled, the time step is adjusted during the simulation using the error tolerance set with tolerance.

  • tolerance (float) – The error tolerance used in adaptive time stepping. This is used in adaptive time stepping to choose a time step which is small enough so the truncation error of a single step is below tolerance.

name = 'explicit'
class ImplicitSolver(pde, *, maxiter=100, maxerror=0.0001, backend='auto')[source]

Bases: SolverBase

Implicit (backward) Euler PDE solver.

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

  • maxiter (int) – The maximal number of iterations per step

  • maxerror (float) – The maximal error that is permitted in each step

  • backend (str) – Determines how the function is created. Accepted values are ‘numpy` and ‘numba’. Alternatively, ‘auto’ lets the code decide for the most optimal backend.

name = 'implicit'
class ScipySolver(pde, *, backend='auto', **kwargs)[source]

Bases: SolverBase

PDE solver using scipy.integrate.solve_ivp().

This class is a thin wrapper around scipy.integrate.solve_ivp(). In particular, it supports all the methods implemented by this function and exposes its arguments, so details can be controlled.

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

  • backend (str) – Determines how the function is created. Accepted values are ‘numpy` and ‘numba’. Alternatively, ‘auto’ lets the code decide for the most optimal backend.

  • **kwargs – All extra arguments are forwarded to scipy.integrate.solve_ivp().

make_stepper(state, dt=None)[source]

Return a stepper function.

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

  • dt (float) – Initial time step for the simulation. If None, the solver will choose a suitable initial value.

Returns:

Function that can be called to advance the state from time t_start to time t_end.

Return type:

Callable[[FieldBase, float, float], float]

name = 'scipy'
registered_solvers()[source]

Returns all solvers that are currently registered.

Returns:

List with the names of the solvers

Return type:

list of str