Construct an integrator
In this example, we showcase how to construct a pyshqg.core.integration.RungeKuttaModelIntegrator instance.
[1]:
from pyshqg.backend.numpy_backend import NumpyBackend as Backend
from pyshqg.preprocessing.reference_data import load_test_data
from pyshqg.core.integration import RungeKuttaModelIntegrator
from pyshqg.core.constructors import construct_model, construct_integrator
Construct the model
The first step is to construct the model. In the present example, we use the test model at spectral resolution T21 and grid resolution T31, implemented with the numpy-based backend.
See the notebook ‘Construct a model’ for more details about how to construct the model.c
[2]:
ds_test = load_test_data(
internal_truncature=21,
grid_truncature=31,
)
backend = Backend('float64')
model = construct_model(backend, ds_test.config)
Manual construction
To construct the integrator, we need:
model: the model to integrate;dt: the integration time step;method: the name of the integration method.
Currently, four integration methods are implemented:
method='ee': explicit Euler;method='abm': second-order Adams-Bashforth;method='rk2': second-order Runge–Kutta;method='rk4': fourth-order Runge–Kutta.
[3]:
integrator = RungeKuttaModelIntegrator(
model=model,
dt=3600,
method='rk4',
)
Construction using a configuration dictionary
Following what has been done for the model, it is possible to use the pyshqg.core.constructors.construct_integrator() function to construct the integrator using a configuration object stored as a dictionary.
For example, the test data contains a dictionary that will produce the integrators used in the unit tests.
[4]:
integrator = construct_integrator(ds_test.config['rk4_integration'], model)