# Chapter 5: Tutorial

If DAGH is not already installed on your system refer to the appendix on how to obtain, install and compile DAGH. The source code and other associated files that will be used for the tutorials are all in the sub-directory /examples/Tutorials .

## The Transport Equation

In our tutorial we will be studying the evolution of a simple 2-dimensional transport equation of the form
u,t + u,x + u,y = 0
where u represents some physical quantity and u,t represents the partial derivative of u with respect to t, and so on. The computational domain is a rectangle. The initial values of u are chosen from a gaussian distributed according to the initial parametrs chosen by the user. We will be using MacCormack scheme which is essentially a predictor-corrector method to study the evolution.

## Code Structure in Pseudo-code

The MacCormack integration of the transport equation is presented in pseudo code. The driver replaces the main program and calls each of the subroutines at the appropriate places. The Fortran 90 code that implements the MacCormack integration scheme (sans the main program) is in the file transport.f. The boundaries are updated by calling a built-in DAGH function BoundaryUpdate rather than by using a Fortran subroutine to do the same. The reader should now examine the file transport.f to identify the corresponding subroutines in the pseudo code.

### Main Program

Initialize the number of grid points nx, ny.
Initialize the initial time tzero.
Initialize the number of iterations.
For number of dimensions do
Initialize lower bound.
Initialize upper bound.
Initialize shape information.
End for.
Calculate the mesh separation dx, dy and time step dt.
Initialize the function u.
Output the values of the function u on the computational domain.
Do for number of iterations specified
Set previous value of function to present value.
Evolve the function u by one time step.
Update the boundaries.
Output the values of u.
End do

### Subroutine initial

Initialize the standard deviation sigma
Initialize the offset from the origin roffset
Do for j = 1 to ny
Calculate y
Do for i = 1 to nx
Calculate x.
Assign to the function u at coordinates (i,j) the value generated by the gaussian function.
End do
End do

### Subroutine evolve

Calculate the backward difference (predictor step).
Calculate the forward difference and average with old value (corrector step).

### Subroutine boundaries

Shift the values of the function lying within and next to the boundary to the boundary.

### End subroutine boundaries

All the subroutines except the subroutine boundaries are in the file transport.f and will be used in the example that follows. We will be using the transport equation to illustrate how to set up the driver for DAGH and run the program in three different situations. In the simplest case we will use just one grid and run our program on a single processor. We will then run the single grid on several processors. Finally we will implement the adaptive mesh refinement technique and run our program on multiple processors.

Next section: Unigrid Sequential Code