Ignore:
Timestamp:
Mar 9, 2026, 10:29:53 AM (5 days ago)
Author:
jbclement
Message:

PEM:

  • Introduction of a configurable display/logging system with options 'out2term', 'out2log', 'verbosity_lvl'. All messages now use verbosity levels ('LVL_NFO', 'LVL_WRN', 'LVL_ERR' and 'LVL_DBG').
  • Code encapsulation improvements with systematic privacy/protection of module variables.
  • Addition of workflow safety checks for required executables, dependencies (e.g. 'ncdump'), input files and callphys keys.
  • Renaming of PEM starting and diagnostic files ("startevol.nc" into "startevo.nc", "diagevol.nc" into "diagevo.nc").

JBC

File:
1 edited

Legend:

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

    r4090 r4110  
    2626use clim_state_init,    only: read_start, read_startfi, read_startpem
    2727use clim_state_rec,     only: write_restart, write_restartfi, write_restartpem
    28 use config,             only: read_rundef
    29 use display,            only: print_ini, print_end, print_msg
     28use config,             only: read_rundef, read_display_config
     29use display,            only: print_ini, print_end, print_msg, LVL_NFO, LVL_WRN
    3030use evolution,          only: n_yr_run, n_yr_sim, ntot_yr_sim, nmax_yr_run, dt, idt, r_plnt2earth_yr, pem_ini_date
    3131use geometry,           only: ngrid, nslope, nday, nsoil_PCM, nsoil, cell_area, total_surface, nlayer
    3232use glaciers,           only: h2oice_flow, co2ice_flow, flow_co2glaciers, flow_h2oglaciers
    3333use ice_table,          only: icetable_equilibrium, icetable_dynamic, icetable_depth, icetable_thickness, ice_porefilling, evolve_ice_table
    34 use layered_deposits,   only: layering, do_layering, del_layering, evolve_layering, ptrarray, layering2surfice, surfice2layering
     34use layered_deposits,   only: layering, do_layering, del_layering, evolve_layering, ptrarray, layering2surfice, surfice2layering, print_layering
    3535use maths,              only: pi
    3636use numerics,           only: dp, qp, di, li, k4, minieps, minieps_qp
    37 use orbit,              only: evol_orbit, read_orbitpm, compute_maxyr_orbit, update_orbit
    38 use output,             only: write_diagevol, dim_ngrid, dim_nsoil
     37use orbit,              only: evo_orbit, read_orbitpm, compute_maxyr_orbit, update_orbit
     38use output,             only: write_diagevo, dim_ngrid, dim_nsoil
    3939use physics,            only: g
    4040use slopes,             only: subslope_dist, def_slope_mean
     
    158158! ~~~~~~~~~~~~~~
    159159! Header
     160call read_display_config()
    160161call print_ini()
    161162
     
    203204call compute_maxyr_orbit(n_yr_sim,nmax_yr_runorb)
    204205
    205 ! Read the "startevol.nc"
     206! Read the "startevo.nc"
    206207allocate(h2o_ice(ngrid,nslope),co2_ice(ngrid,nslope))
    207208allocate(h2o_ads_reg(ngrid,nsoil,nslope),co2_ads_reg(ngrid,nsoil,nslope),delta_h2o_ads(ngrid),delta_co2_ads(ngrid))
     
    214215! Compute ice tendencies from yearly minima
    215216allocate(d_h2oice(ngrid,nslope),d_co2ice(ngrid,nslope))
    216 call print_msg('> Computing surface ice tendencies')
     217call print_msg('> Computing surface ice tendencies',LVL_NFO)
    217218call compute_tendice(minPCM_h2operice + minPCM_h2ofrost,h2o_ice(:,:) > 0._dp,d_h2oice)
    218 call print_msg('H2O ice tendencies [kg/m2/yr] (min|max): '//real2str(minval(d_h2oice))//' | '//real2str(maxval(d_h2oice)))
     219call print_msg('H2O ice tendencies [kg/m2/yr] (min|max): '//real2str(minval(d_h2oice))//' | '//real2str(maxval(d_h2oice)),LVL_NFO)
    219220call compute_tendice(minPCM_co2perice + minPCM_co2frost,co2_ice(:,:) > 0._dp,d_co2ice)
    220 call print_msg('CO2 ice tendencies [kg/m2/yr] (min|max): '//real2str(minval(d_co2ice))//' | '//real2str(maxval(d_co2ice)))
     221call print_msg('CO2 ice tendencies [kg/m2/yr] (min|max): '//real2str(minval(d_co2ice))//' | '//real2str(maxval(d_co2ice)),LVL_NFO)
    221222deallocate(minPCM_h2operice,minPCM_co2perice,minPCM_h2ofrost,minPCM_co2frost)
    222223
    223224! Save initial set-up useful for the next computations
    224 call print_msg('> Saving some initial climate state variables')
     225call print_msg('> Saving some initial climate state variables',LVL_NFO)
    225226allocate(d_co2ice_ini(ngrid,nslope),q_co2_ts_ini(ngrid,nday))
    226227allocate(is_h2oice_ini(ngrid,nslope),is_co2ice_ini(ngrid,nslope))
     
    250251    end do
    251252end do
    252 call print_msg("Initial global average pressure [Pa] = "//real2str(ps_avg_glob_ini))
    253 call print_msg("Initial surface area of sublimating CO2 ice [m2] = "//real2str(co2ice_sublim_coverage_ini))
    254 call print_msg("Initial surface area of sublimating H2O ice [m2] = "//real2str(h2oice_sublim_coverage_ini))
     253call print_msg("Initial global average pressure [Pa] = "//real2str(ps_avg_glob_ini),LVL_NFO)
     254call print_msg("Initial surface area of sublimating CO2 ice [m2] = "//real2str(co2ice_sublim_coverage_ini),LVL_NFO)
     255call print_msg("Initial surface area of sublimating H2O ice [m2] = "//real2str(h2oice_sublim_coverage_ini),LVL_NFO)
    255256if (do_sorption) call compute_totmass_adsorbed(h2o_ads_reg,co2_ads_reg,totmass_adsco2_ini,totmass_adsh2o)
    256257
    257258! Main evolution loop
    258259! ~~~~~~~~~~~~~~~~~~~
    259 call print_msg('')
    260 call print_msg('********* Evolution *********')
     260call print_msg('',LVL_NFO)
     261call print_msg('********* Evolution *********',LVL_NFO)
    261262if (do_layering) then
    262263    allocate(h2oice_depth(ngrid,nslope),h2oice_depth_old(ngrid,nslope),new_str(ngrid,nslope),new_lag(ngrid,nslope),current(ngrid,nslope))
     
    284285idt = 0
    285286do while (n_yr_run < min(nmax_yr_runorb,nmax_yr_run) .and. n_yr_sim < ntot_yr_sim)
    286     call print_msg('**** Iteration of the PEM run [Planetary years]: '//real2str(n_yr_run + dt))
     287    call print_msg('**** Iteration of the PEM run [Planetary years]: '//real2str(n_yr_run + dt),LVL_NFO)
    287288    ! Evolve global surface pressure
    288289    call evolve_pressure(d_co2ice,delta_co2_ads,do_sorption,ps_avg_glob_old,ps_avg_glob,ps_avg)
     
    298299            do i = 1,ngrid
    299300                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)
    300                 !call print_layering(layerings_map(i,islope))
     301                call print_layering(layerings_map(i,islope))
    301302            end do
    302303        end do
     
    355356
    356357    ! Output the results
    357     call print_msg('> Standard outputs')
    358     call write_diagevol('ps_avg_glob','Global average pressure','Pa',ps_avg_glob)
     358    call print_msg('> Standard outputs',LVL_NFO)
     359    call write_diagevo('ps_avg_glob','Global average pressure','Pa',ps_avg_glob)
    359360    do islope = 1,nslope
    360361        if (nslope /= 1) then
     
    363364            num = '_slope'//num
    364365        end if
    365         call write_diagevol('h2oice'//num,'H2O ice','kg.m-2',h2o_ice(:,islope),(/dim_ngrid/))
    366         call write_diagevol('co2ice'//num,'CO2 ice','kg.m-2',co2_ice(:,islope),(/dim_ngrid/))
    367         call write_diagevol('d_h2oice'//num,'H2O ice tendency','kg.m-2.yr-1',d_h2oice(:,islope),(/dim_ngrid/))
    368         call write_diagevol('d_co2ice'//num,'CO2 ice tendency','kg.m-2.yr-1',d_co2ice(:,islope),(/dim_ngrid/))
     366        call write_diagevo('h2oice'//num,'H2O ice','kg.m-2',h2o_ice(:,islope),(/dim_ngrid/))
     367        call write_diagevo('co2ice'//num,'CO2 ice','kg.m-2',co2_ice(:,islope),(/dim_ngrid/))
     368        call write_diagevo('d_h2oice'//num,'H2O ice tendency','kg.m-2.yr-1',d_h2oice(:,islope),(/dim_ngrid/))
     369        call write_diagevo('d_co2ice'//num,'CO2 ice tendency','kg.m-2.yr-1',d_co2ice(:,islope),(/dim_ngrid/))
    369370        if (co2ice_flow) then
    370             call write_diagevol('Flow_co2ice'//num,'CO2 ice flow location','T/F',merge(1._dp,0._dp,is_co2ice_flow(:,islope)),(/dim_ngrid/))
     371            call write_diagevo('Flow_co2ice'//num,'CO2 ice flow location','T/F',merge(1._dp,0._dp,is_co2ice_flow(:,islope)),(/dim_ngrid/))
    371372            deallocate(is_co2ice_flow)
    372373        end if
    373374        if (h2oice_flow) then
    374             call write_diagevol('Flow_h2oice'//num,'H2O ice flow location','T/F',merge(1._dp,0._dp,is_h2oice_flow(:,islope)),(/dim_ngrid/))
     375            call write_diagevo('Flow_h2oice'//num,'H2O ice flow location','T/F',merge(1._dp,0._dp,is_h2oice_flow(:,islope)),(/dim_ngrid/))
    375376            deallocate(is_h2oice_flow)
    376377        end if
    377         call write_diagevol('tsurf'//num,'Surface temperature','K',tsurf_avg(:,islope),(/dim_ngrid/))
     378        call write_diagevo('tsurf'//num,'Surface temperature','K',tsurf_avg(:,islope),(/dim_ngrid/))
    378379        if (do_soil) then
    379380            if (icetable_equilibrium) then
    380                 call write_diagevol('icetable_depth'//num,'Ice table depth','m',icetable_depth(:,islope),(/dim_ngrid/))
    381                 call write_diagevol('icetable_thick'//num,'Ice table thickness','m',icetable_thickness(:,islope),(/dim_ngrid/))
     381                call write_diagevo('icetable_depth'//num,'Ice table depth','m',icetable_depth(:,islope),(/dim_ngrid/))
     382                call write_diagevo('icetable_thick'//num,'Ice table thickness','m',icetable_thickness(:,islope),(/dim_ngrid/))
    382383            else if (icetable_dynamic) then
    383                 call write_diagevol('icetable_depth'//num,'Ice table depth','m',icetable_depth(:,islope),(/dim_ngrid/))
    384                 call write_diagevol('ice_porefilling'//num,'Ice pore filling','-',ice_porefilling(:,:,islope),(/dim_ngrid,dim_nsoil/))
     384                call write_diagevo('icetable_depth'//num,'Ice table depth','m',icetable_depth(:,islope),(/dim_ngrid/))
     385                call write_diagevo('ice_porefilling'//num,'Ice pore filling','-',ice_porefilling(:,:,islope),(/dim_ngrid,dim_nsoil/))
    385386            end if
    386             call write_diagevol('tsoil_avg'//num,'Soil temperature','K',tsoil_avg(:,:,islope),(/dim_ngrid,dim_nsoil/))
    387             call write_diagevol('inertiesoil'//num,'Thermal inertia','SI',TI(:,:,islope),(/dim_ngrid,dim_nsoil/))
     387            call write_diagevo('tsoil_avg'//num,'Soil temperature','K',tsoil_avg(:,:,islope),(/dim_ngrid,dim_nsoil/))
     388            call write_diagevo('inertiesoil'//num,'Thermal inertia','SI',TI(:,:,islope),(/dim_ngrid,dim_nsoil/))
    388389            if (do_sorption) then
    389                 call write_diagevol('co2_ads_reg'//num,'CO2 adsorbed in regolith','kg.m-2',co2_ads_reg(:,:,islope),(/dim_ngrid,dim_nsoil/))
    390                 call write_diagevol('h2o_ads_reg'//num,'H2O adsorbed in regolith','kg.m-2',h2o_ads_reg(:,:,islope),(/dim_ngrid,dim_nsoil/))
     390                call write_diagevo('co2_ads_reg'//num,'CO2 adsorbed in regolith','kg.m-2',co2_ads_reg(:,:,islope),(/dim_ngrid,dim_nsoil/))
     391                call write_diagevo('h2o_ads_reg'//num,'H2O adsorbed in regolith','kg.m-2',h2o_ads_reg(:,:,islope),(/dim_ngrid,dim_nsoil/))
    391392            end if
    392393        end if
     
    404405        end do
    405406        totmass_ini = max(totmass_atmco2_ini + totmass_co2ice_ini + totmass_adsco2_ini,minieps_qp) ! To avoid division by 0
    406         call print_msg(" > Relative total CO2 mass balance = "//real2str(100._qp*(totmass_atmco2 + totmass_co2ice + totmass_adsco2 - totmass_atmco2_ini - totmass_co2ice_ini - totmass_adsco2_ini)/totmass_ini)//' %')
     407        call print_msg(" > Relative total CO2 mass balance = "//real2str(100._qp*(totmass_atmco2 + totmass_co2ice + totmass_adsco2 - totmass_atmco2_ini - totmass_co2ice_ini - totmass_adsco2_ini)/totmass_ini)//' %',LVL_NFO)
    407408        if (abs((totmass_atmco2 + totmass_co2ice + totmass_adsco2 - totmass_atmco2_ini - totmass_co2ice_ini - totmass_adsco2_ini)/totmass_ini) > 0.01_qp) then
    408             call print_msg('  /!\ Warning: mass balance is not conserved!')
     409            call print_msg('Mass balance is not conserved!',LVL_WRN)
    409410            totmass_ini = max(totmass_atmco2_ini,minieps_qp) ! To avoid division by 0
    410             call print_msg('       Atmospheric CO2 mass balance = '//real2str(100._qp*(totmass_atmco2 - totmass_atmco2_ini)/totmass_ini)//' %')
     411            call print_msg('    Atmospheric CO2 mass balance = '//real2str(100._qp*(totmass_atmco2 - totmass_atmco2_ini)/totmass_ini)//' %',LVL_WRN)
    411412            totmass_ini = max(totmass_co2ice_ini,minieps_qp) ! To avoid division by 0
    412             call print_msg('       CO2 ice mass balance         = '//real2str(100._qp*(totmass_co2ice - totmass_co2ice_ini)/totmass_ini)//' %')
     413            call print_msg('    CO2 ice mass balance         = '//real2str(100._qp*(totmass_co2ice - totmass_co2ice_ini)/totmass_ini)//' %',LVL_WRN)
    413414            totmass_ini = max(totmass_adsco2_ini,minieps_qp) ! To avoid division by 0
    414             call print_msg('       Adsorbed CO2 mass balance    = '//real2str(100._qp*(totmass_adsco2 - totmass_adsco2_ini)/totmass_ini)//' %')
     415            call print_msg('    Adsorbed CO2 mass balance    = '//real2str(100._qp*(totmass_adsco2 - totmass_adsco2_ini)/totmass_ini)//' %',LVL_WRN)
    415416        end if
    416417    end if
     
    438439
    439440    ! Check the stopping criteria
    440     call print_msg("> Checking the stopping criteria")
     441    call print_msg("> Checking the stopping criteria",LVL_NFO)
    441442    call stopping_crit_pressure(ps_avg_glob_ini,ps_avg_glob,stopcrit)
    442443    call stopping_crit_h2oice(h2oice_sublim_coverage_ini,h2o_ice,d_h2oice,stopcrit)
     
    448449    if (stopcrit%stop_code() == 0 .and. timewall .and. real(c2 - c1,dp)/real(cr,dp) >= timelimit - antetime) stopcrit%time_limit_reached = .true.
    449450    if (stopcrit%is_any_set()) then
    450         call print_msg(stopcrit%stop_message())
     451        call print_msg(stopcrit%stop_message(),LVL_NFO)
    451452        exit
    452453    else
    453         call print_msg('**** This run has achieved '//real2str(n_yr_run)//' Planetary years.')
    454         call print_msg('**** The workflow has achieved '//real2str(n_yr_sim)//' Planetary years.')
    455         call print_msg('**** This run is continuing!')
    456         call print_msg('****')
     454        call print_msg('**** This run has achieved '//real2str(n_yr_run)//' Planetary years.',LVL_NFO)
     455        call print_msg('**** The workflow has achieved '//real2str(n_yr_sim)//' Planetary years.',LVL_NFO)
     456        call print_msg('**** This run is continuing!',LVL_NFO)
     457        call print_msg('****',LVL_NFO)
    457458    end if
    458459end do ! End of the evolution loop
     
    461462! Finalization
    462463! ~~~~~~~~~~~~
    463 call print_msg('')
    464 call print_msg('********* Finalization *********')
     464call print_msg('',LVL_NFO)
     465call print_msg('********* Finalization *********',LVL_NFO)
    465466! Update orbital parameters
    466 if (evol_orbit) call update_orbit(n_yr_sim,n_yr_run)
     467if (evo_orbit) call update_orbit(n_yr_sim,n_yr_run)
    467468
    468469! Build ice for the PCM
     
    492493call build4PCM_surf_rad_prop(h2o_ice,co2_ice,albedo4PCM,emissivity4PCM)
    493494
    494 ! Write the "startevol.nc"
     495! Write the "startevo.nc"
    495496call write_restartpem(h2o_ice,co2_ice,tsoil_avg,TI,icetable_depth,icetable_thickness,ice_porefilling,h2o_ads_reg,co2_ads_reg,layerings_map)
    496497
Note: See TracChangeset for help on using the changeset viewer.