SourceForge


A SIMPLE WORKED EXAMPLE

Here we provide a simple worked example of the use of the AMR package with a 1D hydrodynamics code, in this case a MUSCL scheme, solving Sod's standard shock tube test problem.

In this example we assume MPI communications.

The basic code structure is outlined here, and the actual Fortran 90 expression of this outline can be seen by following the links. For clarity, in these code listings, we clearly identify the separation between blocks of `serial' user code and the coding built around it to marry it to the amr package. Wherever a slight edit has to be made inside a block of user code it will be indicated by the character string `!<<< EDITED' to the right of the screen.

The main program has the following simple structure:

The routine which initializes the solution on the initial grid blocks also has a very simple structure. It is essentially the users original serial code which initializes the solution on a uniform grid, but now placed inside a loop over the leaf grid blocks on the current processor. Note that because we use user supplied code to set the initial solution, using user defined Fortran variable names, we have to connect these variable names to those defined inside the amr package. This can be done by explicitly copying data between the two data structures, or by using pointers to establish the link. In this example we choose to use pointers. The pointers are declared inside the include file pointers.fh. It is also necessary to make sure that all lines defining `target' variables in the files physicaldata.F90 and workspace.F90 are uncommented when using this pointer approach.

This loop also illustrates how the NEIGH array which stores the locations of neighbor blocks is used to identify blocks which are at an external boundary.

The subroutines called in the user-supplied section of code all operate on a single grid block. We do not illustrate them here. The routine which advances the solution through one timestep has 3 main sections. Each section is constructed from a block of serial code supplied by the user, which is then placed within a loop over the leaf grid blocks.

        Section 1.
-----
| loop over leaf grid blocks
| compute this blocks timestep (users code)
| end loop
|
| find minimum timestep amongst all blocks
| (an inter-processor communication step)
-----


Section 2.
-----
| loop over leaf grid blocks
| call Muscl solver on this block (users code)
| end loop
-----


call amr_flux_conserve



Section 3.
-----
| loop over leaf grid blocks
| uses fluxes to update solution on this block (users code)
| end loop
-----
The first section computes the timestep on each leaf block, keeping track, as it proceeds, of the smallest timestep found on the local processor. From these, the shortest timestep across all the processors is found and provided to each processor. The second section applies the user supplied hydrodynamics routine (a Muscl scheme in this case) on each leaf block. Since this hydro calculation must conserve certain quantities, such as mass, the user supplied hydro routine returns fluxes at the interfaces between grid cells, and does not update the solution directly. Once these fluxes have been computed on each leaf block, we call the routine AMR_FLUX_CONSERVE. This ensures that the fluxes used at the interfaces between grid blocks at different refinement levels are consistent. By default, the boundary flux on the coarser of the two neighboring blocks is replaced by the equivalent flux on its refined neighbor. With this patch-up of the fluxes, conservation is guaranteed. Finally, in section 3, we loop over the leaf blocks applying these newly computed and patched-up fluxes to advance the solution.

The figure below shows an expanded version of the refined area about the shock shown in the illustration above, as it propagates to the right. The grid points are shown unconnected to better illustrate the resolution variations. In this example the refinement and derefinement criteria were based on the variation of mass density between neighboring cells.

Return to Main Page.