Skip to content

Commit

Permalink
Added a video and readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
larsgeb committed Nov 10, 2020
1 parent eacf30a commit 38eea81
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
A finite difference code to simulate 2D advection-convection, or Rayleigh-Bernard, systems.
Has the dependencies:

1. Python 3.7
2. Numpy
3. SciPy
4. Matplotlib

Run the code by changing the configuration values in `main.py` and entering the following on your terminal:

```
python main.py
```

Make a video out of the results by going into the `simulations` directory and using ffmpeg like this:

```
ffmpeg -framerate 5 -pattern_type glob -i '*.png' \
-c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
```

An example simulation with an unstable initial condition and 3:1 aspect ratio (which will favour 3 convection cells) is given below. This is the parameters currently set in `main.py`.

![](example_simulation.gif)
Binary file added example_simulation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 14 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

# --- Setup; using the config as a 'global variable module' --- #
config.ny = 40
config.nx = 80
config.nx = 120
config.dy = 1.0 / (config.ny)
config.dx = 2.0 / (config.nx)
config.dt = 0.001
config.nt = int(0.5 / config.dt)
config.dx = 3.0 / (config.nx)
config.dt = 0.000125
config.nt = int(0.2 / config.dt)
dt = config.dt
nt = config.nt
ny = config.ny
Expand Down Expand Up @@ -159,27 +159,28 @@
ax2.set_xlabel("t [time]")
ax2.set_ylabel("max V [speed]")
ax2.set_xlim([0, nt * dt])
ax2.set_ylim([0.01, ax2.set_ylim()[1]])

# plot heat fluxes
ax3.plot(t[::generateEvery], heatFluxAdvectionArr)
ax3.plot(t[::generateEvery], heatFluxConductionArr)
ax3.plot(t[::generateEvery], totalHeatFluxArr, linestyle=':')
ax3.semilogy(t[::generateEvery], heatFluxAdvectionArr)
ax3.semilogy(t[::generateEvery], heatFluxConductionArr)
ax3.semilogy(t[::generateEvery], totalHeatFluxArr, linestyle=':')
ax3.legend(['Advective heat flux', 'Conductive heat flux', 'Total heat flux'], fontsize=5,
loc='center left')
loc='lower right')
ax3.set_xlabel("t [time]")
ax3.set_ylabel("q [heat flux]")
ax3.set_xlim([0, nt * dt])
ymax = totalHeatFluxArr[0] * 1.3
ax3.set_ylim([0, ymax if np.max(totalHeatFluxArr) * 1.1 < ymax else np.max(totalHeatFluxArr) * 1.1])
ax3.set_ylim([0.01, ymax if np.max(totalHeatFluxArr) * 1.1 < ymax else np.max(totalHeatFluxArr) * 1.1])

# Plot titles
ax1.set_title("Temperature and velocity field\nstep = %i, dt = %.2e, t = %.2f" % (it, dt, t[-1] - dt),
FontSize=7)
ax2.set_title("Maximum fluid velocity over time", FontSize=7)
ax3.set_title("Heat fluxes over time", FontSize=7)
fontsize=7)
ax2.set_title("Maximum fluid velocity over time", fontsize=7)
ax3.set_title("Heat fluxes over time", fontsize=7)

# Plot and redo!
plt.savefig("simulations/field%i.png" % (it / generateEvery))
plt.savefig("simulations/field%05i.png" % (it / generateEvery))
clrbr.remove()
ax1.clear()
ax2.clear()
Expand Down
2 changes: 2 additions & 0 deletions simulations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.png

0 comments on commit 38eea81

Please sign in to comment.