-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_acdc.f90
150 lines (131 loc) · 5.22 KB
/
run_acdc.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
program run_acdc
use acdc_system, only : nclust, temp ! number of equations
use driver, only : acdc_driver ! driver
implicit none
!integer :: ncoefs = 44,
real(kind(1.d0)), parameter :: kB = 1.3806504d-23 ! Boltzmann constant
real(kind(1.d0)), parameter :: pres_atm = 101325.d0 ! atmospheric pressure
integer :: i,j, k, m, n_tpoints
logical :: solver_ok
real(kind(1.d0)) :: theta_evap(39)
real(kind(1.d0)) :: initial_concentrations(nclust), Ca_vector(7), Cb_vector(3)
real(kind(1.d0)) :: conc_final(nclust), conc_output(21*nclust), sigma
real :: start, finish
Ca_vector = 1.d6*(/1.d7, 21544346.9003188d0, 46415888.3361278d0, 100000000d0, 215443469.003189d0, 464158883.361277d0, 5.d7/) !mol/m3
!Ca_vector = 1.d6*(/1.d7, 21544346.9003188d0, 46415888.3361278d0, 100000000d0, 215443469.003189d0, 464158883.361277d0, 1.d9/) !mol/m3
!Cb_vector = (/1d0, 5d0, 35d0/) !ppt
Cb_vector = (/1d0, 5d0, 100d0/) !ppt
call init_evap_rates(theta_evap)
call cpu_time(start) !Find the time rate
m = 0
do i = 1, size(Ca_vector) ! loop over all the ambient conditions
do j = 1, size(Cb_vector)
initial_concentrations = 0.d0
initial_concentrations(1) = Ca_vector(i)
initial_concentrations(3) = 1.d6*Cb_vector(j)*1.d-18*pres_atm/kB/temp
!first calculate coefficients for all loss terms
write(*,*) 'Parameter vector'
call acdc_driver(initial_concentrations,conc_final,solver_ok, theta_evap) !This is what gets timed
print *, 'Sulfuric acid and ammonia vapor concentrations '
write(*,*) 'Steady+state concentrations'
write(*,*) (conc_final(k), k=1,size(conc_final) ), initial_concentrations(1), initial_concentrations(3)
conc_output(m+1:m+nclust) = conc_final(1:nclust)
m = m + nclust
end do
end do
call cpu_time(finish) ! !Stop Timer
print '("Time = ",f6.3," seconds.")',finish-start
!write(*,*) 'Output concentrations'
!write(*,*) (conc_output(k), k=1,size(conc_output) )
sigma = 1.d-3
CALL add_nrand_noise(conc_output,sigma)
! write(*,*) 'Output concentrations with gaussian noise'
!write(*,*) (conc_output(k), k=1,size(conc_output) )
open(24,file = 'c_steady_state_mcmc.dat')
rewind(24)
do k=1,nclust*21
write (24,'(i3x,g20.13)') k, conc_output(k)
end do
! write(24,*) (conc_final(j),j=1,16)
close(24)
contains
!------------------------------------------------------------------------------------------
! subroutine get_coefs_names(ncoefs,coef_names)
! implicit none
! integer ncoefs
! character(len=11), dimension(ncoefs) :: coef_names
!
! coef_names(1)(:) = 'dH_2A'
!coef_names(2)(:) = 'dS_2A/dH_2A'
! coef_names(3)(:) = 'dH_3A'
! coef_names(4)(:) = 'dS_3A/dH_3A'
! coef_names(5)(:) = 'dH_4A'
! coef_names(6)(:) = 'dS_4A/dH_4A'
! coef_names(7)(:) = 'dH_5A'
! coef_names(8)(:) = 'dS_5A/dH_5A'
! coef_names(9)(:) = 'dH_1A1N'
! coef_names(10)(:) = 'dS_1A1N/dH_1A1N'
! coef_names(11)(:) = 'dH_2A1N'
! coef_names(12)(:) = 'dS_2A1N/dH_2A1N'
! coef_names(13)(:) = 'dH_3A1N/dH_2A1N'
! coef_names(14)(:) = 'dH_4A1N/dH_2A1N'
! coef_names(15)(:) = 'dH_5A1N/dH_2A1N'
! coef_names(16)(:) = 'dS_3A1N/dH_2A1N'
! coef_names(17)(:) = 'dS_4A1N/dH_2A1N'
! coef_names(18)(:) = 'dS_5A1N/dH_2A1N'
! coef_names(19)(:) = 'dH_2N'
! coef_names(20)(:) = 'dS_2N/dH_2N'
! coef_names(21)(:) = 'dH_2A2N'
! coef_names(22)(:) = 'dS_2A2N/dH_2A2N'
! coef_names(23)(:) = 'dH_3A2N/dH_2A2N'
! coef_names(24)(:) = 'dH_4A2N/dH_2A2N'
! coef_names(25)(:) = 'dH_5A2N/dH_2A2N'
! coef_names(26)(:) = 'dS_3A2N/dH_2A2N'
! coef_names(27)(:) = 'dS_4A2N/dH_2A2N'
! coef_names(28)(:) = 'dS_5A2N/dH_2A2N'
! coef_names(29)(:) = 'dH_3N'
!! coef_names(30)(:) = 'dS_3N/dH_3N'
! coef_names(31)(:) = 'dH_3A3N'
! coef_names(32)(:) = 'dS_3A3N/dH_3A3N'
! coef_names(33)(:) = 'dH_4A3N/dH_3A3N'
! coef_names(34)(:) = 'dH_5A3N/dH_3A3N'
! coef_names(35)(:) = 'dS_4A3N/dH_3A3N'
! coef_names(36)(:) = 'dS_5A3N/dH_3A3N'
! coef_names(37)(:) = 'dH_4N'
! coef_names(38)(:) = 'dS_4N/dH_4N'
! coef_names(39)(:) = 'dH_4A4N'
! coef_names(40)(:) = 'dS_4A4N/dH_4A4N'
! coef_names(41)(:) = 'dH_5A4N/dH_4A4N'
! coef_names(42)(:) = 'dS_5A4N/dH_4A4N'
! coef_names(43)(:) = 'dH_5A5N'
! coef_names(44)(:) = 'dS_5A5N/dH_5A5N'
!
!end subroutine get_coefs_names
subroutine init_evap_rates(theta_evap)
implicit none
integer :: j
integer :: Reason
real(kind(1.d0)) :: coef_axil, theta_evap(39)
j = 1
Reason = 0
! Reading IJ_evap
! open(23,file="evap_rates.txt", status='old', access='sequential', action='read' )
open(23,file="mcmcmean_steady_states.dat", status='old', access='sequential', action='read' )
DO while (Reason .GE. 0 .AND. j <40)
READ(23,*,IOSTAT=Reason) coef_axil
theta_evap(j) = coef_axil
j = j + 1
END DO
close(23)
end subroutine init_evap_rates
subroutine add_nrand_noise(y,sigma)
implicit none
real(kind(1.d0)) :: sigma, delta(21*nclust), y(21*nclust), w(21*nclust,2)
real(kind(1.d0)), parameter :: pi = 4.d0*atan(1.d0)
write(*,*) 'Function invoked'
!CALL init_random_seed() ! see example of RANDOM_SEED
CALL random_number(w)
delta = sqrt(-2.d0*log(w(:,1)))*sin(2.d0*pi*w(:,2))*sigma*y
y = y+delta
end subroutine add_nrand_noise
end program run_acdc