xso.solvers

Module Contents

Classes

SolverABC

Abstract base class of backend solver class,

IVPSolver

Solver backend using scipy.integrate.solve_ivp to solve model.

StepwiseSolver

Solver that can handle stepwise calculation built into xsimlab framework.

Functions

to_ndarray(value)

Helper function to always have at least 1d numpy array returned.

xso.solvers.to_ndarray(value)[source]

Helper function to always have at least 1d numpy array returned.

class xso.solvers.SolverABC[source]

Bases: abc.ABC

Abstract base class of backend solver class, use subclass to solve model within the XSO framework.

class MathFunctionWrappers[source]

Default inner class providing mathematical function wrappers using numpy and math.

This nested class can be modified in any implemented solver, if it requires specific math functions.

Accessible within XSO components using self.m as defined in backendcomps.py class Backend.

pi
e
exp()[source]

Exponential function

sqrt()[source]

Square root function

log()[source]

Logarithmic function

product()[source]

Product function

sum(axis=None)[source]

Sum function

min(x2)[source]

Minimum function

max(x2)[source]

Maximum function

abs()[source]

Absolute value function

sin()[source]

Sine function

abstract add_variable(label, initial_value, model)[source]

Method to reformat a variable object for use with solver, should return storage object of value.

abstract add_parameter(label, value)[source]

Method to reformat a parameter object for use with solver.

abstract register_flux(label, flux, model, dims)[source]

Method to reformat a flux function for use with solver, should return storage object of value.

abstract add_forcing(label, flux, time)[source]

Method to reformat a forcing function for use with solver, should return storage object of value.

abstract assemble(model)[source]

Method to initialize model.

abstract solve(model, time_step)[source]

Method to solve model, specific to solver chosen.

abstract cleanup()[source]

Method to clean up temporary storage or perform other actions after the model has been run.

class xso.solvers.IVPSolver[source]

Bases: SolverABC

Solver backend using scipy.integrate.solve_ivp to solve model.

SOLVE_IVP is a variable step-size solver for ordinary differential equations, included in the SciPy Python package.

By default, it utilizes an explicit Runge-Kutta method of order 5(4).

static return_dims_and_array(value, model_time)[source]

Helper function to expand numpy array to appropriate size for odeint solver based on value and model time.

add_variable(label, initial_value, model)[source]

Reformats variable to comply with solver and return storage array.

add_parameter(label, value)[source]

Returns parameter as numpy array.

register_flux(label, flux, model, dims)[source]

Method to reformat flux function with appropriate inputs and to proper size.

add_forcing(label, forcing_func, model)[source]

Compute forcing for model time.

assemble(model)[source]

Define full model dimensions after initialization.

solve(model, time_step)[source]

Solve model using scipy.integrate.solve_ivp, passing model_function, initial values and model.time. The model output is then assigned to the previously initialized storage arrays within xsimlab backend.

cleanup()[source]

Empty cleanup method, not necessary for this solver.

class xso.solvers.StepwiseSolver[source]

Bases: SolverABC

Solver that can handle stepwise calculation built into xsimlab framework.

Model output is computed step by step and assigned to the appropriate storage arrays in xsimlab backend.

static return_dims_and_array(value, model_time)[source]

Helper function to create arrays of appropriate size, and assign initial value(s) to first index

add_variable(label, initial_value, model)[source]

Method to reformat variable and return storage array.

add_parameter(label, value)[source]

Method to reformat parameter and return array.

register_flux(label, flux, model, dims)[source]

Method to reformat flux function with appropriate inputs and to proper size.

add_forcing(label, forcing_func, model)[source]

Compute forcing over model time and provide as array.

assemble(model)[source]

Assemble full model dimension and order fluxes for proper unpacking.

solve(model, time_step)[source]

Solve model in a stepwise fashion, calling this function at each time step.

cleanup()[source]

Empty cleanup method, not necessary for this solver.