Skip to content

Commit 1e2bff8

Browse files
Update Nemo tutorial periodic boundaries
1 parent c4f81a6 commit 1e2bff8

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

docs/user_guide/examples/tutorial_nemo.ipynb

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
")\n",
156156
"\n",
157157
"pset.execute(\n",
158-
" [parcels.kernels.AdvectionEE],\n",
158+
" parcels.kernels.AdvectionRK2,\n",
159159
" runtime=runtime,\n",
160160
" dt=np.timedelta64(1, \"D\"),\n",
161161
" output_file=pfile,\n",
@@ -203,7 +203,7 @@
203203
"metadata": {},
204204
"outputs": [],
205205
"source": [
206-
"# post processing\n",
206+
"# handling periodic boundary conditions in post processing\n",
207207
"df = df.with_columns((pl.col(\"x\") % 360).alias(\"x\"))\n",
208208
"df = df.with_columns(\n",
209209
" pl.when(pl.col(\"x\") <= 180)\n",
@@ -223,8 +223,23 @@
223223
},
224224
"outputs": [],
225225
"source": [
226-
"# with a Kernel\n",
227-
"def periodicBC(particles, fieldset): # pragma: no cover\n",
226+
"# with a custom Kernel\n",
227+
"def AdvectionRK2_periodicBC(particles, fieldset): # pragma: no cover\n",
228+
" \"\"\"Advection of particles using second-order Runge-Kutta integration,\n",
229+
" keeping particles between -180 and 180 degrees longitude.\n",
230+
" \"\"\"\n",
231+
" (u1, v1) = fieldset.UV[particles]\n",
232+
" x1 = particles.x + u1 * 0.5 * particles.dt\n",
233+
" y1 = particles.y + v1 * 0.5 * particles.dt\n",
234+
" x1 = np.where(x1 > 180, x1 - 360, x1) # keep particles within [-180, 180]\n",
235+
"\n",
236+
" (u2, v2) = fieldset.UV[\n",
237+
" particles.t + 0.5 * particles.dt, particles.z, y1, x1, particles\n",
238+
" ]\n",
239+
" particles.dx += u2 * particles.dt\n",
240+
" particles.dy += v2 * particles.dt\n",
241+
"\n",
242+
" # update particles.dx to stay within [-180, 180]\n",
228243
" particles.dx = np.where(\n",
229244
" particles.x + particles.dx > 180, particles.dx - 360, particles.dx\n",
230245
" )\n",
@@ -236,7 +251,7 @@
236251
")\n",
237252
"\n",
238253
"pset.execute(\n",
239-
" [parcels.kernels.AdvectionEE, periodicBC],\n",
254+
" AdvectionRK2_periodicBC,\n",
240255
" runtime=runtime,\n",
241256
" dt=np.timedelta64(1, \"D\"),\n",
242257
" output_file=pfile,\n",

0 commit comments

Comments
 (0)