The main driver, called after MPI and GPUs are initialized
subroutine main use mod_global_parameters use mod_input_output use mod_usr_methods use mod_ghostcells_update use mod_usr use mod_initialize use mod_initialize_amr, only: initlevelone, modify_IC use mod_initialize_amr, only: improve_initial_condition use mod_selectgrids, only: selectgrids use mod_particles use mod_fix_conserve use mod_advance, only: process use mod_multigrid_coupling use mod_convert, only: init_convert use mod_physics use mod_amr_grid, only: resettree, settree, resettree_convert !FIXME: ! use mod_trac, only: initialize_trac_after_settree use mod_convert_files, only: generate_plotfile use mod_comm_lib, only: comm_start, comm_finalize,mpistop use mod_geometry, only: set_coordinate_system_from_config, sync_geometry_host double precision :: time0, time_in logical,save :: part_file_exists=.false. call comm_start() time0 = MPI_WTIME() time_advance = .false. time_bc = zero ! read command line arguments first call read_arguments() ! Derive the coordinate system from the GEOM define before usr_init, so ! that ndir is set before phys_activate needs it and coordinate is set ! before read_par_files converts the angular domain bounds. A case may ! still call set_coordinate_system itself; it need not. call set_coordinate_system_from_config() ! the user_init routine should load a physics module call usr_init() call initialize_amrvac() if (restart_from_file /= undefined) then !AGILE: not yet implemented, data movement needs to happen here ! #ifdef _OPENACC ! call mpistop("restart or convert on GPU not yet implemented") ! #endif ! restart from previous file or dat file conversion ! get input data from previous AMRVAC run ! read in dat file call read_snapshot() ! rewrite it=0 snapshot when restart from it=0 state if(it==0.and.itsave(1,2)==0) snapshotnext=snapshotnext-1 if (reset_time) then ! reset it and global time to original value it = it_init global_time = time_init ! reset snapshot number snapshotnext=0 end if if (reset_it) then ! reset it to original value it = it_init end if ! modify initial condition if (firstprocess) then ! update ghost cells for all need-boundary variables before modification call getbc(global_time,0.d0,ps,1,nwflux+nwaux) call modify_IC end if ! select active grids call selectgrids ! update ghost cells for all need-boundary variables call getbc(global_time,0.d0,ps,1,nwflux+nwaux) ! reset AMR grid if (reset_grid) then call settree end if ! all blocks refined to the same level for output if(convert .and. level_io>0 .or. level_io_min.ne.1 .or. & level_io_max.ne.nlevelshi) call resettree_convert ! improve initial condition after restart and modification if(firstprocess) call improve_initial_condition() if (use_multigrid) call mg_setup_multigrid() if(use_particles) then call read_particles_snapshot(part_file_exists) call init_gridvars() if (.not. part_file_exists) call particles_create() if(convert) then call handle_particles() call finish_gridvars() call time_spent_on_particles() call comm_finalize stop end if end if if(convert) then if (npe/=1.and.(.not.(index(convert_type,& 'mpi')>=1)) .and. convert_type .ne. 'user') call & mpistop("non-mpi conversion only uses 1 cpu") if(mype==0.and.level_io>0) write(unitterm,& *)'reset tree to fixed level=',level_io ! Optionally call a user method that can modify the grid variables ! before saving the converted data if (associated(usr_process_grid) .or. associated(usr_process_global)) & then call process(it,global_time) end if !here requires -1 snapshot if (autoconvert .or. snapshotnext>0) snapshotnext = snapshotnext - 1 if(associated(phys_special_advance)) then ! e.g. calculate MF velocity from magnetic field call phys_special_advance(global_time,ps) end if ! standalone convert bypasses saveamrfile, so this is where the ! device-side cell metrics have to come back to the host call sync_geometry_host() call generate_plotfile call comm_finalize stop end if else ! form and initialize all grids at level one call initlevelone ! set up and initialize finer level grids, if needed call settree if (use_multigrid) call mg_setup_multigrid() ! improve initial condition call improve_initial_condition() ! select active grids call selectgrids if (use_particles) then call init_gridvars() call particles_create() end if end if !FIXME: ! initialize something base on tree information ! call initialize_trac_after_settree if (mype==0) then print*,'-------------------------------------------------------------------------------' write(*,'(a,f17.3,a)')' Startup phase took : ',MPI_WTIME()-time0,' sec' print*,'-------------------------------------------------------------------------------' end if ! an interface to allow user to do special things before the main loop if (associated(usr_before_main_loop)) call usr_before_main_loop() ! do time integration of all grids on all levels call timeintegration(time0) if (mype==0) then print*,'-------------------------------------------------------------------------------' write(*,'(a,f17.3,a)')' Finished AMRVAC in : ',MPI_WTIME()-time0,' sec' print*,'-------------------------------------------------------------------------------' end if call comm_finalize end subroutine main