Skip to content

Commit

Permalink
Adjust CFL formula
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Campforts authored and Benjamin Campforts committed Dec 11, 2023
1 parent c6c9331 commit 5fcd747
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lessons/python/advection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"- Wind speed `v = 10` m/s\n",
"- Grid spacing `dx = 500` m (see previous code block)\n",
"- Total model run duration = 3 hours\n",
"- Calculate time step `dt` using the CFL criterion: `dt = 0.9 * v / dx`\n",
"- Calculate time step `dt` using the CFL criterion: `dt = 0.9 * dx / abs(v)`\n",
"- Periodic boundary conditions: the solution at the left boundary depends on the solution at the right boundary if velocity is positive and vice versa for negative velocities. \n",
"- Plot the wave every 10^5 iterations \n",
"\n",
Expand All @@ -190,7 +190,7 @@
" if v > 0:\n",
" # here comes the solution of the advection equation \n",
" \n",
" if iter % 1e5 == 0: \n",
" if iter % 10 == 0: \n",
" plt.plot(x/1.e3, T, 'b') \n",
" plt.xlim((0, max(x/1e3)))\n",
" plt.xlabel('x (km)')\n",
Expand All @@ -211,7 +211,7 @@
"# Set parameter values\n",
"v = 10\n",
"run_duration = 3 * 60 * 60.0\n",
"dt = 0.9 * v / dx\n",
"dt = 0.9 * dx / abs(v)\n",
"print(f\"Time step = {dt} s\")"
]
},
Expand Down Expand Up @@ -245,7 +245,7 @@
" T[1:] -= v * dt / dx * np.diff(T)\n",
" T[0] = T[-1]\n",
"\n",
" if iter % 1e5 == 0:\n",
" if iter % 10 == 0:\n",
" plt.plot(x / 1.0e3, T, \"b\")\n",
" plt.xlim((0, max(x / 1e3)))\n",
" plt.xlabel(\"x (km)\")\n",
Expand Down Expand Up @@ -312,7 +312,7 @@
" T[:-1] -= v * dt / dx * np.diff(T)\n",
" T[-1] = T[0]\n",
"\n",
" if iter % 1e5 == 0:\n",
" if iter % 10 == 0:\n",
" plt.plot(x / 1.0e3, T, \"r\")\n",
" plt.xlim((0, max(x / 1e3)))\n",
" plt.xlabel(\"x (km)\")\n",
Expand Down Expand Up @@ -390,7 +390,7 @@
"- Assume an advection velocity of 10 km/h (that is, the wind speed at which ash aerosols are advected towards the continent)\n",
"- Calculate the time step by combining the CFL criterium for advection (see above) and diffusion:\n",
"~~~\n",
"dt_a = 0.9*v/dx\n",
"dt_a = 0.9*dx/v\n",
"dt_d = dx*dx/D/2.5\n",
"dt = min(dt_a,dt_d)\n",
"print('dt is: ' + str(dt) + 'hours')\n",
Expand Down Expand Up @@ -445,7 +445,7 @@
"plt.scatter(x[ind_Bru], C[ind_Bru], c=\"r\")\n",
"\n",
"# Calculate a stable time step\n",
"dt_a = 0.9 * v / dx\n",
"dt_a = 0.9 * dx / v\n",
"dt_d = dx * dx / D / 2.5\n",
"dt = min(dt_a, dt_d)\n",
"print(\"dt is: \" + str(dt) + \"hours\")"
Expand Down Expand Up @@ -539,9 +539,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Ivy",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "ivy"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand Down

0 comments on commit 5fcd747

Please sign in to comment.