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.
The basic structure of the routine Simulation_init should consist of
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.
idens=dBaseKeyNumber('dens') ucons(1,i) = solnData(idens,i,j,k)
ucons(1,i) = solnData(DENS_VAR,i,j,k)
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