-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path#C2Ray.F90#
More file actions
163 lines (143 loc) · 5.38 KB
/
Copy path#C2Ray.F90#
File metadata and controls
163 lines (143 loc) · 5.38 KB
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
!>
!! \brief Main program for C2Ray-1D
!!
!! \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.
! Does not include hydrodynamics
! Assumes constant time step
! Needs following `modules'
! c2ray_parameters : all the tunable parameters for the code
! my_mpi : sets up the MPI parallel environment
! output_module : output routines
! grid : sets up the grid
! radiation : radiation tools
! pmfast : interface to PMFAST output
! cosmology : cosmological utilities
! material : material properties
! times : time and time step utilities
! sourceprops : source properties
! evolve : evolve grid in time
use precision, only: dp
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,sourcetype
use cosmology, only: cosmology_init, redshift_evol, &
time2zred, zred2time, zred, cosmo_evol
use c2ray_parameters, only: cosmological
!use cosmological_evolution, only: cosmo_evol
use material, only: mat_ini, testnum,zred00,isothermal
use times, only: time_ini, number_timesteps
use sourceprops, only: source_properties_ini
use evolve, only: evolve1D
use file_admin, only:stdinput
use times, only: end_time,dt,output_time, timess, outputsteps
use radiative_cooling, only: setup_cool
#ifdef XLF
USE XLFUTILITY, only: iargc, getarg, flush => flush_
#endif
implicit none
! CPU time variables
real :: tstart !< Start time for CPU report
real :: tend !< End time for CPU report
! Wall clock time variables
integer :: cntr1 !< Start time wall clock
integer :: cntr2 !< End time wall clock
integer :: countspersec !< counts per second (for wall clock time)
integer :: nstep
integer :: restart,nz,flag
! Time variables
real(kind=dp) :: time !< actual time (s)
real(kind=dp) :: next_output_time !< time of next output (s)
real(kind=dp) :: actual_dt !< actual time step (s)
real(kind=dp) :: test, test2
character(len=512) :: inputfile !> Input file
call cpu_time(tstart) ! Initialize cpu timer
call system_clock(cntr1) ! Initialize wall cock times
call mpi_setup() ! Set up MPI structure
if (iargc() > 0) then ! Set up input stream (either standard input or from file given
call getarg(1,inputfile) ! by first argument)
if (rank == 0) then
write(*,*) 'reading input from ',trim(adjustl(inputfile))
open(unit=stdinput,file=inputfile)
endif
endif
call setup_output() ! Initialize output
call grid_ini() ! Initialize grid
call mat_ini (restart) ! Initialize the material properties (calls also ini_rec_colion_factors)
if (.not.isothermal) call setup_cool () ! moved here from radiation
call rad_ini( ) ! Initialize photo-ionization calculation
call source_properties_ini (sourcetype) ! Initialize source property
call time_ini () ! Initialize time step parameters
time=0.0 ! Set time to zero
next_output_time=0.0 !*
if (cosmological) then ! Initialize cosmology
write(*,*) zred, time,zred00
call cosmology_init(zred00,time)
call redshift_evol(time)
write(*,*) zred, time
call cosmo_evol( )
write(*,*) zred
endif
do nstep=1,number_timesteps!-1
time=timess(nstep)
dt=time-timess(nstep-1)
actual_dt=dt
! Write output
! if (mod(nstep,outputsteps).lt.1.0) then
! call output(nstep,time,dt,end_time)
! write(50,*) time/YEAR
! endif
! ! Write output
! if (abs(time-next_output_time).le.1e-6*time) then
! call output(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(abs(next_output_time-time),dt)
! nstep=nstep+1
! Report time and time step
write(30,'(A,2(1pe10.3,1x),A)') 'Time, dt:', &
time/YEAR,actual_dt/YEAR,' (years)'
! write(48,*) '0', nstep
! For cosmological simulations evolve proper quantities
if (cosmological) then
call redshift_evol(time+0.5*actual_dt)
call cosmo_evol()
endif
! Take one time step
call evolve1D(actual_dt) ! Take one time step
if (mod(nstep,outputsteps).lt.1.0) then
call output(nstep,number_timesteps,time,dt,end_time)
write(50,*) time/YEAR
endif
time=time+actual_dt ! Update time
! if (abs(time-end_time).lt.1e-6*end_time) exit
enddo
nstep=number_timesteps
if (cosmological) then ! Scale to the current redshift
call redshift_evol(time)
call cosmo_evol()
endif
!if (abs(time-end_time).gt.100) then
! call output(nstep,time,dt,end_time)! Write final output
! write(50,*) time/YEAR
!endif
! write(*,*)'fit,~1,table=',mycountertest,mycountertest2,mycountertest3
call close_down ()! Clean up some stuff
call cpu_time(tend)! Find out CPU time
call system_clock(cntr2,countspersec)
write(30,*) 'CPU time: ',tend-tstart,' s'
write(30,*) 'Wall clock time: ',(cntr2-cntr1)/countspersec,' s'
write(*,*) 'Wall clock time: ',(cntr2-cntr1)/countspersec,' s'
call mpi_end () ! End the run
end Program C2Ray