Closed gacuervol closed 2 years ago
Hi,
As the message error indicates, this is happening because the particle (at location 41.375000, -26.375000) tried to get through the surface, thus out of water.
You can fix that for example in two ways:
def DeleteParticle(particle, fieldset, time):
particle.delete()
pset.execute(AdvectionRK4_3D + k_dist, # the kernel (which defines how particles move)
runtime=timedelta(days=dias), # the total length of the run
dt=timedelta(days=1), # the timestep of the kernel
recovery={ErrorCode.ErrorThroughSurface: DeleteParticle},
output_file=output_file,
)
In that case, you will need to import the ErrorCode class and a recovery kernel.
The example shows a kernel that deletes the particle above the surface.
from parcels import ErrorCode
Another way is to create your own AdvectionRK4_3D kernel limiting particles to the surface (example below). Since a negative depth means a particle above the surface, we limited the depth up to 0 meters using the max function.
def AdvectionRK4_3D_surface_limited(particle, fieldset, time):
"""Run AdvectionRK4_3D kernel keeping particles on 0-depth, avoiding Through-surface error."""
(u1, v1, w1) = fieldset.UVW[particle]
lon1 = particle.lon + u1 * 0.5 * particle.dt
lat1 = particle.lat + v1 * 0.5 * particle.dt
dep1 = particle.depth + w1 * 0.5 * particle.dt
dep1 = max(0, dep1)
(u2, v2, w2) = fieldset.UVW[time + 0.5 * particle.dt, dep1, lat1, lon1, particle]
lon2 = particle.lon + u2 * 0.5 * particle.dt
lat2 = particle.lat + v2 * 0.5 * particle.dt
dep2 = particle.depth + w2 * 0.5 * particle.dt
dep2 = max(0, dep2)
(u3, v3, w3) = fieldset.UVW[time + 0.5 * particle.dt, dep2, lat2, lon2, particle]
lon3 = particle.lon + u3 * particle.dt
lat3 = particle.lat + v3 * particle.dt
dep3 = particle.depth + w3 * particle.dt
dep3 = max(0, dep3)
(u4, v4, w4) = fieldset.UVW[time + particle.dt, dep3, lat3, lon3, particle]
particle.lon += (u1 + 2 * u2 + 2 * u3 + u4) / 6.0 * particle.dt
particle.lat += (v1 + 2 * v2 + 2 * v3 + v4) / 6.0 * particle.dt
particle.depth += (w1 + 2 * w2 + 2 * w3 + w4) / 6.0 * particle.dt
particle.depth = max(0, particle.depth)
Thanks for picking up this answer, @axnsantana! You are completely right! I'll close the issue now
Hello,
First I wanted to say thank you for this wonderful Python module. I am using the following data:
I am currently trying to simulate the 3D advection of 6 particles located in the axis of a cyclonic eddy at different depths. Using the following code:
However, when I run the simulation with AdvectionRK4_3D, I get the following error:
I must say that no error occurs with the AdvectionRK4 advection kernel.
I really appreciate any help.