Skip to content

Commit 09397cf

Browse files
reint-fischerreint-fischer
authored andcommitted
scaffold explanation, complete guide, and add todo notes
1 parent 46785a7 commit 09397cf

2 files changed

Lines changed: 46 additions & 12 deletions

File tree

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Interpolator explanation
2+
23
Interpolation is an important functionality of Parcels. On this page we will discuss the way it is
34
implemented in **Parcels** and how to write a custom interpolator function.
45

@@ -7,48 +8,55 @@ TODO: expand explanation (similar to Kernel loop explanation)
78
```
89

910
When we want to know the state of particles in an environmental field, such as temperature or velocity,
10-
we _evaluate_ the `parcels.Field` at the particles real position in time and space (`t`, `z`, `lat`, `lon`).
11+
we _evaluate_ the `parcels.Field` at the particles real position in time and space (`t`, `z`, `lat`, `lon`).
1112
In Parcels we can do this using square brackets:
13+
1214
```
1315
particles.temperature = fieldset.temperature[particles.time, particles.z, particles.lat, particles.lon]
1416
```
17+
1518
The values of the `temperature` field at the particles' positions are determined using an interpolation
16-
method. This interpolation method defines how the discretized values of the `parcels.Field` should
17-
relate to the value at any point within a grid cell.
19+
method. This interpolation method defines how the discretized values of the `parcels.Field` should
20+
relate to the value at any point within a grid cell.
1821

1922
Each `parcels.Field` is defined on a (structured) `parcels.XGrid` or (unstructured) `parcels.UXGrid`.
2023
The interpolation function takes information about the particles position relative to this grid (`grid_positions`),
2124
as well as the `parcels.Field` values of the surrounding grid points in time and space, to calculate
2225
the requested value at the particles location.
2326

2427
## Interpolator API
25-
The interpolators included in Parcels are designed for common interpolation schemes in Parcels simulations.
28+
29+
The interpolators included in Parcels are designed for common interpolation schemes in Parcels simulations.
2630
If we want to add a custom interpolation method, we need to look at the interpolator API:
2731

28-
We can write an interpolator function that takes a `parcels.Field`, a dictionary with the `particle_positions`
32+
We can write an interpolator function that takes a `parcels.Field`, a dictionary with the `particle_positions`
2933
in real space and time, and a dictionary with the `grid_positions`.
3034

3135
The `particle_positions` dictionary contains:
36+
3237
```
3338
particle_positions = {"time", time, "z", z, "lat", lat, "lon", lon}
3439
```
3540

3641
For structured (`X`) grids, the `grid_positions` dictionary looks like:
42+
3743
```
3844
grid_positions = {
39-
"T": {"index": ti, "bcoord": tau},
40-
"Z": {"index": zi, "bcoord": zeta},
41-
"Y": {"index": yi, "bcoord": eta},
45+
"T": {"index": ti, "bcoord": tau},
46+
"Z": {"index": zi, "bcoord": zeta},
47+
"Y": {"index": yi, "bcoord": eta},
4248
"X": {"index": xi, "bcoord", xsi},
4349
}
4450
```
51+
4552
where `index` is the grid index in the corresponding dimension, and `bcoord` is the barycentric coordinate in the grid cell.
4653

4754
For unstructured (`UX`) grids, the same dictionary is defined as:
55+
4856
```
4957
grid_positions = {
50-
"T": {"index": ti, "bcoord": tau},
51-
"Z": {"index": zi, "bcoord": zeta},
58+
"T": {"index": ti, "bcoord": tau},
59+
"Z": {"index": zi, "bcoord": zeta},
5260
"FACE": {"index": fi, "bcoord": bcoord}
5361
}
54-
```
62+
```

docs/user_guide/examples/tutorial_interpolation.ipynb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,11 @@
219219
"1. `interp_method=parcels.interpolators.XLinear`: compute linear interpolation\n",
220220
"2. `interp_method=parcels.interpolators.XLinearInvdistLandTracer`: compute linear interpolation except near land (where field value is zero). In that case, inverse distance weighting interpolation is computed, weighting by squares of the distance.\n",
221221
"3. `interp_method=parcels.interpolators.XNearest`: return nearest field value\n",
222-
"4. `interp_method=parcels.interpolators.CGridTracer`: return nearest field value supposing C cells\n"
222+
"4. `interp_method=parcels.interpolators.CGridTracer`: return nearest field value supposing C cells\n",
223+
"\n",
224+
"In the special case where a `parcels.Field` is constant in time and space, such as implementing constant diffusion on a spherical mesh, we can use:\n",
225+
"\n",
226+
"5. `interp_method=parcels.interpolators.XConstantField`: return single value of a Constant Field"
223227
]
224228
},
225229
{
@@ -231,6 +235,28 @@
231235
"```"
232236
]
233237
},
238+
{
239+
"cell_type": "markdown",
240+
"metadata": {},
241+
"source": [
242+
"## Interpolation on unstructured grids\n",
243+
"```{note}\n",
244+
"TODO: add example on simple unstructured fieldset\n",
245+
"```\n",
246+
"- UXPiecewiseConstantFace\n",
247+
"- UXPiecewiseLinearNode"
248+
]
249+
},
250+
{
251+
"cell_type": "markdown",
252+
"metadata": {},
253+
"source": [
254+
"## Interpolation at boundaries\n",
255+
"In some cases we need to implement specific boundary conditions, for example to prevent particles from \n",
256+
"getting \"stuck\" near land. [This guide](../examples_v3/documentation_unstuck_Agrid.ipynb) describes \n",
257+
"how to implement this in parcels using `parcels.interpolators.XFreeslip` and `parcels.interpolators.XPartialslip`."
258+
]
259+
},
234260
{
235261
"cell_type": "markdown",
236262
"metadata": {},

0 commit comments

Comments
 (0)