diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/README.md b/README.md new file mode 100644 index 0000000..969fde0 --- /dev/null +++ b/README.md @@ -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) diff --git a/example_simulation.gif b/example_simulation.gif new file mode 100644 index 0000000..906cbdf Binary files /dev/null and b/example_simulation.gif differ diff --git a/main.py b/main.py index b35a362..15ee6ea 100644 --- a/main.py +++ b/main.py @@ -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 @@ -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() diff --git a/simulations/.gitignore b/simulations/.gitignore new file mode 100644 index 0000000..2fa80d6 --- /dev/null +++ b/simulations/.gitignore @@ -0,0 +1,2 @@ +*.png +