pararealml package

Submodules

pararealml.boundary_condition module

class pararealml.boundary_condition.BoundaryCondition[source]

Bases: abc.ABC

A base class for boundary conditions.

d_y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of the derivative of y at the coordinates along the boundary specified by x with respect to the normal vector to the boundary passing through the same point. To avoid imposing a condition on elements of the spatial derivative of elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of the derivative of y with respect to the normal vector to the boundary at the points defined by x

has_d_y_condition

Whether the boundary conditions restrict the value of the derivative of y with respect to the normal vector of the boundary.

has_y_condition

Whether the boundary conditions restrict the value of y.

is_static

Whether the boundary condition is time independent.

y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of y at the coordinates along the boundary specified by x. To avoid imposing a condition on elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of y at the boundary points

class pararealml.boundary_condition.CauchyBoundaryCondition(y_condition: Callable[[numpy.ndarray, Optional[float]], numpy.ndarray], d_y_condition: Callable[[numpy.ndarray, Optional[float]], numpy.ndarray], is_static: bool = False)[source]

Bases: pararealml.boundary_condition.BoundaryCondition

A combination of Dirichlet and Neumann boundary conditions.

d_y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of the derivative of y at the coordinates along the boundary specified by x with respect to the normal vector to the boundary passing through the same point. To avoid imposing a condition on elements of the spatial derivative of elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of the derivative of y with respect to the normal vector to the boundary at the points defined by x

has_d_y_condition

Whether the boundary conditions restrict the value of the derivative of y with respect to the normal vector of the boundary.

has_y_condition

Whether the boundary conditions restrict the value of y.

is_static

Whether the boundary condition is time independent.

y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of y at the coordinates along the boundary specified by x. To avoid imposing a condition on elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of y at the boundary points

class pararealml.boundary_condition.DirichletBoundaryCondition(y_condition: Callable[[numpy.ndarray, Optional[float]], numpy.ndarray], is_static: bool = False)[source]

Bases: pararealml.boundary_condition.BoundaryCondition

Dirichlet boundary conditions that restrict the values of y along the boundary.

d_y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of the derivative of y at the coordinates along the boundary specified by x with respect to the normal vector to the boundary passing through the same point. To avoid imposing a condition on elements of the spatial derivative of elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of the derivative of y with respect to the normal vector to the boundary at the points defined by x

has_d_y_condition

Whether the boundary conditions restrict the value of the derivative of y with respect to the normal vector of the boundary.

has_y_condition

Whether the boundary conditions restrict the value of y.

is_static

Whether the boundary condition is time independent.

y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of y at the coordinates along the boundary specified by x. To avoid imposing a condition on elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of y at the boundary points

class pararealml.boundary_condition.NeumannBoundaryCondition(d_y_condition: Callable[[numpy.ndarray, Optional[float]], numpy.ndarray], is_static: bool = False)[source]

Bases: pararealml.boundary_condition.BoundaryCondition

Neumann boundary conditions that restrict the values of the derivative of y with respect to the normal of the boundary.

d_y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of the derivative of y at the coordinates along the boundary specified by x with respect to the normal vector to the boundary passing through the same point. To avoid imposing a condition on elements of the spatial derivative of elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of the derivative of y with respect to the normal vector to the boundary at the points defined by x

has_d_y_condition

Whether the boundary conditions restrict the value of the derivative of y with respect to the normal vector of the boundary.

has_y_condition

Whether the boundary conditions restrict the value of y.

is_static

Whether the boundary condition is time independent.

y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of y at the coordinates along the boundary specified by x. To avoid imposing a condition on elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of y at the boundary points

pararealml.boundary_condition.vectorize_bc_function(bc_function: Callable[[Sequence[float], Optional[float]], Sequence[Optional[float]]]) → Callable[[numpy.ndarray, Optional[float]], numpy.ndarray][source]

Vectorizes a boundary condition function that operates on a single coordinate sequence so that it can operate on an array of coordinate sequences.

The implementation of the vectorized function is nothing more than a for loop over the rows of coordinate sequences in the x argument.

Parameters:bc_function – the non-vectorized boundary condition function
Returns:the vectorized boundary condition function

pararealml.constrained_problem module

class pararealml.constrained_problem.ConstrainedProblem(diff_eq: pararealml.differential_equation.DifferentialEquation, mesh: Optional[pararealml.mesh.Mesh] = None, boundary_conditions: Optional[Sequence[Tuple[pararealml.boundary_condition.BoundaryCondition, pararealml.boundary_condition.BoundaryCondition]]] = None)[source]

Bases: object

A representation of a simple ordinary differential equation or a partial differential equation constrained in space by a mesh and boundary conditions.

are_all_boundary_conditions_static

Whether all boundary conditions of the constrained problem are static.

are_there_boundary_conditions_on_y

Whether any of the boundary conditions constrain the value of y. For example if all the boundary conditions are Neumann conditions, the value of this property is False. However, if there are any Dirichlet or Cauchy boundary conditions, it is True.

boundary_conditions

The boundary conditions of the differential equation. If differential equation is an ODE, it is None.

create_boundary_constraints(vertex_oriented: bool, t: Optional[float] = None) → Tuple[Optional[numpy.ndarray], Optional[numpy.ndarray]][source]

Creates a tuple of two 2D arrays (x dimension, y dimension) of boundary value constraint pairs that represent the lower and upper boundary conditions of y and the spatial derivative of y respectively, evaluated on the boundaries of the corresponding axes of the mesh.

Parameters:
  • vertex_oriented – whether the constraints are to be evaluated at the boundary vertices or the exterior faces of the boundary cells
  • t – the time value
Returns:

a tuple of two 2D arrays of boundary value constraint pairs

create_y_vertex_constraints(y_boundary_vertex_constraints: Optional[numpy.ndarray]) → Optional[numpy.ndarray][source]

Creates a 1D array of solution value constraints evaluated on all vertices of the mesh.

Parameters:y_boundary_vertex_constraints – a 2D array (x dimension, y dimension) of boundary value constraint pairs
Returns:a 1D array (y dimension) of solution constraints
differential_equation

The differential equation.

mesh

The mesh over which the differential equation is to be solved.

static_boundary_cell_constraints

A tuple of two 2D arrays (x dimension, y dimension) of boundary value constraint pairs that represent the lower and upper boundary conditions of y and the spatial derivative of y normal to the boundaries respectively.

The constraints are evaluated on the centers of the exterior faces of the boundary cells of the corresponding axes of the mesh.

All the elements of the constraint arrays corresponding to dynamic boundary conditions are None.

If the differential equation is an ODE, this property’s value is None.

static_boundary_constraints(vertex_oriented: bool) → Optional[Tuple[numpy.ndarray, numpy.ndarray]][source]

A tuple of two 2D arrays (x dimension, y dimension) of boundary value constraint pairs that represent the lower and upper boundary conditions of y and the spatial derivative of y normal to the boundaries respectively.

The constraints are evaluated either on the boundary vertices or on the the centers of the exterior faces of the boundary cells of the corresponding axes of the mesh.

All the elements of the constraint arrays corresponding to dynamic boundary conditions are None.

If the differential equation is an ODE, None is returned.

Parameters:vertex_oriented – whether the constraints are to be evaluated at the boundary vertices or the exterior faces of the boundary cells
Returns:an array of boundary value constraints
static_boundary_vertex_constraints

A tuple of two 2D arrays (x dimension, y dimension) of boundary value constraint pairs that represent the lower and upper boundary conditions of y and the spatial derivative of y normal to the boundaries respectively.

The constraints are evaluated on the boundary vertices of the corresponding axes of the mesh.

All the elements of the constraint arrays corresponding to dynamic boundary conditions are None.

If the differential equation is an ODE, this property’s value is None.

static_y_vertex_constraints

A 1D array (y dimension) of solution constraints that represent the boundary conditions of y evaluated on all vertices of the mesh.

If the differential equation is an ODE, this property’s value is None.

y_cells_shape

The shape of the array representing the cell centers of the discretized solution to the constrained problem.

y_shape(vertex_oriented: Optional[bool] = None) → Tuple[int, ...][source]

Returns the shape of the array of the array representing the discretized solution to the constrained problem.

Parameters:vertex_oriented – whether the solution is to be evaluated at the vertices or the cells of the discretized spatial domain; if the differential equation is an ODE, it can be None
Returns:the shape of result evaluated at the vertices or the cells
y_vertices_shape

The shape of the array representing the vertices of the discretized solution to the constrained problem.

pararealml.constraint module

class pararealml.constraint.Constraint(values: numpy.ndarray, mask: numpy.ndarray)[source]

Bases: object

A representation of constraints on the values of an array.

apply(array: numpy.ndarray) → numpy.ndarray[source]

It applies the constraints to the provided array in-place and returns the constrained array.

Parameters:array – the array to constrain
Returns:the constrained array
mask

The mask denoting the elements of the array that are to be constrained.

multiply_and_add(addend: numpy.ndarray, multiplier: Union[float, numpy.ndarray], result: numpy.ndarray) → numpy.ndarray[source]

It constrains the result array in-place to the sum of the constraint values multiplied by the provided multiplier and the corresponding elements of the provided addend. It also returns the constrained result array.

Parameters:
  • addend – the array whose values selected by the mask are to be added to the multiplied constraint values
  • multiplier – the factor by which the constraint values are to be multiplied
  • result – the array to constrain by the result of the operation
Returns:

the constrained result array

values

The constraint values.

pararealml.constraint.apply_constraints_along_last_axis(constraints: Union[Sequence[Optional[pararealml.constraint.Constraint]], numpy.ndarray, None], array: numpy.ndarray) → numpy.ndarray[source]

Applies the provided constraints to the array in-place and returns the constrained array.

Parameters:
  • constraints – the constraints on the values of the array
  • array – the array to which the constraints are to be applied
Returns:

the constrained array

pararealml.differential_equation module

class pararealml.differential_equation.BurgerEquation(x_dimension: int, re: float = 4000.0)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A system of partial differential equations providing a simplified model of fluid flow.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.differential_equation.CahnHilliardEquation(x_dimension: int, d: float = 0.1, gamma: float = 0.01)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A partial differential equation modelling phase separation.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.differential_equation.ConvectionDiffusionEquation(x_dimension: int, velocity: Sequence[float], d: float = 1.0)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A partial differential equation modelling the convection and diffusion of particles.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.differential_equation.DifferentialEquation(x_dimension: int, y_dimension: int, all_vector_field_indices: Optional[Sequence[Sequence[int]]] = None)[source]

Bases: abc.ABC

A representation of a time-dependent differential equation.

all_vector_field_indices

An optional sequence of index sequences denoting the components of vector fields the solution contains.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

symbols

All valid symbols that can be used to define a differential equation of this many spatial dimensions and unknown variables.

x_dimension

The dimension of the non-temporal domain of the differential equation’s solution. If the differential equation is an ODE, it is 0.

y_dimension

The dimension of the image of the differential equation’s solution. If the solution is not vector-valued, its dimension is 1.

class pararealml.differential_equation.DiffusionEquation(x_dimension: int, d: float = 1.0)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A partial differential equation modelling the diffusion of particles.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.differential_equation.Lhs[source]

Bases: enum.Enum

An enumeration defining the types of the left-hand sides of symbolic equations making up systems of differential equations.

D_Y_OVER_D_T = (0,)
Y = (1,)
Y_LAPLACIAN = 2
class pararealml.differential_equation.LorenzEquation(sigma: float = 10.0, rho: float = 28.0, beta: float = 2.6666666666666665)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A system of three ordinary differential equations modelling atmospheric convection.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.differential_equation.LotkaVolterraEquation(alpha: float = 2.0, beta: float = 0.04, gamma: float = 1.06, delta: float = 0.02)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A system of two ordinary differential equations modelling the dynamics of populations of preys and predators.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.differential_equation.NBodyGravitationalEquation(n_dims: int, masses: Sequence[float], g: float = 6.6743e-11)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A system of ordinary differential equations modelling the motion of planetary objects.

masses

Returns the masses of the planetary objects.

n_objects

Returns the number of planetary objects.

spatial_dimension

Returns the number of spatial dimensions.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.differential_equation.NavierStokesEquation(re: float = 4000.0)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A system of four partial differential equations modelling the velocity, vorticity, and stream function of incompressible fluids in two spatial dimensions.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.differential_equation.PopulationGrowthEquation(r: float = 0.01)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A simple ordinary differential equation modelling the growth of a population over time.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.differential_equation.ShallowWaterEquation(h: float, b: float = 0.01, v: float = 0.1, f: float = 0.0, g: float = 9.80665)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A system of partial differential equations providing a non-conservative model of fluid flow below a pressure surface.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.differential_equation.SymbolicEquationSystem(rhs: Union[Sequence[sympy.core.expr.Expr], numpy.ndarray[Any, numpy.dtype[sympy.core.expr.Expr]]], lhs_types: Optional[Sequence[pararealml.differential_equation.Lhs]] = None)[source]

Bases: object

A system of symbolic equations for defining differential equations.

equation_indices_by_type(lhs_type: pararealml.differential_equation.Lhs) → Sequence[int][source]

Returns a sequence of integers denoting the indices of all equations of the equation system with the specified type of left-hand side.

Parameters:lhs_type – the type of left-hand side
Returns:the sequence of indices
lhs_types

The types of the left-hand side of the symbolic equation system.

rhs

The right-hand side of the symbolic equation system.

class pararealml.differential_equation.Symbols(x_dimension: int, y_dimension: int)[source]

Bases: object

A class containing the symbols for expressing a coordinate system agnostic differential equation system with a specified number of unknown variables and spatial dimensions.

t

A symbol denoting the temporal coordinate.

x

An array of symbols denoting the elements of the spatial coordinates.

y

An array of symbols denoting the elements of the solution of the differential equation.

y_curl

A multidimensional array of symbols denoting the spatial curl of the corresponding elements of the differential equation’s solution.

For two spatial dimensions, this corresponds to a scalar field. However, for three spatial dimensions, it corresponds to a vector field, therefore an additional axis is appended to this multidimensional array to allow for indexing the components of this vector field. For differential equations with less than two or more than three spatial dimensions, the curl is not defined.

y_divergence

A multidimensional array of symbols denoting the spatial divergence of the corresponding elements of the differential equation’s solution.

y_gradient

A 2D array of symbols denoting the first spatial derivatives of the solution where the first rank is the element of the solution and the second rank is the spatial axis.

y_hessian

A 3D array of symbols denoting the second spatial derivatives of the solution where the first rank is the element of the solution, the second rank is the first spatial axis, and the third rank is the second spatial axis.

y_laplacian

An array of symbols denoting the spatial scalar Laplacian of the elements of the differential equation’s solution.

y_vector_laplacian

A multidimensional array of symbols denoting the spatial vector Laplacian of the corresponding elements of the differential equation’s solution.

An additional axis is appended to this multidimensional array to allow for indexing the components of the vector Laplacian.

class pararealml.differential_equation.WaveEquation(x_dimension: int, c: float = 1.0)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A partial differential equation modelling the propagation of waves.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

pararealml.initial_condition module

class pararealml.initial_condition.BetaInitialCondition(cp: pararealml.constrained_problem.ConstrainedProblem, alpha_and_betas: Sequence[Tuple[float, float]])[source]

Bases: pararealml.initial_condition.ContinuousInitialCondition

An initial condition defined explicitly by Beta probability density functions.

class pararealml.initial_condition.ContinuousInitialCondition(cp: pararealml.constrained_problem.ConstrainedProblem, y_0_func: Callable[[Optional[numpy.ndarray]], numpy.ndarray])[source]

Bases: pararealml.initial_condition.InitialCondition

An initial condition defined by a function.

discrete_y_0(vertex_oriented: Optional[bool] = None) → numpy.ndarray[source]

Returns the discretized initial values of y evaluated at the vertices or cell centers of the spatial mesh.

Parameters:vertex_oriented – whether the initial conditions are to be evaluated at the vertices or cell centers of the spatial mesh
Returns:the discretized initial values
y_0(x: Optional[numpy.ndarray]) → numpy.ndarray[source]

Returns the initial value of y at the points in the spatial domain defined by x.

Parameters:x – a 2D array (n, x_dimension) of the spatial coordinates for PDEs and None for ODEs
Returns:a 2D array (n, y_dimension) of the initial value of y at the coordinates for PDEs and a 1D array (y_dimension) for ODEs
class pararealml.initial_condition.DiscreteInitialCondition(cp: pararealml.constrained_problem.ConstrainedProblem, y_0: numpy.ndarray, vertex_oriented: Optional[bool] = None, interpolation_method: str = 'linear')[source]

Bases: pararealml.initial_condition.InitialCondition

An initial condition defined by a fixed array of values.

discrete_y_0(vertex_oriented: Optional[bool] = None) → numpy.ndarray[source]

Returns the discretized initial values of y evaluated at the vertices or cell centers of the spatial mesh.

Parameters:vertex_oriented – whether the initial conditions are to be evaluated at the vertices or cell centers of the spatial mesh
Returns:the discretized initial values
y_0(x: Optional[numpy.ndarray]) → numpy.ndarray[source]

Returns the initial value of y at the points in the spatial domain defined by x.

Parameters:x – a 2D array (n, x_dimension) of the spatial coordinates for PDEs and None for ODEs
Returns:a 2D array (n, y_dimension) of the initial value of y at the coordinates for PDEs and a 1D array (y_dimension) for ODEs
class pararealml.initial_condition.GaussianInitialCondition(cp: pararealml.constrained_problem.ConstrainedProblem, means_and_covs: Sequence[Tuple[numpy.ndarray, numpy.ndarray]], multipliers: Optional[Sequence[float]] = None)[source]

Bases: pararealml.initial_condition.ContinuousInitialCondition

An initial condition defined explicitly by Gaussian probability density functions.

class pararealml.initial_condition.InitialCondition[source]

Bases: abc.ABC

A base class for initial conditions.

discrete_y_0(vertex_oriented: Optional[bool] = None) → numpy.ndarray[source]

Returns the discretized initial values of y evaluated at the vertices or cell centers of the spatial mesh.

Parameters:vertex_oriented – whether the initial conditions are to be evaluated at the vertices or cell centers of the spatial mesh
Returns:the discretized initial values
y_0(x: Optional[numpy.ndarray]) → numpy.ndarray[source]

Returns the initial value of y at the points in the spatial domain defined by x.

Parameters:x – a 2D array (n, x_dimension) of the spatial coordinates for PDEs and None for ODEs
Returns:a 2D array (n, y_dimension) of the initial value of y at the coordinates for PDEs and a 1D array (y_dimension) for ODEs
pararealml.initial_condition.vectorize_ic_function(ic_function: Callable[[Optional[Sequence[float]]], Sequence[float]]) → Callable[[Optional[numpy.ndarray]], numpy.ndarray][source]

Vectorizes an initial condition function that operates on a single coordinate sequence so that it can operate on an array of coordinate sequences.

The implementation of the vectorized function is nothing more than a for loop over the rows of coordinate sequences in the x argument.

Parameters:ic_function – the non-vectorized initial condition function
Returns:the vectorized initial condition function

pararealml.initial_value_problem module

class pararealml.initial_value_problem.InitialValueProblem(cp: pararealml.constrained_problem.ConstrainedProblem, t_interval: Tuple[float, float], initial_condition: pararealml.initial_condition.InitialCondition, exact_y: Optional[Callable[[pararealml.initial_value_problem.InitialValueProblem, float, Optional[numpy.ndarray]], numpy.ndarray]] = None)[source]

Bases: object

A representation of an initial value problem around a boundary value problem.

constrained_problem

The constrained problem the IVP is based on.

exact_y(t: float, x: Optional[numpy.ndarray] = None) → numpy.ndarray[source]

Returns the exact value of y(t, x).

Parameters:
  • t – the point in the temporal domain
  • x – the points in the non-temporal domain. If the differential equation is an ODE, it is None.
Returns:

the value of y(t, x) or y(t) if it is an ODE.

has_exact_solution

Whether the differential equation has an analytic solution

initial_condition

The initial condition of the IVP.

t_interval

The bounds of the temporal domain of the differential equation.

pararealml.mesh module

class pararealml.mesh.CoordinateSystem[source]

Bases: enum.Enum

An enumeration defining the types of coordinate systems supported.

CARTESIAN = (0,)
CYLINDRICAL = (2,)
POLAR = (1,)
SPHERICAL = 3
class pararealml.mesh.Mesh(x_intervals: Sequence[Tuple[float, float]], d_x: Sequence[float], coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0,)>)[source]

Bases: object

A hyper-rectangular grid of arbitrary dimensionality and shape with a uniform spacing of grid points along each axis.

all_index_coordinates(vertex_oriented: bool, flatten: bool = False) → numpy.ndarray[source]

Returns an array containing the coordinates of all the points of the mesh.

Parameters:
  • vertex_oriented – whether the coordinates should be those of the vertices or the cell centers
  • flatten – whether to flatten the array into a 2D array where each row represents the coordinates of a single point
Returns:

an array of coordinates

axis_coordinates(vertex_oriented: bool) → Tuple[numpy.ndarray, ...][source]

Returns a tuple of the coordinates of the vertices or cell centers of the mesh along each axis separately.

Parameters:vertex_oriented – whether the coordinates of the vertices or the cell centers of the mesh is to be returned
Returns:a tuple of arrays each representing the coordinates along the corresponding axis
cartesian_coordinate_grids(vertex_oriented: bool) → Tuple[numpy.ndarray, ...][source]

Returns a tuple of grids where each element contains the Cartesian coordinates along the corresponding axis at all the vertices or cell centers of the mesh.

Parameters:vertex_oriented – whether to return grids of coordinates at the vertices or the cell centers of the mesh
Returns:a tuple arrays containing the Cartesian coordinate grids
cell_center_axis_coordinates

A tuple of the coordinates of the cell centers of the mesh along each axis.

cell_center_coordinate_grids

A tuple of grids where each element contains the coordinates along the corresponding axis at all the cell centers of the mesh.

cells_shape

The shape of the array of the cell centers of the discretized domain.

coordinate_grids(vertex_oriented: bool) → Tuple[numpy.ndarray, ...][source]

Returns a tuple of grids where each element contains the coordinates along the corresponding axis at all the vertices or cell centers of the mesh.

Parameters:vertex_oriented – whether to return grids of coordinates at the vertices or the cell centers of the mesh
Returns:a tuple arrays containing the coordinate grids
coordinate_system_type

The coordinate system type used by the mesh.

d_x

The step sizes along each axis of the domain.

dimensions

The number of spatial dimensions the mesh spans.

shape(vertex_oriented: bool) → Tuple[int, ...][source]

Returns the shape of the array of the discretized domain.

Parameters:vertex_oriented – whether the shape of the vertices or the cells of the mesh is to be returned
Returns:the shape of the vertices or the cells
unit_vector_grids(vertex_oriented: bool) → Tuple[numpy.ndarray, ...][source]

Returns a tuple of orthonormal unit vector grids such that each element of this tuple is an array containing the Cartesian coordinates of one of the unit vectors of the mesh’s coordinate system at each vertex or cell center of the mesh.

Parameters:vertex_oriented – whether to return the unit vectors at the vertices or the cell centers of the mesh
Returns:a tuple of arrays containing the unit vector grids
vertex_axis_coordinates

A tuple of the coordinates of the vertices of the mesh along each axis.

vertex_coordinate_grids

A tuple of grids where each element contains the coordinates along the corresponding axis at all the vertices of the mesh.

vertices_shape

The shape of the array of the vertices of the discretized domain.

x_intervals

The bounds of each axis of the domain

pararealml.mesh.from_cartesian_coordinates(x: Sequence[Coordinate], to_coordinate_system_type: pararealml.mesh.CoordinateSystem) → Sequence[Coordinate][source]

Converts the provided Cartesian coordinates to the specified type of coordinate system.

Parameters:
  • x – the Cartesian coordinates to convert
  • to_coordinate_system_type – the coordinate system to convert the Cartesian coordinates to
Returns:

the converted coordinates

pararealml.mesh.to_cartesian_coordinates(x: Sequence[Coordinate], from_coordinate_system_type: pararealml.mesh.CoordinateSystem) → Sequence[Coordinate][source]

Converts the provided coordinates from the specified type of coordinate system to Cartesian coordinates.

Parameters:
  • x – the coordinates to convert to Cartesian coordinates
  • from_coordinate_system_type – the coordinate system the coordinates are from
Returns:

the coordinates converted to Cartesian coordinates

pararealml.mesh.unit_vectors_at(x: Sequence[Coordinate], coordinate_system_type: pararealml.mesh.CoordinateSystem) → Sequence[Sequence[Coordinate]][source]

Calculates the unit vectors of the specified coordinate system at the provided spatial coordinates.

Each element of the returned sequence represents one unit vector in Cartesian coordinates.

Parameters:
  • x – the spatial coordinates
  • coordinate_system_type – the coordinate system to compute the unit vectors in
Returns:

the sequence of unit vectors at the provided spatial coordinates

pararealml.operator module

class pararealml.operator.Operator(d_t: float, vertex_oriented: Optional[bool])[source]

Bases: abc.ABC

A base class for an operator to estimate the solution of a differential equation over a specific time domain interval given an initial value.

d_t

The temporal step size of the operator.

solve(ivp: pararealml.initial_value_problem.InitialValueProblem, parallel_enabled: bool = True) → pararealml.solution.Solution[source]

Returns the IVP’s solution.

Parameters:
  • ivp – the initial value problem to solve
  • parallel_enabled – whether in-time parallelization is enabled
Returns:

the solution of the IVP

vertex_oriented

Whether the operator evaluates the solutions at the vertices of the spatial mesh or at the cell centers. If the operator is only an ODE solver, it may be None.

pararealml.operator.discretize_time_domain(t: Tuple[float, float], d_t: float) → numpy.ndarray[source]

Returns a discretization of the temporal interval using the provided temporal step size.

Parameters:
  • t – the time interval to discretize
  • d_t – the temporal step size
Returns:

the array containing the discretized temporal domain

pararealml.plot module

class pararealml.plot.AnimatedPlot(figure: matplotlib.figure.Figure, init_func: Callable[[], None], update_func: Callable[[int], None], n_time_steps: int, n_frames: int, interval: int)[source]

Bases: pararealml.plot.Plot

A base class for animated plots of the solutions of differential equations.

save(file_path: str, extension: str = 'gif', **kwargs) → pararealml.plot.Plot[source]

Saves the plot to the file system.

Invoking this method after invoking show() results in undefined behaviour.

Parameters:
  • file_path – the path to save the image file to excluding any extensions
  • extension – the file extension to use
  • kwargs – any extra arguments
Returns:

the plot object the method is invoked on

class pararealml.plot.ContourPlot(y: numpy.ndarray, mesh: pararealml.mesh.Mesh, vertex_oriented: bool, n_frames: int = 100, interval: int = 100, color_map: matplotlib.colors.Colormap = <matplotlib.colors.ListedColormap object>, v_min: Optional[float] = None, v_max: Optional[float] = None, **_)[source]

Bases: pararealml.plot.AnimatedPlot

A contour plot to visualize the solutions of 2D partial differential equations.

class pararealml.plot.NBodyPlot(y: numpy.ndarray, diff_eq: pararealml.differential_equation.NBodyGravitationalEquation, n_frames: int = 100, interval: int = 100, color_map: matplotlib.colors.Colormap = <matplotlib.colors.ListedColormap object>, smallest_marker_size: float = 10.0, draw_trajectory: bool = True, trajectory_line_style: str = ':', trajectory_line_width: float = 0.5, span_scaling_factor: float = 0.25, **_)[source]

Bases: pararealml.plot.AnimatedPlot

A 2D or 3D animated scatter plot to visualize the solutions of 2D or 3D n-body gravitational simulations.

class pararealml.plot.PhaseSpacePlot(y: numpy.ndarray, **_)[source]

Bases: pararealml.plot.Plot

A phase-space plot to visualize the solutions of systems of two or three ordinary differential equations.

class pararealml.plot.Plot(figure: matplotlib.figure.Figure)[source]

Bases: object

A base class for plots of the solutions of differential equations.

close()[source]

Closes the plot.

save(file_path: str, extension: str = 'png', **kwargs) → pararealml.plot.Plot[source]

Saves the plot to the file system.

Invoking this method after invoking show() results in undefined behaviour.

Parameters:
  • file_path – the path to save the image file to excluding any extensions
  • extension – the file extension to use
  • kwargs – any extra arguments
Returns:

the plot object the method is invoked on

show() → pararealml.plot.Plot[source]

Displays the plot.

If there are any other instantiated and unclosed plot objects, invoking this method displays those plots as well.

Invoking the save() method after invoking this one results in undefined behaviour since the plot may get closed as a side effect of this method.

Returns:the plot object the method is invoked on
class pararealml.plot.QuiverPlot(y: numpy.ndarray, mesh: pararealml.mesh.Mesh, vertex_oriented: bool, n_frames: int = 100, interval: int = 100, normalize: bool = False, pivot: str = 'middle', quiver_scale: float = 10.0, **_)[source]

Bases: pararealml.plot.AnimatedPlot

A 2D or 3D quiver plot to visualize the solution vector fields of 2D or 3D partial differential equation systems.

class pararealml.plot.ScatterPlot(y: numpy.ndarray, mesh: pararealml.mesh.Mesh, vertex_oriented: bool, n_frames: int = 100, interval: int = 100, color_map: matplotlib.colors.Colormap = <matplotlib.colors.ListedColormap object>, v_min: Optional[float] = None, v_max: Optional[float] = None, marker_shape: str = 'o', marker_size: Union[float, numpy.ndarray] = 20.0, marker_opacity: float = 1.0, **_)[source]

Bases: pararealml.plot.AnimatedPlot

A 3D scatter plot to visualize the solutions of 3D partial differential equations.

class pararealml.plot.SpaceLinePlot(y: numpy.ndarray, mesh: pararealml.mesh.Mesh, vertex_oriented: bool, n_frames: int = 100, interval: int = 100, v_min: Optional[float] = None, v_max: Optional[float] = None, equal_scale: bool = False, **_)[source]

Bases: pararealml.plot.AnimatedPlot

An animated line plot to visualise the solutions of 1D partial differential equations.

class pararealml.plot.StreamPlot(y: numpy.ndarray, mesh: pararealml.mesh.Mesh, vertex_oriented: bool, n_frames: int = 100, interval: int = 100, color: str = 'black', density: float = 1.0, **_)[source]

Bases: pararealml.plot.AnimatedPlot

A 2D stream plot to visualize the solution vector fields of 2D partial differential equation systems.

class pararealml.plot.SurfacePlot(y: numpy.ndarray, mesh: pararealml.mesh.Mesh, vertex_oriented: bool, n_frames: int = 100, interval: int = 100, color_map: matplotlib.colors.Colormap = <matplotlib.colors.ListedColormap object>, v_min: Optional[float] = None, v_max: Optional[float] = None, equal_scale: bool = False, **_)[source]

Bases: pararealml.plot.AnimatedPlot

A 3D surface plot to visualize the solutions of 2D partial differential equations.

class pararealml.plot.TimePlot(y: numpy.ndarray, t: numpy.ndarray, legend_location: Optional[str] = None, **_)[source]

Bases: pararealml.plot.Plot

A simple y against t plot to visualize the solutions of systems of ordinary differential equations.

pararealml.solution module

class pararealml.solution.Diffs[source]

Bases: tuple

A representation of the difference between a solution and one or more other solutions at time points that match across all solutions.

differences

Alias for field number 1

matching_time_points

Alias for field number 0

class pararealml.solution.Solution(ivp: pararealml.initial_value_problem.InitialValueProblem, t_coordinates: numpy.ndarray, discrete_y: numpy.ndarray, vertex_oriented: Optional[bool] = None, d_t: Optional[float] = None)[source]

Bases: object

A solution to an IVP.

d_t

The temporal step size of the solution.

diff(solutions: Sequence[pararealml.solution.Solution], atol: float = 1e-08) → pararealml.solution.Diffs[source]

Calculates and returns the difference between the provided solutions and this solution at every matching time point across all solutions.

Parameters:
  • solutions – the solutions to compare to
  • atol – the maximum absolute difference between two time points considered to be matching
Returns:

a Diffs instance containing a 1D array representing the matching time points and a sequence of sequence of arrays representing the differences between this solution and each of the provided solutions at the matching time points

discrete_y(vertex_oriented: Optional[bool] = None, interpolation_method: str = 'linear') → numpy.ndarray[source]

Returns the discrete solution evaluated either at vertices or the cell centers of the spatial mesh.

Parameters:
  • vertex_oriented – whether the solution returned should be evaluated at the vertices or the cell centers of the spatial mesh; only interpolation is supported, therefore, it is not possible to evaluate the solution at the vertices based on a cell-oriented solution
  • interpolation_method – the interpolation method to use
Returns:

the discrete solution

generate_plots(**kwargs) → Generator[pararealml.plot.Plot, None, None][source]

Returns a generator for generating all applicable plots for the solution.

Parameters:kwargs – arguments to pass onto the generated plot objects
Returns:a generator for generating all plots
initial_value_problem

The solved initial value problem.

t_coordinates

The time coordinates at which the solution is evaluated.

vertex_oriented

Whether the solution is vertex or cell oriented along the spatial domain. If the solution is that of an ODE, it is None.

y(x: Optional[numpy.ndarray] = None, interpolation_method: str = 'linear') → numpy.ndarray[source]

Interpolates and returns the values of y at the specified spatial coordinates at every time step.

Parameters:
  • x – the spatial coordinates with a shape of (…, x_dimension)
  • interpolation_method – the interpolation method to use
Returns:

the interpolated value of y at the provided spatial coordinates at every time step

Module contents

class pararealml.BoundaryCondition[source]

Bases: abc.ABC

A base class for boundary conditions.

d_y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of the derivative of y at the coordinates along the boundary specified by x with respect to the normal vector to the boundary passing through the same point. To avoid imposing a condition on elements of the spatial derivative of elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of the derivative of y with respect to the normal vector to the boundary at the points defined by x

has_d_y_condition

Whether the boundary conditions restrict the value of the derivative of y with respect to the normal vector of the boundary.

has_y_condition

Whether the boundary conditions restrict the value of y.

is_static

Whether the boundary condition is time independent.

y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of y at the coordinates along the boundary specified by x. To avoid imposing a condition on elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of y at the boundary points

class pararealml.DirichletBoundaryCondition(y_condition: Callable[[numpy.ndarray, Optional[float]], numpy.ndarray], is_static: bool = False)[source]

Bases: pararealml.boundary_condition.BoundaryCondition

Dirichlet boundary conditions that restrict the values of y along the boundary.

d_y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of the derivative of y at the coordinates along the boundary specified by x with respect to the normal vector to the boundary passing through the same point. To avoid imposing a condition on elements of the spatial derivative of elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of the derivative of y with respect to the normal vector to the boundary at the points defined by x

has_d_y_condition

Whether the boundary conditions restrict the value of the derivative of y with respect to the normal vector of the boundary.

has_y_condition

Whether the boundary conditions restrict the value of y.

is_static

Whether the boundary condition is time independent.

y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of y at the coordinates along the boundary specified by x. To avoid imposing a condition on elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of y at the boundary points

class pararealml.NeumannBoundaryCondition(d_y_condition: Callable[[numpy.ndarray, Optional[float]], numpy.ndarray], is_static: bool = False)[source]

Bases: pararealml.boundary_condition.BoundaryCondition

Neumann boundary conditions that restrict the values of the derivative of y with respect to the normal of the boundary.

d_y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of the derivative of y at the coordinates along the boundary specified by x with respect to the normal vector to the boundary passing through the same point. To avoid imposing a condition on elements of the spatial derivative of elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of the derivative of y with respect to the normal vector to the boundary at the points defined by x

has_d_y_condition

Whether the boundary conditions restrict the value of the derivative of y with respect to the normal vector of the boundary.

has_y_condition

Whether the boundary conditions restrict the value of y.

is_static

Whether the boundary condition is time independent.

y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of y at the coordinates along the boundary specified by x. To avoid imposing a condition on elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of y at the boundary points

class pararealml.CauchyBoundaryCondition(y_condition: Callable[[numpy.ndarray, Optional[float]], numpy.ndarray], d_y_condition: Callable[[numpy.ndarray, Optional[float]], numpy.ndarray], is_static: bool = False)[source]

Bases: pararealml.boundary_condition.BoundaryCondition

A combination of Dirichlet and Neumann boundary conditions.

d_y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of the derivative of y at the coordinates along the boundary specified by x with respect to the normal vector to the boundary passing through the same point. To avoid imposing a condition on elements of the spatial derivative of elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of the derivative of y with respect to the normal vector to the boundary at the points defined by x

has_d_y_condition

Whether the boundary conditions restrict the value of the derivative of y with respect to the normal vector of the boundary.

has_y_condition

Whether the boundary conditions restrict the value of y.

is_static

Whether the boundary condition is time independent.

y_condition(x: numpy.ndarray, t: Optional[float]) → numpy.ndarray[source]

Returns the value of y at the coordinates along the boundary specified by x. To avoid imposing a condition on elements of y, the corresponding elements of the returned array may be NaNs.

Parameters:
  • x – a 2D array (n, x_dimension) of the boundary coordinates
  • t – the time value; if the condition is static, it may be None
Returns:

a 2D array (n, y_dimension) of the constrained value of y at the boundary points

pararealml.vectorize_bc_function(bc_function: Callable[[Sequence[float], Optional[float]], Sequence[Optional[float]]]) → Callable[[numpy.ndarray, Optional[float]], numpy.ndarray][source]

Vectorizes a boundary condition function that operates on a single coordinate sequence so that it can operate on an array of coordinate sequences.

The implementation of the vectorized function is nothing more than a for loop over the rows of coordinate sequences in the x argument.

Parameters:bc_function – the non-vectorized boundary condition function
Returns:the vectorized boundary condition function
class pararealml.ConstrainedProblem(diff_eq: pararealml.differential_equation.DifferentialEquation, mesh: Optional[pararealml.mesh.Mesh] = None, boundary_conditions: Optional[Sequence[Tuple[pararealml.boundary_condition.BoundaryCondition, pararealml.boundary_condition.BoundaryCondition]]] = None)[source]

Bases: object

A representation of a simple ordinary differential equation or a partial differential equation constrained in space by a mesh and boundary conditions.

are_all_boundary_conditions_static

Whether all boundary conditions of the constrained problem are static.

are_there_boundary_conditions_on_y

Whether any of the boundary conditions constrain the value of y. For example if all the boundary conditions are Neumann conditions, the value of this property is False. However, if there are any Dirichlet or Cauchy boundary conditions, it is True.

boundary_conditions

The boundary conditions of the differential equation. If differential equation is an ODE, it is None.

create_boundary_constraints(vertex_oriented: bool, t: Optional[float] = None) → Tuple[Optional[numpy.ndarray], Optional[numpy.ndarray]][source]

Creates a tuple of two 2D arrays (x dimension, y dimension) of boundary value constraint pairs that represent the lower and upper boundary conditions of y and the spatial derivative of y respectively, evaluated on the boundaries of the corresponding axes of the mesh.

Parameters:
  • vertex_oriented – whether the constraints are to be evaluated at the boundary vertices or the exterior faces of the boundary cells
  • t – the time value
Returns:

a tuple of two 2D arrays of boundary value constraint pairs

create_y_vertex_constraints(y_boundary_vertex_constraints: Optional[numpy.ndarray]) → Optional[numpy.ndarray][source]

Creates a 1D array of solution value constraints evaluated on all vertices of the mesh.

Parameters:y_boundary_vertex_constraints – a 2D array (x dimension, y dimension) of boundary value constraint pairs
Returns:a 1D array (y dimension) of solution constraints
differential_equation

The differential equation.

mesh

The mesh over which the differential equation is to be solved.

static_boundary_cell_constraints

A tuple of two 2D arrays (x dimension, y dimension) of boundary value constraint pairs that represent the lower and upper boundary conditions of y and the spatial derivative of y normal to the boundaries respectively.

The constraints are evaluated on the centers of the exterior faces of the boundary cells of the corresponding axes of the mesh.

All the elements of the constraint arrays corresponding to dynamic boundary conditions are None.

If the differential equation is an ODE, this property’s value is None.

static_boundary_constraints(vertex_oriented: bool) → Optional[Tuple[numpy.ndarray, numpy.ndarray]][source]

A tuple of two 2D arrays (x dimension, y dimension) of boundary value constraint pairs that represent the lower and upper boundary conditions of y and the spatial derivative of y normal to the boundaries respectively.

The constraints are evaluated either on the boundary vertices or on the the centers of the exterior faces of the boundary cells of the corresponding axes of the mesh.

All the elements of the constraint arrays corresponding to dynamic boundary conditions are None.

If the differential equation is an ODE, None is returned.

Parameters:vertex_oriented – whether the constraints are to be evaluated at the boundary vertices or the exterior faces of the boundary cells
Returns:an array of boundary value constraints
static_boundary_vertex_constraints

A tuple of two 2D arrays (x dimension, y dimension) of boundary value constraint pairs that represent the lower and upper boundary conditions of y and the spatial derivative of y normal to the boundaries respectively.

The constraints are evaluated on the boundary vertices of the corresponding axes of the mesh.

All the elements of the constraint arrays corresponding to dynamic boundary conditions are None.

If the differential equation is an ODE, this property’s value is None.

static_y_vertex_constraints

A 1D array (y dimension) of solution constraints that represent the boundary conditions of y evaluated on all vertices of the mesh.

If the differential equation is an ODE, this property’s value is None.

y_cells_shape

The shape of the array representing the cell centers of the discretized solution to the constrained problem.

y_shape(vertex_oriented: Optional[bool] = None) → Tuple[int, ...][source]

Returns the shape of the array of the array representing the discretized solution to the constrained problem.

Parameters:vertex_oriented – whether the solution is to be evaluated at the vertices or the cells of the discretized spatial domain; if the differential equation is an ODE, it can be None
Returns:the shape of result evaluated at the vertices or the cells
y_vertices_shape

The shape of the array representing the vertices of the discretized solution to the constrained problem.

pararealml.apply_constraints_along_last_axis(constraints: Union[Sequence[Optional[pararealml.constraint.Constraint]], numpy.ndarray, None], array: numpy.ndarray) → numpy.ndarray[source]

Applies the provided constraints to the array in-place and returns the constrained array.

Parameters:
  • constraints – the constraints on the values of the array
  • array – the array to which the constraints are to be applied
Returns:

the constrained array

class pararealml.Constraint(values: numpy.ndarray, mask: numpy.ndarray)[source]

Bases: object

A representation of constraints on the values of an array.

apply(array: numpy.ndarray) → numpy.ndarray[source]

It applies the constraints to the provided array in-place and returns the constrained array.

Parameters:array – the array to constrain
Returns:the constrained array
mask

The mask denoting the elements of the array that are to be constrained.

multiply_and_add(addend: numpy.ndarray, multiplier: Union[float, numpy.ndarray], result: numpy.ndarray) → numpy.ndarray[source]

It constrains the result array in-place to the sum of the constraint values multiplied by the provided multiplier and the corresponding elements of the provided addend. It also returns the constrained result array.

Parameters:
  • addend – the array whose values selected by the mask are to be added to the multiplied constraint values
  • multiplier – the factor by which the constraint values are to be multiplied
  • result – the array to constrain by the result of the operation
Returns:

the constrained result array

values

The constraint values.

class pararealml.Symbols(x_dimension: int, y_dimension: int)[source]

Bases: object

A class containing the symbols for expressing a coordinate system agnostic differential equation system with a specified number of unknown variables and spatial dimensions.

t

A symbol denoting the temporal coordinate.

x

An array of symbols denoting the elements of the spatial coordinates.

y

An array of symbols denoting the elements of the solution of the differential equation.

y_curl

A multidimensional array of symbols denoting the spatial curl of the corresponding elements of the differential equation’s solution.

For two spatial dimensions, this corresponds to a scalar field. However, for three spatial dimensions, it corresponds to a vector field, therefore an additional axis is appended to this multidimensional array to allow for indexing the components of this vector field. For differential equations with less than two or more than three spatial dimensions, the curl is not defined.

y_divergence

A multidimensional array of symbols denoting the spatial divergence of the corresponding elements of the differential equation’s solution.

y_gradient

A 2D array of symbols denoting the first spatial derivatives of the solution where the first rank is the element of the solution and the second rank is the spatial axis.

y_hessian

A 3D array of symbols denoting the second spatial derivatives of the solution where the first rank is the element of the solution, the second rank is the first spatial axis, and the third rank is the second spatial axis.

y_laplacian

An array of symbols denoting the spatial scalar Laplacian of the elements of the differential equation’s solution.

y_vector_laplacian

A multidimensional array of symbols denoting the spatial vector Laplacian of the corresponding elements of the differential equation’s solution.

An additional axis is appended to this multidimensional array to allow for indexing the components of the vector Laplacian.

class pararealml.Lhs[source]

Bases: enum.Enum

An enumeration defining the types of the left-hand sides of symbolic equations making up systems of differential equations.

D_Y_OVER_D_T = (0,)
Y = (1,)
Y_LAPLACIAN = 2
class pararealml.SymbolicEquationSystem(rhs: Union[Sequence[sympy.core.expr.Expr], numpy.ndarray[Any, numpy.dtype[sympy.core.expr.Expr]]], lhs_types: Optional[Sequence[pararealml.differential_equation.Lhs]] = None)[source]

Bases: object

A system of symbolic equations for defining differential equations.

equation_indices_by_type(lhs_type: pararealml.differential_equation.Lhs) → Sequence[int][source]

Returns a sequence of integers denoting the indices of all equations of the equation system with the specified type of left-hand side.

Parameters:lhs_type – the type of left-hand side
Returns:the sequence of indices
lhs_types

The types of the left-hand side of the symbolic equation system.

rhs

The right-hand side of the symbolic equation system.

class pararealml.DifferentialEquation(x_dimension: int, y_dimension: int, all_vector_field_indices: Optional[Sequence[Sequence[int]]] = None)[source]

Bases: abc.ABC

A representation of a time-dependent differential equation.

all_vector_field_indices

An optional sequence of index sequences denoting the components of vector fields the solution contains.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

symbols

All valid symbols that can be used to define a differential equation of this many spatial dimensions and unknown variables.

x_dimension

The dimension of the non-temporal domain of the differential equation’s solution. If the differential equation is an ODE, it is 0.

y_dimension

The dimension of the image of the differential equation’s solution. If the solution is not vector-valued, its dimension is 1.

class pararealml.PopulationGrowthEquation(r: float = 0.01)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A simple ordinary differential equation modelling the growth of a population over time.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.LotkaVolterraEquation(alpha: float = 2.0, beta: float = 0.04, gamma: float = 1.06, delta: float = 0.02)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A system of two ordinary differential equations modelling the dynamics of populations of preys and predators.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.LorenzEquation(sigma: float = 10.0, rho: float = 28.0, beta: float = 2.6666666666666665)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A system of three ordinary differential equations modelling atmospheric convection.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.NBodyGravitationalEquation(n_dims: int, masses: Sequence[float], g: float = 6.6743e-11)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A system of ordinary differential equations modelling the motion of planetary objects.

masses

Returns the masses of the planetary objects.

n_objects

Returns the number of planetary objects.

spatial_dimension

Returns the number of spatial dimensions.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.DiffusionEquation(x_dimension: int, d: float = 1.0)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A partial differential equation modelling the diffusion of particles.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.ConvectionDiffusionEquation(x_dimension: int, velocity: Sequence[float], d: float = 1.0)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A partial differential equation modelling the convection and diffusion of particles.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.WaveEquation(x_dimension: int, c: float = 1.0)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A partial differential equation modelling the propagation of waves.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.CahnHilliardEquation(x_dimension: int, d: float = 0.1, gamma: float = 0.01)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A partial differential equation modelling phase separation.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.BurgerEquation(x_dimension: int, re: float = 4000.0)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A system of partial differential equations providing a simplified model of fluid flow.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.ShallowWaterEquation(h: float, b: float = 0.01, v: float = 0.1, f: float = 0.0, g: float = 9.80665)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A system of partial differential equations providing a non-conservative model of fluid flow below a pressure surface.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.NavierStokesEquation(re: float = 4000.0)[source]

Bases: pararealml.differential_equation.DifferentialEquation

A system of four partial differential equations modelling the velocity, vorticity, and stream function of incompressible fluids in two spatial dimensions.

symbolic_equation_system

A system of symbolic equations defining the differential equation system. Every element of the right-hand side of the returned system defines the first time derivative, the direct value, or the spatial Laplacian of the respective element of the vector-valued solution of the differential equation system depending on the type of the left-hand side of the equation.

class pararealml.InitialCondition[source]

Bases: abc.ABC

A base class for initial conditions.

discrete_y_0(vertex_oriented: Optional[bool] = None) → numpy.ndarray[source]

Returns the discretized initial values of y evaluated at the vertices or cell centers of the spatial mesh.

Parameters:vertex_oriented – whether the initial conditions are to be evaluated at the vertices or cell centers of the spatial mesh
Returns:the discretized initial values
y_0(x: Optional[numpy.ndarray]) → numpy.ndarray[source]

Returns the initial value of y at the points in the spatial domain defined by x.

Parameters:x – a 2D array (n, x_dimension) of the spatial coordinates for PDEs and None for ODEs
Returns:a 2D array (n, y_dimension) of the initial value of y at the coordinates for PDEs and a 1D array (y_dimension) for ODEs
class pararealml.DiscreteInitialCondition(cp: pararealml.constrained_problem.ConstrainedProblem, y_0: numpy.ndarray, vertex_oriented: Optional[bool] = None, interpolation_method: str = 'linear')[source]

Bases: pararealml.initial_condition.InitialCondition

An initial condition defined by a fixed array of values.

discrete_y_0(vertex_oriented: Optional[bool] = None) → numpy.ndarray[source]

Returns the discretized initial values of y evaluated at the vertices or cell centers of the spatial mesh.

Parameters:vertex_oriented – whether the initial conditions are to be evaluated at the vertices or cell centers of the spatial mesh
Returns:the discretized initial values
y_0(x: Optional[numpy.ndarray]) → numpy.ndarray[source]

Returns the initial value of y at the points in the spatial domain defined by x.

Parameters:x – a 2D array (n, x_dimension) of the spatial coordinates for PDEs and None for ODEs
Returns:a 2D array (n, y_dimension) of the initial value of y at the coordinates for PDEs and a 1D array (y_dimension) for ODEs
class pararealml.ContinuousInitialCondition(cp: pararealml.constrained_problem.ConstrainedProblem, y_0_func: Callable[[Optional[numpy.ndarray]], numpy.ndarray])[source]

Bases: pararealml.initial_condition.InitialCondition

An initial condition defined by a function.

discrete_y_0(vertex_oriented: Optional[bool] = None) → numpy.ndarray[source]

Returns the discretized initial values of y evaluated at the vertices or cell centers of the spatial mesh.

Parameters:vertex_oriented – whether the initial conditions are to be evaluated at the vertices or cell centers of the spatial mesh
Returns:the discretized initial values
y_0(x: Optional[numpy.ndarray]) → numpy.ndarray[source]

Returns the initial value of y at the points in the spatial domain defined by x.

Parameters:x – a 2D array (n, x_dimension) of the spatial coordinates for PDEs and None for ODEs
Returns:a 2D array (n, y_dimension) of the initial value of y at the coordinates for PDEs and a 1D array (y_dimension) for ODEs
class pararealml.GaussianInitialCondition(cp: pararealml.constrained_problem.ConstrainedProblem, means_and_covs: Sequence[Tuple[numpy.ndarray, numpy.ndarray]], multipliers: Optional[Sequence[float]] = None)[source]

Bases: pararealml.initial_condition.ContinuousInitialCondition

An initial condition defined explicitly by Gaussian probability density functions.

class pararealml.BetaInitialCondition(cp: pararealml.constrained_problem.ConstrainedProblem, alpha_and_betas: Sequence[Tuple[float, float]])[source]

Bases: pararealml.initial_condition.ContinuousInitialCondition

An initial condition defined explicitly by Beta probability density functions.

pararealml.vectorize_ic_function(ic_function: Callable[[Optional[Sequence[float]]], Sequence[float]]) → Callable[[Optional[numpy.ndarray]], numpy.ndarray][source]

Vectorizes an initial condition function that operates on a single coordinate sequence so that it can operate on an array of coordinate sequences.

The implementation of the vectorized function is nothing more than a for loop over the rows of coordinate sequences in the x argument.

Parameters:ic_function – the non-vectorized initial condition function
Returns:the vectorized initial condition function
class pararealml.InitialValueProblem(cp: pararealml.constrained_problem.ConstrainedProblem, t_interval: Tuple[float, float], initial_condition: pararealml.initial_condition.InitialCondition, exact_y: Optional[Callable[[pararealml.initial_value_problem.InitialValueProblem, float, Optional[numpy.ndarray]], numpy.ndarray]] = None)[source]

Bases: object

A representation of an initial value problem around a boundary value problem.

constrained_problem

The constrained problem the IVP is based on.

exact_y(t: float, x: Optional[numpy.ndarray] = None) → numpy.ndarray[source]

Returns the exact value of y(t, x).

Parameters:
  • t – the point in the temporal domain
  • x – the points in the non-temporal domain. If the differential equation is an ODE, it is None.
Returns:

the value of y(t, x) or y(t) if it is an ODE.

has_exact_solution

Whether the differential equation has an analytic solution

initial_condition

The initial condition of the IVP.

t_interval

The bounds of the temporal domain of the differential equation.

class pararealml.CoordinateSystem[source]

Bases: enum.Enum

An enumeration defining the types of coordinate systems supported.

CARTESIAN = (0,)
CYLINDRICAL = (2,)
POLAR = (1,)
SPHERICAL = 3
class pararealml.Mesh(x_intervals: Sequence[Tuple[float, float]], d_x: Sequence[float], coordinate_system_type: pararealml.mesh.CoordinateSystem = <CoordinateSystem.CARTESIAN: (0,)>)[source]

Bases: object

A hyper-rectangular grid of arbitrary dimensionality and shape with a uniform spacing of grid points along each axis.

all_index_coordinates(vertex_oriented: bool, flatten: bool = False) → numpy.ndarray[source]

Returns an array containing the coordinates of all the points of the mesh.

Parameters:
  • vertex_oriented – whether the coordinates should be those of the vertices or the cell centers
  • flatten – whether to flatten the array into a 2D array where each row represents the coordinates of a single point
Returns:

an array of coordinates

axis_coordinates(vertex_oriented: bool) → Tuple[numpy.ndarray, ...][source]

Returns a tuple of the coordinates of the vertices or cell centers of the mesh along each axis separately.

Parameters:vertex_oriented – whether the coordinates of the vertices or the cell centers of the mesh is to be returned
Returns:a tuple of arrays each representing the coordinates along the corresponding axis
cartesian_coordinate_grids(vertex_oriented: bool) → Tuple[numpy.ndarray, ...][source]

Returns a tuple of grids where each element contains the Cartesian coordinates along the corresponding axis at all the vertices or cell centers of the mesh.

Parameters:vertex_oriented – whether to return grids of coordinates at the vertices or the cell centers of the mesh
Returns:a tuple arrays containing the Cartesian coordinate grids
cell_center_axis_coordinates

A tuple of the coordinates of the cell centers of the mesh along each axis.

cell_center_coordinate_grids

A tuple of grids where each element contains the coordinates along the corresponding axis at all the cell centers of the mesh.

cells_shape

The shape of the array of the cell centers of the discretized domain.

coordinate_grids(vertex_oriented: bool) → Tuple[numpy.ndarray, ...][source]

Returns a tuple of grids where each element contains the coordinates along the corresponding axis at all the vertices or cell centers of the mesh.

Parameters:vertex_oriented – whether to return grids of coordinates at the vertices or the cell centers of the mesh
Returns:a tuple arrays containing the coordinate grids
coordinate_system_type

The coordinate system type used by the mesh.

d_x

The step sizes along each axis of the domain.

dimensions

The number of spatial dimensions the mesh spans.

shape(vertex_oriented: bool) → Tuple[int, ...][source]

Returns the shape of the array of the discretized domain.

Parameters:vertex_oriented – whether the shape of the vertices or the cells of the mesh is to be returned
Returns:the shape of the vertices or the cells
unit_vector_grids(vertex_oriented: bool) → Tuple[numpy.ndarray, ...][source]

Returns a tuple of orthonormal unit vector grids such that each element of this tuple is an array containing the Cartesian coordinates of one of the unit vectors of the mesh’s coordinate system at each vertex or cell center of the mesh.

Parameters:vertex_oriented – whether to return the unit vectors at the vertices or the cell centers of the mesh
Returns:a tuple of arrays containing the unit vector grids
vertex_axis_coordinates

A tuple of the coordinates of the vertices of the mesh along each axis.

vertex_coordinate_grids

A tuple of grids where each element contains the coordinates along the corresponding axis at all the vertices of the mesh.

vertices_shape

The shape of the array of the vertices of the discretized domain.

x_intervals

The bounds of each axis of the domain

pararealml.to_cartesian_coordinates(x: Sequence[Coordinate], from_coordinate_system_type: pararealml.mesh.CoordinateSystem) → Sequence[Coordinate][source]

Converts the provided coordinates from the specified type of coordinate system to Cartesian coordinates.

Parameters:
  • x – the coordinates to convert to Cartesian coordinates
  • from_coordinate_system_type – the coordinate system the coordinates are from
Returns:

the coordinates converted to Cartesian coordinates

pararealml.from_cartesian_coordinates(x: Sequence[Coordinate], to_coordinate_system_type: pararealml.mesh.CoordinateSystem) → Sequence[Coordinate][source]

Converts the provided Cartesian coordinates to the specified type of coordinate system.

Parameters:
  • x – the Cartesian coordinates to convert
  • to_coordinate_system_type – the coordinate system to convert the Cartesian coordinates to
Returns:

the converted coordinates

pararealml.unit_vectors_at(x: Sequence[Coordinate], coordinate_system_type: pararealml.mesh.CoordinateSystem) → Sequence[Sequence[Coordinate]][source]

Calculates the unit vectors of the specified coordinate system at the provided spatial coordinates.

Each element of the returned sequence represents one unit vector in Cartesian coordinates.

Parameters:
  • x – the spatial coordinates
  • coordinate_system_type – the coordinate system to compute the unit vectors in
Returns:

the sequence of unit vectors at the provided spatial coordinates

class pararealml.Plot(figure: matplotlib.figure.Figure)[source]

Bases: object

A base class for plots of the solutions of differential equations.

close()[source]

Closes the plot.

save(file_path: str, extension: str = 'png', **kwargs) → pararealml.plot.Plot[source]

Saves the plot to the file system.

Invoking this method after invoking show() results in undefined behaviour.

Parameters:
  • file_path – the path to save the image file to excluding any extensions
  • extension – the file extension to use
  • kwargs – any extra arguments
Returns:

the plot object the method is invoked on

show() → pararealml.plot.Plot[source]

Displays the plot.

If there are any other instantiated and unclosed plot objects, invoking this method displays those plots as well.

Invoking the save() method after invoking this one results in undefined behaviour since the plot may get closed as a side effect of this method.

Returns:the plot object the method is invoked on
class pararealml.AnimatedPlot(figure: matplotlib.figure.Figure, init_func: Callable[[], None], update_func: Callable[[int], None], n_time_steps: int, n_frames: int, interval: int)[source]

Bases: pararealml.plot.Plot

A base class for animated plots of the solutions of differential equations.

save(file_path: str, extension: str = 'gif', **kwargs) → pararealml.plot.Plot[source]

Saves the plot to the file system.

Invoking this method after invoking show() results in undefined behaviour.

Parameters:
  • file_path – the path to save the image file to excluding any extensions
  • extension – the file extension to use
  • kwargs – any extra arguments
Returns:

the plot object the method is invoked on

class pararealml.TimePlot(y: numpy.ndarray, t: numpy.ndarray, legend_location: Optional[str] = None, **_)[source]

Bases: pararealml.plot.Plot

A simple y against t plot to visualize the solutions of systems of ordinary differential equations.

class pararealml.PhaseSpacePlot(y: numpy.ndarray, **_)[source]

Bases: pararealml.plot.Plot

A phase-space plot to visualize the solutions of systems of two or three ordinary differential equations.

class pararealml.NBodyPlot(y: numpy.ndarray, diff_eq: pararealml.differential_equation.NBodyGravitationalEquation, n_frames: int = 100, interval: int = 100, color_map: matplotlib.colors.Colormap = <matplotlib.colors.ListedColormap object>, smallest_marker_size: float = 10.0, draw_trajectory: bool = True, trajectory_line_style: str = ':', trajectory_line_width: float = 0.5, span_scaling_factor: float = 0.25, **_)[source]

Bases: pararealml.plot.AnimatedPlot

A 2D or 3D animated scatter plot to visualize the solutions of 2D or 3D n-body gravitational simulations.

class pararealml.SpaceLinePlot(y: numpy.ndarray, mesh: pararealml.mesh.Mesh, vertex_oriented: bool, n_frames: int = 100, interval: int = 100, v_min: Optional[float] = None, v_max: Optional[float] = None, equal_scale: bool = False, **_)[source]

Bases: pararealml.plot.AnimatedPlot

An animated line plot to visualise the solutions of 1D partial differential equations.

class pararealml.ContourPlot(y: numpy.ndarray, mesh: pararealml.mesh.Mesh, vertex_oriented: bool, n_frames: int = 100, interval: int = 100, color_map: matplotlib.colors.Colormap = <matplotlib.colors.ListedColormap object>, v_min: Optional[float] = None, v_max: Optional[float] = None, **_)[source]

Bases: pararealml.plot.AnimatedPlot

A contour plot to visualize the solutions of 2D partial differential equations.

class pararealml.SurfacePlot(y: numpy.ndarray, mesh: pararealml.mesh.Mesh, vertex_oriented: bool, n_frames: int = 100, interval: int = 100, color_map: matplotlib.colors.Colormap = <matplotlib.colors.ListedColormap object>, v_min: Optional[float] = None, v_max: Optional[float] = None, equal_scale: bool = False, **_)[source]

Bases: pararealml.plot.AnimatedPlot

A 3D surface plot to visualize the solutions of 2D partial differential equations.

class pararealml.ScatterPlot(y: numpy.ndarray, mesh: pararealml.mesh.Mesh, vertex_oriented: bool, n_frames: int = 100, interval: int = 100, color_map: matplotlib.colors.Colormap = <matplotlib.colors.ListedColormap object>, v_min: Optional[float] = None, v_max: Optional[float] = None, marker_shape: str = 'o', marker_size: Union[float, numpy.ndarray] = 20.0, marker_opacity: float = 1.0, **_)[source]

Bases: pararealml.plot.AnimatedPlot

A 3D scatter plot to visualize the solutions of 3D partial differential equations.

class pararealml.StreamPlot(y: numpy.ndarray, mesh: pararealml.mesh.Mesh, vertex_oriented: bool, n_frames: int = 100, interval: int = 100, color: str = 'black', density: float = 1.0, **_)[source]

Bases: pararealml.plot.AnimatedPlot

A 2D stream plot to visualize the solution vector fields of 2D partial differential equation systems.

class pararealml.QuiverPlot(y: numpy.ndarray, mesh: pararealml.mesh.Mesh, vertex_oriented: bool, n_frames: int = 100, interval: int = 100, normalize: bool = False, pivot: str = 'middle', quiver_scale: float = 10.0, **_)[source]

Bases: pararealml.plot.AnimatedPlot

A 2D or 3D quiver plot to visualize the solution vector fields of 2D or 3D partial differential equation systems.

class pararealml.Solution(ivp: pararealml.initial_value_problem.InitialValueProblem, t_coordinates: numpy.ndarray, discrete_y: numpy.ndarray, vertex_oriented: Optional[bool] = None, d_t: Optional[float] = None)[source]

Bases: object

A solution to an IVP.

d_t

The temporal step size of the solution.

diff(solutions: Sequence[pararealml.solution.Solution], atol: float = 1e-08) → pararealml.solution.Diffs[source]

Calculates and returns the difference between the provided solutions and this solution at every matching time point across all solutions.

Parameters:
  • solutions – the solutions to compare to
  • atol – the maximum absolute difference between two time points considered to be matching
Returns:

a Diffs instance containing a 1D array representing the matching time points and a sequence of sequence of arrays representing the differences between this solution and each of the provided solutions at the matching time points

discrete_y(vertex_oriented: Optional[bool] = None, interpolation_method: str = 'linear') → numpy.ndarray[source]

Returns the discrete solution evaluated either at vertices or the cell centers of the spatial mesh.

Parameters:
  • vertex_oriented – whether the solution returned should be evaluated at the vertices or the cell centers of the spatial mesh; only interpolation is supported, therefore, it is not possible to evaluate the solution at the vertices based on a cell-oriented solution
  • interpolation_method – the interpolation method to use
Returns:

the discrete solution

generate_plots(**kwargs) → Generator[pararealml.plot.Plot, None, None][source]

Returns a generator for generating all applicable plots for the solution.

Parameters:kwargs – arguments to pass onto the generated plot objects
Returns:a generator for generating all plots
initial_value_problem

The solved initial value problem.

t_coordinates

The time coordinates at which the solution is evaluated.

vertex_oriented

Whether the solution is vertex or cell oriented along the spatial domain. If the solution is that of an ODE, it is None.

y(x: Optional[numpy.ndarray] = None, interpolation_method: str = 'linear') → numpy.ndarray[source]

Interpolates and returns the values of y at the specified spatial coordinates at every time step.

Parameters:
  • x – the spatial coordinates with a shape of (…, x_dimension)
  • interpolation_method – the interpolation method to use
Returns:

the interpolated value of y at the provided spatial coordinates at every time step