Repository navigation
Add example of limiting particle timestep by local cfl in schism tuto… - #3016
fluidnumericsJoe wants to merge 9 commits into
Conversation
for more information, see https://pre-commit.ci
erikvansebille
left a comment
There was a problem hiding this comment.
Thanks for adding this extra context, @fluidnumericsJoe! Below a few small comments (I can't put comments directly on the notebook in GitHub)
- Is "altitude" the right word in the comment of cell [5]? That to me suggests (3D) height?
- Avoid variable names like
h,eandpin that same cell - make them more explicit so users understand what's going on? - CFL number hasn't been introduced in cell [5]. Could you move that whole cell down to the section of cell [9]? That will also make it easier to refer to this part of the tutorial directly, because all information is in one subsection
- Make explicit that the math symbol
$C$ is the same asCFL_target - Should we add a link to the CFL-section on the
tutorial_dt_integratorstoo?
|
erikvansebille
left a comment
There was a problem hiding this comment.
Thanks for making these updates, however I don't see the link back from the dt_integration notebook to this notebook?
It's in the section titled "Limit the timestep by the local CFL number" under the text "See a priori estimation of dt for the same reasoning applied to a structured grid." It's also in the last cell titled "Adapting this tutorial to your own SCHISM setup" under the text " choosing a timestep and integration method" |
|
Sorry, I meant the other way around. So a link from the https://docs.parcels-code.org/en/latest/user_guide/examples/tutorial_dt_integrators.html notebook to this new notebook |
I have now added such a link in e88f57d - as I was working on merging your code with the new |
|
I now realise that the def CFLLimitedDt(particles, fieldset):
"""Shrink each particle's dt so it moves at most CFL_target cell widths per step."""
cell_width = fieldset.cell_width[particles]
u, v = fieldset.UV[particles]
dt_cfl = (
fieldset.CFL_target * cell_width / np.maximum(np.sqrt(u * u + v * v), 1e-12)
)
particles.dt = np.sign(particles.dt) * np.minimum(np.abs(particles.dt), dt_cfl)Should the @fluidnumericsJoe, any thoughts? |
|
I got the "old" behaviour back by using the diff --git a/docs/user_guide/convert_schism.ipynb b/docs/user_guide/convert_schism.ipynb
index 5692fb20..661a7c7a 100644
--- a/docs/user_guide/convert_schism.ipynb
+++ b/docs/user_guide/convert_schism.ipynb
@@ -271,7 +271,10 @@
"SchismParticle = parcels.Particle.add_variable(\n",
- " parcels.Variable(\"out_of_bounds\", dtype=np.int32, initial=0)\n",
+ " [\n",
+ " parcels.Variable(\"out_of_bounds\", dtype=np.int32, initial=0),\n",
+ " parcels.Variable(\"next_dt\", dtype=np.float32, initial=0),\n",
+ " ]\n",
")\n",
@@ -363,6 +366,7 @@
" dt_cfl = (\n",
" fieldset.CFL_target * cell_width / np.maximum(np.sqrt(u * u + v * v), 1e-12)\n",
" )\n",
+ " particles.next_dt = particles.dt.copy()\n",
" particles.dt = np.sign(particles.dt) * np.minimum(np.abs(particles.dt), dt_cfl)\n",
diff --git a/src/parcels/_core/kernel.py b/src/parcels/_core/kernel.py
index 5d216749..ebd7c6e2 100644
--- a/src/parcels/_core/kernel.py
+++ b/src/parcels/_core/kernel.py
@@ -127,8 +127,8 @@ class Kernel:
- if hasattr(self.fieldset, "RK45_tol"):
- # Update dt in case it's increased in RK45 kernel
+ if "next_dt" in particles._data:
+ # Update dt in case it's set by the kernel
particles.dt = particles.next_dtThis is of course not ideal, as it requires using the |
Description
This PR adds an example of limiting particle timestep by local cfl in schism tutorial
Checklist
mainfor normal development,v3-supportfor v3 support)