|
37 | 37 | "import matplotlib.pyplot as plt\n", |
38 | 38 | "import numpy as np\n", |
39 | 39 | "import polars as pl\n", |
40 | | - "import xarray as xr\n", |
41 | 40 | "\n", |
42 | 41 | "import parcels\n", |
43 | 42 | "import parcels.tutorial\n", |
44 | 43 | "\n", |
45 | | - "ds_fields = parcels.tutorial.open_dataset(\"CROCOidealized_data/data\")\n", |
46 | | - "\n", |
47 | | - "ds_fields.load(); # Preload data to speed up access" |
| 44 | + "ds_fields = parcels.tutorial.open_dataset(\"CROCOidealized_data/data\")" |
48 | 45 | ] |
49 | 46 | }, |
50 | 47 | { |
|
92 | 89 | "fieldset = parcels.FieldSet.from_sgrid_conventions(ds_fset)\n", |
93 | 90 | "\n", |
94 | 91 | "# Add the critical depth (`hc`) as context to the fieldset\n", |
95 | | - "fieldset.add_context(\"hc\", ds_fields.hc.item())" |
| 92 | + "fieldset.add_context(\"hc\", ds_fields.hc.item())\n", |
| 93 | + "\n", |
| 94 | + "# Convert the FieldSet to windowed arrays for better performance\n", |
| 95 | + "fieldset = fieldset.to_windowed_arrays()" |
96 | 96 | ] |
97 | 97 | }, |
98 | 98 | { |
|
132 | 132 | ")\n", |
133 | 133 | "\n", |
134 | 134 | "pset.execute(\n", |
135 | | - " [parcels.kernels.AdvectionRK4_3D_CROCO, DeleteParticle],\n", |
| 135 | + " [parcels.kernels.AdvectionRK2_3D_CROCO, DeleteParticle],\n", |
136 | 136 | " runtime=np.timedelta64(50_000, \"s\"),\n", |
137 | 137 | " dt=np.timedelta64(100, \"s\"),\n", |
138 | 138 | " output_file=outputfile,\n", |
|
173 | 173 | "ax.set_xlabel(\"X [km]\")\n", |
174 | 174 | "ax.set_xlim(30, 170)\n", |
175 | 175 | "ax.set_ylabel(\"Depth [m]\")\n", |
176 | | - "ax.set_title(\"Particles in idealized CROCO velocity field using AdvectionRK4_3D_CROCO\")\n", |
| 176 | + "ax.set_title(\"Particles in idealized CROCO velocity field using AdvectionRK2_3D_CROCO\")\n", |
177 | 177 | "plt.tight_layout()\n", |
178 | 178 | "plt.show()" |
179 | 179 | ] |
|
189 | 189 | "cell_type": "markdown", |
190 | 190 | "metadata": {}, |
191 | 191 | "source": [ |
192 | | - "It may be insightful to compare this 3D run with the `AdvectionRK4_3D_CROCO` kernel with a run where the vertical velocity (`W`) is set to zero. In that case, the particles will not stay on their initial depth levels but instead follow sigma-layers." |
| 192 | + "It may be insightful to compare this 3D run with the `AdvectionRK2_3D_CROCO` kernel with a run where the vertical velocity (`W`) is set to zero. In that case, the particles will not stay on their initial depth levels but instead follow sigma-layers." |
193 | 193 | ] |
194 | 194 | }, |
195 | 195 | { |
|
205 | 205 | "fieldset_noW = parcels.FieldSet.from_sgrid_conventions(ds_fset)\n", |
206 | 206 | "fieldset_noW.W.data[:] = 0.0\n", |
207 | 207 | "fieldset_noW.add_context(\"hc\", ds_fields.hc.item())\n", |
| 208 | + "fieldset_noW = fieldset_noW.to_windowed_arrays()\n", |
208 | 209 | "\n", |
209 | 210 | "X, Z = np.meshgrid(\n", |
210 | 211 | " [40e3, 80e3, 120e3],\n", |
|
221 | 222 | ")\n", |
222 | 223 | "\n", |
223 | 224 | "pset_noW.execute(\n", |
224 | | - " [parcels.kernels.AdvectionRK4_3D_CROCO, DeleteParticle],\n", |
| 225 | + " [parcels.kernels.AdvectionRK2_3D_CROCO, DeleteParticle],\n", |
225 | 226 | " runtime=np.timedelta64(50_000, \"s\"),\n", |
226 | 227 | " dt=np.timedelta64(100, \"s\"),\n", |
227 | 228 | " output_file=outputfile,\n", |
|
273 | 274 | "cell_type": "markdown", |
274 | 275 | "metadata": {}, |
275 | 276 | "source": [ |
276 | | - "For Advection, you will need to use the `AdvectionRK4_3D_CROCO` kernel, which works slightly different from the normal 3D advection kernel because it converts the vertical velocity in sigma-units. The conversion from z to sigma is done at every time step, using the `convert_z_to_sigma_croco()` function.\n", |
| 277 | + "For Advection, you will need to use the `AdvectionRK2_3D_CROCO` kernel, which works slightly different from the normal 3D advection kernel because it converts the vertical velocity in sigma-units. The conversion from z to sigma is done at every time step, using the `convert_z_to_sigma_croco()` function.\n", |
277 | 278 | "\n", |
278 | | - "In particular, the following algorithm is used (note that the RK4 version is slightly more complex than this Euler-Forward version, but the idea is identical). Also note that the vertical velocity is linearly interpolated here, which gives much better results than the default C-grid interpolation.\n", |
| 279 | + "In particular, the following algorithm is used (note that the RK2 version is slightly more complex than this Euler-Forward version, but the idea is identical). Also note that the vertical velocity is linearly interpolated here, which gives much better results than the default C-grid interpolation.\n", |
279 | 280 | "\n", |
280 | 281 | "```python\n", |
281 | 282 | "sigma = particles.z / fieldset.h[particles.t, 0, particles.y, particles.x]\n", |
|
297 | 298 | "z_new = sigma_new * fieldset.h[particles.t, 0, y_new, x_new, particles]\n", |
298 | 299 | "```" |
299 | 300 | ] |
| 301 | + }, |
| 302 | + { |
| 303 | + "cell_type": "markdown", |
| 304 | + "metadata": {}, |
| 305 | + "source": [] |
300 | 306 | } |
301 | 307 | ], |
302 | 308 | "metadata": { |
|
0 commit comments