2010-10-06 23:03:47 -03:00
|
|
|
!!******************************************************************************
|
2008-11-04 13:08:01 -06:00
|
|
|
!!
|
2012-07-22 12:30:20 -03:00
|
|
|
!! This file is part of the AMUN source code, a program to perform
|
|
|
|
!! Newtonian or relativistic magnetohydrodynamical simulations on uniform or
|
|
|
|
!! adaptive mesh.
|
2008-11-04 13:08:01 -06:00
|
|
|
!!
|
2013-12-10 15:23:28 -02:00
|
|
|
!! Copyright (C) 2008-2013 Grzegorz Kowal <grzegorz@amuncode.org>
|
2008-11-04 13:08:01 -06:00
|
|
|
!!
|
2012-07-22 12:30:20 -03:00
|
|
|
!! This program is free software: you can redistribute it and/or modify
|
|
|
|
!! it under the terms of the GNU General Public License as published by
|
|
|
|
!! the Free Software Foundation, either version 3 of the License, or
|
|
|
|
!! (at your option) any later version.
|
2008-11-04 13:08:01 -06:00
|
|
|
!!
|
2011-04-29 11:21:30 -03:00
|
|
|
!! This program is distributed in the hope that it will be useful,
|
2008-11-04 13:08:01 -06:00
|
|
|
!! but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
!! GNU General Public License for more details.
|
|
|
|
!!
|
|
|
|
!! You should have received a copy of the GNU General Public License
|
2012-07-22 12:30:20 -03:00
|
|
|
!! along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-11-04 13:08:01 -06:00
|
|
|
!!
|
2010-10-06 23:03:47 -03:00
|
|
|
!!******************************************************************************
|
2008-11-04 13:08:01 -06:00
|
|
|
!!
|
2012-07-22 12:30:20 -03:00
|
|
|
!! program: AMUN
|
|
|
|
!!
|
2012-07-28 12:24:12 -03:00
|
|
|
!! AMUN is a code to perform numerical simulations in a fluid approximation on
|
|
|
|
!! adaptive mesh for Newtonian and relativistic environments with or without
|
|
|
|
!! magnetic field.
|
|
|
|
!!
|
2012-07-28 13:48:15 -03:00
|
|
|
!!
|
2012-07-22 12:30:20 -03:00
|
|
|
!!******************************************************************************
|
2008-11-04 13:08:01 -06:00
|
|
|
!
|
2011-04-25 13:44:34 -03:00
|
|
|
program amun
|
2008-11-04 13:08:01 -06:00
|
|
|
|
2012-07-28 12:24:12 -03:00
|
|
|
! include external subroutines used in this module
|
2008-11-04 21:00:50 -06:00
|
|
|
!
|
2012-07-22 22:47:25 -03:00
|
|
|
use blocks , only : initialize_blocks, finalize_blocks, get_nleafs
|
2012-07-27 17:18:24 -03:00
|
|
|
use boundaries , only : initialize_boundaries
|
2012-07-28 12:24:12 -03:00
|
|
|
use coordinates , only : initialize_coordinates, finalize_coordinates
|
2013-12-10 20:56:37 -02:00
|
|
|
use equations , only : initialize_equations, finalize_equations
|
2012-07-31 15:13:51 -03:00
|
|
|
use evolution , only : initialize_evolution, advance
|
2012-07-28 11:47:14 -03:00
|
|
|
use evolution , only : n, t, dt, dtn, cfl
|
2010-12-08 12:21:41 -02:00
|
|
|
#ifdef FORCE
|
2012-07-27 16:55:32 -03:00
|
|
|
use forcing , only : initialize_forcing, clear_forcing
|
2010-12-08 12:21:41 -02:00
|
|
|
#endif /* FORCE */
|
2012-07-28 12:24:12 -03:00
|
|
|
use integrals , only : init_integrals, clear_integrals, store_integrals
|
2012-07-27 16:46:36 -03:00
|
|
|
use interpolations, only : initialize_interpolations
|
2012-08-02 00:35:37 -03:00
|
|
|
use io , only : initialize_io, write_data, write_restart_data &
|
|
|
|
, restart_job
|
2012-07-27 10:34:19 -03:00
|
|
|
use mesh , only : initialize_mesh, clear_mesh
|
|
|
|
use mesh , only : generate_mesh, store_mesh_stats
|
2011-05-14 19:37:40 -03:00
|
|
|
#ifdef MPI
|
2012-07-28 12:24:12 -03:00
|
|
|
use mesh , only : redistribute_blocks
|
2011-05-14 19:37:40 -03:00
|
|
|
#endif /* MPI */
|
2012-07-28 13:48:15 -03:00
|
|
|
use mpitools , only : initialize_mpitools, finalize_mpitools, setup_mpi
|
2012-07-22 19:01:27 -03:00
|
|
|
#ifdef MPI
|
2012-07-22 19:32:21 -03:00
|
|
|
use mpitools , only : bcast_integer_variable
|
|
|
|
use mpitools , only : reduce_maximum_integer
|
2012-07-22 19:01:27 -03:00
|
|
|
#endif /* MPI */
|
2012-07-28 12:24:12 -03:00
|
|
|
use mpitools , only : master, nprocs, nproc
|
2012-07-22 19:32:21 -03:00
|
|
|
use parameters , only : read_parameters, finalize_parameters
|
|
|
|
#ifdef MPI
|
|
|
|
use parameters , only : redistribute_parameters
|
|
|
|
#endif /* MPI */
|
2012-07-28 12:12:35 -03:00
|
|
|
use parameters , only : get_parameter_integer, get_parameter_real &
|
|
|
|
, get_parameter_string
|
2012-07-27 21:13:43 -03:00
|
|
|
use problems , only : initialize_problems
|
2012-07-22 19:37:58 -03:00
|
|
|
use random , only : initialize_random, finalize_random
|
2012-07-27 21:28:59 -03:00
|
|
|
use refinement , only : initialize_refinement
|
2013-12-11 10:16:06 -02:00
|
|
|
use schemes , only : initialize_schemes, finalize_schemes
|
2012-07-28 12:24:12 -03:00
|
|
|
use timers , only : initialize_timers, start_timer, stop_timer &
|
|
|
|
, set_timer, get_timer, get_timer_total &
|
|
|
|
, timer_enabled, timer_description, ntimers
|
|
|
|
|
|
|
|
! module variables are not implicit by default
|
2008-11-04 13:08:01 -06:00
|
|
|
!
|
2012-07-28 12:24:12 -03:00
|
|
|
implicit none
|
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! default parameters
|
2008-11-04 13:08:01 -06:00
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
integer, dimension(3) :: div = 1
|
|
|
|
logical, dimension(3) :: per = .true.
|
|
|
|
integer :: nmax = 0, ndat = 1, nres = -1, ires = -1
|
2012-08-02 00:35:37 -03:00
|
|
|
real :: dtini = 1.0d-8
|
2012-07-28 12:12:35 -03:00
|
|
|
real :: tmax = 0.0d0, trun = 9999.0d0, tsav = 20.0d0
|
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! temporary variables
|
2012-07-22 15:46:56 -03:00
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
character(len=64) :: lbnd, ubnd
|
2012-07-22 15:46:56 -03:00
|
|
|
|
2012-07-28 12:03:17 -03:00
|
|
|
! the termination and status flags
|
|
|
|
!
|
|
|
|
integer :: iterm, iret
|
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! timer indices
|
2012-07-22 15:46:56 -03:00
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
integer :: iin, iev, itm
|
|
|
|
#ifdef PROFILE
|
|
|
|
integer :: ipr, ipi
|
|
|
|
#endif /* PROFILE */
|
|
|
|
|
|
|
|
! local snapshot file counters
|
|
|
|
!
|
|
|
|
integer :: nrun = 1
|
|
|
|
|
|
|
|
! iteration and time variables
|
|
|
|
!
|
|
|
|
integer :: i, ed, eh, em, es, ec
|
|
|
|
integer :: nsteps = 1
|
|
|
|
character(len=80) :: fmt, tmp
|
|
|
|
|
|
|
|
real :: tbeg, thrs
|
|
|
|
real(kind=8) :: tm_curr, tm_exec, tm_conv
|
2012-07-22 15:46:56 -03:00
|
|
|
|
2012-07-28 12:24:12 -03:00
|
|
|
#ifdef INTEL
|
|
|
|
! the type of the function SIGNAL should be defined for Intel compiler
|
|
|
|
!
|
|
|
|
integer(kind=4) :: signal
|
|
|
|
#endif /* INTEL */
|
|
|
|
|
2011-05-06 09:51:40 -03:00
|
|
|
#ifdef SIGNALS
|
2011-04-29 00:51:28 -03:00
|
|
|
! references to functions handling signals
|
|
|
|
!
|
2011-06-07 17:29:03 -03:00
|
|
|
#ifdef GNU
|
2011-04-29 00:51:28 -03:00
|
|
|
intrinsic signal
|
2011-06-07 17:29:03 -03:00
|
|
|
#endif /* GNU */
|
2011-04-29 00:51:28 -03:00
|
|
|
external terminate
|
|
|
|
|
|
|
|
! signal definitions
|
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
integer, parameter :: SIGINT = 2, SIGABRT = 6, SIGTERM = 15
|
2011-04-29 00:51:28 -03:00
|
|
|
#endif /* SIGNALS */
|
2012-07-28 12:03:17 -03:00
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! an array to store execution times
|
|
|
|
!
|
|
|
|
real(kind=8), dimension(ntimers) :: tm
|
|
|
|
|
2012-07-28 12:03:17 -03:00
|
|
|
! common block
|
|
|
|
!
|
|
|
|
common /termination/ iterm
|
2008-11-04 13:08:01 -06:00
|
|
|
!
|
2008-12-08 21:11:17 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-11-04 21:00:50 -06:00
|
|
|
!
|
2012-07-28 12:24:12 -03:00
|
|
|
! initialize the termination flag
|
|
|
|
!
|
|
|
|
iterm = 0
|
|
|
|
|
|
|
|
! initialize module TIMES
|
2012-07-22 15:46:56 -03:00
|
|
|
!
|
|
|
|
call initialize_timers()
|
|
|
|
|
|
|
|
! set timer descriptions
|
|
|
|
!
|
2012-07-28 12:24:12 -03:00
|
|
|
call set_timer('INITIALIZATION', iin)
|
|
|
|
call set_timer('EVOLUTION' , iev)
|
|
|
|
call set_timer('TERMINATION' , itm)
|
2012-07-22 15:46:56 -03:00
|
|
|
|
|
|
|
! start time accounting for the initialization
|
|
|
|
!
|
|
|
|
call start_timer(iin)
|
|
|
|
|
2011-04-29 00:51:28 -03:00
|
|
|
#ifdef SIGNALS
|
2012-07-28 12:24:12 -03:00
|
|
|
! assign function terminate() with signals
|
2011-04-29 00:51:28 -03:00
|
|
|
!
|
2011-06-07 17:29:03 -03:00
|
|
|
#ifdef GNU
|
|
|
|
iret = signal(SIGINT , terminate)
|
|
|
|
iret = signal(SIGABRT, terminate)
|
|
|
|
iret = signal(SIGTERM, terminate)
|
2011-06-17 20:21:10 -03:00
|
|
|
#else /* GNU */
|
2011-06-07 17:29:03 -03:00
|
|
|
iret = signal(SIGINT , terminate, -1)
|
|
|
|
iret = signal(SIGABRT, terminate, -1)
|
|
|
|
iret = signal(SIGTERM, terminate, -1)
|
2011-06-17 20:21:10 -03:00
|
|
|
#endif /* GNU */
|
2011-04-29 00:51:28 -03:00
|
|
|
#endif /* SIGNALS */
|
2011-06-17 20:21:10 -03:00
|
|
|
|
2012-07-28 12:24:12 -03:00
|
|
|
! initialize module MPITOOLS
|
2008-12-22 14:57:31 -06:00
|
|
|
!
|
2012-07-28 12:29:44 -03:00
|
|
|
call initialize_mpitools()
|
2008-12-22 14:57:31 -06:00
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! print the welcome message
|
2008-11-04 13:08:01 -06:00
|
|
|
!
|
2012-07-22 19:01:27 -03:00
|
|
|
if (master) then
|
2012-07-28 13:48:15 -03:00
|
|
|
|
2008-12-22 14:57:31 -06:00
|
|
|
write (*,"(1x,78('-'))")
|
2012-07-28 13:48:15 -03:00
|
|
|
write (*,"(1x,18('='),17x,a,17x,19('='))") 'A M U N'
|
2011-03-21 18:24:55 -03:00
|
|
|
write (*,"(1x,16('='),4x,a,4x,16('='))") &
|
2013-12-11 00:06:30 -02:00
|
|
|
'Copyright (C) 2008-2013 Grzegorz Kowal'
|
2012-07-28 13:48:15 -03:00
|
|
|
write (*,"(1x,18('='),9x,a,9x,19('='))") &
|
|
|
|
'under GNU GPLv3 license'
|
2008-12-22 14:57:31 -06:00
|
|
|
write (*,"(1x,78('-'))")
|
|
|
|
write (*,*)
|
2012-07-28 13:48:15 -03:00
|
|
|
|
2010-10-06 23:11:22 -03:00
|
|
|
end if
|
2008-11-04 13:08:01 -06:00
|
|
|
|
2012-07-22 19:32:21 -03:00
|
|
|
! initialize and read parameters from the parameter file
|
|
|
|
!
|
|
|
|
if (master) call read_parameters(iterm)
|
|
|
|
|
|
|
|
#ifdef MPI
|
|
|
|
! broadcast the termination flag
|
|
|
|
!
|
|
|
|
call bcast_integer_variable(iterm, iret)
|
|
|
|
|
|
|
|
! check if the termination flag was broadcaster successfully
|
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
if (iterm > 0) go to 20
|
2012-07-22 19:32:21 -03:00
|
|
|
|
|
|
|
! reset the termination flag
|
|
|
|
!
|
|
|
|
iterm = 0
|
|
|
|
|
|
|
|
! redistribute parameters among all processors
|
|
|
|
!
|
|
|
|
call redistribute_parameters(iterm)
|
|
|
|
|
|
|
|
! reduce the termination flag over all processors to check if everything is fine
|
|
|
|
!
|
|
|
|
call reduce_maximum_integer(iterm, iret)
|
|
|
|
#endif /* MPI */
|
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! check if the termination flag was broadcaster successfully
|
|
|
|
!
|
|
|
|
if (iterm > 0) go to 20
|
|
|
|
|
|
|
|
! reset the termination flag
|
|
|
|
!
|
|
|
|
iterm = 0
|
|
|
|
|
|
|
|
! check if the domain is periodic
|
|
|
|
!
|
|
|
|
lbnd = "periodic"
|
|
|
|
ubnd = "periodic"
|
|
|
|
call get_parameter_string("xlbndry" , lbnd)
|
|
|
|
call get_parameter_string("xubndry" , ubnd)
|
|
|
|
per(1) = (lbnd == "periodic") .and. (ubnd == "periodic")
|
|
|
|
lbnd = "periodic"
|
|
|
|
ubnd = "periodic"
|
|
|
|
call get_parameter_string("ylbndry" , lbnd)
|
|
|
|
call get_parameter_string("yubndry" , ubnd)
|
|
|
|
per(2) = (lbnd == "periodic") .and. (ubnd == "periodic")
|
|
|
|
#ifdef R3D
|
|
|
|
lbnd = "periodic"
|
|
|
|
ubnd = "periodic"
|
|
|
|
call get_parameter_string("zlbndry" , lbnd)
|
|
|
|
call get_parameter_string("zubndry" , ubnd)
|
|
|
|
per(3) = (lbnd == "periodic") .and. (ubnd == "periodic")
|
|
|
|
#endif /* R3D */
|
|
|
|
|
2012-07-28 12:12:35 -03:00
|
|
|
! get the execution termination parameters
|
|
|
|
!
|
|
|
|
call get_parameter_integer("nmax" , nmax)
|
|
|
|
call get_parameter_real ("tmax" , tmax)
|
|
|
|
call get_parameter_real ("trun" , trun)
|
|
|
|
call get_parameter_real ("tsav" , tsav)
|
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! get the initial time step
|
|
|
|
!
|
2012-07-28 12:12:35 -03:00
|
|
|
call get_parameter_real ("dtini", dtini)
|
2008-11-05 22:16:24 -06:00
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! get integral calculation interval
|
2011-04-14 00:19:45 +02:00
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
call get_parameter_integer("ndat" , ndat)
|
|
|
|
|
|
|
|
! get counter and interval for restart snapshots
|
|
|
|
!
|
|
|
|
call get_parameter_integer("nres" , nres)
|
|
|
|
call get_parameter_integer("ires" , ires)
|
|
|
|
|
|
|
|
! set up the MPI geometry
|
|
|
|
!
|
|
|
|
call setup_mpi(div(:), per(:), .false.)
|
2011-04-14 00:19:45 +02:00
|
|
|
|
2012-07-22 19:37:58 -03:00
|
|
|
! initialize the random number generator
|
2010-12-08 11:37:56 -02:00
|
|
|
!
|
2012-07-22 19:37:58 -03:00
|
|
|
call initialize_random(nprocs, nproc)
|
2010-12-08 11:37:56 -02:00
|
|
|
|
2013-12-11 00:09:15 -02:00
|
|
|
! initialize module EQUATIONS
|
|
|
|
!
|
|
|
|
call initialize_equations(master, iret)
|
|
|
|
|
|
|
|
! jump to the end if the equations could not be initialized
|
2013-12-11 10:16:06 -02:00
|
|
|
!
|
|
|
|
if (iret > 0) go to 40
|
|
|
|
|
|
|
|
! initialize module SCHEMES
|
|
|
|
!
|
|
|
|
call initialize_schemes(master, iret)
|
|
|
|
|
|
|
|
! jump to the end if the schemes could not be initialized
|
2013-12-11 00:09:15 -02:00
|
|
|
!
|
|
|
|
if (iret > 0) go to 30
|
|
|
|
|
2011-04-14 00:19:45 +02:00
|
|
|
! initialize block module
|
2008-12-07 15:14:18 -06:00
|
|
|
!
|
2012-07-22 22:47:25 -03:00
|
|
|
call initialize_blocks()
|
2011-03-02 15:04:16 -03:00
|
|
|
|
2012-07-23 22:43:23 -03:00
|
|
|
! initialize module COORDINATES
|
2011-05-11 15:32:01 -03:00
|
|
|
!
|
2012-07-23 22:43:23 -03:00
|
|
|
call initialize_coordinates(master)
|
2011-05-11 15:32:01 -03:00
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! initialize module INTERPOLATIONS
|
2012-07-27 17:18:24 -03:00
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
call initialize_interpolations()
|
2012-07-27 17:18:24 -03:00
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! initialize boundaries
|
2012-07-27 16:46:36 -03:00
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
call initialize_boundaries()
|
2012-07-27 16:46:36 -03:00
|
|
|
|
2012-07-27 21:13:43 -03:00
|
|
|
! initialize module PROBLEMS
|
|
|
|
!
|
|
|
|
call initialize_problems()
|
|
|
|
|
2012-07-27 21:28:59 -03:00
|
|
|
! initialize module REFINEMENT
|
|
|
|
!
|
|
|
|
call initialize_refinement()
|
|
|
|
|
2012-08-02 00:35:37 -03:00
|
|
|
! initialize module IO
|
|
|
|
!
|
|
|
|
call initialize_io()
|
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! reset number of iterations and time, etc.
|
2012-07-28 11:47:14 -03:00
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
n = 0
|
|
|
|
t = 0.0
|
|
|
|
dt = cfl * dtini
|
|
|
|
dtn = dtini
|
2012-07-28 11:47:14 -03:00
|
|
|
|
2011-04-11 16:27:08 +02:00
|
|
|
! check if we initiate new problem or restart previous job
|
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
if (nres < 0) then
|
2011-04-11 16:27:08 +02:00
|
|
|
|
2011-04-28 12:04:22 -03:00
|
|
|
! initialize the mesh module
|
|
|
|
!
|
2012-07-27 10:34:19 -03:00
|
|
|
call initialize_mesh(.true.)
|
2011-04-28 12:04:22 -03:00
|
|
|
|
2011-04-26 11:37:27 -03:00
|
|
|
! initialize the integrals module
|
|
|
|
!
|
|
|
|
call init_integrals(.true.)
|
|
|
|
|
2011-04-27 22:35:38 -03:00
|
|
|
! generate the initial mesh, refine that mesh to the desired level according to
|
|
|
|
! the initialized problem
|
2011-04-11 16:27:08 +02:00
|
|
|
!
|
2011-04-27 22:35:38 -03:00
|
|
|
call generate_mesh()
|
2011-04-11 16:27:08 +02:00
|
|
|
|
2011-04-28 12:04:22 -03:00
|
|
|
! store mesh statistics
|
|
|
|
!
|
|
|
|
call store_mesh_stats(n, t)
|
|
|
|
|
2011-04-11 16:27:08 +02:00
|
|
|
else
|
|
|
|
|
2011-04-28 12:04:22 -03:00
|
|
|
! initialize the mesh module
|
|
|
|
!
|
2012-07-27 10:34:19 -03:00
|
|
|
call initialize_mesh(.false.)
|
2011-04-28 12:04:22 -03:00
|
|
|
|
2011-04-26 11:37:27 -03:00
|
|
|
! initialize the integrals module
|
|
|
|
!
|
|
|
|
call init_integrals(.false.)
|
|
|
|
|
2011-04-11 16:27:08 +02:00
|
|
|
! reconstruct the meta and data block structures from a given restart file
|
|
|
|
!
|
2011-05-02 21:54:32 -03:00
|
|
|
call restart_job()
|
2011-04-11 16:27:08 +02:00
|
|
|
|
2011-05-14 19:37:40 -03:00
|
|
|
#ifdef MPI
|
2011-05-10 17:15:33 -03:00
|
|
|
! redistribute blocks between processors in case the number of processors has
|
|
|
|
! changed
|
|
|
|
!
|
|
|
|
call redistribute_blocks()
|
2011-05-14 19:37:40 -03:00
|
|
|
#endif /* MPI */
|
2011-05-10 17:15:33 -03:00
|
|
|
|
2011-04-23 23:11:22 -03:00
|
|
|
end if
|
2011-03-02 15:52:33 -03:00
|
|
|
|
2011-04-28 12:04:22 -03:00
|
|
|
#ifdef FORCE
|
|
|
|
! if the forcing time step is larger than the initial time step decrease it
|
|
|
|
!
|
|
|
|
fdt = min(fdt, 0.1d0 * dtini)
|
|
|
|
|
|
|
|
! round the initial time step to the integer number of forcing time steps
|
|
|
|
!
|
|
|
|
dt = fdt * floor(dt / fdt)
|
|
|
|
|
|
|
|
! initialize forcing module
|
|
|
|
!
|
2012-07-27 16:55:32 -03:00
|
|
|
call initialize_forcing()
|
2011-04-28 12:04:22 -03:00
|
|
|
#endif /* FORCE */
|
2011-05-02 23:43:58 -03:00
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! initialize evolution
|
|
|
|
!
|
|
|
|
call initialize_evolution()
|
|
|
|
|
|
|
|
#ifdef MPI
|
|
|
|
! reduce termination flag over all processors
|
|
|
|
!
|
|
|
|
call reduce_maximum_integer(iterm, iret)
|
|
|
|
#endif /* MPI */
|
|
|
|
|
|
|
|
! check if the problem was successfully initialized or restarted
|
|
|
|
!
|
|
|
|
if (iterm > 0) go to 10
|
|
|
|
|
|
|
|
! store integrals and data to a file
|
|
|
|
!
|
|
|
|
if (nres < 0) then
|
|
|
|
|
|
|
|
call store_integrals()
|
|
|
|
call write_data()
|
|
|
|
|
|
|
|
#ifdef MPI
|
|
|
|
! reduce termination flag over all processors
|
|
|
|
!
|
|
|
|
call reduce_maximum_integer(iterm, iret)
|
|
|
|
#endif /* MPI */
|
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
! if the initial data were not successfully writen, exit the program
|
|
|
|
!
|
|
|
|
if (iterm > 0) go to 10
|
|
|
|
|
|
|
|
! reset the termination flag
|
|
|
|
!
|
|
|
|
iterm = 0
|
2012-08-02 15:09:44 -03:00
|
|
|
iret = 0
|
2012-07-28 13:48:15 -03:00
|
|
|
|
2012-07-22 15:46:56 -03:00
|
|
|
! stop time accounting for the initialization
|
2011-05-02 23:43:58 -03:00
|
|
|
!
|
2012-07-22 15:46:56 -03:00
|
|
|
call stop_timer(iin)
|
|
|
|
|
|
|
|
! start time accounting for the evolution
|
|
|
|
!
|
|
|
|
call start_timer(iev)
|
2011-05-02 23:43:58 -03:00
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! get current time in seconds
|
|
|
|
!
|
|
|
|
if (master) &
|
|
|
|
tbeg = t
|
|
|
|
|
|
|
|
! print progress info on master processor
|
2008-12-07 15:14:18 -06:00
|
|
|
!
|
2012-07-22 19:01:27 -03:00
|
|
|
if (master) then
|
2012-07-28 13:48:15 -03:00
|
|
|
|
|
|
|
! initialize estimated remaining time of calculations
|
|
|
|
!
|
|
|
|
ed = 9999
|
|
|
|
eh = 23
|
|
|
|
em = 59
|
|
|
|
es = 59
|
|
|
|
|
|
|
|
! print progress info
|
|
|
|
!
|
|
|
|
write(*,*)
|
2011-03-10 15:22:10 -03:00
|
|
|
write(*,"(1x,a)" ) "Evolving the system:"
|
2011-02-28 16:04:38 -03:00
|
|
|
write(*,'(4x,a4,5x,a4,11x,a2,12x,a6,7x,a3)') 'step', 'time', 'dt' &
|
|
|
|
, 'blocks', 'ETA'
|
2011-06-18 10:16:45 -03:00
|
|
|
#if defined INTEL || defined PATHSCALE
|
2011-02-28 16:04:38 -03:00
|
|
|
write(*,'(i8,2(1x,1pe14.6),2x,i8,2x,1i4.1,"d",1i2.2,"h",1i2.2,"m"' // &
|
2011-06-17 20:05:15 -03:00
|
|
|
',1i2.2,"s",15x,a1,$)') &
|
2011-06-07 16:50:17 -03:00
|
|
|
n, t, dt, get_nleafs(), ed, eh, em, es, char(13)
|
2011-06-18 10:16:45 -03:00
|
|
|
#else /* INTEL | PATHSCALE */
|
2011-06-07 17:29:03 -03:00
|
|
|
write(*,'(i8,2(1x,1pe14.6),2x,i8,2x,1i4.1,"d",1i2.2,"h",1i2.2,"m"' // &
|
2011-06-17 20:05:15 -03:00
|
|
|
',1i2.2,"s",15x,a1)',advance="no") &
|
2011-06-07 17:29:03 -03:00
|
|
|
n, t, dt, get_nleafs(), ed, eh, em, es, char(13)
|
2011-06-18 10:16:45 -03:00
|
|
|
#endif /* INTEL | PATHSCALE */
|
2008-12-07 15:14:18 -06:00
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
end if
|
2011-05-06 09:51:40 -03:00
|
|
|
|
2008-12-07 15:14:18 -06:00
|
|
|
! main loop
|
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
do while((nsteps < nmax) .and. (t <= tmax) .and. (iterm == 0))
|
2008-12-07 15:14:18 -06:00
|
|
|
|
2008-12-09 14:51:33 -06:00
|
|
|
! compute new time step
|
|
|
|
!
|
2010-12-08 18:11:15 -02:00
|
|
|
dt = min(cfl * dtn, 2.0d0 * dt)
|
|
|
|
|
|
|
|
#ifdef FORCE
|
|
|
|
! limit the time step to the integer number of forcing time steps
|
|
|
|
!
|
|
|
|
dt = fdt * floor(dt / fdt)
|
|
|
|
#endif /* FORCE */
|
2008-12-09 14:51:33 -06:00
|
|
|
|
2008-12-07 15:14:18 -06:00
|
|
|
! advance the iteration number and time
|
|
|
|
!
|
|
|
|
t = t + dt
|
|
|
|
n = n + 1
|
2012-07-28 13:48:15 -03:00
|
|
|
nsteps = nsteps + 1
|
2008-12-07 15:14:18 -06:00
|
|
|
|
2008-12-07 18:57:08 -06:00
|
|
|
! performe one step evolution
|
|
|
|
!
|
2012-07-31 15:04:40 -03:00
|
|
|
call advance()
|
2008-12-07 18:57:08 -06:00
|
|
|
|
2011-04-28 12:04:22 -03:00
|
|
|
! store mesh statistics
|
|
|
|
!
|
|
|
|
call store_mesh_stats(n, t)
|
|
|
|
|
2011-03-02 15:52:33 -03:00
|
|
|
! store integrals
|
|
|
|
!
|
|
|
|
call store_integrals()
|
|
|
|
|
2008-12-09 12:42:10 -06:00
|
|
|
! store data
|
|
|
|
!
|
2012-08-02 00:35:37 -03:00
|
|
|
call write_data()
|
2008-12-09 12:42:10 -06:00
|
|
|
|
2008-12-16 22:34:54 -06:00
|
|
|
! get current time in seconds
|
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
tm_curr = get_timer_total()
|
2008-12-16 22:34:54 -06:00
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! compute elapsed time
|
2008-12-07 15:14:18 -06:00
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
thrs = (tm_curr / 60.0 + tsav) / 60.0
|
|
|
|
|
|
|
|
! check if the time exceeds execution time limit
|
|
|
|
!
|
|
|
|
if (thrs >= trun) iterm = 100
|
|
|
|
|
|
|
|
! print progress info to console
|
|
|
|
!
|
|
|
|
if (master) then
|
|
|
|
|
|
|
|
! calculate days, hours, seconds
|
|
|
|
!
|
|
|
|
ec = int(tm_curr * (tmax - t) / max(1.0e-8, t - tbeg), kind = 4)
|
|
|
|
es = max(0, int(mod(ec, 60)))
|
|
|
|
em = int(mod(ec / 60, 60))
|
|
|
|
eh = int(ec / 3600)
|
|
|
|
ed = int(eh / 24)
|
|
|
|
eh = int(mod(eh, 24))
|
|
|
|
ed = min(9999,ed)
|
|
|
|
|
2011-06-18 10:16:45 -03:00
|
|
|
#if defined INTEL || defined PATHSCALE
|
2011-06-13 16:58:39 -03:00
|
|
|
write(*,'(i8,2(1x,1pe14.6),2x,i8,2x,1i4.1,"d",1i2.2,"h",1i2.2,"m"' // &
|
|
|
|
',1i2.2,"s",15x,a1,$)') &
|
|
|
|
n, t, dt, get_nleafs(), ed, eh, em, es, char(13)
|
2011-06-18 10:16:45 -03:00
|
|
|
#else /* INTEL | PATHSCALE */
|
2011-02-28 16:04:38 -03:00
|
|
|
write(*,'(i8,2(1x,1pe14.6),2x,i8,2x,1i4.1,"d",1i2.2,"h",1i2.2,"m"' // &
|
2011-06-10 18:13:23 -03:00
|
|
|
',1i2.2,"s",15x,a1)',advance="no") &
|
2011-06-07 16:50:17 -03:00
|
|
|
n, t, dt, get_nleafs(), ed, eh, em, es, char(13)
|
2011-06-18 10:16:45 -03:00
|
|
|
#endif /* INTEL | PATHSCALE */
|
2011-06-07 14:34:54 -03:00
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
end if
|
2011-06-07 14:34:54 -03:00
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! prepare iterm
|
2011-06-18 10:16:45 -03:00
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
iterm = max(iterm, iret)
|
2011-06-07 14:34:54 -03:00
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
#ifdef MPI
|
2011-04-29 00:51:28 -03:00
|
|
|
! reduce termination flag over all processors
|
|
|
|
!
|
2012-07-22 19:01:27 -03:00
|
|
|
call reduce_maximum_integer(iterm, iret)
|
2012-07-28 13:48:15 -03:00
|
|
|
#endif /* MPI */
|
|
|
|
|
2008-12-07 15:14:18 -06:00
|
|
|
end do
|
|
|
|
|
2011-02-27 22:39:56 -03:00
|
|
|
! add one empty line
|
|
|
|
!
|
2012-07-22 19:01:27 -03:00
|
|
|
if (master) write(*,*)
|
2011-02-27 22:39:56 -03:00
|
|
|
|
2012-07-22 15:46:56 -03:00
|
|
|
! stop time accounting for the evolution
|
2011-04-14 16:16:58 +02:00
|
|
|
!
|
2012-07-22 15:46:56 -03:00
|
|
|
call stop_timer(iev)
|
|
|
|
|
|
|
|
! start time accounting for the termination
|
|
|
|
!
|
|
|
|
call start_timer(itm)
|
2011-04-14 16:16:58 +02:00
|
|
|
|
2012-07-22 15:46:56 -03:00
|
|
|
! write down the restart dump
|
2011-05-02 23:43:58 -03:00
|
|
|
!
|
2012-07-22 15:46:56 -03:00
|
|
|
call write_restart_data()
|
2011-05-02 23:43:58 -03:00
|
|
|
|
2012-07-28 13:48:15 -03:00
|
|
|
! a label to go to if there are any problems, but since all modules have been
|
|
|
|
! initialized, we have to finalize them first
|
|
|
|
!
|
|
|
|
10 continue
|
|
|
|
|
2010-12-08 12:21:41 -02:00
|
|
|
#ifdef FORCE
|
|
|
|
! finalize forcing module
|
|
|
|
!
|
|
|
|
call clear_forcing()
|
2011-03-02 15:04:16 -03:00
|
|
|
|
2010-12-08 12:21:41 -02:00
|
|
|
#endif /* FORCE */
|
2011-03-02 15:52:33 -03:00
|
|
|
! clear up the integrals module
|
|
|
|
!
|
|
|
|
call clear_integrals()
|
|
|
|
|
2011-03-02 15:04:16 -03:00
|
|
|
! deallocate and reset mesh
|
|
|
|
!
|
|
|
|
call clear_mesh()
|
2010-12-08 12:21:41 -02:00
|
|
|
|
2012-07-23 22:43:23 -03:00
|
|
|
! finalize module COORDINATES
|
2011-05-11 15:32:01 -03:00
|
|
|
!
|
2012-07-23 22:43:23 -03:00
|
|
|
call finalize_coordinates()
|
2011-05-11 15:32:01 -03:00
|
|
|
|
2012-07-22 22:47:25 -03:00
|
|
|
! deallocate block structure
|
|
|
|
!
|
|
|
|
call finalize_blocks()
|
|
|
|
|
2012-07-22 19:37:58 -03:00
|
|
|
! finalize the random number generator
|
|
|
|
!
|
|
|
|
call finalize_random()
|
|
|
|
|
2012-07-22 15:46:56 -03:00
|
|
|
! stop time accounting for the termination
|
|
|
|
!
|
|
|
|
call stop_timer(itm)
|
|
|
|
|
2008-12-07 14:06:04 -06:00
|
|
|
! get total time
|
|
|
|
!
|
2012-07-22 15:46:56 -03:00
|
|
|
tm(1) = get_timer_total()
|
|
|
|
|
|
|
|
! get subtasks timers
|
|
|
|
!
|
|
|
|
do i = 2, ntimers
|
|
|
|
tm(i) = get_timer(i)
|
|
|
|
end do
|
|
|
|
|
|
|
|
! print timings only on master processor
|
|
|
|
!
|
2012-07-22 19:01:27 -03:00
|
|
|
if (master) then
|
2012-07-22 15:46:56 -03:00
|
|
|
|
|
|
|
! print one empty line
|
|
|
|
!
|
|
|
|
write (*,'(a)') ''
|
|
|
|
|
|
|
|
! calculate the conversion factor
|
|
|
|
!
|
|
|
|
tm_conv = 100.0 / tm(1)
|
|
|
|
|
|
|
|
! get the execution time
|
|
|
|
!
|
|
|
|
tm_exec = get_timer_total()
|
|
|
|
|
|
|
|
! prepare the string formatting
|
|
|
|
!
|
|
|
|
write (tmp,"(i64)") int(tm(1))
|
|
|
|
write (tmp,"(i64)") len_trim(adjustl(tmp)) + 6
|
|
|
|
|
|
|
|
! print the execution times
|
|
|
|
!
|
|
|
|
write (fmt,"(a)") "(2x,a32,1x,':',1x,1f" // trim(adjustl(tmp)) // &
|
|
|
|
".3,' secs = ',f6.2,' %')"
|
|
|
|
|
|
|
|
write (*,'(1x,a)') 'EXECUTION TIMINGS'
|
|
|
|
do i = 2, ntimers
|
|
|
|
if (timer_enabled(i)) write (*,fmt) timer_description(i), tm(i) &
|
|
|
|
, tm_conv * tm(i)
|
|
|
|
end do
|
|
|
|
|
|
|
|
! print the CPU times
|
|
|
|
!
|
|
|
|
write (tmp,"(a)") "(1x,a14,20x,':',1x,1f" // trim(adjustl(tmp)) // &
|
|
|
|
".3,' secs = ',f6.2,' %')"
|
|
|
|
write (*,tmp) 'TOTAL CPU TIME', tm(1) , 100.0
|
|
|
|
write (*,tmp) 'TIME PER STEP ', tm(1) / nsteps, 100.0 / nsteps
|
|
|
|
#ifdef MPI
|
|
|
|
write (*,tmp) 'TIME PER CPU ', tm(1) / nprocs, 100.0 / nprocs
|
|
|
|
#endif /* MPI */
|
|
|
|
|
|
|
|
! print the execution time
|
|
|
|
|
|
|
|
write (tmp,"(i64)") int(tm(1))
|
|
|
|
write (tmp,"(i64)") len_trim(adjustl(tmp)) + 6
|
|
|
|
write (tmp,"(a)") "(1x,a14,20x,':',1x,1f" // trim(adjustl(tmp)) // &
|
|
|
|
".3,' secs')"
|
|
|
|
write (*,tmp) 'EXECUTION TIME', tm_exec
|
|
|
|
|
|
|
|
end if
|
2008-12-07 14:06:04 -06:00
|
|
|
|
2012-07-22 19:32:21 -03:00
|
|
|
! a label to go to if there are any problems
|
2011-04-29 00:51:28 -03:00
|
|
|
!
|
2012-07-22 19:32:21 -03:00
|
|
|
20 continue
|
|
|
|
|
2012-07-22 19:01:27 -03:00
|
|
|
if (master) then
|
2012-07-22 19:32:21 -03:00
|
|
|
|
|
|
|
! print info about termination due to a signal
|
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
if (iterm >= 1 .and. iterm <= 32) then
|
2012-07-22 19:32:21 -03:00
|
|
|
write (*,'(a)') ''
|
|
|
|
write (*,"(1x,a,i2)") "Terminating program after receiving a" // &
|
|
|
|
" termination signal no. ", iterm
|
|
|
|
write (*,"(1x,a)") "Restart files have been successfully written."
|
|
|
|
end if
|
2012-07-28 13:48:15 -03:00
|
|
|
if (iterm == 100) then
|
2012-07-22 19:32:21 -03:00
|
|
|
write (*,'(a)') ''
|
|
|
|
write (*,"(1x,a)") "Terminating program after exceeding the" // &
|
2011-06-07 17:29:03 -03:00
|
|
|
" execution time."
|
2012-07-22 19:32:21 -03:00
|
|
|
write (*,"(1x,a)") "Restart files have been successfully written."
|
|
|
|
end if
|
2012-07-28 13:48:15 -03:00
|
|
|
if (iterm >= 101) then
|
2012-07-22 19:32:21 -03:00
|
|
|
write (*,'(a)') ''
|
|
|
|
write (*,"(1x,a)") "The initial conditions for the selected problem" // &
|
|
|
|
" could not be set."
|
|
|
|
write (*,"(1x,a)") "Program has been terminated."
|
2011-06-07 17:29:03 -03:00
|
|
|
end if
|
2012-07-28 13:48:15 -03:00
|
|
|
if (iterm >= 120 .and. iterm < 125) then
|
2012-07-22 19:32:21 -03:00
|
|
|
write (*,'(a)') ''
|
|
|
|
write (*,"(1x,a)") "Problem with restarting job from restart snapshots."
|
|
|
|
write (*,"(1x,a)") "Program has been terminated."
|
|
|
|
end if
|
2012-07-28 13:48:15 -03:00
|
|
|
if (iterm >= 125 .and. iterm < 130) then
|
2012-07-22 19:32:21 -03:00
|
|
|
write (*,'(a)') ''
|
|
|
|
write (*,"(1x,a)") "Problem with storing snapshots."
|
|
|
|
write (*,"(1x,a)") "Program has been terminated."
|
2011-04-29 00:51:28 -03:00
|
|
|
end if
|
2011-06-07 01:05:42 -03:00
|
|
|
|
2012-07-22 19:32:21 -03:00
|
|
|
! print one empty line
|
2011-06-07 01:05:42 -03:00
|
|
|
!
|
2012-07-22 15:46:56 -03:00
|
|
|
write (*,'(a)') ''
|
2011-06-07 01:05:42 -03:00
|
|
|
|
2010-10-06 23:11:22 -03:00
|
|
|
end if
|
2008-12-22 14:57:31 -06:00
|
|
|
|
2013-12-11 10:16:06 -02:00
|
|
|
! finalize module SCHEMES
|
|
|
|
!
|
|
|
|
call finalize_schemes(iret)
|
|
|
|
|
|
|
|
! jump point
|
|
|
|
!
|
|
|
|
30 continue
|
|
|
|
|
2013-12-10 20:56:37 -02:00
|
|
|
! finalize module EQUATIONS
|
|
|
|
!
|
|
|
|
call finalize_equations(iret)
|
|
|
|
|
|
|
|
! jump point
|
|
|
|
!
|
2013-12-11 10:16:06 -02:00
|
|
|
40 continue
|
2013-12-10 20:56:37 -02:00
|
|
|
|
2012-07-22 19:32:21 -03:00
|
|
|
! finalize parameters
|
|
|
|
!
|
|
|
|
call finalize_parameters()
|
|
|
|
|
2012-07-28 12:29:44 -03:00
|
|
|
! finalize module MPITOOLS
|
2008-12-22 14:57:31 -06:00
|
|
|
!
|
2012-07-28 12:29:44 -03:00
|
|
|
call finalize_mpitools()
|
2008-12-07 14:06:04 -06:00
|
|
|
|
2008-12-08 21:11:17 -06:00
|
|
|
!-------------------------------------------------------------------------------
|
2008-11-04 13:08:01 -06:00
|
|
|
!
|
|
|
|
end program
|
2012-07-28 12:24:12 -03:00
|
|
|
|
2011-04-29 00:51:28 -03:00
|
|
|
#ifdef SIGNALS
|
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
2012-07-28 13:48:15 -03:00
|
|
|
! function TERMINATE:
|
|
|
|
! ------------------
|
|
|
|
!
|
|
|
|
! Function sets variable iterm after receiving a signal.
|
|
|
|
!
|
2011-04-29 00:51:28 -03:00
|
|
|
!
|
|
|
|
!===============================================================================
|
|
|
|
!
|
2011-06-07 17:29:03 -03:00
|
|
|
integer(kind=4) function terminate(sig_num)
|
2011-04-29 00:51:28 -03:00
|
|
|
|
2011-06-07 16:46:09 -03:00
|
|
|
implicit none
|
2011-04-29 00:51:28 -03:00
|
|
|
|
2011-06-07 17:29:03 -03:00
|
|
|
! input arguments
|
|
|
|
!
|
|
|
|
integer(kind=4), intent(in) :: sig_num
|
2012-07-28 12:03:17 -03:00
|
|
|
integer :: iterm
|
|
|
|
|
|
|
|
! common block
|
|
|
|
!
|
|
|
|
common /termination/ iterm
|
2011-06-07 17:29:03 -03:00
|
|
|
|
2011-04-29 00:51:28 -03:00
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
2011-06-07 17:29:03 -03:00
|
|
|
#ifdef INTEL
|
|
|
|
iterm = sig_num
|
2011-06-17 20:21:10 -03:00
|
|
|
#else /* INTEL */
|
|
|
|
iterm = 15
|
2011-06-07 17:29:03 -03:00
|
|
|
#endif /* INTEL */
|
|
|
|
terminate = 1
|
2011-04-29 00:51:28 -03:00
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
end
|
|
|
|
#endif /* SIGNALS */
|
|
|
|
|
|
|
|
!===============================================================================
|
|
|
|
!
|