|
30 | 30 |
|
31 | 31 | @pytest.mark.parametrize("mesh", ["spherical", "flat"]) |
32 | 32 | def test_advection_zonal(mesh, npart=10): |
33 | | - """Particles at high latitude move geographically faster due to the pole correction in `GeographicPolar`.""" |
| 33 | + """Particles at high latitude move geographically faster due to the pole correction.""" |
34 | 34 | ds = simple_UV_dataset(mesh=mesh) |
35 | 35 | ds["U"].data[:] = 1.0 |
36 | 36 | fieldset = FieldSet.from_sgrid_conventions(ds, mesh=mesh) |
37 | 37 |
|
38 | | - pset = ParticleSet(fieldset, lon=np.zeros(npart) + 20.0, lat=np.linspace(0, 80, npart)) |
39 | | - pset.execute(AdvectionRK4, runtime=np.timedelta64(2, "h"), dt=np.timedelta64(15, "m")) |
| 38 | + runtime = 7200 |
| 39 | + startlat = np.linspace(0, 80, npart) |
| 40 | + startlon = 20.0 + np.zeros(npart) |
| 41 | + pset = ParticleSet(fieldset, lon=startlon, lat=startlat) |
| 42 | + pset.execute(AdvectionRK4, runtime=runtime, dt=np.timedelta64(15, "m")) |
40 | 43 |
|
| 44 | + expected_dlon = runtime |
41 | 45 | if mesh == "spherical": |
42 | | - assert (np.diff(pset.lon) > 1.0e-4).all() |
43 | | - else: |
44 | | - assert (np.diff(pset.lon) < 1.0e-4).all() |
| 46 | + expected_dlon /= 1852 * 60 * np.cos(np.deg2rad(pset.lat)) |
| 47 | + |
| 48 | + np.testing.assert_allclose(pset.lon - startlon, expected_dlon, atol=1e-5) |
| 49 | + np.testing.assert_allclose(pset.lat, startlat, atol=1e-5) |
45 | 50 |
|
46 | 51 |
|
47 | 52 | def test_advection_zonal_with_particlefile(tmp_store): |
48 | | - """Particles at high latitude move geographically faster due to the pole correction in `GeographicPolar`.""" |
| 53 | + """Particles at high latitude move geographically faster due to the pole correction.""" |
49 | 54 | npart = 10 |
50 | 55 | ds = simple_UV_dataset(mesh="flat") |
51 | 56 | ds["U"].data[:] = 1.0 |
@@ -88,6 +93,27 @@ def test_advection_zonal_periodic(): |
88 | 93 | np.testing.assert_allclose(pset.lat, 0.5, atol=1e-5) |
89 | 94 |
|
90 | 95 |
|
| 96 | +@pytest.mark.parametrize("mesh", ["spherical", "flat"]) |
| 97 | +def test_advection_meridional(mesh, npart=10): |
| 98 | + """All particles move the same in meridional direction, regardless of latitude.""" |
| 99 | + ds = simple_UV_dataset(mesh=mesh) |
| 100 | + ds["V"].data[:] = 1.0 |
| 101 | + fieldset = FieldSet.from_sgrid_conventions(ds, mesh=mesh) |
| 102 | + |
| 103 | + runtime = 7200 |
| 104 | + startlat = np.linspace(0, 80, npart) |
| 105 | + startlon = 20.0 + np.zeros(npart) |
| 106 | + pset = ParticleSet(fieldset, lon=startlon, lat=startlat) |
| 107 | + pset.execute(AdvectionRK4, runtime=runtime, dt=np.timedelta64(15, "m")) |
| 108 | + |
| 109 | + expected_dlat = runtime |
| 110 | + if mesh == "spherical": |
| 111 | + expected_dlat /= 1852 * 60 |
| 112 | + |
| 113 | + np.testing.assert_allclose(pset.lon, startlon, atol=1e-5) |
| 114 | + np.testing.assert_allclose(pset.lat - startlat, expected_dlat, atol=1e-4) |
| 115 | + |
| 116 | + |
91 | 117 | def test_horizontal_advection_in_3D_flow(npart=10): |
92 | 118 | """Flat 2D zonal flow that increases linearly with z from 0 m/s to 1 m/s.""" |
93 | 119 | ds = simple_UV_dataset(mesh="flat") |
|
0 commit comments