Ignore:
Timestamp:
Mar 16, 2026, 3:24:12 PM (13 days ago)
Author:
jbclement
Message:

PEM:

  • Add a periodic backup based on a single wrapper which builds PCM-compatible climate state and writes "restart" files.
  • Remove condition "if (.not. allocated(*))" for more strict safeguard.

JBC

File:
1 edited

Legend:

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

    r4117 r4134  
    2323! PEM modules
    2424use allocation,         only: ini_allocation, end_allocation
    25 use atmosphere,         only: ps_PCM, evolve_pressure, CO2cond_ps_PCM, build4PCM_atmosphere
     25use atmosphere,         only: ps_PCM, evolve_pressure, CO2cond_ps_PCM
     26use backup,             only: save_clim_state, backup_rate
    2627use clim_state_init,    only: read_start, read_startfi, read_startpem
    27 use clim_state_rec,     only: write_restart, write_restartfi, write_restartpem
    2828use config,             only: read_rundef, read_display_config
    2929use display,            only: print_ini, print_end, print_msg, LVL_NFO, LVL_WRN
     
    3939use physics,            only: g
    4040use slopes,             only: subslope_dist, def_slope_mean
    41 use soil,               only: do_soil, set_soil, TI, build4PCM_soil
     41use soil,               only: do_soil, set_soil, TI
    4242use soil_temp,          only: tsoil_PCM, shift_tsoil2surf, evolve_soil_temp
    4343use soil_therm_inertia, only: update_soil_TI
    4444use sorption,           only: do_sorption, compute_totmass_adsorbed, evolve_regolith_adsorption
    4545use stopping_crit,      only: stopFlags, stopping_crit_pressure, stopping_crit_h2o, stopping_crit_h2oice, stopping_crit_co2ice
    46 use surface,            only: emissivity_PCM, build4PCM_surf_rad_prop
    47 use surf_ice,           only: evolve_co2ice, evolve_h2oice, balance_h2oice_reservoirs, build4PCM_perice
    48 use surf_temp,          only: tsurf_PCM, adapt_tsurf2disappearedice, build4PCM_tsurf
     46use surface,            only: emissivity_PCM
     47use surf_ice,           only: evolve_co2ice, evolve_h2oice, balance_h2oice_reservoirs
     48use surf_temp,          only: tsurf_PCM, adapt_tsurf2disappearedice
    4949use tendencies,         only: compute_tendice, evolve_tend_co2ice, evolve_tend_h2oice
    50 use tracers,            only: adapt_tracers2pressure, build4PCM_tracers, nq
     50use tracers,            only: adapt_tracers2pressure
    5151use utility,            only: real2str
    5252use workflow_status,    only: i_pem_run, read_workflow_status, update_workflow_status
     
    7171real(dp)                              :: ps_avg_glob_old ! Global average pressure of previous time step [Pa]
    7272real(dp)                              :: ps_avg_glob     ! Global average pressure of current time step [Pa]
    73 real(dp), dimension(:),   allocatable :: ps4PCM          ! Surface pressure reconstruction to feed back into PCM [Pa]
    74 real(dp), dimension(:,:), allocatable :: teta4PCM        ! Potential temperature reconstruction to feed back into PCM [K]
    75 real(dp), dimension(:,:), allocatable :: air_mass4PCM    ! Air mass reconstruction to feed back into PCM [kg]
    76 real(dp)                              :: pa4PCM          ! Transition pressure (for hybrid coord.) [Pa]
    77 real(dp)                              :: preff4PCM       ! Reference pressure [Pa]
    7873! Ice-related:
    7974real(dp),    dimension(:,:),   allocatable :: h2o_ice                    ! H2O ice [kg.m-2]
     
    8984real(dp),    dimension(:,:,:), allocatable :: minPCM_h2ofrost               ! Minimum of H2O frost over the last PCM year [kg.m-2]
    9085real(dp),    dimension(:,:,:), allocatable :: minPCM_co2frost               ! Minimum of CO2 frost over the last PCM year [kg.m-2]
    91 real(dp),    dimension(:,:),   allocatable :: h2o_ice4PCM                ! H2O ice reconstruction to feed back into PCM [kg.m-2]
    92 real(dp),    dimension(:,:),   allocatable :: co2_ice4PCM                ! CO2 ice reconstruction to feed back into PCM [kg.m-2]
    93 logical(k4), dimension(:),     allocatable :: is_h2o_perice              ! Location of H2O infinite reservoir, called 'watercaptag' in PCM
    9486logical(k4), dimension(:,:),   allocatable :: is_co2ice_disappeared      ! Flag to check if CO2 ice disappeared at the previous timestep
    9587! Surface-related:
     
    10092real(dp), dimension(:,:), allocatable :: zshift_surf         ! Elevation shift for the surface [m]
    10193real(dp), dimension(:,:), allocatable :: zlag                ! Newly built lag thickness [m]
    102 real(dp), dimension(:,:), allocatable :: albedo4PCM          ! Albedo reconstruction to feed back into PCM
    103 real(dp), dimension(:,:), allocatable :: emissivity4PCM      ! Emissivity reconstruction to feed back into PCM
    104 real(dp), dimension(:,:), allocatable :: tsurf4PCM           ! Surface temperature reconstruction to feed back into PCM [K]
    10594! Soil-related:
    10695real(dp), dimension(:,:,:),   allocatable :: tsoil_avg                ! Average soil temperature [K]
     
    112101real(dp), dimension(:),       allocatable :: delta_h2o_ads            ! Quantity of H2O exchanged due to adsorption/desorption [kg/m^2]
    113102real(qp)                                  :: totmass_adsh2o           ! Total mass of H2O exchanged because of adsorption/desorption [kg]
    114 real(dp), dimension(:,:,:),   allocatable :: inertiesoil4PCM          ! Soil thermal inertia reconstruction to feed back into PCM [SI]
    115 real(dp), dimension(:,:,:),   allocatable :: tsoil4PCM                ! Average soil temperature reconstruction to feed back into PCM [K]
    116 real(dp), dimension(:,:),     allocatable :: flux_geo4PCM             ! Geothermal flux reconstruction to feed back into PCM [W/m2]
    117103real(dp), dimension(:,:,:),   allocatable :: h2o_ads_reg              ! H2O adsorbed in the regolith [kg/m^2]
    118104real(dp), dimension(:,:,:),   allocatable :: co2_ads_reg              ! CO2 adsorbed in the regolith [kg/m^2]
     
    123109real(dp), dimension(:,:),   allocatable :: q_co2_ts_ini ! Initial CO2 mass mixing ratio in the first layer [kg/kg]
    124110real(dp), dimension(:,:),   allocatable :: q_h2o_ts     ! H2O mass mixing ratio in the first layer [kg/kg]
    125 real(dp), dimension(:,:,:), allocatable :: q4PCM        ! Tracers reconstruction to feed back into PCM [kg/kg]
    126111! Tendency-related:
    127112real(dp), dimension(:,:), allocatable :: d_co2ice     ! Tendency of perennial CO2 ice [kg/m2/y]
     
    440425    idt = idt + 1
    441426
     427    ! Save periodic backups of restart files
     428    if (backup_rate > 0 .and. mod(idt,backup_rate) == 0) then
     429        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, &
     430                             icetable_depth,icetable_thickness,ice_porefilling,h2o_ads_reg,co2_ads_reg,layerings_map,idt)
     431    end if
     432
    442433    ! Check the stopping criteria
    443434    call print_msg("> Checking the stopping criteria",LVL_NFO)
     
    469460if (evo_orbit) call update_orbit(n_yr_sim,n_yr_run)
    470461
    471 ! Build ice for the PCM
    472 allocate(h2o_ice4PCM(ngrid,nslope),co2_ice4PCM(ngrid,nslope),is_h2o_perice(ngrid))
    473 call build4PCM_perice(h2o_ice,co2_ice,is_h2o_perice,h2o_ice4PCM,co2_ice4PCM)
    474 
    475 ! Build surface temperature for the PCM
    476 allocate(tsurf4PCM(ngrid,nslope))
    477 call build4PCM_tsurf(tsurf_avg,tsurf_dev,tsurf4PCM)
    478 
    479 ! Build soil for the PCM
    480 if (do_soil) then
    481     allocate(tsoil4PCM(ngrid,nsoil_PCM,nslope),inertiesoil4PCM(ngrid,nsoil_PCM,nslope),flux_geo4PCM(ngrid,nslope))
    482     call build4PCM_soil(tsoil_avg,tsoil_dev,inertiesoil4PCM,tsoil4PCM,flux_geo4PCM)
    483 end if
    484 
    485 ! Build atmosphere for the PCM
    486 allocate(ps4PCM(ngrid),teta4PCM(ngrid,nlayer),air_mass4PCM(ngrid,nlayer))
    487 call build4PCM_atmosphere(ps_avg,ps_dev,ps_avg_glob,ps_avg_glob_ini,ps4PCM,pa4PCM,preff4PCM,teta4PCM,air_mass4PCM)
    488 
    489 ! Build tracers for the PCM
    490 allocate(q4PCM(ngrid,nlayer,nq))
    491 call build4PCM_tracers(ps4PCM,q4PCM)
    492 
    493 ! Build surface radiative properties state for the PCM
    494 allocate(albedo4PCM(ngrid,nslope),emissivity4PCM(ngrid,nslope))
    495 call build4PCM_surf_rad_prop(h2o_ice,co2_ice,albedo4PCM,emissivity4PCM)
    496 
    497 ! Write the "startevo.nc"
    498 call write_restartpem(h2o_ice,co2_ice,tsoil_avg,TI,icetable_depth,icetable_thickness,ice_porefilling,h2o_ads_reg,co2_ads_reg,layerings_map)
    499 
    500 ! Write the "startfi.nc"
    501 call write_restartfi(is_h2o_perice,h2o_ice4PCM,co2_ice4PCM,tsurf4PCM,tsoil4PCM,inertiesoil4PCM,albedo4PCM,emissivity4PCM,flux_geo4PCM)
    502 
    503 ! Write the "start.nc"
    504 call write_restart(ps4PCM,pa4PCM,preff4PCM,q4PCM,teta4PCM,air_mass4PCM)
     462call 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, &
     463                     icetable_depth,icetable_thickness,ice_porefilling,h2o_ads_reg,co2_ads_reg,layerings_map)
    505464
    506465! Update the duration information of the workflow
     
    508467
    509468! Deallocation
    510 deallocate(emissivity4PCM,albedo4PCM)
    511 deallocate(q4PCM)
    512 deallocate(ps4PCM,teta4PCM,air_mass4PCM)
    513 if (do_soil) deallocate(tsoil4PCM,inertiesoil4PCM,flux_geo4PCM)
    514 deallocate(tsurf4PCM)
    515 deallocate(co2_ice4PCM,h2o_ice4PCM,is_h2o_perice)
    516469deallocate(num)
    517470if (do_layering) then
Note: See TracChangeset for help on using the changeset viewer.