Skip to content

Commit e659f40

Browse files
committed
Add 3d advection benchmark
1 parent 6a6b8bf commit e659f40

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

asv_bench/benchmarks/benchmarks.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,41 @@
44
# TODO: Write some benchmarks for parcels
55

66

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+
742
class ExampleTimeSuite:
843
"""
944
An example benchmark that times the performance of various kinds

0 commit comments

Comments
 (0)