4.3.8. pde.pdes.pde module

Defines a PDE class whose right hand side is given as a string

class PDE(rhs, *, noise=0, bc='auto_periodic_neumann', bc_ops=None, user_funcs=None, consts=None)[source]

Bases: PDEBase

PDE defined by mathematical expressions


The name of the variables (i.e., fields) in the order they are expected to appear in the state.




This implementation uses exec() and should therefore not be used in a context where malicious input could occur.

  • rhs (dict) – The expressions defining the evolution rate. The dictionary keys define the name of the fields whose evolution is considered, while the values specify their evolution rate as a string that can be parsed by sympy. These expression may contain variables (i.e., the fields themselves, spatial coordinates of the grid, and t for the time), standard local mathematical operators defined by sympy, and the operators defined in the pde package. Note that operators need to be specified with their full name, i.e., laplace for a scalar Laplacian and vector_laplace for a Laplacian operating on a vector field. Moreover, the dot product between two vector fields can be denoted by using dot(field1, field2) in the expression, an outer product is calculated using outer(field1, field2), and integral(field) denotes an integral over a field. More information can be found in the expression documentation.

  • noise (float or ndarray) – Magnitude of additive Gaussian white noise. The default value of zero implies deterministic partial differential equations will be solved. Different noise magnitudes can be supplied for each field in coupled PDEs by either specifying a sequence of numbers or a dictionary with values for each field.

  • bc (BoundariesData) – Boundary conditions for the operators used in the expression. The conditions here are applied to all operators that do not have a specialized condition given in bc_ops. Boundary conditions are generally given as a list with one condition for each axis. For periodic axis, only periodic boundary conditions are allowed (indicated by ‘periodic’ and ‘anti-periodic’). For non-periodic axes, different boundary conditions can be specified for the lower and upper end (using a tuple of two conditions). For instance, Dirichlet conditions enforcing a value NUM (specified by {‘value’: NUM}) and Neumann conditions enforcing the value DERIV for the derivative in the normal direction (specified by {‘derivative’: DERIV}) are supported. Note that the special value ‘natural’ imposes periodic boundary conditions for periodic axis and a vanishing derivative otherwise. More information can be found in the boundaries documentation.

  • bc_ops (dict) – Special boundary conditions for some operators. The keys in this dictionary specify where the boundary condition will be applied. The keys follow the format “VARIABLE:OPERATOR”, where VARIABLE specifies the expression in rhs where the boundary condition is applied to the operator specified by OPERATOR. For both identifiers, the wildcard symbol “*” denotes that all fields and operators are affected, respectively. For instance, the identifier “c:*” allows specifying a condition for all operators of the field named c.

  • user_funcs (dict, optional) – A dictionary with user defined functions that can be used in the expressions in rhs.

  • consts (dict, optional) – A dictionary with user defined constants that can be used in the expression. These can be either scalar numbers or fields defined on the same grid as the actual simulation.


The order in which the fields are given in rhs defines the order in which they need to appear in the state variable when the evolution rate is calculated. Note that dict keep the insertion order since Python version 3.7, so a normal dictionary can be used to define the equations.

diagnostics: Dict[str, Any]

Diagnostic information (available after the PDE has been solved)



evolution_rate(state, t=0.0)[source]

evaluate the right hand side of the PDE

  • state (FieldBase) – The field describing the state of the PDE

  • t (float) – The current time point


Field describing the evolution rate of the PDE

Return type


property expressions: Dict[str, str]

show the expressions of the PDE