You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/getting_started/explanation_concepts.md
+44-38Lines changed: 44 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ A Parcels simulation is generally built up from four different components:
13
13
1.[**FieldSet**](#1-fieldset). The input dataset of gridded fields (e.g. ocean current velocity, temperature) in which virtual particles are defined.
14
14
2.[**ParticleSet**](#2-particleset). The dataset of virtual particles. These always contain time, z, lat, and lon, for which initial values must be defined, and may contain other variables.
15
15
3.[**Kernels**](#3-kernels). Kernels perform some specific operation on the particles every time step (e.g. interpolate the temperature from the temperature field to the particle location).
16
-
4.[**Execute**](#4-execution). Execute the simulation. The core method which integrates the operations defined in Kernels for a given time and timestep, and writes output to a ParticleFile.
16
+
4.[**Execute**](#4-execute). Execute the simulation. The core method which integrates the operations defined in Kernels for a given time and timestep, and writes output to a ParticleFile.
17
17
18
18
We discuss each component in more detail below. The subsections titled **"Learn how to"** link to more detailed [how-to guide notebooks](../user_guide/index.md) and more detailed _explanations_ of Parcels functionality are included under **"Read more about"** subsections. The full list of classes and methods is in the [API reference](../reference.md). If you want to learn by doing, check out the [quickstart tutorial](./tutorial_quickstart.md) to start creating your first Parcels simulation.
19
19
@@ -57,91 +57,97 @@ Each `parcels.Field` is defined on a grid. With Parcels we can simulate particle
57
57
58
58
### Interpolation
59
59
60
-
To find the value of a `parcels.Field` at any particle location, Parcels uses interpolation. Depending on the variable, grid, and required accuracy, different interpolation methods may be appropriate. Parcels comes with a number of built-in **`parcels.interpolators`**:
60
+
To find the value of a `parcels.Field` at any particle location, Parcels interpolates the gridded field. Depending on the variable, grid, and required accuracy, different interpolation methods may be appropriate. Parcels comes with a number of built-in **`parcels.interpolators`**.
61
61
62
-
```{code-cell}
63
-
import parcels
64
-
65
-
for interpolator in parcels.interpolators.__all__:
Once the environment has a `parcels.FieldSet` object, you can start defining your particles in a **`parcels.ParticleSet`** object. This object requires:
80
73
81
74
1. The `parcels.FieldSet` object in which the particles will be released.
82
-
2. The type of `parcels.Particle`: A default `Particle` or a custom `Particle`-type with additional `Variable`s.
75
+
2. The type of `parcels.Particle`: A default `Particle` or a custom `Particle`-type with additional `Variable`s (see the [custom kernel example](custom-kernel)).
83
76
3. Initial conditions for each `Variable` defined in the `Particle`, most notably the release coordinates of `time`, `z`, `lat` and `lon`.
84
77
85
-
### Learn how to
78
+
### Learn how to create ParticleSets
86
79
87
80
-[Release particles at different times](../user_guide/examples/tutorial_delaystart.ipynb)
88
81
89
82
## 3. Kernels
90
83
91
-
**`parcels.Kernel`**objects are little snippets of code, which are applied to the particles in the `ParticleSet`, for every time step during a simulation. They define the computation or numerical integration done by Parcels, and can represent many processes such as advection, ageing, growth, or simply the sampling of a field.
84
+
A **`parcels.Kernel`**object is a little snippet of code, which is applied to the particles in the `ParticleSet`, for every time step during a simulation. Kernels define the computation or numerical integration done by Parcels, and can represent many processes such as advection, ageing, growth, or simply the sampling of a field.
92
85
93
-
Basic kernels are included in Parcels, among which several types of advection kernels:
86
+
Advection of a particle by the flow, the change in position $\mathbf{x}(t) = (lon(t), lat(t))$ at time $t$, can be described by the equation:
We can also write custom kernels, to add certain types of 'behaviour' to the particles. To do so we write a function with two arguments: `particles` and `fieldset`. We can then write any computation as a function of any variables defined in the `Particle` and any `Field` defined in the `FieldSet`. Kernels can then be combined by creating a `list` of the kernels. Note that the kernels are executed in order:
94
+
where $\mathbf{v}(\mathbf{x},t) = (u(\mathbf{x},t), v(\mathbf{x},t))$ describes the ocean velocity field at position $\mathbf{x}$ at time $t$.
95
+
96
+
In Parcels, we can write a kernel function which integrates this equation at each timestep `particles.dt`. To do so, we need the ocean velocity field `fieldset.UV` at the `particles` location, and compute the change in position, `particles.dlon` and `particles.dlat`.
101
97
102
98
```python
103
-
# Create a custom kernel which displaces each particle southward
99
+
defAdvectionEE(particles, fieldset):
100
+
"""Advection of particles using Explicit Euler (aka Euler Forward) integration."""
101
+
(u1, v1) = fieldset.UV[particles]
102
+
particles.dlon += u1 * particles.dt
103
+
particles.dlat += v1 * particles.dt
104
+
```
104
105
105
-
defNorthVel(particles, fieldset):
106
-
vvel =-1e-4
107
-
particles.dlat += vvel * particles.dt
106
+
Basic kernels are included in Parcels to compute advection and diffusion. The standard advection kernel is `parcels.kernels.AdvectionRK4`, a [4-th order Runge-Kutta integrator](https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods#The_Runge%E2%80%93Kutta_method) of the advection function.
108
107
108
+
```{warning}
109
+
It is advised _not_ to update the particle coordinates (`particles.time`, `particles.z`, `particles.lat`, or `particles.lon`) directly, as that can negatively interfere with the way that particle movements by different kernels are vectorially added. Use a change in the coordinates: `particles.dlon`, `particles.dlat`, `particles.dz`, and/or `particles.dt` instead, and be careful with `particles.dt`. Read the [kernel loop tutorial](https://docs.oceanparcels.org/en/latest/examples/tutorial_kernelloop.html) to understand why.
110
+
```
109
111
110
-
# Create a custom kernel which keeps track of the particle age
112
+
(custom-kernel)=
113
+
We can write custom kernels to add many different types of 'behaviour' to the particles. To do so we write a function with two arguments: `particles` and `fieldset`. We can then write any computation as a function of any variables defined in the `Particle` and any `Field` defined in the `FieldSet`. Kernels can then be combined by creating a `list` of the kernels. The kernels are executed in order:
114
+
115
+
```python
116
+
# Create a custom Particle object with an "age" variable
117
+
CustomParticle = parcels.Particle.add_variable(
118
+
parcels.Variable("age", initial=np.nan)
119
+
)
111
120
121
+
# Create a custom kernel which keeps track of the particle age
112
122
defAge(particles, fieldset):
113
123
particles.age += particles.dt
114
124
115
125
# define all kernels to be executed on particles using an (ordered) list
Every Kernel must be a function with the following (and only those) arguments: `(particles, fieldset)`
121
131
```
122
132
123
-
```{warning}
124
-
It is advised _not_ to update the particle coordinates (`particles.time`, `particles.z`, `particles.lat`, or `particles.lon`) directly, as that can negatively interfere with the way that particle movements by different kernels are vectorially added. Use a change in the coordinates: `particles.dlon`, `particles.dlat`, `particles.dz`, and/or `particles.dt` instead, and be careful with `particles.dt`. See also the [kernel loop tutorial](https://docs.oceanparcels.org/en/latest/examples/tutorial_kernelloop.html).
125
-
```
126
-
127
133
```{warning}
128
134
We have to be careful with writing kernels for vector fields on Curvilinear grids. While Parcels automatically rotates the "U" and "V" field when necessary, this is not the case for other fields such as Stokes drift. [This guide](../user_guide/examples/tutorial_nemo_curvilinear.ipynb) describes how to use a curvilinear grid in Parcels.
-[Sample fields like temperature](../user_guide/examples/tutorial_sampling.ipynb).
138
144
-[Mimic the behaviour of ARGO floats](../user_guide/examples/tutorial_Argofloats.ipynb).
139
145
-[Add diffusion to approximate subgrid-scale processes and unresolved physics](../user_guide/examples/tutorial_diffusion.ipynb).
140
-
-[Convert between units in m/s and degree/s](../user_guide/examples/tutorial_unitconverters.ipynb).
146
+
-[Convert between units in m/s and degrees](../user_guide/examples/tutorial_unitconverters.ipynb).
141
147
142
-
## 4. Execution
148
+
## 4. Execute
143
149
144
-
The execution of the simulation, given the `FieldSet`, `ParticleSet`, and `Kernels` defined in the previous steps, is done using the method **`parcels.ParticleSet.execute()`**. This method requires the following arguments:
150
+
The execution of the simulation is done using the method **`parcels.ParticleSet.execute()`**, given the `FieldSet`, `ParticleSet`, and `Kernels` defined in the previous steps. This method requires the following arguments:
145
151
146
152
1. The kernels to be executed.
147
153
2. The `runtime` defining how long the execution loop runs. Alternatively, you may define the `endtime` at which the execution loop stops.
@@ -156,5 +162,5 @@ There are many ways to analyze particle output, and although we provide [a short
156
162
157
163
#### Learn how to
158
164
159
-
-[choose an appropriate timestep](../user_guide/examples/tutorial_numerical_accuracy.ipynb)
160
-
-[work with Parcels output](./tutorial_output.ipynb)
165
+
-[Choose an appropriate timestep](../user_guide/examples/tutorial_numerical_accuracy.ipynb)
166
+
-[Work with Parcels output](./tutorial_output.ipynb)
0 commit comments