Skip to content

Commit 184f3e9

Browse files
authored
Merge pull request #77 from Parcels-code/main
Pull main branch into optimise_kernels branch.
2 parents 613e8b7 + 3218321 commit 184f3e9

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

plasticparcels/constructors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ def create_particleset(fieldset, settings, release_locations):
232232
else:
233233
plastic_amounts = np.full_like(lons, np.nan)
234234

235+
if 'depths' in release_locations.keys():
236+
depths = release_locations['depths']
237+
else:
238+
depths = np.full_like(lons, 0.)
239+
235240
# Set particle properties
236241
plastic_densities = np.full(lons.shape, settings['plastictype']['plastic_density'])
237242
plastic_diameters = np.full(lons.shape, settings['plastictype']['plastic_diameter'])
@@ -254,6 +259,7 @@ def create_particleset(fieldset, settings, release_locations):
254259
PlasticParticle,
255260
lon=lons,
256261
lat=lats,
262+
depth=depths,
257263
plastic_diameter=plastic_diameters,
258264
plastic_density=plastic_densities,
259265
wind_coefficient=wind_coefficients,

tests/test_kernels.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,50 @@ def test_mixing():
243243

244244
# Assert that the particles move from their initial location
245245
assert (np.sum(np.abs(pset.lon - pset_mixing.lon)) > 0.) & (np.sum(np.abs(pset.lat - pset_mixing.lat)) > 0.)
246+
247+
@pytest.mark.parametrize("mode", ["scipy", "jit"])
248+
def test_TEOSdensity_kernels(mode):
249+
""" Adapted test from Parcels v3 codebase.
250+
"""
251+
settings_file = 'tests/test_data/test_settings.json'
252+
settings = pp.utils.load_settings(settings_file)
253+
254+
settings['simulation'] = make_standard_simulation_settings()
255+
settings['plastictype'] = make_standard_plastictype_settings()
256+
257+
# Turn off all other processes
258+
settings['use_3D'] = False
259+
settings['use_biofouling'] = False
260+
settings['use_stokes'] = False
261+
settings['use_wind'] = False
262+
settings['use_mixing'] = False
263+
264+
def generate_fieldset(xdim=2, ydim=2, zdim=2, tdim=1):
265+
lon = np.linspace(0.0, 10.0, xdim, dtype=np.float32)
266+
lat = np.linspace(0.0, 10.0, ydim, dtype=np.float32)
267+
depth = np.linspace(0, 2000, zdim, dtype=np.float32)
268+
time = np.zeros(tdim, dtype=np.float64)
269+
U = np.ones((tdim, zdim, ydim, xdim))
270+
V = np.ones((tdim, zdim, ydim, xdim))
271+
abs_salinity = 30 * np.ones((tdim, zdim, ydim, xdim))
272+
cons_temperature = 10 * np.ones((tdim, zdim, ydim, xdim))
273+
dimensions = {"lat": lat, "lon": lon, "depth": depth, "time": time}
274+
data = {
275+
"U": np.array(U, dtype=np.float32),
276+
"V": np.array(V, dtype=np.float32),
277+
"absolute_salinity": np.array(abs_salinity, dtype=np.float32),
278+
"conservative_temperature": np.array(cons_temperature, dtype=np.float32),
279+
}
280+
return (data, dimensions)
281+
282+
data, dimensions = generate_fieldset()
283+
fieldset = parcels.FieldSet.from_data(data, dimensions)
284+
285+
release_locations = {'lons': [5], 'lats': [5], 'depths': [1000],
286+
'plastic_amount': [1]}
287+
288+
pset = pp.constructors.create_particleset(fieldset, settings, release_locations)
289+
290+
pset.execute(pp.kernels.PolyTEOS10_bsq, runtime=1)
291+
292+
assert np.allclose(pset[0].seawater_density, 1027.45140)

0 commit comments

Comments
 (0)