Ignore:
Timestamp:
Apr 8, 2026, 11:36:16 AM (3 days ago)
Author:
jbclement
Message:

PEM:
Refactor of H2O flux balancing:

  • centralizes flux balancing logic;
  • removes intermediate variables, especially related to of H2O mass bookkeeping;
  • adds new stopping criterion when H2O flux balance fails8 (sanity check);
  • introduces configurable weighting strategies for H2O flux balancing.

JBC

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.COMMON/libf/evolution/pem.F90

    r4170 r4174  
    3333use display,            only: print_ini, print_end, print_msg, LVL_NFO, LVL_WRN
    3434use evolution,          only: n_yr_run, n_yr_sim, ntot_yr_sim, nmax_yr_run, dt, idt, r_plnt2earth_yr, pem_ini_date
    35 use geometry,           only: ngrid, nslope, nday, nsoil_PCM, nsoil, cell_area, total_surface
     35use geometry,           only: ngrid, nslope, nsoil_PCM, nsoil, cell_area, total_surface
    3636use glaciers,           only: h2oice_flow, co2ice_flow, flow_co2glaciers, flow_h2oglaciers
    3737use ice_table,          only: icetable_equilibrium, icetable_dynamic, evolve_ice_table
     
    4848use soil_therm_inertia, only: update_soil_TI
    4949use sorption,           only: do_sorption, compute_totmass_adsorbed, evolve_regolith_adsorption
    50 use stopping_crit,      only: stopFlags, stopping_crit_pressure, stopping_crit_h2o, stopping_crit_h2oice, stopping_crit_co2ice
     50use stopping_crit,      only: stopFlags, stopping_crit_pressure, stopping_crit_h2oice, stopping_crit_co2ice
    5151use surface,            only: emissivity_PCM
    52 use surf_ice,           only: evolve_co2ice, evolve_h2oice, balance_h2oice_reservoirs
     52use surf_ice,           only: evolve_co2ice, evolve_h2oice, balance_h2o_fluxes
    5353use surf_temp,          only: tsurf_PCM, adapt_tsurf2disappearedice
    5454use tendencies,         only: compute_tendice, evolve_tend_co2ice, evolve_flux_ssice
     
    8080real(dp), dimension(:,:), allocatable :: zshift_surf   ! Elevation shift for the surface [m]
    8181real(dp), dimension(:,:), allocatable :: zlag          ! Newly built lag thickness [m]
    82 ! Tendency-related:
    83 real(dp), dimension(:,:), allocatable :: d_h2oice_new ! Adjusted tendency of perennial H2O ice to keep balance between donor and recipient [kg/m2/y]
    8482! Layering-related:
    8583type(ptrarray), dimension(:,:), allocatable :: current          ! Current active stratum in the layering
     
    9593real(qp) :: totmass_ini                                                ! Initial total CO2 mass [kg]
    9694real(qp) :: totmass_adsh2o                                             ! Current total adsorbed H2O mass [kg]
    97 real(qp) :: S_atm_2_h2o, S_h2o_2_atm, S_atm_2_h2oice, S_h2oice_2_atm   ! Variables to balance H2O ice reservoirs
    9895
    9996! CODE
     
    235232    allocate(zshift_surf(ngrid,nslope),zlag(ngrid,nslope))
    236233    if (do_layering) then
    237         allocate(d_h2oice_new(ngrid,nslope))
    238234        h2oice_depth_old(:,:) = h2oice_depth(:,:)
    239235        ! The sublimating tendency coming from subsurface ice is given through the surface ice tendency
     
    241237        do islope = 1,nslope
    242238            do i = 1,ngrid
    243                 call evolve_layering(layerings_map(i,islope),d_co2ice(i,islope),d_h2oice_new(i,islope),new_str(i,islope),zshift_surf(i,islope),new_lag(i,islope),zlag(i,islope),current(i,islope)%p)
     239                call evolve_layering(layerings_map(i,islope),d_co2ice(i,islope),d_h2oice(i,islope),new_str(i,islope),zshift_surf(i,islope),new_lag(i,islope),zlag(i,islope),current(i,islope)%p)
    244240                call print_layering(layerings_map(i,islope))
    245241            end do
     
    248244        call layering2surfice(layerings_map,h2o_ice,co2_ice,h2oice_depth)
    249245        ! Balance H2O ice reservoirs
    250         call stopping_crit_h2o(delta_h2o_ads,delta_icetable,h2o_ice,d_h2oice,S_atm_2_h2o,S_h2o_2_atm,S_atm_2_h2oice,S_h2oice_2_atm,stopcrit)
    251         call balance_h2oice_reservoirs(S_atm_2_h2o,S_h2o_2_atm,S_atm_2_h2oice,S_h2oice_2_atm,h2o_ice,d_h2oice,d_h2oice_new)
    252         deallocate(d_h2oice_new)
     246        call balance_h2o_fluxes(delta_h2o_ads,delta_icetable,h2o_ice,d_h2oice,stopcrit)
     247        if (stopcrit%stop_code() > 0) then
     248            deallocate(zshift_surf,zlag)
     249            call print_msg(stopcrit%stop_message(),LVL_NFO)
     250            exit
     251        end if
    253252    else
    254253        zlag(:,:) = 0._dp
     
    376375    if (backup_rate > 0) then
    377376        if (mod(idt,backup_rate) == 0) call save_clim_state(h2o_ice,co2_ice,tsurf_avg,tsurf_dev,tsoil_avg,tsoil_dev,ps_avg,ps_dev,ps_avg_glob,ps_avg_glob_ini, &
    378                                                             icetable_depth,icetable_thickness,ice_porefilling,h2oice_depth,flux_ssice_avg,h2o_ads_reg,co2_ads_reg,layerings_map,idt)
     377                                                            icetable_depth,icetable_thickness,ice_porefilling,h2oice_depth,h2o_ads_reg,co2_ads_reg,layerings_map,idt)
    379378    end if
    380379
     
    408407
    409408call save_clim_state(h2o_ice,co2_ice,tsurf_avg,tsurf_dev,tsoil_avg,tsoil_dev,ps_avg,ps_dev,ps_avg_glob,ps_avg_glob_ini, &
    410                      icetable_depth,icetable_thickness,ice_porefilling,h2oice_depth,flux_ssice_avg,h2o_ads_reg,co2_ads_reg,layerings_map)
     409                     icetable_depth,icetable_thickness,ice_porefilling,h2oice_depth,h2o_ads_reg,co2_ads_reg,layerings_map)
    411410
    412411! Update the duration information of the workflow
Note: See TracChangeset for help on using the changeset viewer.