4.3.2. pde.pdes.base module
Base class for defining partial differential equations
- class PDEBase(*, noise=0, rng=None)[source]
base class for defining partial differential equations (PDEs)
Custom PDEs can be implemented by subclassing
PDEBaseto specify the evolution rate. In the simple case of deterministic PDEs, the methods
PDEBase._make_pde_rhs_numba()need to be overwritten for supporting the numpy and numba backend, respectively.
noise (float or
ndarray) – Variance of the additive Gaussian white noise that is supported for all PDEs by default. If set to zero, a deterministic partial differential equation will be solved. Different noise magnitudes can be supplied for each field in coupled PDEs.
Generator) – Random number generator (default:
default_rng()). Note that this random number generator is only used for numpy function, while compiled numba code is unaffected. Moreover, in simulations using multiprocessing, setting the same generator in all processes might yield unintended correlations in the simulation results.
If more complicated noise structures are required, the methods
PDEBase._make_noise_realization_numba()need to be overwritten for the numpy and numba backend, respectively.
- cache_rhs: bool = False
Flag indicating whether the right hand side of the equation should be cached. If True, the same implementation is used in subsequent calls to solve. Note that this might lead to wrong results if the parameters of the PDE are changed after the first call. This option is thus disabled by default and should be used with care.
- check_implementation: bool = True
Flag determining whether numba-compiled functions should be checked against their numpy counter-parts. This can help with implementing a correct compiled version for a PDE class.
- check_rhs_consistency(state, t=0, *, tol=1e-07, rhs_numba=None, **kwargs)[source]
check the numba compiled right hand side versus the numpy variant
FieldBase) – The state for which the evolution rates should be compared
t (float) – The associated time point
tol (float) – Acceptance tolerance. The check passes if the evolution rates differ by less then this value
rhs_numba (callable) – The implementation of the numba variant that is to be checked. If omitted, an implementation is obtained by calling
- complex_valued: bool = False
Flag indicating whether the right hand side is a complex-valued PDE, which requires all involved variables to have complex data type.
- diagnostics: Dict[str, Any]
Diagnostic information (available after the PDE has been solved)
- abstract evolution_rate(state, t=0)[source]
state (TState) –
t (float) –
- Return type:
- explicit_time_dependence: bool | None = None
Flag indicating whether the right hand side of the PDE has an explicit time dependence.
- property is_sde: bool
flag indicating whether this is a stochastic differential equation
BasePDFclass supports additive Gaussian white noise, whose magnitude is controlled by the noise property. In this case, is_sde is True if self.noise != 0.
returns a function that can be called to modify a state
This function is applied to the state after each integration step when an explicit stepper is used. The default behavior is to not change the state.
- make_pde_rhs(state, backend='auto', **kwargs)[source]
return a function for evaluating the right hand side of the PDE
FieldBase) – An example for the state from which the grid and other information can be extracted.
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.
Function determining the right hand side of the PDE
- Return type:
- make_sde_rhs(state, backend='auto', **kwargs)[source]
return a function for evaluating the right hand side of the SDE
FieldBase) – An example for the state from which the grid and other information can be extracted
backend (str) – Determines how the function is created. Accepted values are ‘python` and ‘numba’. Alternatively, ‘auto’ lets the code decide for the most optimal backend.
Function determining the deterministic part of the right hand side of the PDE together with a noise realization.
- Return type:
- noise_realization(state, t=0, *, label='Noise realization')[source]
returns a realization for the noise
- solve(state, t_range, dt=None, tracker='auto', *, solver='explicit', ret_info=False, **kwargs)[source]
solves the partial differential equation
The method constructs a suitable solver (
SolverBase) and controller (
Controller) to advance the state over the temporal range specified by t_range. This method only exposes the most common functions, so explicit construction of these classes might offer more flexibility.
FieldBase) – The initial state (which also defines the spatial grid).
t_range (float or tuple) – Sets the time range for which the PDE is solved. This should typically be a tuple of two numbers, (t_start, t_end), specifying the initial and final time of the simulation. If only a single value is given, it is interpreted as t_end and the time range is assumed to be (0, t_end).
dt (float) – Time step of the chosen stepping scheme. If None, a default value based on the stepper will be chosen. If an adaptive stepper is used (supported by
ExplicitSolver), the value given here sets the initial time step.
tracker (Sequence[TrackerBase | str] | TrackerBase | str | None) – Defines a tracker that process the state of the simulation at specified times. A tracker is either an instance of
TrackerBaseor a string, which identifies a tracker. All 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’). More general trackers are defined in
trackers, where all options are explained in detail. In particular, the interval at which the tracker is evaluated can be chosen when creating a tracker object explicitly.
SolverBaseor str) – Specifies the method for solving the differential equation. This can either be an instance of
SolverBaseor a descriptive name like ‘explicit’ or ‘scipy’. The valid names are given by
pde.solvers.registered_solvers(). Details of the solvers and additional features (like adaptive time steps) are explained in
ret_info (bool) – Flag determining whether diagnostic information about the solver process should be returned. Note that the same information is also available as the
**kwargs – Additional keyword arguments are forwarded to the solver class chosen with the method argument. In particular,
ExplicitSolversupports several schemes and an adaptive stepper can be enabled using
ScipySolveraccepts the additional arguments of
The state at the final time point. If ret_info == True, a tuple with the final state and a dictionary with additional information is returned. Note that None instead of a field is returned in multiprocessing simulations if the current node is not the main MPI node.
- Return type: