-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathC2Ray.F90
170 lines (134 loc) · 4.44 KB
/
C2Ray.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
!>
!! \brief Main program for C2Ray-1D
!!
!! C2Ray-1D does a one-dimensional photo-ionization calculation
!! one of a series of test problems.\n
!! The main programme calls a number of initialization routines
!! and then enters the main integration loop, which ends when one
!! of the stopping conditions is met. At specified times it calls
!! the output module routines to produce output.
!! After the integration loop ends, a number of closing down routines
!! are called and the programme stops.
!!
!! \b Author: Garrelt Mellema \n
!!
!! \b Date: 23-Sep-2006
!<
Program C2Ray
! Author: Garrelt Mellema
! Date: 23-Sep-2006
! Goal:
! One dimensional photo-ionization calculation for a series of
! test problems.
! Version notes:
! - Does not include hydrodynamics
! - Assumes time step
! Needs following modules
use precision, only: dp
use clocks, only: setup_clocks, update_clocks, report_clocks
use file_admin, only: stdinput, logf, file_input, flag_for_file_input
use astroconstants, only: YEAR
use my_mpi, only: mpi_setup, mpi_end, rank
use output_module, only: setup_output,output,close_down
use grid, only: grid_ini
use radiation, only: rad_ini
use cosmology, only: cosmology_init, redshift_evol, &
time2zred, zred2time, zred, cosmological
use cosmological_evolution, only: cosmo_evol
use material, only: mat_ini, testnum
use times, only: time_ini, end_time,dt,output_time
use evolve, only: evolve1D
#ifdef XLF
! Modules for the xlf (IBM) compiler
USE XLFUTILITY, only: iargc, getarg, flush => flush_
#endif
implicit none
! Integer variables
integer :: nstep !< time step counter
integer :: restart !< restart if not zero (not used in 1D code)
! Time variables
real(kind=dp) :: sim_time !< actual time (s)
real(kind=dp) :: next_output_time !< time of next output (s)
real(kind=dp) :: actual_dt !< actual time step (s)
!> Input file
character(len=512) :: inputfile
! Initialize clocks (cpu and wall)
call setup_clocks
! Set up MPI structure (compatibility mode) & open log file
call mpi_setup()
! Set up input stream (either standard input or from file given
! by first argument)
if (rank == 0) then
write(logf,*) "screen input or file input?"
flush(logf)
if (COMMAND_ARGUMENT_COUNT () > 0) then
call GET_COMMAND_ARGUMENT(1,inputfile)
write(logf,*) "reading input from ",trim(adjustl(inputfile))
open(unit=stdinput,file=inputfile,status="old")
call flag_for_file_input(.true.)
else
write(logf,*) "reading input from command line"
endif
flush(logf)
endif
! Initialize output
call setup_output ()
! Initialize grid
call grid_ini ()
! Initialize the material properties
call mat_ini (restart)
! Initialize photo-ionization calculation
call rad_ini( )
! Initialize time step parameters
call time_ini ()
! Set time to zero
sim_time=0.0
next_output_time=0.0
! Update cosmology (transform from comoving to proper values)
if (cosmological) then
call redshift_evol(sim_time)
call cosmo_evol( )
!write(*,*) zred
endif
! Loop until end time is reached
nstep=0
do
! Write output
if (abs(sim_time-next_output_time) <= 1e-6*sim_time) then
call output(nstep,sim_time,dt,end_time)
next_output_time=next_output_time+output_time
endif
! Make sure you produce output at the correct time
! dt=YEAR*10.0**(min(5.0,(-2.0+real(nstep)/1e5*10.0)))
actual_dt=min(next_output_time-sim_time,dt)
nstep=nstep+1
! Report time and time step
write(logf,'(A,2(1pe10.3,1x),A)') 'Time, dt:', &
sim_time/YEAR,actual_dt/YEAR,' (years)'
! For cosmological simulations evolve proper quantities
if (cosmological) then
call redshift_evol(sim_time+0.5*actual_dt)
call cosmo_evol()
endif
! Take one time step
call evolve1D(actual_dt)
! Update time
sim_time=sim_time+actual_dt
if (abs(sim_time-end_time) < 1e-6*end_time) exit
! Update clock counters (cpu + wall, to avoid overflowing the counter)
call update_clocks ()
enddo
! Scale to the current redshift
if (cosmological) then
call redshift_evol(sim_time)
call cosmo_evol()
endif
! Write final output
call output(nstep,sim_time,dt,end_time)
! Clean up some stuff
call close_down ()
! Report clocks (cpu and wall)
call report_clocks ()
! End the run
call mpi_end ()
end Program C2Ray