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/user_guide/examples/explanation_kernelloop.md
+26-25Lines changed: 26 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ kernelspec:
6
6
7
7
# The Parcels Kernel loop
8
8
9
-
This tutorial explains how Parcels executes multiple Kernels, and what happens under the hood when you combine Kernels.
9
+
On this page we discuss Parcels' execution loop, and what happens under the hood when you combine multiple Kernels.
10
10
11
11
This is probably not very relevant when you only use the built-in Advection kernels, but can be important when you are writing and combining your own Kernels!
12
12
@@ -18,7 +18,7 @@ In order to make sure that the displacements of a particle in the different Kern
18
18
19
19
## Basic implementation
20
20
21
-
Below is a structured overview of the Kernel loop is implemented. Note that this is for `lon` only, but the same process is applied for`lat` and `z`.
21
+
Below is a structured overview of how the Kernel loop is implemented. Note that this is for `time` and `lon` only, but the process for `lon`is also applied to`lat` and `z`.
22
22
23
23
1. Initialise an extra Variable `particles.dlon=0`
24
24
@@ -38,9 +38,9 @@ Below is a structured overview of the Kernel loop is implemented. Note that this
38
38
39
39
Besides having commutable Kernels, the main advantage of this implementation is that, when using Field Sampling with e.g. `particles.temp = fieldset.Temp[particles.time, particles.z, particles.lat, particles.lon]`, the particle location stays the same throughout the entire Kernel loop. Additionally, this implementation ensures that the particle location is the same as the location of the sampled field in the output file.
40
40
41
-
## Example with multiple Kernels
41
+
## Example with currents and winds
42
42
43
-
Below is a simple example of some particles at the surface of the ocean. We create an idealised zonal wind flow that will "push" a particle that is already affected by the surface currents. The Kernel loop ensures that these two forces act at the same time and location, as we will show.
43
+
Below is a simple example of some particles at the surface of the ocean. We create an idealised zonal wind flow that will "push" a particle that is already affected by the surface currents. The Kernel loop ensures that these two forces act at the same time and location.
@@ -160,34 +161,34 @@ Once an error is thrown (for example, a Field Interpolation error), then the `pa
160
161
For example, you can write a Kernel that checks for `particles.state == StatusCode.ErrorOutOfBounds` and deletes the particle, and then append this to the Kernel list in `pset.execute()`.
161
162
162
163
```
163
-
def CheckOutOfBounds(particles, fieldset):
164
-
if particles.state == StatusCode.ErrorOutOfBounds:
if particles.state >= 50: # This captures all Errors
170
-
particles.delete()
169
+
def DeleteAnyError(particles, fieldset):
170
+
any_error = particles.state >= 50 # This captures all Errors
171
+
particles[any_error].state = StatusCode.Delete
171
172
```
172
173
173
174
But of course, you can also write code for more sophisticated behaviour than just deleting the particle. It's up to you! Note that if you don't delete the particle, you will have to update the `particles.state = StatusCode.Success` yourself. For example:
174
175
175
176
```
176
177
def Move1DegreeWest(particles, fieldset):
177
-
if particles.state == StatusCode.ErrorOutOfBounds:
Kernel functions such as the ones above can then be added to the list of kernels in `pset.execute()`.
192
193
193
-
Note that these Kernels that control what to do with `particles.state` should typically be added at the _end_ of the Kernel list, because otherwise later Kernels may overwrite the `particles.state` or the `particle_dlon` variables.
194
+
Note that these Kernels that control what to do with `particles.state` should typically be added at the _end_ of the Kernel list, because otherwise later Kernels may overwrite the `particles.state` or the `particle.dlon` variables.
0 commit comments