Ignore:
Timestamp:
Feb 12, 2026, 9:09:12 AM (2 weeks ago)
Author:
jbclement
Message:

PEM:
Major refactor following the previous ones (r3989 and r3991) completing the large structural reorganization and cleanup of the PEM codebase. This revision introduces newly designed modules, standardizes interfaces with explicit ini/end APIs and adds native NetCDF I/O together with explicit PCM/PEM adapters. In detail:

  • Some PEM models were corrected or improved:
    • Frost/perennial ice semantics are clarified via renaming;
    • Soil temperature remapping clarified, notably by removing the rescaling of temperature deviation;
    • Geothermal flux for the PCM is computed based on the PEM state;
  • New explicit PEM/PCM adapters ("set_*"/"build4PCM_*") to decouple PEM internal representation from PCM file layouts and reconstruct consistent fields returned to the PCM;
  • New explicit build/teardown routines that centralize allocation and initialization ordering, reducing accidental use of uninitialized data and making the model lifecycle explicit;
  • Add native read/write helpers for NetCDF that centralize all low-level NetCDF interactions with major improvements (and more simplicity) compared to legacy PEM/PCM I/O (see the modules "io_netcdf" and "output"). They support reading, creation and writing of "diagevol.nc" (renamed from "diagpem.nc") and start/restart files;
  • Provide well-focused modules ("numerics"/"maths"/"utility"/"display") to host commonly-used primitives:
    • "numerics" defines numerical types and constants for reproducibility, portability across compilers and future transitions (e.g. quadruple precision experiments);
    • "display" provides a single controlled interface for runtime messages, status output and diagnostics, avoiding direct 'print'/'write' to enable silent mode, log redirection, and MPI-safe output in the future.
    • "utility" (new module) hosts generic helpers used throughout the code (e.g. "int2str" or "real2str");
  • Add modules "clim_state_init"/"clim_state_rec" which provide robust read/write logic for "start/startfi/startpem", including 1D fallbacks, mesh conversions and dimension checks. NetCDF file creation is centralized and explicit. Restart files are now self-consistent and future-proof, requiring changes only to affected variables;
  • Add module "atmosphere" which computes pressure fields, reconstructs potential temperature and air mass. It also holds the whole logic to define sigma or hybrid coordinates for altitudes;
  • Add module "geometry" to centrilize dimensions logic and grid conversions routines (including 2 new ones "dyngrd2vect"/"vect2dyngrd");
  • Add module "slopes" to isolate slopes handling;
  • Add module "surface" to isolate surface management. Notably, albedo and emissivity are now fully reconstructed following the PCM settings;
  • Add module "allocation" to check the dimension initialization and centrilize allocation/deallocation;
  • Finalize module decomposition and renaming to consolidate domain-based modules, purpose-based routines and physics/process-based variables;
  • The main program now drives a clearer sequence of conceptual steps (initialization / reading / evolution / update / build / writing) and fails explicitly instead of silently defaulting;
  • Ice table logic is made restart-safe;
  • 'Open'/'read' intrinsic logic is made safe and automatic;
  • Improve discoverability and standardize the data handling (private vs protected vs public);
  • Apply consistent documentation/header style already introduced;
  • Update deftank scripts to reflect new names and launch wrappers;

This revision is a structural milestone aiming to be behavior-preserving where possible. It has been tested via compilation and short integration runs. However, due to extensive renames, moves, and API changes, full validation is still ongoing.
Note: the revision includes one (possibly two) easter egg hidden in the code for future archaeologists of the PEM. No physics were harmed.
JBC

File:
1 edited

Legend:

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

    r3991 r4065  
    1717!-----------------------------------------------------------------------
    1818
     19! DEPENDENCIES
     20! ------------
     21use numerics, only: dp, di
     22
    1923! DECLARATION
    2024! -----------
    2125implicit none
    2226
    23 ! MODULE PARAMETERS
    24 ! -----------------
     27! PARAMETERS
     28! ----------
    2529real(8), parameter :: dt = 0.02  ! in units of Mars solar days
    2630!real(8), parameter :: Fgeotherm = 0.
     
    4751! orbital elements remain constant
    4852!***********************************************************************
    49   use constants_marspem_mod, only: sec_per_sol
    50   use phys_constants,        only: pi
     53  use orbit, only: sol_len_s
     54  use maths, only: pi
    5155  ! DECLARATION
    5256! -----------
     
    139143 !    print *,'  latitude (deg)',latitude(k),' rho*c (J/m^3/K)',rhoc(k),' thIn=',thIn(k)
    140144 !    print *,'  total pressure=',p0(k),'partial pressure=',pfrost(k)
    141      delta = thIn(k)/rhoc(k)*sqrt(sec_per_sol/pi)
     145     delta = thIn(k)/rhoc(k)*sqrt(sol_len_s/pi)
    142146 !    print *,'  skin depths (m)',delta,delta*sqrt(solsperyear)
    143147     call soilthprop(porosity,1.d0,rhoc(k),thIn(k),1,newrhoc,newti,icefrac)
     
    222226!     output are newti and newrhoc
    223227!***********************************************************************
    224   ! DECLARATION
     228
     229! DEPENDENCIES
     230! ------------
     231use stoppage, only: stop_clean
     232
     233! DECLARATION
    225234! -----------
    226235implicit none
     
    281290
    282291  case default
    283      error stop 'invalid layer type'
     292     call stop_clean(__FILE__,__LINE__,'invalid layer type',1)
    284293
    285294  end select
     
    338347! latitude  [degree]
    339348!*************************************************************************
    340   use ice_table,      only: rho_ice
     349  !use ice_table,      only: rho_ice
    341350  !use omp_lib
    342351  ! DECLARATION
     
    457466!  Tb>0 initializes temperatures with Tb
    458467!***********************************************************************
    459   use constants_marspem_mod, only: sols_per_my, sec_per_sol
     468  use orbit, only: yr_len_sol, sol_len_s
    460469  ! DECLARATION
    461470! -----------
     
    485494  real(8) rhosatav0, rhosatav(nz), rlow
    486495
    487   tmax = EQUILTIME*sols_per_my
     496  tmax = EQUILTIME*yr_len_sol
    488497  nsteps = int(tmax/dt)     ! calculate total number of timesteps
    489498
     
    523532  do n=0,nsteps-1
    524533     time = (n+1)*dt         !   time at n+1
    525    !  tdays = time*(sec_per_sol/earthDay) ! parenthesis may improve roundoff
     534   !  tdays = time*(sol_len_s/earthDay) ! parenthesis may improve roundoff
    526535   !  call generalorbit(tdays,a,ecc,omega,eps,marsLs,marsDec,marsR)
    527536   !  HA = 2.*pi*mod(time,1.d0)  ! hour angle
     
    533542     Told(1:nz) = T(1:nz)
    534543     if (m<=0. .or. Tsurf>Tco2frost) then
    535        ! call conductionQ(nz,z,dt*sec_per_sol,Qn,Qnp1,T,ti,rhocv,emiss, &
     544       ! call conductionQ(nz,z,dt*sol_len_s,Qn,Qnp1,T,ti,rhocv,emiss, &
    536545       !      &           Tsurf,Fgeotherm,Fsurf)
    537546     endif
    538547     if (Tsurf<Tco2frost .or. m>0.) then ! CO2 condensation
    539548        T(1:nz) = Told(1:nz)
    540         !call conductionT(nz,z,dt*sec_per_sol,T,Tsurfold,Tco2frost,ti, &
     549        !call conductionT(nz,z,dt*sol_len_s,T,Tsurfold,Tco2frost,ti, &
    541550             !&              rhocv,Fgeotherm,Fsurf)
    542551        Tsurf = Tco2frost
    543552    !    dE = (- Qn - Qnp1 + Fsurfold + Fsurf + &
    544553    !         &      emiss*sigSB*(Tsurfold**4+Tsurf**4)/2.
    545         m = m + dt*sec_per_sol*dE/Lco2frost
     554        m = m + dt*sol_len_s*dE/Lco2frost
    546555     endif
    547556     if (Tsurf>Tco2frost .or. m<=0.) then
     
    554563     !Qn=Qnp1
    555564
    556      if (time>=tmax-sols_per_my) then
     565     if (time>=tmax-yr_len_sol) then
    557566        Tmean1 = Tmean1 + Tsurf
    558567        Tmean3 = Tmean3 + T(nz)
     
    715724!  B = Diff*bigstep/(porosity*icedensity)  [SI units]
    716725!***********************************************************************
    717   use math_toolkit, only: deriv2_simple, deriv1_onesided, deriv1, colint
    718   use ice_table,    only: constriction
     726  use maths,     only: deriv2_simple, deriv1_onesided, deriv1, colint
    719727  ! DECLARATION
    720728! -----------
     
    848856! a crucial subroutine
    849857!***********************************************************
    850   use math_toolkit, only: colint
    851   use ice_table,    only: rho_ice
     858  use maths,    only: colint
     859  !use ice_table, only: rho_ice
    852860  ! DECLARATION
    853861! -----------
     
    933941end subroutine icechanges
    934942
     943!=======================================================================
     944FUNCTION constriction(porefill) RESULT(eta)
     945!-----------------------------------------------------------------------
     946! NAME
     947!     constriction
     948!
     949! DESCRIPTION
     950!     Compute the constriction of vapor flux by pore ice.
     951!
     952! AUTHORS & DATE
     953!     L. Lange
     954!     JB Clement, 2023-2025
     955!
     956! NOTES
     957!
     958!-----------------------------------------------------------------------
     959
     960! DECLARATION
     961! -----------
     962implicit none
     963
     964! ARGUMENTS
     965! ---------
     966real, intent(in) :: porefill ! pore filling fraction
     967
     968! LOCAL VARIABLES
     969! ---------------
     970real :: eta ! constriction
     971
     972! CODE
     973! ----
     974if (porefill <= 0.) then
     975    eta = 1.
     976else if (0 < porefill .and. porefill < 1.) then
     977    eta = (1-porefill)**2 ! Hudson et al., JGR, 2009
     978else
     979    eta = 0.
     980endif
     981
     982END FUNCTION constriction
     983!=======================================================================
     984
    935985END MODULE subsurface_ice
Note: See TracChangeset for help on using the changeset viewer.