Ignore:
Timestamp:
Mar 26, 2026, 4:29:10 PM (11 days ago)
Author:
jbclement
Message:

PEM:

  • Separate variables ownership between the module "planet" for persistent climate state and the program "pem" for transient workflow logic. It provides a meaningful structure.
  • Add lifecycle helpers for clear allocation/deallocation logic.
  • Simplify string suffix for slopes variables.

JBC

File:
1 edited

Legend:

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

    r4135 r4157  
    55!
    66! DESCRIPTION
    7 !     Legacy compatibility module for planet-specific definitions.
    8 !
    9 ! AUTHORS & DATE
    10 !     R. Vandemeulebrouck
    11 !     JB Clement, 2023-2025
    12 !
    13 ! NOTES
    14 !     Only valid for the Mars planet.
    15 !-----------------------------------------------------------------------
    16 
    17 ! DECLARATION
    18 ! -----------
    19 implicit none
    20 
    21 ! NOTE
    22 ! ----
     7!     Centralized climate-state storage and lifecycle helpers for PEM.
     8!
     9! AUTHORS & DATE
     10!     JB Clement, 03/2026
     11!
     12! NOTES
     13!     Ownership criterion for declarations:
     14!       - Declare in module "planet" variables that are persistent climate
     15!         state or persistent references used across multiple time steps.
     16!       - Declare in program "pem.F90" transient workflow/control varaibles,
     17!         one-shot initialization buffers and per-iteration working buffers.
     18!-----------------------------------------------------------------------
     19
     20! DEPENDENCIES
     21! ------------
     22use numerics,         only: dp, qp, k4
     23use layered_deposits, only: layering
     24
     25! DECLARATION
     26! -----------
     27implicit none
     28
     29! PARAMETERS
     30! ----------
     31! Pressure-related:
     32real(dp), dimension(:),   allocatable :: ps_avg          ! Average surface pressure [Pa]
     33real(dp), dimension(:,:), allocatable :: ps_ts           ! Surface pressure timeseries [Pa]
     34real(dp), dimension(:),   allocatable :: ps_dev          ! Deviation of surface pressure [Pa]
     35real(dp)                              :: ps_avg_glob_ini ! Global average pressure at initialization [Pa]
     36real(dp)                              :: ps_avg_glob_old ! Global average pressure of previous time step [Pa]
     37real(dp)                              :: ps_avg_glob     ! Global average pressure of current time step [Pa]
     38
     39! Ice-related:
     40real(dp),    dimension(:,:), allocatable :: h2o_ice                    ! H2O ice [kg.m-2]
     41real(dp),    dimension(:,:), allocatable :: co2_ice                    ! CO2 ice [kg.m-2]
     42real(dp)                                 :: h2oice_sublim_coverage_ini ! Initial surface area of sublimating H2O ice [m2]
     43real(dp)                                 :: co2ice_sublim_coverage_ini ! Initial surface area of sublimating CO2 ice [m2]
     44logical(k4), dimension(:,:), allocatable :: is_h2oice_ini              ! Initial location of H2O ice
     45logical(k4), dimension(:,:), allocatable :: is_co2ice_ini              ! Initial location of CO2 ice
     46logical(k4), dimension(:,:), allocatable :: is_co2ice_disappeared      ! Flag to check if CO2 ice disappeared at the previous timestep
     47
     48! Surface-related:
     49real(dp), dimension(:,:), allocatable :: tsurf_avg           ! Average surface temperature [K]
     50real(dp), dimension(:,:), allocatable :: tsurf_dev           ! Deviation of surface temperature [K]
     51real(dp), dimension(:,:), allocatable :: h2o_surfdensity_avg ! Average water surface density [kg/m^3]
     52
     53! Soil-related:
     54real(dp), dimension(:,:,:),   allocatable :: tsoil_avg    ! Average soil temperature [K]
     55real(dp), dimension(:,:,:),   allocatable :: tsoil_dev    ! Deviation of soil temperature [K]
     56real(dp), dimension(:,:,:,:), allocatable :: tsoil_ts     ! Soil temperature timeseries [K]
     57real(dp), dimension(:,:,:,:), allocatable :: tsoil_ts_old ! Soil temperature timeseries at the previous time step [K]
     58
     59! Layering-related:
     60type(layering), dimension(:,:), allocatable :: layerings_map ! Layering for each grid point and slope
     61
     62! Sorption-related:
     63real(dp), dimension(:,:,:), allocatable :: h2o_soildensity_avg ! Average of soil water soil density [kg/m^3]
     64real(dp), dimension(:),     allocatable :: delta_co2_ads       ! Quantity of CO2 exchanged due to adsorption/desorption [kg/m^2]
     65real(dp), dimension(:),     allocatable :: delta_h2o_ads       ! Quantity of H2O exchanged due to adsorption/desorption [kg/m^2]
     66real(dp), dimension(:,:,:), allocatable :: h2o_ads_reg         ! H2O adsorbed in the regolith [kg/m^2]
     67real(dp), dimension(:,:,:), allocatable :: co2_ads_reg         ! CO2 adsorbed in the regolith [kg/m^2]
     68
     69! Ice table-related:
     70real(dp), dimension(:,:),   allocatable :: icetable_depth     ! Depth of the ice table [m]
     71real(dp), dimension(:,:),   allocatable :: icetable_thickness ! Thickness of the ice table [m]
     72real(dp), dimension(:,:,:), allocatable :: ice_porefilling    ! Amount of porefilling [m^3/m^3]
     73real(dp), dimension(:,:),   allocatable :: icetable_depth_old ! Old depth of the ice table [m]
     74real(dp), dimension(:),     allocatable :: delta_icetable     ! Total mass of the H2O exchanged with the ice table [kg]
     75
     76! Tracer-related:
     77real(dp), dimension(:,:), allocatable :: q_co2_ts     ! CO2 mass mixing ratio in the first layer [kg/kg]
     78real(dp), dimension(:,:), allocatable :: q_co2_ts_ini ! Initial CO2 mass mixing ratio in the first layer [kg/kg]
     79real(dp), dimension(:,:), allocatable :: q_h2o_ts     ! H2O mass mixing ratio in the first layer [kg/kg]
     80
     81! Tendency-related:
     82real(dp), dimension(:,:), allocatable :: d_co2ice     ! Tendency of perennial CO2 ice [kg/m2/y]
     83real(dp), dimension(:,:), allocatable :: d_co2ice_ini ! Tendency of perennial CO2 ice at the beginning [kg/m2/y]
     84real(dp), dimension(:,:), allocatable :: d_h2oice     ! Tendency of perennial H2O ice [kg/m2/y]
    2385
    2486contains
    2587!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    2688
     89!=======================================================================
     90SUBROUTINE ini_planet()
     91!-----------------------------------------------------------------------
     92! NAME
     93!     ini_planet
     94!
     95! DESCRIPTION
     96!     Initialize scalar state values of module planet.
     97!
     98! AUTHORS & DATE
     99!     JB Clement, 03/2026
     100!
     101! NOTES
     102!
     103!-----------------------------------------------------------------------
     104
     105! DECLARATION
     106! -----------
     107implicit none
     108
     109! CODE
     110! ----
     111ps_avg_glob_ini = 0._dp
     112ps_avg_glob_old = 0._dp
     113ps_avg_glob = 0._dp
     114h2oice_sublim_coverage_ini = 0._dp
     115co2ice_sublim_coverage_ini = 0._dp
     116
     117END SUBROUTINE ini_planet
     118!=======================================================================
     119
     120!=======================================================================
     121SUBROUTINE allocate_xios_state()
     122!-----------------------------------------------------------------------
     123! NAME
     124!     allocate_xios_state
     125!
     126! DESCRIPTION
     127!     Allocate arrays needed before loading PCM/XIOS data.
     128!
     129! AUTHORS & DATE
     130!     JB Clement, 03/2026
     131!
     132! NOTES
     133!
     134!-----------------------------------------------------------------------
     135
     136! DEPENDENCIES
     137! ------------
     138use geometry, only: ngrid, nslope, nday, nsoil
     139
     140! DECLARATION
     141! -----------
     142implicit none
     143
     144! CODE
     145! ----
     146allocate(ps_avg(ngrid))
     147allocate(ps_ts(ngrid,nday))
     148allocate(tsurf_avg(ngrid,nslope))
     149allocate(h2o_surfdensity_avg(ngrid,nslope))
     150allocate(tsoil_avg(ngrid,nsoil,nslope))
     151allocate(tsoil_ts(ngrid,nsoil,nslope,nday))
     152allocate(h2o_soildensity_avg(ngrid,nsoil,nslope))
     153allocate(q_h2o_ts(ngrid,nday))
     154allocate(q_co2_ts(ngrid,nday))
     155
     156ps_avg(:) = 0._dp
     157ps_ts(:,:) = 0._dp
     158tsurf_avg(:,:) = 0._dp
     159h2o_surfdensity_avg(:,:) = 0._dp
     160tsoil_avg(:,:,:) = 0._dp
     161tsoil_ts(:,:,:,:) = 0._dp
     162h2o_soildensity_avg(:,:,:) = 0._dp
     163q_h2o_ts(:,:) = 0._dp
     164q_co2_ts(:,:) = 0._dp
     165
     166END SUBROUTINE allocate_xios_state
     167!=======================================================================
     168
     169!=======================================================================
     170SUBROUTINE allocate_deviation_state()
     171!-----------------------------------------------------------------------
     172! NAME
     173!     allocate_deviation_state
     174!
     175! DESCRIPTION
     176!     Allocate persistent deviation fields derived from PCM averages.
     177!
     178! AUTHORS & DATE
     179!     JB Clement, 03/2026
     180!
     181! NOTES
     182!
     183!-----------------------------------------------------------------------
     184
     185! DEPENDENCIES
     186! ------------
     187use geometry, only: ngrid, nslope, nsoil_PCM
     188
     189! DECLARATION
     190! -----------
     191implicit none
     192
     193! CODE
     194! ----
     195allocate(ps_dev(ngrid))
     196allocate(tsurf_dev(ngrid,nslope))
     197allocate(tsoil_dev(ngrid,nsoil_PCM,nslope))
     198
     199ps_dev(:) = 0._dp
     200tsurf_dev(:,:) = 0._dp
     201tsoil_dev(:,:,:) = 0._dp
     202
     203END SUBROUTINE allocate_deviation_state
     204!=======================================================================
     205
     206!=======================================================================
     207SUBROUTINE allocate_startevo_state()
     208!-----------------------------------------------------------------------
     209! NAME
     210!     allocate_startevo_state
     211!
     212! DESCRIPTION
     213!     Allocate arrays loaded from startevo or evolving afterward.
     214!
     215! AUTHORS & DATE
     216!     JB Clement, 03/2026
     217!
     218! NOTES
     219!
     220!-----------------------------------------------------------------------
     221
     222! DEPENDENCIES
     223! ------------
     224use geometry, only: ngrid, nslope, nsoil
     225
     226! DECLARATION
     227! -----------
     228implicit none
     229
     230! CODE
     231! ----
     232allocate(h2o_ice(ngrid,nslope))
     233allocate(co2_ice(ngrid,nslope))
     234allocate(icetable_depth(ngrid,nslope))
     235allocate(icetable_thickness(ngrid,nslope))
     236allocate(ice_porefilling(ngrid,nsoil,nslope))
     237allocate(h2o_ads_reg(ngrid,nsoil,nslope))
     238allocate(co2_ads_reg(ngrid,nsoil,nslope))
     239allocate(delta_h2o_ads(ngrid))
     240allocate(delta_co2_ads(ngrid))
     241allocate(layerings_map(ngrid,nslope))
     242
     243h2o_ice(:,:) = 0._dp
     244co2_ice(:,:) = 0._dp
     245icetable_depth(:,:) = 0._dp
     246icetable_thickness(:,:) = 0._dp
     247ice_porefilling(:,:,:) = 0._dp
     248h2o_ads_reg(:,:,:) = 0._dp
     249co2_ads_reg(:,:,:) = 0._dp
     250delta_h2o_ads(:) = 0._dp
     251delta_co2_ads(:) = 0._dp
     252
     253END SUBROUTINE allocate_startevo_state
     254!=======================================================================
     255
     256!=======================================================================
     257SUBROUTINE allocate_tendencies()
     258!-----------------------------------------------------------------------
     259! NAME
     260!     allocate_tendencies
     261!
     262! DESCRIPTION
     263!     Allocate perennial ice tendency arrays.
     264!
     265! AUTHORS & DATE
     266!     JB Clement, 03/2026
     267!
     268! NOTES
     269!
     270!-----------------------------------------------------------------------
     271
     272! DEPENDENCIES
     273! ------------
     274use geometry, only: ngrid, nslope
     275
     276! DECLARATION
     277! -----------
     278implicit none
     279
     280! CODE
     281! ----
     282allocate(d_h2oice(ngrid,nslope))
     283allocate(d_co2ice(ngrid,nslope))
     284
     285d_h2oice(:,:) = 0._dp
     286d_co2ice(:,:) = 0._dp
     287
     288END SUBROUTINE allocate_tendencies
     289!=======================================================================
     290
     291!=======================================================================
     292SUBROUTINE allocate_initial_snapshots()
     293!-----------------------------------------------------------------------
     294! NAME
     295!     allocate_initial_snapshots
     296!
     297! DESCRIPTION
     298!     Allocate arrays storing initial-state snapshots.
     299!
     300! AUTHORS & DATE
     301!     JB Clement, 03/2026
     302!
     303! NOTES
     304!
     305!-----------------------------------------------------------------------
     306
     307! DEPENDENCIES
     308! ------------
     309use geometry, only: ngrid, nslope, nday
     310
     311! DECLARATION
     312! -----------
     313implicit none
     314
     315! CODE
     316! ----
     317allocate(d_co2ice_ini(ngrid,nslope))
     318allocate(q_co2_ts_ini(ngrid,nday))
     319allocate(is_h2oice_ini(ngrid,nslope))
     320allocate(is_co2ice_ini(ngrid,nslope))
     321
     322d_co2ice_ini(:,:) = 0._dp
     323q_co2_ts_ini(:,:) = 0._dp
     324is_h2oice_ini(:,:) = .false.
     325is_co2ice_ini(:,:) = .false.
     326
     327END SUBROUTINE allocate_initial_snapshots
     328!=======================================================================
     329
     330!=======================================================================
     331SUBROUTINE allocate_loop_state()
     332!-----------------------------------------------------------------------
     333! NAME
     334!     allocate_loop_state
     335!
     336! DESCRIPTION
     337!     Allocate arrays that start being used during the main PEM loop.
     338!
     339! AUTHORS & DATE
     340!     JB Clement, 03/2026
     341!
     342! NOTES
     343!
     344!-----------------------------------------------------------------------
     345
     346! DEPENDENCIES
     347! ------------
     348use geometry, only: ngrid, nslope, nsoil, nday
     349
     350! DECLARATION
     351! -----------
     352implicit none
     353
     354! CODE
     355! ----
     356allocate(delta_icetable(ngrid))
     357allocate(icetable_depth_old(ngrid,nslope))
     358allocate(is_co2ice_disappeared(ngrid,nslope))
     359allocate(tsoil_ts_old(ngrid,nsoil,nslope,nday))
     360
     361delta_icetable(:) = 0._dp
     362icetable_depth_old(:,:) = 0._dp
     363is_co2ice_disappeared(:,:) = .false.
     364tsoil_ts_old(:,:,:,:) = 0._dp
     365
     366END SUBROUTINE allocate_loop_state
     367!=======================================================================
     368
     369!=======================================================================
     370SUBROUTINE end_planet()
     371!-----------------------------------------------------------------------
     372! NAME
     373!     end_planet
     374!
     375! DESCRIPTION
     376!     Finalize module planet.
     377!
     378! AUTHORS & DATE
     379!     JB Clement, 03/2026
     380!
     381! NOTES
     382!     Deallocate all allocatable state arrays of module planet.
     383!-----------------------------------------------------------------------
     384
     385! DECLARATION
     386! -----------
     387implicit none
     388
     389! CODE
     390! ----
     391if (allocated(ps_avg)) deallocate(ps_avg)
     392if (allocated(ps_ts)) deallocate(ps_ts)
     393if (allocated(ps_dev)) deallocate(ps_dev)
     394if (allocated(h2o_ice)) deallocate(h2o_ice)
     395if (allocated(co2_ice)) deallocate(co2_ice)
     396if (allocated(is_h2oice_ini)) deallocate(is_h2oice_ini)
     397if (allocated(is_co2ice_ini)) deallocate(is_co2ice_ini)
     398if (allocated(is_co2ice_disappeared)) deallocate(is_co2ice_disappeared)
     399if (allocated(tsurf_avg)) deallocate(tsurf_avg)
     400if (allocated(tsurf_dev)) deallocate(tsurf_dev)
     401if (allocated(h2o_surfdensity_avg)) deallocate(h2o_surfdensity_avg)
     402if (allocated(tsoil_avg)) deallocate(tsoil_avg)
     403if (allocated(tsoil_dev)) deallocate(tsoil_dev)
     404if (allocated(tsoil_ts)) deallocate(tsoil_ts)
     405if (allocated(tsoil_ts_old)) deallocate(tsoil_ts_old)
     406if (allocated(layerings_map)) deallocate(layerings_map)
     407if (allocated(h2o_soildensity_avg)) deallocate(h2o_soildensity_avg)
     408if (allocated(delta_co2_ads)) deallocate(delta_co2_ads)
     409if (allocated(delta_h2o_ads)) deallocate(delta_h2o_ads)
     410if (allocated(h2o_ads_reg)) deallocate(h2o_ads_reg)
     411if (allocated(co2_ads_reg)) deallocate(co2_ads_reg)
     412if (allocated(icetable_depth)) deallocate(icetable_depth)
     413if (allocated(icetable_thickness)) deallocate(icetable_thickness)
     414if (allocated(ice_porefilling)) deallocate(ice_porefilling)
     415if (allocated(icetable_depth_old)) deallocate(icetable_depth_old)
     416if (allocated(delta_icetable)) deallocate(delta_icetable)
     417if (allocated(q_co2_ts)) deallocate(q_co2_ts)
     418if (allocated(q_co2_ts_ini)) deallocate(q_co2_ts_ini)
     419if (allocated(q_h2o_ts)) deallocate(q_h2o_ts)
     420if (allocated(d_co2ice)) deallocate(d_co2ice)
     421if (allocated(d_co2ice_ini)) deallocate(d_co2ice_ini)
     422if (allocated(d_h2oice)) deallocate(d_h2oice)
     423if (allocated(layerings_map)) deallocate(layerings_map)
     424
     425END SUBROUTINE end_planet
     426!=======================================================================
     427
    27428END MODULE planet
Note: See TracChangeset for help on using the changeset viewer.