|
76 | 76 | "\n", |
77 | 77 | "The spatial derivatives in the EM and M1 schemes can be approximated by a central difference. Higher order numerical schemes (see [Gräwe et al., 2012](https://doi.org/10.1007/s10236-012-0523-y)) include higher order derivatives.\n", |
78 | 78 | "\n", |
| 79 | + "```{note}\n", |
| 80 | + "TODO: explore higher order derivatives and numerical schemes (using cubic spline interpolation) in v4 \n", |
| 81 | + "```\n", |
| 82 | + "\n", |
79 | 83 | "An overview of numerical approximations for SDEs in a particle tracking setting can be found in [Gräwe (2011)](https://doi.org/10.1016/j.ocemod.2010.10.002).\n", |
80 | 84 | "\n", |
81 | 85 | "## Using Advection-Diffusion Kernels in Parcels\n", |
82 | 86 | "\n", |
83 | 87 | "The EM and M1 advection-diffusion approximations are available as `AdvectionDiffusionEM` and `AdvectionDiffusionM1`, respectively. The `AdvectionDiffusionM1` kernel should be the default choice, as the increased accuracy comes at negligible computational cost.\n", |
84 | 88 | "\n", |
85 | | - "The advection component of these kernels is similar to that of the Explicit Euler advection kernel (`AdvectionEE`). In the special case where diffusivity is constant over the entire domain, the diffusion-only kernel `DiffusionUniformKh` can be used in combination with an advection kernel of choice. Since the diffusivity here is space-independent, gradients are not calculated, increasing efficiency. The diffusion-step can in this case be computed after or before advection, thus allowing you to chain kernels using the `+` operator.\n", |
| 89 | + "The advection component of these kernels is similar to that of the Explicit Euler advection kernel (`AdvectionEE`). In the special case where diffusivity is constant over the entire domain, the diffusion-only kernel `DiffusionUniformKh` can be used in combination with an advection kernel of choice. Since the diffusivity here is space-independent, gradients are not calculated, increasing efficiency. The diffusion-step can in this case be computed after or before advection, thus allowing you to chain kernels in a list.\n", |
86 | 90 | "\n", |
87 | 91 | "Just like velocities, diffusivities are passed to Parcels in the form of `Field` objects. When using `DiffusionUniformKh`, they should be added to the `FieldSet` object as constant fields, e.g. `fieldset.add_constant_field(\"Kh_zonal\", 1, mesh=\"flat\")`.\n", |
88 | 92 | "\n", |
|
193 | 197 | "ds = simple_UV_dataset(dims=(1, 1, Ny, 1), mesh=\"flat\").isel(time=0, depth=0)\n", |
194 | 198 | "ds[\"lat\"][:] = np.linspace(-0.01, 1.01, Ny)\n", |
195 | 199 | "ds[\"lon\"][:] = np.ones(len(ds.XG))\n", |
196 | | - "# dx, dy = 1.0 / len(ds.XG), 1.0 / len(ds.YG)\n", |
197 | | - "ds[\"Kh_zonal\"] = ds[\"U\"] + K_bar * np.ones((Ny, 1))\n", |
198 | 200 | "ds[\"Kh_meridional\"] = ds[\"U\"] + Kh_meridional[:, None]\n", |
199 | 201 | "ds" |
200 | 202 | ] |
|
209 | 211 | "U = parcels.Field(\"U\", ds[\"U\"], grid, interp_method=parcels.interpolators.XLinear)\n", |
210 | 212 | "V = parcels.Field(\"V\", ds[\"V\"], grid, interp_method=parcels.interpolators.XLinear)\n", |
211 | 213 | "UV = parcels.VectorField(\"UV\", U, V)\n", |
212 | | - "Kh_zonal_field = parcels.Field(\n", |
213 | | - " \"Kh_zonal\", ds[\"Kh_zonal\"], grid, interp_method=parcels.interpolators.XLinear\n", |
214 | | - ")\n", |
| 214 | + "\n", |
215 | 215 | "Kh_meridional_field = parcels.Field(\n", |
216 | 216 | " \"Kh_meridional\",\n", |
217 | 217 | " ds[\"Kh_meridional\"],\n", |
218 | 218 | " grid,\n", |
219 | 219 | " interp_method=parcels.interpolators.XLinear,\n", |
220 | 220 | ")\n", |
221 | | - "fieldset = parcels.FieldSet([U, V, UV, Kh_zonal_field, Kh_meridional_field])\n", |
| 221 | + "fieldset = parcels.FieldSet([U, V, UV, Kh_meridional_field])\n", |
| 222 | + "fieldset.add_constant_field(\"Kh_zonal\", 1, mesh=\"flat\")\n", |
222 | 223 | "\n", |
223 | 224 | "fieldset.add_constant(\"dres\", 0.00005)" |
224 | 225 | ] |
|
244 | 245 | " lon=np.zeros(100),\n", |
245 | 246 | " lat=np.ones(100) * 0.75,\n", |
246 | 247 | " time=np.repeat(np.timedelta64(0, \"s\"), 100),\n", |
247 | | - " # lonlatdepth_dtype=np.float64,\n", |
248 | 248 | " )" |
249 | 249 | ] |
250 | 250 | }, |
|
539 | 539 | "da_cell_areas = xr.DataArray(\n", |
540 | 540 | " data=calc_cell_areas(fieldset.U.grid),\n", |
541 | 541 | " coords=dict(\n", |
542 | | - " latitude=([\"latitude\"], ds_fields.latitude.values),\n", |
543 | | - " longitude=([\"longitude\"], ds_fields.longitude.values),\n", |
| 542 | + " latitude=([\"lat\"], ds_fields.latitude.values),\n", |
| 543 | + " longitude=([\"lon\"], ds_fields.longitude.values),\n", |
544 | 544 | " ),\n", |
545 | | - " dims=[\"latitude\", \"longitude\"],\n", |
| 545 | + " dims=[\"lat\", \"lon\"],\n", |
546 | 546 | ")\n", |
547 | 547 | "\n", |
548 | | - "ds_fields[\"cell_areas\"] = da_cell_areas\n", |
549 | | - "ds_fields[\"latitude\"].attrs[\"axis\"] = \"Y\"\n", |
550 | | - "ds_fields[\"longitude\"].attrs[\"axis\"] = \"X\"\n", |
551 | | - "\n", |
552 | | - "# TODO: add parcels.Field instead of creating new fieldset once defining from existing XGrid is implemented\n", |
553 | | - "fieldset = parcels.FieldSet.from_copernicusmarine(ds_fields)\n", |
554 | | - "\n", |
555 | | - "fieldset.add_constant(\"Cs\", 0.1)\n", |
| 548 | + "cell_areas_field = parcels.Field(\n", |
| 549 | + " \"cell_areas\",\n", |
| 550 | + " da_cell_areas,\n", |
| 551 | + " fieldset.U.grid,\n", |
| 552 | + " interp_method=parcels.interpolators.XNearest,\n", |
| 553 | + ")\n", |
| 554 | + "fieldset.add_field(cell_areas_field)\n", |
556 | 555 | "\n", |
557 | | - "ds_fields" |
| 556 | + "fieldset.add_constant(\"Cs\", 0.1)" |
558 | 557 | ] |
559 | 558 | }, |
560 | 559 | { |
|
645 | 644 | "\n", |
646 | 645 | "Smagorinsky, J. (1963). “General circulation experiments with primitive equations. 1. The basic experiment.” _Monthly Weather Review_, 91, 99–164. https://doi.org/10.1175/1520-0493(1963)091%3C0099:GCEWTP%3E2.3.CO;2\n" |
647 | 646 | ] |
648 | | - }, |
649 | | - { |
650 | | - "cell_type": "markdown", |
651 | | - "metadata": {}, |
652 | | - "source": [] |
653 | 647 | } |
654 | 648 | ], |
655 | 649 | "metadata": { |
|
0 commit comments