Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust CFL formula #133

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ jobs:
- name: Test
env:
MPLBACKEND: "Agg"
run: nox -s test-notebooks
run: nox -s test-notebooks --python "3.11"
16 changes: 8 additions & 8 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 @@ -553,7 +553,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.11.0"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test(session: nox.Session) -> None:
session.run("pytest", *args)


@nox.session(name="test-notebooks", venv_backend="mamba")
@nox.session(name="test-notebooks", venv_backend="mamba", python="3.11")
def test_notebooks(session: nox.Session) -> None:
"""Run the notebooks."""
args = [
Expand Down
Loading