1 | MODULE layering_mod |
---|
2 | |
---|
3 | !======================================================================= |
---|
4 | ! Purpose: Manage layered layerings_map in the PEM with a linked list data structure |
---|
5 | ! |
---|
6 | ! Author: JBC |
---|
7 | ! Date: 08/03/2024 |
---|
8 | !======================================================================= |
---|
9 | |
---|
10 | use glaciers_mod, only: rho_co2ice, rho_h2oice |
---|
11 | |
---|
12 | implicit none |
---|
13 | |
---|
14 | !---- Declarations |
---|
15 | ! Numerical parameter |
---|
16 | real, parameter :: eps = epsilon(1.), tol = 1.e2*eps |
---|
17 | integer :: nb_str_max |
---|
18 | logical :: layering_algo |
---|
19 | |
---|
20 | ! Physical parameters |
---|
21 | real, parameter :: d_dust = 1.e-3 ! Tendency of dust [kg.m-2.y-1] |
---|
22 | real, parameter :: dry_lag_porosity = 0.4 ! Porosity of dust lag |
---|
23 | real, parameter :: wet_lag_porosity = 0.1 ! Porosity of water ice lag |
---|
24 | real, parameter :: regolith_porosity = 0.4 ! Porosity of regolith |
---|
25 | real, parameter :: breccia_porosity = 0.1 ! Porosity of breccia |
---|
26 | real, parameter :: co2ice_porosity = 0. ! Porosity of CO2 ice |
---|
27 | real, parameter :: h2oice_porosity = 0. ! Porosity of H2O ice |
---|
28 | real, parameter :: rho_dust = 2500. ! Density of dust [kg.m-3] |
---|
29 | real, parameter :: rho_rock = 3200. ! Density of rock [kg.m-3] |
---|
30 | real, parameter :: h_patchy_dust = 5.e-4 ! Height under which a dust lag is considered patchy [m] |
---|
31 | real, parameter :: h_patchy_ice = 5.e-4 ! Height under which a H2O ice lag is considered patchy [m] |
---|
32 | |
---|
33 | ! Parameters for CO2 flux correction (inspired by Levrard et al. 2007) |
---|
34 | real, parameter :: hmin_lag_co2 = 0.5 ! Minimal height of the lag deposit to reduce the sublimation rate [m] |
---|
35 | real, parameter :: fred_sublco2 = 0.1 ! Reduction factor of sublimation rate |
---|
36 | |
---|
37 | ! Stratum = node of the linked list |
---|
38 | type :: stratum |
---|
39 | real :: top_elevation ! Layer top_elevation (top height from the surface) [m] |
---|
40 | real :: h_co2ice ! Height of CO2 ice [m] |
---|
41 | real :: h_h2oice ! Height of H2O ice [m] |
---|
42 | real :: h_dust ! Height of dust [m] |
---|
43 | real :: h_pore ! Height of pores [m] |
---|
44 | real :: poreice_volfrac ! Pore-filled ice volumetric fraction |
---|
45 | type(stratum), pointer :: up => null() ! Upper stratum (next node) |
---|
46 | type(stratum), pointer :: down => null() ! Lower stratum (previous node) |
---|
47 | end type stratum |
---|
48 | |
---|
49 | ! Layering = linked list |
---|
50 | type layering |
---|
51 | integer :: nb_str = 0 ! Number of strata |
---|
52 | type(stratum), pointer :: bottom => null() ! First stratum (head of the list) |
---|
53 | type(stratum), pointer :: top => null() ! Last stratum (tail of the list) |
---|
54 | !real :: h_toplag ! Height of dust layer at the top [m] |
---|
55 | !type(stratum), pointer :: subice => null() ! Shallower stratum containing ice |
---|
56 | !type(stratum), pointer :: surf => null() ! Surface stratum |
---|
57 | end type layering |
---|
58 | |
---|
59 | ! Array of pointers to "stratum" |
---|
60 | type ptrarray |
---|
61 | type(stratum), pointer :: p |
---|
62 | end type ptrarray |
---|
63 | |
---|
64 | !======================================================================= |
---|
65 | contains |
---|
66 | ! Procedures to manipulate the data structure: |
---|
67 | ! > print_stratum |
---|
68 | ! > add_stratum |
---|
69 | ! > insert_stratum |
---|
70 | ! > del_stratum |
---|
71 | ! > get_stratum |
---|
72 | ! > ini_layering |
---|
73 | ! > del_layering |
---|
74 | ! > print_layering |
---|
75 | ! > get_nb_str_max |
---|
76 | ! > stratif2array |
---|
77 | ! > array2stratif |
---|
78 | ! > print_layerings_map |
---|
79 | ! Procedures to get information about a stratum: |
---|
80 | ! > thickness |
---|
81 | ! > is_co2ice_str |
---|
82 | ! > is_h2oice_str |
---|
83 | ! > is_dust_str |
---|
84 | ! > is_dust_lag |
---|
85 | ! > subsurface_ice_layering |
---|
86 | ! Procedures for the algorithm to evolve the layering: |
---|
87 | ! > make_layering |
---|
88 | ! > lift_dust |
---|
89 | ! > subl_ice_str |
---|
90 | !======================================================================= |
---|
91 | ! To display a stratum |
---|
92 | SUBROUTINE print_stratum(this) |
---|
93 | |
---|
94 | implicit none |
---|
95 | |
---|
96 | !---- Arguments |
---|
97 | type(stratum), intent(in) :: this |
---|
98 | |
---|
99 | !---- Code |
---|
100 | write(*,'(a,es13.6)') 'Top elevation [m]: ', this%top_elevation |
---|
101 | write(*,'(a,es13.6)') 'Height of CO2 ice [m]: ', this%h_co2ice |
---|
102 | write(*,'(a,es13.6)') 'Height of H2O ice [m]: ', this%h_h2oice |
---|
103 | write(*,'(a,es13.6)') 'Height of dust [m]: ', this%h_dust |
---|
104 | write(*,'(a,es13.6)') 'Height of pores [m]: ', this%h_pore |
---|
105 | write(*,'(a,es13.6)') 'Pore-filled ice [m3/m3]: ', this%poreice_volfrac |
---|
106 | |
---|
107 | END SUBROUTINE print_stratum |
---|
108 | |
---|
109 | !======================================================================= |
---|
110 | ! To add a stratum to the top of a layering |
---|
111 | SUBROUTINE add_stratum(this,top_elevation,co2ice,h2oice,dust,pore,poreice) |
---|
112 | |
---|
113 | implicit none |
---|
114 | |
---|
115 | !---- Arguments |
---|
116 | type(layering), intent(inout) :: this |
---|
117 | real, intent(in), optional :: top_elevation, co2ice, h2oice, dust, pore, poreice |
---|
118 | |
---|
119 | !---- Local variables |
---|
120 | type(stratum), pointer :: str |
---|
121 | |
---|
122 | !---- Code |
---|
123 | ! Creation of the stratum |
---|
124 | allocate(str) |
---|
125 | nullify(str%up,str%down) |
---|
126 | str%top_elevation = 1. |
---|
127 | str%h_co2ice = 0. |
---|
128 | str%h_h2oice = 0. |
---|
129 | str%h_dust = 1. |
---|
130 | str%h_pore = 0. |
---|
131 | str%poreice_volfrac = 0. |
---|
132 | if (present(top_elevation)) str%top_elevation = top_elevation |
---|
133 | if (present(co2ice)) str%h_co2ice = co2ice |
---|
134 | if (present(h2oice)) str%h_h2oice = h2oice |
---|
135 | if (present(dust)) str%h_dust = dust |
---|
136 | if (present(pore)) str%h_pore = pore |
---|
137 | if (present(poreice)) str%poreice_volfrac = poreice |
---|
138 | |
---|
139 | ! Increment the number of strata |
---|
140 | this%nb_str = this%nb_str + 1 |
---|
141 | |
---|
142 | ! Add the stratum to the layering |
---|
143 | if (.not. associated(this%bottom)) then ! If it is the very first one |
---|
144 | this%bottom => str |
---|
145 | this%top => str |
---|
146 | else |
---|
147 | str%down => this%top |
---|
148 | this%top%up => str |
---|
149 | this%top => str |
---|
150 | endif |
---|
151 | |
---|
152 | END SUBROUTINE add_stratum |
---|
153 | |
---|
154 | !======================================================================= |
---|
155 | ! To insert a stratum after another one in a layering |
---|
156 | SUBROUTINE insert_stratum(this,str_prev,top_elevation,co2ice,h2oice,dust,pore,poreice) |
---|
157 | |
---|
158 | implicit none |
---|
159 | |
---|
160 | !---- Arguments |
---|
161 | type(layering), intent(inout) :: this |
---|
162 | type(stratum), pointer, intent(inout) :: str_prev |
---|
163 | real, intent(in), optional :: top_elevation, co2ice, h2oice, dust, pore, poreice |
---|
164 | |
---|
165 | !---- Local variables |
---|
166 | type(stratum), pointer :: str, current |
---|
167 | |
---|
168 | !---- Code |
---|
169 | if (.not. associated(str_prev%up)) then ! If str_prev is the top stratum of the layering |
---|
170 | call add_stratum(this,top_elevation,co2ice,h2oice,dust,pore,poreice) |
---|
171 | else |
---|
172 | ! Creation of the stratum |
---|
173 | allocate(str) |
---|
174 | nullify(str%up,str%down) |
---|
175 | str%top_elevation = 1. |
---|
176 | str%h_co2ice = 0. |
---|
177 | str%h_h2oice = 0. |
---|
178 | str%h_dust = 1. |
---|
179 | str%h_pore = 0. |
---|
180 | str%poreice_volfrac = 0. |
---|
181 | if (present(top_elevation)) str%top_elevation = top_elevation |
---|
182 | if (present(co2ice)) str%h_co2ice = co2ice |
---|
183 | if (present(h2oice)) str%h_h2oice = h2oice |
---|
184 | if (present(dust)) str%h_dust = dust |
---|
185 | if (present(pore)) str%h_pore = pore |
---|
186 | if (present(poreice)) str%poreice_volfrac = poreice |
---|
187 | |
---|
188 | ! Increment the number of strata |
---|
189 | this%nb_str = this%nb_str + 1 |
---|
190 | |
---|
191 | ! Insert the stratum into the layering at the right place |
---|
192 | str%down => str_prev |
---|
193 | str%up => str_prev%up |
---|
194 | str_prev%up => str |
---|
195 | str%up%down => str |
---|
196 | |
---|
197 | ! Correct the value of top_elevation for the upper strata |
---|
198 | current => str%up |
---|
199 | do while (associated(current)) |
---|
200 | current%top_elevation = current%down%top_elevation + thickness(current) |
---|
201 | current => current%up |
---|
202 | enddo |
---|
203 | endif |
---|
204 | |
---|
205 | END SUBROUTINE insert_stratum |
---|
206 | |
---|
207 | !======================================================================= |
---|
208 | ! To remove a stratum in a layering |
---|
209 | SUBROUTINE del_stratum(this,str) |
---|
210 | |
---|
211 | implicit none |
---|
212 | |
---|
213 | !---- Arguments |
---|
214 | type(layering), intent(inout) :: this |
---|
215 | type(stratum), pointer, intent(inout) :: str |
---|
216 | |
---|
217 | !---- Local variables |
---|
218 | type(stratum), pointer :: new_str ! To make the argument point towards something |
---|
219 | |
---|
220 | !---- Code |
---|
221 | ! Protect the sub-surface strata from deletion |
---|
222 | if (str%top_elevation <= 0.) return |
---|
223 | |
---|
224 | ! Decrement the number of strata |
---|
225 | this%nb_str = this%nb_str - 1 |
---|
226 | |
---|
227 | ! Making the new links |
---|
228 | if (associated(str%down)) then ! If there is a lower stratum |
---|
229 | str%down%up => str%up |
---|
230 | else ! If it was the first stratum (bottom of layering) |
---|
231 | this%bottom => str%up |
---|
232 | endif |
---|
233 | if (associated(str%up)) then ! If there is an upper stratum |
---|
234 | str%up%down => str%down |
---|
235 | else ! If it was the last stratum (top of layering) |
---|
236 | this%top => str%down |
---|
237 | endif |
---|
238 | |
---|
239 | ! Remove the stratum from the layering |
---|
240 | new_str => str%down |
---|
241 | nullify(str%up,str%down) |
---|
242 | deallocate(str) |
---|
243 | nullify(str) |
---|
244 | str => new_str |
---|
245 | |
---|
246 | END SUBROUTINE del_stratum |
---|
247 | |
---|
248 | !======================================================================= |
---|
249 | ! To get a specific stratum in a layering |
---|
250 | FUNCTION get_stratum(lay,i) RESULT(str) |
---|
251 | |
---|
252 | implicit none |
---|
253 | |
---|
254 | !---- Arguments |
---|
255 | type(layering), intent(in) :: lay |
---|
256 | integer, intent(in) :: i |
---|
257 | type(stratum), pointer :: str |
---|
258 | |
---|
259 | !---- Local variables |
---|
260 | integer :: k |
---|
261 | |
---|
262 | !---- Code |
---|
263 | if (i < 1 .or. i > lay%nb_str) error stop 'get_stratum: requested number is beyond the number of strata of the layering!' |
---|
264 | k = 1 |
---|
265 | str => lay%bottom |
---|
266 | do while (k /= i) |
---|
267 | str => str%up |
---|
268 | k = k + 1 |
---|
269 | enddo |
---|
270 | |
---|
271 | END FUNCTION get_stratum |
---|
272 | |
---|
273 | !======================================================================= |
---|
274 | ! To initialize the layering |
---|
275 | SUBROUTINE ini_layering(this) |
---|
276 | |
---|
277 | use comsoil_h_PEM, only: soil_pem, nsoilmx_PEM, layer_PEM, index_breccia, index_bedrock |
---|
278 | |
---|
279 | implicit none |
---|
280 | |
---|
281 | !---- Arguments |
---|
282 | type(layering), intent(inout) :: this |
---|
283 | |
---|
284 | !---- Local variables |
---|
285 | integer :: i |
---|
286 | real :: h_soil, h_pore, h_tot |
---|
287 | |
---|
288 | !---- Code |
---|
289 | ! Creation of strata at the bottom of the layering to describe the sub-surface |
---|
290 | if (soil_pem) then |
---|
291 | do i = nsoilmx_PEM,index_bedrock,-1 |
---|
292 | h_soil = layer_PEM(i) - layer_PEM(i - 1) ! No porosity |
---|
293 | call add_stratum(this,-layer_PEM(i - 1),0.,0.,h_soil,0.,0.) |
---|
294 | enddo |
---|
295 | do i = index_bedrock - 1,index_breccia,-1 |
---|
296 | h_tot = layer_PEM(i) - layer_PEM(i - 1) |
---|
297 | h_pore = h_tot*breccia_porosity |
---|
298 | h_soil = h_tot - h_pore |
---|
299 | call add_stratum(this,-layer_PEM(i - 1),0.,0.,h_soil,h_pore,0.) |
---|
300 | enddo |
---|
301 | do i = index_breccia - 1,2,-1 |
---|
302 | h_tot = layer_PEM(i) - layer_PEM(i - 1) |
---|
303 | h_pore = h_tot*regolith_porosity |
---|
304 | h_soil = h_tot - h_pore |
---|
305 | call add_stratum(this,-layer_PEM(i - 1),0.,0.,h_soil,h_pore,0.) |
---|
306 | enddo |
---|
307 | h_pore = layer_PEM(1)*regolith_porosity |
---|
308 | h_soil = layer_PEM(1) - h_pore |
---|
309 | call add_stratum(this,0.,0.,0.,h_soil,h_pore,0.) |
---|
310 | endif |
---|
311 | |
---|
312 | END SUBROUTINE ini_layering |
---|
313 | |
---|
314 | !======================================================================= |
---|
315 | ! To delete the entire layering |
---|
316 | SUBROUTINE del_layering(this) |
---|
317 | |
---|
318 | implicit none |
---|
319 | |
---|
320 | !---- Arguments |
---|
321 | type(layering), intent(inout) :: this |
---|
322 | |
---|
323 | !---- Local variables |
---|
324 | type(stratum), pointer :: current, next |
---|
325 | |
---|
326 | !---- Code |
---|
327 | current => this%bottom |
---|
328 | do while (associated(current)) |
---|
329 | next => current%up |
---|
330 | deallocate(current) |
---|
331 | nullify(current) |
---|
332 | current => next |
---|
333 | enddo |
---|
334 | this%nb_str = 0 |
---|
335 | |
---|
336 | END SUBROUTINE del_layering |
---|
337 | |
---|
338 | !======================================================================= |
---|
339 | ! To display a layering |
---|
340 | SUBROUTINE print_layering(this) |
---|
341 | |
---|
342 | implicit none |
---|
343 | |
---|
344 | !---- Arguments |
---|
345 | type(layering), intent(in) :: this |
---|
346 | |
---|
347 | !---- Local variables |
---|
348 | type(stratum), pointer :: current |
---|
349 | integer :: i |
---|
350 | |
---|
351 | !---- Code |
---|
352 | current => this%top |
---|
353 | |
---|
354 | i = this%nb_str |
---|
355 | do while (associated(current)) |
---|
356 | write(*,'(a,i4)') 'Stratum ', i |
---|
357 | call print_stratum(current) |
---|
358 | write(*,*) |
---|
359 | current => current%down |
---|
360 | i = i - 1 |
---|
361 | enddo |
---|
362 | |
---|
363 | END SUBROUTINE print_layering |
---|
364 | |
---|
365 | !======================================================================= |
---|
366 | ! To get the maximum number of "stratum" in the stratification (layerings) |
---|
367 | FUNCTION get_nb_str_max(layerings_map,ngrid,nslope) RESULT(nb_str_max) |
---|
368 | |
---|
369 | implicit none |
---|
370 | |
---|
371 | !---- Arguments |
---|
372 | type(layering), dimension(ngrid,nslope), intent(in) :: layerings_map |
---|
373 | integer, intent(in) :: ngrid, nslope |
---|
374 | integer :: nb_str_max |
---|
375 | |
---|
376 | !---- Local variables |
---|
377 | integer :: ig, islope |
---|
378 | |
---|
379 | !---- Code |
---|
380 | nb_str_max = 0 |
---|
381 | do islope = 1,nslope |
---|
382 | do ig = 1,ngrid |
---|
383 | nb_str_max = max(layerings_map(ig,islope)%nb_str,nb_str_max) |
---|
384 | enddo |
---|
385 | enddo |
---|
386 | |
---|
387 | END FUNCTION get_nb_str_max |
---|
388 | |
---|
389 | !======================================================================= |
---|
390 | ! To convert the layerings map into an array able to be outputted |
---|
391 | SUBROUTINE stratif2array(layerings_map,ngrid,nslope,stratif_array) |
---|
392 | |
---|
393 | implicit none |
---|
394 | |
---|
395 | !---- Arguments |
---|
396 | integer, intent(in) :: ngrid, nslope |
---|
397 | type(layering), dimension(ngrid,nslope), intent(in) :: layerings_map |
---|
398 | real, dimension(:,:,:,:), allocatable, intent(inout) :: stratif_array |
---|
399 | |
---|
400 | !---- Local variables |
---|
401 | type(stratum), pointer :: current |
---|
402 | integer :: ig, islope, k |
---|
403 | |
---|
404 | !---- Code |
---|
405 | stratif_array = 0. |
---|
406 | do islope = 1,nslope |
---|
407 | do ig = 1,ngrid |
---|
408 | current => layerings_map(ig,islope)%bottom |
---|
409 | k = 1 |
---|
410 | do while (associated(current)) |
---|
411 | stratif_array(ig,islope,k,1) = current%top_elevation |
---|
412 | stratif_array(ig,islope,k,2) = current%h_co2ice |
---|
413 | stratif_array(ig,islope,k,3) = current%h_h2oice |
---|
414 | stratif_array(ig,islope,k,4) = current%h_dust |
---|
415 | stratif_array(ig,islope,k,5) = current%h_pore |
---|
416 | stratif_array(ig,islope,k,6) = current%poreice_volfrac |
---|
417 | current => current%up |
---|
418 | k = k + 1 |
---|
419 | enddo |
---|
420 | enddo |
---|
421 | enddo |
---|
422 | |
---|
423 | END SUBROUTINE stratif2array |
---|
424 | |
---|
425 | !======================================================================= |
---|
426 | ! To convert the stratification array into the layerings map |
---|
427 | SUBROUTINE array2stratif(stratif_array,ngrid,nslope,layerings_map) |
---|
428 | |
---|
429 | implicit none |
---|
430 | |
---|
431 | !---- Arguments |
---|
432 | integer, intent(in) :: ngrid, nslope |
---|
433 | real, dimension(:,:,:,:), allocatable, intent(in) :: stratif_array |
---|
434 | type(layering), dimension(ngrid,nslope), intent(inout) :: layerings_map |
---|
435 | |
---|
436 | !---- Local variables |
---|
437 | integer :: ig, islope, k |
---|
438 | |
---|
439 | !---- Code |
---|
440 | do islope = 1,nslope |
---|
441 | do ig = 1,ngrid |
---|
442 | do k = 1,size(stratif_array,3) |
---|
443 | call add_stratum(layerings_map(ig,islope),stratif_array(ig,islope,k,1),stratif_array(ig,islope,k,2),stratif_array(ig,islope,k,3),stratif_array(ig,islope,k,4),stratif_array(ig,islope,k,5),stratif_array(ig,islope,k,6)) |
---|
444 | enddo |
---|
445 | enddo |
---|
446 | enddo |
---|
447 | |
---|
448 | END SUBROUTINE array2stratif |
---|
449 | |
---|
450 | !======================================================================= |
---|
451 | ! To display the map of layerings |
---|
452 | SUBROUTINE print_layerings_map(this,ngrid,nslope) |
---|
453 | |
---|
454 | implicit none |
---|
455 | |
---|
456 | !---- Arguments |
---|
457 | integer, intent(in) :: ngrid, nslope |
---|
458 | type(layering), dimension(ngrid,nslope), intent(in) :: this |
---|
459 | |
---|
460 | !---- Local variables |
---|
461 | integer :: ig, islope |
---|
462 | |
---|
463 | !---- Code |
---|
464 | do ig = 1,ngrid |
---|
465 | write(*,'(a10,i4)') 'Grid cell ', ig |
---|
466 | do islope = 1,nslope |
---|
467 | write(*,'(a13,i1)') 'Slope number ', islope |
---|
468 | call print_layering(this(ig,islope)) |
---|
469 | write(*,*) '~~~~~~~~~~' |
---|
470 | enddo |
---|
471 | write(*,*) '--------------------' |
---|
472 | enddo |
---|
473 | |
---|
474 | END SUBROUTINE print_layerings_map |
---|
475 | |
---|
476 | !======================================================================= |
---|
477 | !======================================================================= |
---|
478 | ! To compute the thickness of a stratum |
---|
479 | FUNCTION thickness(this) RESULT(h_str) |
---|
480 | |
---|
481 | implicit none |
---|
482 | |
---|
483 | !---- Arguments |
---|
484 | type(stratum), intent(in) :: this |
---|
485 | real :: h_str |
---|
486 | |
---|
487 | !---- Code |
---|
488 | h_str = this%h_co2ice + this%h_h2oice + this%h_dust + this%h_pore |
---|
489 | |
---|
490 | END FUNCTION thickness |
---|
491 | |
---|
492 | !======================================================================= |
---|
493 | ! To know whether the stratum can be considered as a CO2 ice layer |
---|
494 | FUNCTION is_co2ice_str(str) RESULT(co2ice_str) |
---|
495 | |
---|
496 | implicit none |
---|
497 | |
---|
498 | !---- Arguments |
---|
499 | type(stratum), intent(in) :: str |
---|
500 | logical :: co2ice_str |
---|
501 | |
---|
502 | !---- Code |
---|
503 | co2ice_str = .false. |
---|
504 | if (str%h_co2ice > str%h_h2oice .and. str%h_co2ice > str%h_dust) co2ice_str = .true. |
---|
505 | |
---|
506 | END FUNCTION is_co2ice_str |
---|
507 | |
---|
508 | !======================================================================= |
---|
509 | ! To know whether the stratum can be considered as a H2O ice layer |
---|
510 | FUNCTION is_h2oice_str(str) RESULT(h2oice_str) |
---|
511 | |
---|
512 | implicit none |
---|
513 | |
---|
514 | !---- Arguments |
---|
515 | type(stratum), intent(in) :: str |
---|
516 | logical :: h2oice_str |
---|
517 | |
---|
518 | !---- Code |
---|
519 | h2oice_str = .false. |
---|
520 | if (str%h_h2oice > str%h_co2ice .and. str%h_h2oice > str%h_dust) h2oice_str = .true. |
---|
521 | |
---|
522 | END FUNCTION is_h2oice_str |
---|
523 | |
---|
524 | !======================================================================= |
---|
525 | ! To know whether the stratum can be considered as a dust layer |
---|
526 | FUNCTION is_dust_str(str) RESULT(dust_str) |
---|
527 | |
---|
528 | implicit none |
---|
529 | |
---|
530 | !---- Arguments |
---|
531 | type(stratum), intent(in) :: str |
---|
532 | logical :: dust_str |
---|
533 | |
---|
534 | !---- Code |
---|
535 | dust_str = .false. |
---|
536 | if (str%h_dust > str%h_co2ice .and. str%h_dust > str%h_h2oice) dust_str = .true. |
---|
537 | |
---|
538 | END FUNCTION is_dust_str |
---|
539 | |
---|
540 | !======================================================================= |
---|
541 | ! To know whether the stratum can be considered as a dust lag |
---|
542 | FUNCTION is_dust_lag(str) RESULT(dust_lag) |
---|
543 | |
---|
544 | implicit none |
---|
545 | |
---|
546 | !---- Arguments |
---|
547 | type(stratum), intent(in) :: str |
---|
548 | logical :: dust_lag |
---|
549 | |
---|
550 | !---- Code |
---|
551 | dust_lag = .false. |
---|
552 | if (str%h_co2ice < tol .and. str%h_h2oice < tol .and. str%poreice_volfrac < tol) dust_lag = .true. |
---|
553 | |
---|
554 | END FUNCTION is_dust_lag |
---|
555 | |
---|
556 | !======================================================================= |
---|
557 | ! To get data about possible subsurface ice in a layering |
---|
558 | SUBROUTINE subsurface_ice_layering(this,h_toplag,h2o_ice,co2_ice) |
---|
559 | |
---|
560 | implicit none |
---|
561 | |
---|
562 | !---- Arguments |
---|
563 | type(layering), intent(in) :: this |
---|
564 | real, intent(out) :: h2o_ice, co2_ice, h_toplag |
---|
565 | |
---|
566 | !---- Local variables |
---|
567 | type(stratum), pointer :: current |
---|
568 | |
---|
569 | !---- Code |
---|
570 | h_toplag = 0. |
---|
571 | h2o_ice = 0. |
---|
572 | co2_ice = 0. |
---|
573 | current => this%top |
---|
574 | ! Is the considered stratum a dust lag? |
---|
575 | if (.not. is_dust_lag(current)) return |
---|
576 | do while (is_dust_lag(current) .and. associated(current)) |
---|
577 | h_toplag = h_toplag + thickness(current) |
---|
578 | current => current%down |
---|
579 | enddo |
---|
580 | ! Is the stratum below the dust lag made of ice? |
---|
581 | if (current%h_h2oice > 0. .and. current%h_h2oice > current%h_co2ice) then ! There is more H2O ice than CO2 ice |
---|
582 | if (h_toplag < h_patchy_dust) then ! But the dust lag is too thin to considered ice as subsurface ice |
---|
583 | h_toplag = 0. |
---|
584 | h2o_ice = current%h_h2oice |
---|
585 | endif |
---|
586 | else if (current%h_co2ice > 0. .and. current%h_co2ice > current%h_h2oice) then ! There is more CO2 ice than H2O ice |
---|
587 | h_toplag = 0. ! Because it matters only for H2O ice |
---|
588 | if (h_toplag < h_patchy_ice) then ! But the dust lag is too thin to considered ice as subsurface ice |
---|
589 | co2_ice = current%h_co2ice |
---|
590 | endif |
---|
591 | endif |
---|
592 | |
---|
593 | END SUBROUTINE subsurface_ice_layering |
---|
594 | |
---|
595 | !======================================================================= |
---|
596 | !======================================================================= |
---|
597 | ! To lift dust in a stratum |
---|
598 | SUBROUTINE lift_dust(this,str,h2lift) |
---|
599 | |
---|
600 | implicit none |
---|
601 | |
---|
602 | !---- Arguments |
---|
603 | type(layering), intent(inout) :: this |
---|
604 | type(stratum), pointer, intent(inout) :: str |
---|
605 | real, intent(in) :: h2lift |
---|
606 | |
---|
607 | !---- Code |
---|
608 | ! Update of properties in the eroding dust lag |
---|
609 | str%top_elevation = str%top_elevation - h2lift*(1. + str%h_pore/str%h_dust) |
---|
610 | str%h_pore = str%h_pore - h2lift*str%h_pore/str%h_dust |
---|
611 | str%h_dust = str%h_dust - h2lift |
---|
612 | |
---|
613 | ! Remove the eroding dust lag if there is no dust anymore |
---|
614 | if (str%h_dust < tol) call del_stratum(this,str) |
---|
615 | |
---|
616 | END SUBROUTINE lift_dust |
---|
617 | |
---|
618 | !======================================================================= |
---|
619 | ! To sublimate ice in a stratum |
---|
620 | SUBROUTINE sublimate_ice(this,str,h2subl_co2ice,h2subl_h2oice,new_lag,zlag) |
---|
621 | |
---|
622 | implicit none |
---|
623 | |
---|
624 | !---- Arguments |
---|
625 | type(layering), intent(inout) :: this |
---|
626 | type(stratum), pointer, intent(inout) :: str |
---|
627 | logical, intent(inout) :: new_lag |
---|
628 | real, intent(inout) :: zlag |
---|
629 | real, intent(in) :: h2subl_co2ice, h2subl_h2oice |
---|
630 | |
---|
631 | !---- Local variables |
---|
632 | real :: h2subl, h_ice, h_pore, h_pore_new, h_tot |
---|
633 | real :: hlag_dust, hlag_h2oice |
---|
634 | type(stratum), pointer :: current |
---|
635 | |
---|
636 | !---- Code |
---|
637 | h_ice = str%h_co2ice + str%h_h2oice |
---|
638 | h_pore = str%h_pore |
---|
639 | h2subl = h2subl_co2ice + h2subl_h2oice |
---|
640 | |
---|
641 | ! How much dust and H2O ice does ice sublimation involve to create the lag? |
---|
642 | hlag_dust = str%h_dust*h2subl/h_ice |
---|
643 | hlag_h2oice = 0. |
---|
644 | if (h2subl_co2ice > 0. .and. h2subl_h2oice < tol) hlag_h2oice = str%h_h2oice*h2subl/h_ice |
---|
645 | |
---|
646 | ! Update of properties in the sublimating stratum |
---|
647 | str%top_elevation = str%top_elevation - h2subl*(1. + h_pore/h_ice) - hlag_dust - hlag_h2oice |
---|
648 | str%h_co2ice = str%h_co2ice - h2subl_co2ice |
---|
649 | str%h_h2oice = str%h_h2oice - h2subl_h2oice - hlag_h2oice |
---|
650 | str%h_dust = str%h_dust - hlag_dust |
---|
651 | str%h_pore = str%h_pore - h2subl*h_pore/h_ice |
---|
652 | |
---|
653 | ! Correct the value of top_elevation for the upper strata |
---|
654 | current => str%up |
---|
655 | do while (associated(current)) |
---|
656 | current%top_elevation = current%down%top_elevation + thickness(current) |
---|
657 | current => current%up |
---|
658 | enddo |
---|
659 | |
---|
660 | ! Remove the sublimating stratum if there is no ice anymore |
---|
661 | if (str%h_co2ice < tol .and. str%h_h2oice < tol) call del_stratum(this,str) |
---|
662 | |
---|
663 | ! Which porosity is considered? |
---|
664 | if (hlag_dust >= hlag_h2oice) then |
---|
665 | h_pore_new = hlag_dust*dry_lag_porosity/(1. - dry_lag_porosity) |
---|
666 | else |
---|
667 | h_pore_new = hlag_h2oice*wet_lag_porosity/(1. - wet_lag_porosity) |
---|
668 | endif |
---|
669 | h_tot = hlag_dust + hlag_h2oice + h_pore_new |
---|
670 | |
---|
671 | ! New stratum above the current stratum as a lag layer |
---|
672 | if (new_lag) then |
---|
673 | call insert_stratum(this,str,str%top_elevation + h_tot,0.,hlag_h2oice,hlag_dust,h_pore_new,0.) |
---|
674 | new_lag = .false. |
---|
675 | else |
---|
676 | str%up%top_elevation = str%up%top_elevation + h_tot |
---|
677 | str%up%h_h2oice = str%up%h_h2oice + hlag_h2oice |
---|
678 | str%up%h_dust = str%up%h_dust + hlag_dust |
---|
679 | str%up%h_pore = str%up%h_pore + h_pore_new |
---|
680 | endif |
---|
681 | |
---|
682 | zlag = zlag + h_tot |
---|
683 | |
---|
684 | END SUBROUTINE sublimate_ice |
---|
685 | |
---|
686 | !======================================================================= |
---|
687 | ! Layering algorithm |
---|
688 | SUBROUTINE make_layering(this,d_co2ice,d_h2oice,new_str,zshift_surf,new_lag,zlag,current) |
---|
689 | |
---|
690 | implicit none |
---|
691 | |
---|
692 | !---- Arguments |
---|
693 | ! Inputs |
---|
694 | |
---|
695 | ! Outputs |
---|
696 | type(layering), intent(inout) :: this |
---|
697 | type(stratum), pointer, intent(inout) :: current |
---|
698 | real, intent(inout) :: d_co2ice, d_h2oice |
---|
699 | logical, intent(inout) :: new_str, new_lag |
---|
700 | real, intent(out) :: zshift_surf, zlag |
---|
701 | |
---|
702 | !---- Local variables |
---|
703 | real :: dh_co2ice, dh_h2oice, dh_dust |
---|
704 | real :: h_co2ice_old, h_h2oice_old, h_dust_old |
---|
705 | real :: h2subl_co2ice, h2subl_h2oice, h2subl_co2ice_tot, h2subl_h2oice_tot |
---|
706 | real :: h2lift, h2lift_tot, h_pore, h_tot, h_toplag, R_subl |
---|
707 | logical :: unexpected |
---|
708 | type(stratum), pointer :: currentloc |
---|
709 | |
---|
710 | !---- Code |
---|
711 | dh_co2ice = d_co2ice/rho_co2ice |
---|
712 | dh_h2oice = d_h2oice/rho_h2oice |
---|
713 | ! To disable dust sedimenation when there is ice sublimation (because dust tendency is fixed) |
---|
714 | if (dh_co2ice > 0. .or. dh_h2oice > 0.) then |
---|
715 | dh_dust = d_dust/rho_dust |
---|
716 | else |
---|
717 | dh_dust = 0. |
---|
718 | endif |
---|
719 | zshift_surf = this%top%top_elevation |
---|
720 | zlag = 0. |
---|
721 | unexpected = .false. |
---|
722 | |
---|
723 | !----------------------------------------------------------------------- |
---|
724 | ! NOTHING HAPPENS |
---|
725 | if (abs(dh_co2ice) < tol .and. abs(dh_h2oice) < tol .and. abs(dh_dust) < tol) then |
---|
726 | ! So we do nothing |
---|
727 | !----------------------------------------------------------------------- |
---|
728 | ! BUILDING A STRATUM (ice condensation and/or dust desimentation) |
---|
729 | else if (dh_co2ice >= 0. .and. dh_h2oice >= 0. .and. dh_dust >= 0.) then |
---|
730 | ! Which porosity is considered? |
---|
731 | if (dh_co2ice > dh_h2oice .and. dh_co2ice > dh_dust) then ! CO2 ice is dominant |
---|
732 | h_pore = dh_co2ice*co2ice_porosity/(1. - co2ice_porosity) |
---|
733 | else if (dh_h2oice > dh_co2ice .and. dh_h2oice > dh_dust) then ! H2O ice is dominant |
---|
734 | h_pore = dh_h2oice*h2oice_porosity/(1. - h2oice_porosity) |
---|
735 | else if (dh_dust > dh_co2ice .and. dh_dust > dh_h2oice) then ! Dust is dominant |
---|
736 | h_pore = dh_dust*regolith_porosity/(1. - regolith_porosity) |
---|
737 | else |
---|
738 | unexpected = .true. |
---|
739 | endif |
---|
740 | h_tot = dh_co2ice + dh_h2oice + dh_dust + h_pore |
---|
741 | ! New stratum at the top of the layering |
---|
742 | if (new_str) then |
---|
743 | call add_stratum(this,this%top%top_elevation + h_tot,dh_co2ice,dh_h2oice,dh_dust,h_pore,0.) |
---|
744 | new_str = .false. |
---|
745 | else |
---|
746 | this%top%top_elevation = this%top%top_elevation + h_tot |
---|
747 | this%top%h_co2ice = this%top%h_co2ice + dh_co2ice |
---|
748 | this%top%h_h2oice = this%top%h_h2oice + dh_h2oice |
---|
749 | this%top%h_dust = this%top%h_dust + dh_dust |
---|
750 | this%top%h_pore = this%top%h_pore + h_pore |
---|
751 | endif |
---|
752 | !----------------------------------------------------------------------- |
---|
753 | ! RETREATING A STRATUM (ice sublimation and/or dust lifting) |
---|
754 | else if (dh_co2ice <= 0. .and. dh_h2oice <= 0. .and. dh_dust <= 0.) then |
---|
755 | h2subl_co2ice_tot = abs(dh_co2ice) |
---|
756 | h2subl_h2oice_tot = abs(dh_h2oice) |
---|
757 | h2lift_tot = abs(dh_dust) |
---|
758 | do while ((h2subl_co2ice_tot > 0. .or. h2subl_h2oice_tot > 0. .or. h2lift_tot > 0.) .and. associated(current)) |
---|
759 | h_co2ice_old = current%h_co2ice |
---|
760 | h_h2oice_old = current%h_h2oice |
---|
761 | |
---|
762 | ! How much is CO2 ice sublimation inhibited by the top dust lag? |
---|
763 | R_subl = 1. |
---|
764 | if (associated(current%up)) then ! If there is an upper stratum |
---|
765 | h_toplag = 0. |
---|
766 | currentloc => current%up |
---|
767 | do while (is_dust_lag(currentloc) .and. associated(currentloc%up)) |
---|
768 | h_toplag = h_toplag + thickness(currentloc) |
---|
769 | currentloc => currentloc%up |
---|
770 | enddo |
---|
771 | if (currentloc%h_h2oice >= h_patchy_ice) then |
---|
772 | R_subl = 0. |
---|
773 | else if (0. < currentloc%h_h2oice .and. currentloc%h_h2oice < h_patchy_ice) then |
---|
774 | h_toplag = h_toplag + thickness(currentloc) |
---|
775 | R_subl = fred_sublco2**(h_toplag/hmin_lag_co2) |
---|
776 | else |
---|
777 | R_subl = fred_sublco2**(h_toplag/hmin_lag_co2) |
---|
778 | endif |
---|
779 | endif |
---|
780 | h2subl_co2ice_tot = h2subl_co2ice_tot*R_subl |
---|
781 | |
---|
782 | ! Is there CO2 ice to sublimate? |
---|
783 | h2subl_co2ice = 0. |
---|
784 | if (h_co2ice_old > 0. .and. h2subl_co2ice_tot > 0.) then |
---|
785 | h2subl_co2ice = min(h2subl_co2ice_tot,h_co2ice_old) |
---|
786 | h2subl_co2ice_tot = h2subl_co2ice_tot - h2subl_co2ice |
---|
787 | endif |
---|
788 | ! Is there H2O ice to sublimate? |
---|
789 | h2subl_h2oice = 0. |
---|
790 | if (h_h2oice_old > 0. .and. h2subl_h2oice_tot > 0.) then |
---|
791 | h2subl_h2oice = min(h2subl_h2oice_tot,h_h2oice_old) |
---|
792 | h2subl_h2oice_tot = h2subl_h2oice_tot - h2subl_h2oice |
---|
793 | endif |
---|
794 | ! Ice sublimation |
---|
795 | if (h2subl_co2ice > 0. .or. h2subl_h2oice > 0.) call sublimate_ice(this,current,h2subl_co2ice,h2subl_h2oice,new_lag,zlag) |
---|
796 | |
---|
797 | ! Is there dust to lift? |
---|
798 | h2lift = 0. |
---|
799 | if (is_dust_lag(current) .and. h2lift_tot > 0.) then |
---|
800 | h2lift = min(h2lift_tot,current%h_dust) |
---|
801 | h2lift_tot = h2lift_tot - h2lift |
---|
802 | ! Dust lifting |
---|
803 | if (h2lift > 0.) call lift_dust(this,current,h2lift) |
---|
804 | else if (associated(current%up)) then |
---|
805 | if (is_dust_lag(current%up) .and. h2lift_tot > 0.) then |
---|
806 | h2lift = min(h2lift_tot,current%up%h_dust) |
---|
807 | h2lift_tot = h2lift_tot - h2lift |
---|
808 | ! Dust lifting |
---|
809 | if (h2lift > 0.) call lift_dust(this,current%up,h2lift) |
---|
810 | endif |
---|
811 | endif |
---|
812 | |
---|
813 | ! Still ice to be sublimated or dust to be lifted and no more ice in the current stratum so we move to the underlying stratum |
---|
814 | if ((h2subl_co2ice_tot > 0. .or. h2subl_h2oice_tot > 0. .or. h2lift_tot > 0.) .and. current%h_co2ice < tol .and. current%h_h2oice < tol .and. current%poreice_volfrac < tol) then |
---|
815 | current => current%down |
---|
816 | new_lag = .true. |
---|
817 | else |
---|
818 | exit |
---|
819 | endif |
---|
820 | enddo |
---|
821 | if (h2subl_co2ice_tot > 0.) dh_co2ice = 0. ! No CO2 ice available anymore so the tendency is set to 0 |
---|
822 | if (h2subl_h2oice_tot > 0.) dh_h2oice = 0. ! No H2O ice available anymore so the tendency is set to 0 |
---|
823 | if (h2lift_tot > 0.) dh_dust = 0. ! No dust available anymore so the tendency is set to 0 |
---|
824 | !----------------------------------------------------------------------- |
---|
825 | ! CO2 ICE SUBLIMATION + H2O ICE CONDENSATION |
---|
826 | else if (dh_co2ice < 0. .and. dh_h2oice > 0.) then |
---|
827 | !~ if (abs(dh_co2ice) > dh_h2oice .and. dh_co2ice < dh_dust .and. dh_dust <= 0.) then ! CO2 sublimation is dominant |
---|
828 | |
---|
829 | !~ else if (dh_h2oice > abs(dh_co2ice) .and. 0 <= dh_dust .and. dh_dust < dh_h2oice) then ! H2O condensation is dominant |
---|
830 | |
---|
831 | !~ else |
---|
832 | unexpected = .true. |
---|
833 | !~ endif |
---|
834 | !----------------------------------------------------------------------- |
---|
835 | ! NOT EXPECTED SITUATION |
---|
836 | else |
---|
837 | unexpected = .true. |
---|
838 | endif |
---|
839 | |
---|
840 | if (unexpected) then |
---|
841 | write(*,'(a)') 'Error: situation for the layering construction not managed!' |
---|
842 | write(*,'(a,es12.3)') ' > dh_co2ice [m/y] = ', dh_co2ice |
---|
843 | write(*,'(a,es12.3)') ' > dh_h2oice [m/y] = ', dh_h2oice |
---|
844 | write(*,'(a,es12.3)') ' > dh_dust [m/y] = ', dh_dust |
---|
845 | error stop |
---|
846 | endif |
---|
847 | |
---|
848 | zshift_surf = this%top%top_elevation - zshift_surf |
---|
849 | |
---|
850 | END SUBROUTINE make_layering |
---|
851 | |
---|
852 | END MODULE layering_mod |
---|