3.4 Creating a Simulation_init.F90

The routine Simulation_init is called by the routine Driver_initFlash at the beginning of the simulation. Driver_initFlash calls Unit_init.F90 routines of every unit to initialize them. In this particular case, the Simulation_init routine will get the necessary runtime parameters and store them in the Simulation_data Fortran module, and also initialize other variables in the module. More generally, all one-time initialization required by the simulation are implemented in the Simulation_init routine.

FLASH3 Transition: In FLASH2, the contents of the if (.firstcall.) clause are now in the Simulation_init routine in FLASH4.

The basic structure of the routine Simulation_init should consist of

  1. Fortran module use statement for the Simulation_data
  2. Fortran module use statement for the Unit_interfaces to access the interface of the RuntimeParameters unit, and any other units being used.
  3. Variable typing implicit none statement
  4. Necessary #include header files
  5. Declaration of arguments and local variables.
  6. Calls to the RuntimeParameters unit interface to obtain the values of runtime parameters.
  7. Calls to the PhysicalConstants unit interface to initialize any necessary physical constants.
  8. Calls to the Multispecies unit interface to initialize the species' properties, if there multiple species are in use
  9. Initialize other unit scope variables, packages and functions
  10. Any other calculations that are needed only once at the beginning of the run.

In this example after the implicit none statement we include two files, "constants.h", and "Flash.h". The "constants.h" file holds global constants defined in the FLASH code such as MDIM, MASTER_PE, and MAX_STRING_LENGTH. It also stores constants that make reading the code easier, such as IAXIS, JAXIS, and KAXIS, which are defined as 1,2, and 3, respectively. More information is available in comments in the distributed constants.h. A complete list of defined constants is available on the Code Support Web Page.

The "Flash.h" file contains all of the definitions specific to a given problem. This file is generated by the setup script and defines the indices for the variables in various data structures. For example, the index for density in the cell centered grid data structure is defined as DENS_VAR. The "Flash.h" file also defines the number of species, number of dimensions, maximum number of blocks, and many more values specific to a given run. Please see Chp:Flash.h for complete description of the Flash.h file.

FLASH3 Transition: The defined constants in "Flash.h" file allows the user direct access to the variable index in `unk.' This direct access is unlike FLASH2, where the user would first have to get the integer index of the variable by calling a data base function and then use the integer variable idens as the variable index. Previously:  
idens=dBaseKeyNumber('dens')
ucons(1,i) = solnData(idens,i,j,k)
Now, the syntax is simpler:  
ucons(1,i) = solnData(DENS_VAR,i,j,k)
This new syntax also allows discovery of specification errors at compile time.

 

subroutine Simulation_init()


use Simulation_data
  use RuntimeParameters_interface, ONLY : RuntimeParameters_get
  implicit none


#include "Flash.h"
#include "constants.h"


! get the runtime parameters relevant for this problem


call RuntimeParameters_get('smallp', sim_smallP)
  call RuntimeParameters_get('smallx', sim_smallX)
  call RuntimeParameters_get('gamma', sim_gamma)
  call RuntimeParameters_get('sim_rhoLeft', sim_rhoLeft)
  call RuntimeParameters_get('sim_rhoRight', sim_rhoRight)
  call RuntimeParameters_get('sim_pLeft', sim_pLeft)
  call RuntimeParameters_get('sim_pRight', sim_pRight)
  call RuntimeParameters_get('sim_uLeft', sim_uLeft)
  call RuntimeParameters_get('sim_uRight', sim_uRight)
  call RuntimeParameters_get('sim_xangle', sim_xAngle)
  call RuntimeParameters_get('sim_yangle', sim_yAngle)
  call RuntimeParameters_get('sim_posn', sim_posn)


! Do other initializations
  ! convert the shock angle parameters


sim_xAngle = sim_xAngle * 0.0174532925 ! Convert to radians.
  sim_yAngle = sim_yAngle * 0.0174532925


sim_xCos = cos(sim_xAngle)


if (NDIM == 1) then
     sim_xCos = 1.
     sim_yCos = 0.
     sim_zCos = 0.


elseif (NDIM == 2) then
     sim_yCos = sqrt(1. - sim_xCos*sim_xCos)
     sim_zCos = 0.


elseif (NDIM == 3) then
     sim_yCos = cos(sim_yAngle)
     sim_zCos = sqrt( max(0., 1. - sim_xCos*sim_xCos - sim_yCos*sim_yCos) )
  endif


end subroutine Simulation_init