source: trunk/LMDZ.COMMON/libf/evolution/stoppage.F90 @ 4066

Last change on this file since 4066 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.1 KB
Line 
1MODULE stoppage
2!-----------------------------------------------------------------------
3! NAME
4!     stoppage
5!
6! DESCRIPTION
7!     Clean stopping utilities for PEM: close outputs and report reason.
8!
9! AUTHORS & DATE
10!     JB Clement, 2025
11!
12! NOTES
13!
14!-----------------------------------------------------------------------
15
16! DEPENDENCIES
17! ------------
18use numerics, only: di
19
20! DECLARATION
21! -----------
22implicit none
23
24contains
25!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
27!=======================================================================
28SUBROUTINE stop_clean(fname,fline,message,ierr)
29!-----------------------------------------------------------------------
30! NAME
31!     stop_clean
32!
33! DESCRIPTION
34!     Stop simulation cleanly, closing files and printing diagnostics.
35!
36! AUTHORS & DATE
37!     JB Clement, 2025
38!
39! NOTES
40!     Taken from Mars PCM.
41!-----------------------------------------------------------------------
42
43! DEPENDENCIES
44! ------------
45#ifdef CPP_IOIPSL
46use IOIPSL
47#else
48! If not using IOIPSL, we still need to use (a local version of) getin_dump
49use ioipsl_getincom
50#endif
51#ifdef CPP_XIOS
52use wxios ! For XIOS outputs
53#endif
54
55! DECLARATION
56! -----------
57implicit none
58
59#include "iniprint.h"
60
61! ARGUMENTS
62! ---------
63character(*), intent(in) :: fname   ! Name of file
64integer(di),      intent(in) :: fline   ! Line number of file
65integer(di),      intent(in) :: ierr    ! Severity of situation (= 0 normal)
66character(*), intent(in) :: message ! Message to print
67
68! CODE
69! ----
70#ifdef CPP_XIOS
71    CALL wxios_close() ! Closing XIOS properly
72#endif
73
74#ifdef CPP_IOIPSL
75    call histclo()
76    call restclo()
77#endif
78
79call getin_dump()
80write(lunout,'(a,i5,a)') ' Stopping in "'//fname//'" at line ',fline,'.'
81write(lunout,'(a)') '     Reason: '//message
82if (ierr == 0) then
83    write(lunout,'(a)') ' Everything is cool!'
84    error stop ierr
85else
86    write(lunout,'(a,i4)') ' Houston, we have a problem! Error code = ',ierr
87    error stop ierr
88end if
89
90END SUBROUTINE stop_clean
91!=======================================================================
92
93END MODULE stoppage
Note: See TracBrowser for help on using the repository browser.