SICOPOLIS V3.1
 All Classes Files Functions Variables Macros
sico_main_loop.F90
Go to the documentation of this file.
1 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 !
3 ! Subroutine : s i c o _ m a i n _ l o o p
4 !
5 !> @file
6 !!
7 !! Main loop of SICOPOLIS.
8 !!
9 !! @section Copyright
10 !!
11 !! Copyright 2009-2013 Ralf Greve
12 !!
13 !! @section License
14 !!
15 !! This file is part of SICOPOLIS.
16 !!
17 !! SICOPOLIS is free software: you can redistribute it and/or modify
18 !! it under the terms of the GNU General Public License as published by
19 !! the Free Software Foundation, either version 3 of the License, or
20 !! (at your option) any later version.
21 !!
22 !! SICOPOLIS is distributed in the hope that it will be useful,
23 !! but WITHOUT ANY WARRANTY; without even the implied warranty of
24 !! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 !! GNU General Public License for more details.
26 !!
27 !! You should have received a copy of the GNU General Public License
28 !! along with SICOPOLIS. If not, see <http://www.gnu.org/licenses/>.
29 !<
30 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31 
32 !-------------------------------------------------------------------------------
33 !> Main loop of SICOPOLIS.
34 !<------------------------------------------------------------------------------
35 subroutine sico_main_loop(delta_ts, glac_index, &
36  mean_accum, mean_accum_inv, &
37  dtime, dtime_temp, dtime_wss, dtime_out, dtime_ser, &
38  time, time_init, time_end, time_output, &
39  dxi, deta, dzeta_c, dzeta_t, dzeta_r, &
40  z_sl, dzsl_dtau, z_mar, &
41  ii, jj, nn, &
42  ndat2d, ndat3d, n_output, &
43  runname)
44 
45 use sico_types
47 
48 implicit none
49 
50 integer(i4b), intent(in) :: ii((imax+1)*(jmax+1)), &
51  jj((imax+1)*(jmax+1)), &
52  nn(0:jmax,0:imax)
53 integer(i4b), intent(in) :: n_output
54 real(dp), intent(in) :: mean_accum, mean_accum_inv
55 real(dp), intent(in) :: dtime, dtime_temp, dtime_wss, &
56  dtime_out, dtime_ser
57 real(dp), intent(in) :: time_init, time_end, time_output(100)
58 real(dp), intent(in) :: dxi, deta, dzeta_c, dzeta_t, dzeta_r
59 character(len=100), intent(in) :: runname
60 
61 integer(i4b), intent(inout) :: ndat2d, ndat3d
62 real(dp), intent(inout) :: delta_ts, glac_index
63 real(dp), intent(inout) :: time
64 real(dp), intent(inout) :: z_sl, dzsl_dtau, z_mar
65 
66 integer(i4b) :: i, j, kc, kt, kr, n
67 integer(i4b) :: itercount, itercount_max
68 integer(i4b) :: iter_temp, iter_wss, iter_ser, iter_out, iter_output(100)
69 real(dp) :: dtime_temp_inv
70 logical :: flag_3d_output
71 
72 !-------- Begin of main loop --------
73 
74 write(unit=6, fmt='(a)') ' '
75 
76 itercount_max = nint((time_end-time_init)/dtime)
77 
78 iter_temp = nint(dtime_temp/dtime)
79 #if REBOUND==2
80 iter_wss = nint(dtime_wss/dtime)
81 #endif
82 iter_ser = nint(dtime_ser/dtime)
83 #if ( OUTPUT==1 || OUTPUT==3 )
84 iter_out = nint(dtime_out/dtime)
85 #endif
86 #if ( OUTPUT==2 || OUTPUT==3 )
87 do n=1, n_output
88  iter_output(n) = nint((time_output(n)-time_init)/dtime)
89 end do
90 #endif
91 
92 main_loop : do itercount=1, itercount_max
93 
94 write(unit=6, fmt='(i7)') itercount
95 
96 !-------- Update of time --------
97 
98 time = time_init + real(itercount,dp)*dtime
99 
100 !-------- Save old mask --------
101 
102 maske_help = maske
103 
104 !-------- Boundary conditions --------
105 
106 call boundary(time, dtime, dxi, deta, delta_ts, glac_index, &
107  z_sl, dzsl_dtau, z_mar)
108 
109 !-------- Temperature, water content, age, flow enhancement factor --------
110 
111 if ( mod(itercount, iter_temp) == 0 ) then
112 
113  write(unit=6, fmt='(a)') ' -------- Computation of T'
114 
115 ! ------ Temperature, water content, age
116 
117 #if CALCMOD==1
118  call calc_temp_poly(dxi, deta, dzeta_c, dzeta_t, dzeta_r, &
119  dtime_temp, mean_accum_inv) ! polythermal mode
120 
121 #elif CALCMOD==0
122  call calc_temp_cold(dxi, deta, dzeta_c, dzeta_t, dzeta_r, &
123  dtime_temp, mean_accum_inv) ! cold-ice mode
124 #endif
125 
126 ! ------ Time derivative of H_t (further time derivatives are
127 ! computed in subroutine calc_top)
128 
129  dtime_temp_inv = 1.0_dp/dtime_temp
130 
131  dh_t_dtau = (h_t_neu - h_t)*dtime_temp_inv
132 
133 ! ------ New values --> old values
134 
135  n_cts = n_cts_neu
136  zm = zm_neu
137  h_c = h_c_neu
138  h_t = h_t_neu
139  temp_c = temp_c_neu
140  age_c = age_c_neu
141  omega_t= omega_t_neu
142  age_t = age_t_neu
143  temp_r = temp_r_neu
144 
145 ! ------ Flow enhancement factor
146 
147  call calc_enhance(time)
148 
149 end if
150 ! End of computation of temperature, water content, age and
151 ! enhancement factor
152 
153 !-------- Velocity --------
154 
155 call calc_vxy_b_sia(time, z_sl)
156 call calc_vxy_sia(dzeta_c, dzeta_t)
157 
158 #if MARGIN==3
159 call calc_vxy_ssa(z_sl, dxi, deta, dzeta_c, ii, jj, nn)
160 #endif
161 
162 call calc_vz_sia(dxi, deta, dzeta_c, dzeta_t)
163 
164 #if MARGIN==3
165 call calc_vz_ssa(z_sl, dxi, deta, dzeta_c)
166 #endif
167 
168 !-------- Topography --------
169 
170 call calc_top(time, time_init, &
171  z_sl, dzsl_dtau, z_mar, &
172  dtime, dxi, deta, dzeta_t, &
173  mean_accum, &
174  ii, jj, nn, itercount, iter_wss)
175 
176 ! ------ New values --> old values
177 
178 zs = zs_neu
179 zm = zm_neu
180 zb = zb_neu
181 zl = zl_neu
182 h_c= h_c_neu
183 h_t= h_t_neu
184 
185 !-------- Melting temperature --------
186 
187 call calc_temp_melt()
188 
189 !-------- Basal temperature --------
190 
191 call calc_temp_bas()
192 
193 !-------- Basal melting rate --------
194 
195 call calc_qbm(time, z_sl, dzeta_c, dzeta_r)
196 
197 !-------- Effective thickness of subglacial water --------
198 
199 call calc_water_bas()
200 
201 !-------- Data output --------
202 
203 #if OUTPUT==1
204 
205 if ( mod(itercount, iter_out) == 0 ) then
206 
207 #if ERGDAT==0
208  flag_3d_output = .false.
209 #elif ERGDAT==1
210  flag_3d_output = .true.
211 #endif
212 
213 #if NETCDF==1
214  call output1(runname, time, delta_ts, glac_index, z_sl, &
215  flag_3d_output, ndat2d, ndat3d)
216 #elif NETCDF==2
217  call output_nc(runname, time, delta_ts, glac_index, z_sl, &
218  flag_3d_output, ndat2d, ndat3d)
219 #endif
220 
221 end if
222 
223 #elif OUTPUT==2
224 
225 do n=1, n_output
226 
227  if (itercount == iter_output(n)) then
228 
229 #if ERGDAT==0
230  flag_3d_output = .false.
231 #elif ERGDAT==1
232  flag_3d_output = .true.
233 #endif
234 
235 #if NETCDF==1
236  call output1(runname, time, delta_ts, glac_index, z_sl, &
237  flag_3d_output, ndat2d, ndat3d)
238 #elif NETCDF==2
239  call output_nc(runname, time, delta_ts, glac_index, z_sl, &
240  flag_3d_output, ndat2d, ndat3d)
241 #endif
242 
243  end if
244 
245 end do
246 
247 #elif OUTPUT==3
248 
249 if ( mod(itercount, iter_out) == 0 ) then
250 
251  flag_3d_output = .false.
252 
253 #if NETCDF==1
254  call output1(runname, time, delta_ts, glac_index, z_sl, &
255  flag_3d_output, ndat2d, ndat3d)
256 #elif NETCDF==2
257  call output_nc(runname, time, delta_ts, glac_index, z_sl, &
258  flag_3d_output, ndat2d, ndat3d)
259 #endif
260 
261 end if
262 
263 do n=1, n_output
264 
265  if (itercount == iter_output(n)) then
266 
267  flag_3d_output = .true.
268 
269 #if NETCDF==1
270  call output1(runname, time, delta_ts, glac_index, z_sl, &
271  flag_3d_output, ndat2d, ndat3d)
272 #elif NETCDF==2
273  call output_nc(runname, time, delta_ts, glac_index, z_sl, &
274  flag_3d_output, ndat2d, ndat3d)
275 #endif
276 
277  end if
278 
279 end do
280 
281 #endif
282 
283 if ( mod(itercount, iter_ser) == 0 ) then
284  call output2(time, dxi, deta, delta_ts, glac_index, z_sl)
285 #if OUTSER==2
286  call output3(time, delta_ts, glac_index, z_sl)
287 #endif
288 #if OUTSER==3
289  call output4(time, dxi, deta, delta_ts, glac_index, z_sl)
290 #endif
291 #if ( defined(ASF) && OUTSER==4 )
292  call output5(time, dxi, deta, delta_ts, glac_index, z_sl)
293 #endif
294 
295 end if
296 
297 end do main_loop ! End of main loop
298 
299 end subroutine sico_main_loop
300 !