source: trunk/LMDZ.COMMON/libf/evolution/allocation.F90 @ 4076

Last change on this file since 4076 was 4065, checked in by jbclement, 2 weeks ago

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 size: 2.9 KB
Line 
1MODULE allocation
2!-----------------------------------------------------------------------
3! NAME
4!     allocation
5!
6! DESCRIPTION
7!     Management of memory throughout the modules of the code.
8!
9! AUTHORS & DATE
10!     JB Clement, 12/2025
11!
12! NOTES
13!
14!-----------------------------------------------------------------------
15
16! DEPENDENCIES
17! ------------
18use geometry,   only: ini_geometry, end_geometry, dim_init
19use atmosphere, only: ini_atmosphere, end_atmosphere
20use tracers,    only: ini_tracers, end_tracers
21use slopes,     only: ini_slopes, end_slopes
22use surface,    only: ini_surface, end_surface
23use surf_temp,  only: ini_surf_temp, end_surf_temp
24use soil_temp,  only: ini_soil_temp, end_soil_temp
25use frost,      only: ini_frost, end_frost
26use soil,       only: ini_soil, end_soil
27use ice_table,  only: ini_ice_table, end_ice_table
28use surf_ice,   only: ini_surf_ice, end_surf_ice
29use orbit,      only: ini_orbit, end_orbit
30use output,     only: ini_output, end_output
31
32! DECLARATION
33! -----------
34implicit none
35
36contains
37!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
38
39!=======================================================================
40SUBROUTINE ini_allocation()
41!-----------------------------------------------------------------------
42! NAME
43!     ini_geometry
44!
45! DESCRIPTION
46!     Initialize module arrays.
47!
48! AUTHORS & DATE
49!     JB Clement, 12/2025
50!
51! NOTES
52!
53!-----------------------------------------------------------------------
54
55! DEPENDENCIES
56! ------------
57use stoppage, only: stop_clean
58
59! DECLARATION
60! -----------
61implicit none
62
63! CODE
64! ----
65! Initialize the dimensions
66call ini_geometry()
67if (.not. dim_init) call stop_clean(__FILE__,__LINE__,"Dimensions of module 'geometry' were not correctly initilized.",1)
68
69! Initialize everything else
70call ini_atmosphere()
71call ini_tracers()
72call ini_slopes()
73call ini_surface()
74call ini_surf_temp()
75call ini_soil_temp()
76call ini_frost()
77call ini_soil()
78call ini_ice_table()
79call ini_surf_ice()
80call ini_orbit()
81call ini_output()
82
83END SUBROUTINE ini_allocation
84!=======================================================================
85
86!=======================================================================
87SUBROUTINE end_allocation()
88!-----------------------------------------------------------------------
89! NAME
90!     end_geometry
91!
92! DESCRIPTION
93!     Deallocate module arrays.
94!
95! AUTHORS & DATE
96!     JB Clement, 12/2025
97!
98! NOTES
99!
100!-----------------------------------------------------------------------
101
102! DECLARATION
103! -----------
104implicit none
105
106! CODE
107! ----
108call end_output()
109call end_orbit()
110call end_surf_ice()
111call end_ice_table()
112call end_soil()
113call end_frost()
114call end_soil_temp()
115call end_surf_temp()
116call end_surface()
117call end_slopes()
118call end_tracers()
119call end_atmosphere()
120call end_geometry()
121
122END SUBROUTINE end_allocation
123!=======================================================================
124
125END MODULE allocation
126
Note: See TracBrowser for help on using the repository browser.