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