setup_m.f90 Source File


This file depends on

sourcefile~~setup_m.f90~~EfferentGraph sourcefile~setup_m.f90 setup_m.f90 sourcefile~config_io_m.f90 config_io_m.f90 sourcefile~setup_m.f90->sourcefile~config_io_m.f90 sourcefile~atmcfg_m.f90 atmcfg_m.f90 sourcefile~setup_m.f90->sourcefile~atmcfg_m.f90 sourcefile~logger_m.f90 logger_m.f90 sourcefile~setup_m.f90->sourcefile~logger_m.f90 sourcefile~simbox_m.f90 simbox_m.f90 sourcefile~setup_m.f90->sourcefile~simbox_m.f90 sourcefile~control_m.f90 control_m.f90 sourcefile~setup_m.f90->sourcefile~control_m.f90 sourcefile~stats_m.f90 stats_m.f90 sourcefile~setup_m.f90->sourcefile~stats_m.f90 sourcefile~bd_solver_m.f90 bd_solver_m.f90 sourcefile~setup_m.f90->sourcefile~bd_solver_m.f90 sourcefile~trajectory_m.f90 trajectory_m.f90 sourcefile~setup_m.f90->sourcefile~trajectory_m.f90 sourcefile~random_m.f90 random_m.f90 sourcefile~setup_m.f90->sourcefile~random_m.f90 sourcefile~constants_m.f90 constants_m.f90 sourcefile~setup_m.f90->sourcefile~constants_m.f90 sourcefile~interaction_m.f90 interaction_m.f90 sourcefile~setup_m.f90->sourcefile~interaction_m.f90 sourcefile~strings_m.f90 strings_m.f90 sourcefile~setup_m.f90->sourcefile~strings_m.f90 sourcefile~config_io_m.f90->sourcefile~atmcfg_m.f90 sourcefile~config_io_m.f90->sourcefile~simbox_m.f90 sourcefile~config_io_m.f90->sourcefile~constants_m.f90 sourcefile~config_io_m.f90->sourcefile~strings_m.f90 sourcefile~atmcfg_m.f90->sourcefile~constants_m.f90 sourcefile~timestamp_m.f90 timestamp_m.f90 sourcefile~logger_m.f90->sourcefile~timestamp_m.f90 sourcefile~simbox_m.f90->sourcefile~random_m.f90 sourcefile~simbox_m.f90->sourcefile~constants_m.f90 sourcefile~control_m.f90->sourcefile~constants_m.f90 sourcefile~control_m.f90->sourcefile~strings_m.f90 sourcefile~stats_m.f90->sourcefile~atmcfg_m.f90 sourcefile~stats_m.f90->sourcefile~simbox_m.f90 sourcefile~stats_m.f90->sourcefile~control_m.f90 sourcefile~stats_m.f90->sourcefile~constants_m.f90 sourcefile~stats_m.f90->sourcefile~strings_m.f90 sourcefile~bd_solver_m.f90->sourcefile~config_io_m.f90 sourcefile~bd_solver_m.f90->sourcefile~atmcfg_m.f90 sourcefile~bd_solver_m.f90->sourcefile~logger_m.f90 sourcefile~bd_solver_m.f90->sourcefile~control_m.f90 sourcefile~bd_solver_m.f90->sourcefile~stats_m.f90 sourcefile~bd_solver_m.f90->sourcefile~trajectory_m.f90 sourcefile~bd_solver_m.f90->sourcefile~constants_m.f90 sourcefile~bd_solver_m.f90->sourcefile~interaction_m.f90 sourcefile~brown_m.f90 brown_m.f90 sourcefile~bd_solver_m.f90->sourcefile~brown_m.f90 sourcefile~trajectory_m.f90->sourcefile~constants_m.f90 sourcefile~random_m.f90->sourcefile~constants_m.f90 sourcefile~interaction_m.f90->sourcefile~atmcfg_m.f90 sourcefile~interaction_m.f90->sourcefile~simbox_m.f90 sourcefile~interaction_m.f90->sourcefile~control_m.f90 sourcefile~interaction_m.f90->sourcefile~stats_m.f90 sourcefile~interaction_m.f90->sourcefile~constants_m.f90 sourcefile~table_m.f90 table_m.f90 sourcefile~interaction_m.f90->sourcefile~table_m.f90 sourcefile~pairtab_m.fpp pairtab_m.fpp sourcefile~interaction_m.f90->sourcefile~pairtab_m.fpp sourcefile~ia_vdw_m.f90 ia_vdw_m.f90 sourcefile~interaction_m.f90->sourcefile~ia_vdw_m.f90 sourcefile~ia_bond_m.f90 ia_bond_m.f90 sourcefile~interaction_m.f90->sourcefile~ia_bond_m.f90 sourcefile~ia_dihedral_m.f90 ia_dihedral_m.f90 sourcefile~interaction_m.f90->sourcefile~ia_dihedral_m.f90 sourcefile~ia_external_m.f90 ia_external_m.f90 sourcefile~interaction_m.f90->sourcefile~ia_external_m.f90 sourcefile~ia_angle_m.f90 ia_angle_m.f90 sourcefile~interaction_m.f90->sourcefile~ia_angle_m.f90 sourcefile~ia_tether_m.f90 ia_tether_m.f90 sourcefile~interaction_m.f90->sourcefile~ia_tether_m.f90 sourcefile~strings_m.f90->sourcefile~constants_m.f90 sourcefile~table_m.f90->sourcefile~constants_m.f90 sourcefile~vector_m.f90 vector_m.f90 sourcefile~table_m.f90->sourcefile~vector_m.f90 sourcefile~pairtab_m.fpp->sourcefile~atmcfg_m.f90 sourcefile~pairtab_m.fpp->sourcefile~simbox_m.f90 sourcefile~pairtab_m.fpp->sourcefile~constants_m.f90 sourcefile~pairtab_m.fpp->sourcefile~table_m.f90 sourcefile~cell_list_m.f90 cell_list_m.f90 sourcefile~pairtab_m.fpp->sourcefile~cell_list_m.f90 sourcefile~connectivity_m.f90 connectivity_m.f90 sourcefile~pairtab_m.fpp->sourcefile~connectivity_m.f90 sourcefile~aabbtree_m.f90 aabbtree_m.f90 sourcefile~pairtab_m.fpp->sourcefile~aabbtree_m.f90 sourcefile~pairtab_m.fpp->sourcefile~vector_m.f90 sourcefile~brown_m.f90->sourcefile~logger_m.f90 sourcefile~brown_m.f90->sourcefile~random_m.f90 sourcefile~brown_m.f90->sourcefile~constants_m.f90 sourcefile~brown_m.f90->sourcefile~strings_m.f90 sourcefile~ia_vdw_m.f90->sourcefile~atmcfg_m.f90 sourcefile~ia_vdw_m.f90->sourcefile~constants_m.f90 sourcefile~ia_bond_m.f90->sourcefile~logger_m.f90 sourcefile~ia_bond_m.f90->sourcefile~constants_m.f90 sourcefile~ia_bond_m.f90->sourcefile~strings_m.f90 sourcefile~ia_dihedral_m.f90->sourcefile~atmcfg_m.f90 sourcefile~ia_dihedral_m.f90->sourcefile~constants_m.f90 sourcefile~ia_external_m.f90->sourcefile~atmcfg_m.f90 sourcefile~ia_external_m.f90->sourcefile~constants_m.f90 sourcefile~ia_angle_m.f90->sourcefile~atmcfg_m.f90 sourcefile~ia_angle_m.f90->sourcefile~constants_m.f90 sourcefile~ia_tether_m.f90->sourcefile~atmcfg_m.f90 sourcefile~ia_tether_m.f90->sourcefile~constants_m.f90 sourcefile~cell_list_m.f90->sourcefile~simbox_m.f90 sourcefile~cell_list_m.f90->sourcefile~constants_m.f90 sourcefile~cell_list_m.f90->sourcefile~vector_m.f90 sourcefile~connectivity_m.f90->sourcefile~constants_m.f90 sourcefile~connectivity_m.f90->sourcefile~table_m.f90 sourcefile~connectivity_m.f90->sourcefile~vector_m.f90 sourcefile~aabbtree_m.f90->sourcefile~constants_m.f90 sourcefile~aabbtree_m.f90->sourcefile~strings_m.f90 sourcefile~aabbtree_m.f90->sourcefile~vector_m.f90 sourcefile~aabb_m.fpp aabb_m.fpp sourcefile~aabbtree_m.f90->sourcefile~aabb_m.fpp sourcefile~vector_m.f90->sourcefile~constants_m.f90 sourcefile~qsort_m.f90 qsort_m.f90 sourcefile~vector_m.f90->sourcefile~qsort_m.f90 sourcefile~aabb_m.fpp->sourcefile~constants_m.f90 sourcefile~aabb_m.fpp->sourcefile~strings_m.f90 sourcefile~qsort_m.f90->sourcefile~constants_m.f90

Files dependent on this one

sourcefile~~setup_m.f90~~AfferentGraph sourcefile~setup_m.f90 setup_m.f90 sourcefile~main.f90 main.f90 sourcefile~main.f90->sourcefile~setup_m.f90

Contents

Source Code


Source Code

module setup_m
    !! Routines for doing allocation, etc. in preparation for simulation run.

use constants_m
use strings_m
use random_m
use logger_m
use simbox_m
use atmcfg_m
use config_io_m
use control_m
use stats_m
use interaction_m
use trajectory_m
use bd_solver_m

implicit none

contains

!*******************************************************************************

subroutine run(cpar, job_tag)

    type(ctrlpar_t),  intent(in) :: cpar
    character(len=*), intent(in) :: job_tag
        !! This string will be used as is, i.e. if there are leading or trailing
        !! white spaces, they will appear in any I/O file names.
    character(len=:), allocatable :: fn
    character(len=128) :: msg
    integer(ip_long) :: ccbeg, ccend, crate
    integer(ip_long) :: nts
    type(smbx_t)     :: simbox
    type(atmcfg_t)   :: atc
    integer :: ierr
    logical :: lexists

    ierr =0

    !Read configuration from appropriate files.
    !Note: Reading from file includes initialization of the simulation box and
    !atom configuration.
    if ( cpar%lrevive ) then
        !Restarting simulation: Read revive file
        fn = cpar%fn_revive//job_tag
        call read_dump(nts, simbox, atc, fn)
        call logger%log_msg('read revive file `'//fn//'`')
    else 
        !New simulation: Read initial configuration file
        fn = cpar%fn_cfg//job_tag
        call read_config(simbox, atc, fn)
        call logger%log_msg('read config file `'//fn//'`')
        nts = 0
    end if

    !Allocate memory for forces. Forces are not saved in revive file or
    !in config file as they can be calculated from position data.
    allocate( atc%forces(3,atc%num_atoms) )
    atc%forces = 0.0_rp

    !Initialize stats collection
    call stats_init(cpar, simbox, atc, job_tag)
    call logger%log_msg('initialized stats collection')

    !Set up interactions
    call ia_setup(cpar, simbox, atc)
    call logger%log_msg('set up interaction params')

    !Set up trajectory if necessary. There can be only one trajectory per
    !simulation.
    if (cpar%write_traj) then
        fn = cpar%fn_traj//job_tag
        if (cpar%lrevive) then
            !Append/write to existing/new trajectory file
            !Check if trajectory file exists
            inquire(file=fn, exist=lexists)
            if (lexists) then
                !Open existing file for appending
                call traj%init(fn, 'rw', ierr)
                if (ierr /=0 ) then
                    call logger%log_msg('failed to open trajectory file ' &
                        //'`'//fn//'`')
                    call finish(atc); return
                else
                    call logger%log_msg('trajectory file opened')
                end if
            else
                !Create new trajectory file
                call traj%init(fn, atc%num_atoms, [integer:: 1, 0, 0, 0])
                call logger%log_msg('trajectory file created')
            end if
        else
            !Create new trajectory file
            call traj%init(fn, atc%num_atoms, [integer:: 1, 0, 0, 0])
            call logger%log_msg('trajectory file created')
        end if
    end if

    !Initialize random number generator
    if (cpar%read_seed) then
        call init_stream('random_seed.txt'//job_tag)
    else 
        call init_stream('')
    end if
    if (cpar%write_seed) call save_seed('random_seed.txt'//job_tag)
    call logger%log_msg('rng initialized')

    !Set up solver.
    call bds_init(cpar, atc%num_atoms, job_tag, ierr)
    if (ierr /= 0) then
        call logger%log_msg('bd solver initialization failed')
        call finish(atc); return
    end if
    call logger%log_msg('bd solver initialized')

    call system_clock(ccbeg, crate)

    call bds_run(nts, simbox, atc, ierr)

    call system_clock(ccend, crate)

    write(msg,'(a,es12.5)') 'execution time(s) = ', (ccend-ccbeg)/real(crate,rp)

    call logger%log_msg(msg)

    call finish(atc)

    end subroutine

!*******************************************************************************

subroutine finish(atc)

    type(atmcfg_t), intent(in out) :: atc

    call bds_finish()
    call traj%delete()
    call ia_finish()
    call stats_finish()
    call atmcfg_delete(atc)

    end subroutine

!*******************************************************************************

end module setup_m