Skip to content

Commit

Permalink
Edits of code and prose
Browse files Browse the repository at this point in the history
  • Loading branch information
mdpiper committed Aug 7, 2023
1 parent d1901c7 commit e5cf51a
Showing 1 changed file with 80 additions and 47 deletions.
127 changes: 80 additions & 47 deletions lessons/python/9_advection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,31 @@
"outputs": [],
"source": [
"# Set parameter values\n",
"v = -10\n",
"\n",
"v = -10"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Initialize temperature array\n",
"T = np.zeros_like(x)\n",
"T[b] = amplitude * np.sin(x[b] * 2 * np.pi / wavelength)\n",
"T[c] = 0\n",
"\n",
"T[c] = 0"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Calculate numerical solution\n",
"iter = 0\n",
"while iter * dt < run_duration:\n",
Expand Down Expand Up @@ -328,8 +346,17 @@
"# Initialize temperature array\n",
"T = np.zeros_like(x)\n",
"T[b] = amplitude * np.sin(x[b] * 2 * np.pi / wavelength)\n",
"T[c] = 0\n",
"\n",
"T[c] = 0"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Calculate numerical solution\n",
"for t in range(int(run_duration)):\n",
" if v * t % dx == 0:\n",
Expand Down Expand Up @@ -368,46 +395,14 @@
"dt = min(dt_a,dt_d)\n",
"print('dt is: ' + str(dt) + 'hours')\n",
"~~~\n",
"- Same question: after how many hours do we get 5 ppm ash aerosols in Brussels?."
"- Same question: after how many hours do we get 5 ppm ash aerosols in Brussels?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Code up the while loop. \n",
"The structure should look like this:\n",
"~~~\n",
"it =0 \n",
"while ...\n",
" it+=1\n",
" \n",
" # Advection \n",
" if v>=0:\n",
" ... \n",
" elif v<0:\n",
" ...\n",
" \n",
" # Boundary conditions\n",
" C[0] = ...\n",
" C[-1] = ... \n",
" \n",
" # Diffusion \n",
" ...\n",
" \n",
" # Source term\n",
" C[ind_vol]...\n",
" \n",
"\n",
" if it%100==0: \n",
" plt.plot(x,C)\n",
" plt.scatter(x[ind_Bru],C[ind_Bru],c='r')\n",
" plt.title('Time is: ' + str(it*dt) + ' sec') \n",
" plt.show()\n",
" \n",
"print('Concentration reached after: ' + str(int(it*dt)) + ' hours')\n",
"print('or : ' + str(int(it*dt/24)) + ' days')\n",
"~~~\n"
"Enter the parameter values and initialize model variables."
]
},
{
Expand Down Expand Up @@ -456,6 +451,45 @@
"print(\"dt is: \" + str(dt) + \"hours\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Code up the while loop. \n",
"The structure should look like this:\n",
"~~~\n",
"iter = 0 \n",
"while ...\n",
" iter += 1\n",
"\n",
" # Advection \n",
" if v >= 0:\n",
" ... \n",
" elif v < 0:\n",
" ...\n",
"\n",
" # Boundary conditions\n",
" C[0] = ...\n",
" C[-1] = ... \n",
" \n",
" # Diffusion \n",
" ...\n",
"\n",
" # Source term\n",
" C[ind_vol] = ...\n",
" \n",
"\n",
" if iter % 100 == 0: \n",
" plt.plot(x, C)\n",
" plt.scatter(x[ind_Bru], C[ind_Bru], c='r')\n",
" plt.title('Time is: ' + str(iter*dt) + ' hours') \n",
" plt.show()\n",
"\n",
"print('Concentration reached after: ' + str(int(iter*dt)) + ' hours')\n",
"print('or : ' + str(int(iter*dt/24)) + ' days')\n",
"~~~\n"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -464,10 +498,9 @@
},
"outputs": [],
"source": [
"it = 0\n",
"\n",
"iter = 0\n",
"while C[ind_Bru] < 5:\n",
" it += 1\n",
" iter += 1\n",
"\n",
" # Advection\n",
" if v >= 0:\n",
Expand All @@ -486,14 +519,14 @@
" C[0] = Cstart\n",
" C[-1] = Cend\n",
"\n",
" if it % 100 == 0:\n",
" if iter % 100 == 0:\n",
" plt.plot(x, C)\n",
" plt.scatter(x[ind_Bru], C[ind_Bru], c=\"r\")\n",
" plt.title(\"Time is: \" + str(it * dt) + \" hours\")\n",
" plt.title(\"Time is: \" + str(iter * dt) + \" hours\")\n",
" plt.show()\n",
"\n",
"print(\"Concentration reached after: \" + str(int(it * dt)) + \" hours\")\n",
"print(\"or : \" + str(int(it * dt / 24)) + \" days\")"
"print(\"Concentration reached after: \" + str(int(iter * dt)) + \" hours\")\n",
"print(\"or : \" + str(int(iter * dt / 24)) + \" days\")"
]
},
{
Expand Down

0 comments on commit e5cf51a

Please sign in to comment.