Skip to content

advect_2d.f90

Jonathan Thurgood edited this page Nov 7, 2018 · 5 revisions

Solves the 2D linear advection equation in conservative form

a_t + [f(a)]_x + [g(a)]_y=0 f(a) = ua g(a) = va a=a(x,y,t) (user defined) u=constant (user defined) v=constant (user defined) [Latex this]

Using either:

  1. dimensionally split 2nd order finite volume predictor-corrector 2.unsplit with "Corner Transport Upwind" (CTU) method (coming soon) with a choice of gradient limiters. Boundaries are periodic.

The main use of this code is to:

  1. demonstrate the extension of advect_1d_FV.f90 to 2D, including subtitles such as Strang splitting (e.g. turn it turn off to see consequence) and choice of DT

when u \neq v 2. Coming soon for CTU...

The code is more "complicated" than it needs to be for such a simple task, which could other wise be coded as a rather simple script. It is broken into various modules and subroutines in anticipation of the requirements of a more sophisticated hydrodynamics code, where such a structure would be useful.

User setup

User set conditions

All modules and subroutines are self-contained within the single text file since it is so short.

It is intended the user change user_control and (if you like) initial_conditions

It is fairly self explanatory: *list the vars

Compiling and running the code

Since its all in one file something like this should do:

gfortran advect_2d.f90 -o advect_2d

./advect_2d

However, there is also a simple makefile.

Output

The code saves the coordinates xb and the function a(x) as .dat files at the step it is terminating (either according to nsteps or t_end) to the current working directory. It also calls a simple python script to automatically render a simple plot of xb vs a(x). This is called "output.png"

You should be able to quickly clean this stuff up with "make clea" and "make cleanall"

Examples

Strang Splitting

Other examples

See also

This particular code's history is an independent Fortran implementation of the algorithms discussed in Chapter 4 of this excellent book http://bender.astro.sunysb.edu/hydro_by_example/CompHydroTutorial.pdf (he also provides python scripts to do the same sort of solves if you are interested to see the different approaches).