|
4 | 4 | # TODO: Write some benchmarks for parcels |
5 | 5 |
|
6 | 6 |
|
| 7 | +import numpy as np |
| 8 | +from parcels import FieldSet, ParticleSet, AdvectionRK4, ScipyParticle |
| 9 | +from datetime import timedelta |
| 10 | + |
| 11 | + |
| 12 | +class Advection3D: |
| 13 | + """Benchmark running the Parcels brownian motion example.""" |
| 14 | + |
| 15 | + def time_run_whole_example(self): |
| 16 | + """Flat 2D zonal flow that increases linearly with depth from 0 m/s to 1 m/s.""" |
| 17 | + xdim = ydim = zdim = 2 |
| 18 | + npart = 11 |
| 19 | + dimensions = { |
| 20 | + "lon": np.linspace(0.0, 1e4, xdim, dtype=np.float32), |
| 21 | + "lat": np.linspace(0.0, 1e4, ydim, dtype=np.float32), |
| 22 | + "depth": np.linspace(0.0, 1.0, zdim, dtype=np.float32), |
| 23 | + } |
| 24 | + data = { |
| 25 | + "U": np.ones((xdim, ydim, zdim), dtype=np.float32), |
| 26 | + "V": np.zeros((xdim, ydim, zdim), dtype=np.float32), |
| 27 | + } |
| 28 | + data["U"][:, :, 0] = 0.0 |
| 29 | + fieldset = FieldSet.from_data(data, dimensions, mesh="flat", transpose=True) |
| 30 | + |
| 31 | + pset = ParticleSet( |
| 32 | + fieldset, |
| 33 | + pclass=ScipyParticle, |
| 34 | + lon=np.zeros(npart), |
| 35 | + lat=np.zeros(npart) + 1e2, |
| 36 | + depth=np.linspace(0, 1, npart), |
| 37 | + ) |
| 38 | + pset.execute(AdvectionRK4, runtime=timedelta(hours=2), dt=timedelta(seconds=30)) |
| 39 | + assert np.allclose(pset.depth * pset.time, pset.lon, atol=1.0e-1) |
| 40 | + |
| 41 | + |
7 | 42 | class ExampleTimeSuite: |
8 | 43 | """ |
9 | 44 | An example benchmark that times the performance of various kinds |
|
0 commit comments