source: trunk/LMDZ.COMMON/libf/evolution/planet.F90 @ 4170

Last change on this file since 4170 was 4170, checked in by jbclement, 6 days ago

PEM:

  • Deletion of 'flux_ssice' ('zqdsdif_tot') from the "startfi.nc" as it is not needed.
  • Using the yearly average flux for the sublimating subsurface ice instead of the value at last timestep.
  • Keeping a clear separation between the subsurface ice flux and the surface ice tendency.
  • Making sure that subsurface ice depth is well given to the PCM at the end of the PEM (ice table VS layering).

JBC

File size: 13.9 KB
Line 
1MODULE planet
2!-----------------------------------------------------------------------
3! NAME
4!     planet
5!
6! DESCRIPTION
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/m2]
41real(dp),    dimension(:,:), allocatable :: co2_ice                    ! CO2 ice [kg/m2]
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]
75real(dp), dimension(:,:),   allocatable :: flux_ssice_avg     ! Average of total flux exchanged with subsurface ice [kg/m2/y]
76
77! Tracer-related:
78real(dp), dimension(:,:), allocatable :: q_co2_ts     ! CO2 mass mixing ratio in the first layer [kg/kg]
79real(dp), dimension(:,:), allocatable :: q_co2_ts_ini ! Initial CO2 mass mixing ratio in the first layer [kg/kg]
80real(dp), dimension(:,:), allocatable :: q_h2o_ts     ! H2O mass mixing ratio in the first layer [kg/kg]
81
82! Tendency-related:
83real(dp), dimension(:,:), allocatable :: d_co2ice     ! Tendency of perennial CO2 ice [kg/m2/y]
84real(dp), dimension(:,:), allocatable :: d_co2ice_ini ! Tendency of perennial CO2 ice at the beginning [kg/m2/y]
85real(dp), dimension(:,:), allocatable :: d_h2oice     ! Tendency of perennial H2O ice [kg/m2/y]
86
87contains
88!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
89
90!=======================================================================
91SUBROUTINE ini_planet()
92!-----------------------------------------------------------------------
93! NAME
94!     ini_planet
95!
96! DESCRIPTION
97!     Initialize scalar state values of module planet.
98!
99! AUTHORS & DATE
100!     JB Clement, 03/2026
101!
102! NOTES
103!
104!-----------------------------------------------------------------------
105
106! DECLARATION
107! -----------
108implicit none
109
110! CODE
111! ----
112ps_avg_glob_ini = 0._dp
113ps_avg_glob_old = 0._dp
114ps_avg_glob = 0._dp
115h2oice_sublim_coverage_ini = 0._dp
116co2ice_sublim_coverage_ini = 0._dp
117
118END SUBROUTINE ini_planet
119!=======================================================================
120
121!=======================================================================
122SUBROUTINE allocate_xios_state()
123!-----------------------------------------------------------------------
124! NAME
125!     allocate_xios_state
126!
127! DESCRIPTION
128!     Allocate arrays needed before loading PCM/XIOS data.
129!
130! AUTHORS & DATE
131!     JB Clement, 03/2026
132!
133! NOTES
134!
135!-----------------------------------------------------------------------
136
137! DEPENDENCIES
138! ------------
139use geometry, only: ngrid, nslope, nday, nsoil
140
141! DECLARATION
142! -----------
143implicit none
144
145! CODE
146! ----
147allocate(ps_avg(ngrid))
148allocate(ps_ts(ngrid,nday))
149allocate(tsurf_avg(ngrid,nslope))
150allocate(h2o_surfdensity_avg(ngrid,nslope))
151allocate(tsoil_avg(ngrid,nsoil,nslope))
152allocate(tsoil_ts(ngrid,nsoil,nslope,nday))
153allocate(h2o_soildensity_avg(ngrid,nsoil,nslope))
154allocate(q_h2o_ts(ngrid,nday))
155allocate(q_co2_ts(ngrid,nday))
156allocate(flux_ssice_avg(ngrid,nslope))
157
158ps_avg(:) = 0._dp
159ps_ts(:,:) = 0._dp
160tsurf_avg(:,:) = 0._dp
161h2o_surfdensity_avg(:,:) = 0._dp
162tsoil_avg(:,:,:) = 0._dp
163tsoil_ts(:,:,:,:) = 0._dp
164h2o_soildensity_avg(:,:,:) = 0._dp
165q_h2o_ts(:,:) = 0._dp
166q_co2_ts(:,:) = 0._dp
167flux_ssice_avg(:,:) = 0._dp
168
169END SUBROUTINE allocate_xios_state
170!=======================================================================
171
172!=======================================================================
173SUBROUTINE allocate_deviation_state()
174!-----------------------------------------------------------------------
175! NAME
176!     allocate_deviation_state
177!
178! DESCRIPTION
179!     Allocate persistent deviation fields derived from PCM averages.
180!
181! AUTHORS & DATE
182!     JB Clement, 03/2026
183!
184! NOTES
185!
186!-----------------------------------------------------------------------
187
188! DEPENDENCIES
189! ------------
190use geometry, only: ngrid, nslope, nsoil_PCM
191
192! DECLARATION
193! -----------
194implicit none
195
196! CODE
197! ----
198allocate(ps_dev(ngrid))
199allocate(tsurf_dev(ngrid,nslope))
200allocate(tsoil_dev(ngrid,nsoil_PCM,nslope))
201
202ps_dev(:) = 0._dp
203tsurf_dev(:,:) = 0._dp
204tsoil_dev(:,:,:) = 0._dp
205
206END SUBROUTINE allocate_deviation_state
207!=======================================================================
208
209!=======================================================================
210SUBROUTINE allocate_startevo_state()
211!-----------------------------------------------------------------------
212! NAME
213!     allocate_startevo_state
214!
215! DESCRIPTION
216!     Allocate arrays loaded from startevo or evolving afterward.
217!
218! AUTHORS & DATE
219!     JB Clement, 03/2026
220!
221! NOTES
222!
223!-----------------------------------------------------------------------
224
225! DEPENDENCIES
226! ------------
227use geometry, only: ngrid, nslope, nsoil
228
229! DECLARATION
230! -----------
231implicit none
232
233! CODE
234! ----
235allocate(h2o_ice(ngrid,nslope))
236allocate(co2_ice(ngrid,nslope))
237allocate(icetable_depth(ngrid,nslope))
238allocate(icetable_thickness(ngrid,nslope))
239allocate(ice_porefilling(ngrid,nsoil,nslope))
240allocate(h2o_ads_reg(ngrid,nsoil,nslope))
241allocate(co2_ads_reg(ngrid,nsoil,nslope))
242allocate(delta_h2o_ads(ngrid))
243allocate(delta_co2_ads(ngrid))
244allocate(layerings_map(ngrid,nslope))
245
246h2o_ice(:,:) = 0._dp
247co2_ice(:,:) = 0._dp
248icetable_depth(:,:) = 0._dp
249icetable_thickness(:,:) = 0._dp
250ice_porefilling(:,:,:) = 0._dp
251h2o_ads_reg(:,:,:) = 0._dp
252co2_ads_reg(:,:,:) = 0._dp
253delta_h2o_ads(:) = 0._dp
254delta_co2_ads(:) = 0._dp
255
256END SUBROUTINE allocate_startevo_state
257!=======================================================================
258
259!=======================================================================
260SUBROUTINE allocate_tendencies()
261!-----------------------------------------------------------------------
262! NAME
263!     allocate_tendencies
264!
265! DESCRIPTION
266!     Allocate perennial ice tendency arrays.
267!
268! AUTHORS & DATE
269!     JB Clement, 03/2026
270!
271! NOTES
272!
273!-----------------------------------------------------------------------
274
275! DEPENDENCIES
276! ------------
277use geometry, only: ngrid, nslope
278
279! DECLARATION
280! -----------
281implicit none
282
283! CODE
284! ----
285allocate(d_h2oice(ngrid,nslope))
286allocate(d_co2ice(ngrid,nslope))
287
288d_h2oice(:,:) = 0._dp
289d_co2ice(:,:) = 0._dp
290
291END SUBROUTINE allocate_tendencies
292!=======================================================================
293
294!=======================================================================
295SUBROUTINE allocate_initial_snapshots()
296!-----------------------------------------------------------------------
297! NAME
298!     allocate_initial_snapshots
299!
300! DESCRIPTION
301!     Allocate arrays storing initial-state snapshots.
302!
303! AUTHORS & DATE
304!     JB Clement, 03/2026
305!
306! NOTES
307!
308!-----------------------------------------------------------------------
309
310! DEPENDENCIES
311! ------------
312use geometry, only: ngrid, nslope, nday
313
314! DECLARATION
315! -----------
316implicit none
317
318! CODE
319! ----
320allocate(d_co2ice_ini(ngrid,nslope))
321allocate(q_co2_ts_ini(ngrid,nday))
322allocate(is_h2oice_ini(ngrid,nslope))
323allocate(is_co2ice_ini(ngrid,nslope))
324
325d_co2ice_ini(:,:) = 0._dp
326q_co2_ts_ini(:,:) = 0._dp
327is_h2oice_ini(:,:) = .false.
328is_co2ice_ini(:,:) = .false.
329
330END SUBROUTINE allocate_initial_snapshots
331!=======================================================================
332
333!=======================================================================
334SUBROUTINE allocate_loop_state()
335!-----------------------------------------------------------------------
336! NAME
337!     allocate_loop_state
338!
339! DESCRIPTION
340!     Allocate arrays that start being used during the main PEM loop.
341!
342! AUTHORS & DATE
343!     JB Clement, 03/2026
344!
345! NOTES
346!
347!-----------------------------------------------------------------------
348
349! DEPENDENCIES
350! ------------
351use geometry, only: ngrid, nslope, nsoil, nday
352
353! DECLARATION
354! -----------
355implicit none
356
357! CODE
358! ----
359allocate(delta_icetable(ngrid))
360allocate(icetable_depth_old(ngrid,nslope))
361allocate(is_co2ice_disappeared(ngrid,nslope))
362allocate(tsoil_ts_old(ngrid,nsoil,nslope,nday))
363
364delta_icetable(:) = 0._dp
365icetable_depth_old(:,:) = 0._dp
366is_co2ice_disappeared(:,:) = .false.
367tsoil_ts_old(:,:,:,:) = 0._dp
368
369END SUBROUTINE allocate_loop_state
370!=======================================================================
371
372!=======================================================================
373SUBROUTINE end_planet()
374!-----------------------------------------------------------------------
375! NAME
376!     end_planet
377!
378! DESCRIPTION
379!     Finalize module planet.
380!
381! AUTHORS & DATE
382!     JB Clement, 03/2026
383!
384! NOTES
385!     Deallocate all allocatable state arrays of module planet.
386!-----------------------------------------------------------------------
387
388! DECLARATION
389! -----------
390implicit none
391
392! CODE
393! ----
394if (allocated(ps_avg)) deallocate(ps_avg)
395if (allocated(ps_ts)) deallocate(ps_ts)
396if (allocated(ps_dev)) deallocate(ps_dev)
397if (allocated(h2o_ice)) deallocate(h2o_ice)
398if (allocated(co2_ice)) deallocate(co2_ice)
399if (allocated(is_h2oice_ini)) deallocate(is_h2oice_ini)
400if (allocated(is_co2ice_ini)) deallocate(is_co2ice_ini)
401if (allocated(is_co2ice_disappeared)) deallocate(is_co2ice_disappeared)
402if (allocated(tsurf_avg)) deallocate(tsurf_avg)
403if (allocated(tsurf_dev)) deallocate(tsurf_dev)
404if (allocated(h2o_surfdensity_avg)) deallocate(h2o_surfdensity_avg)
405if (allocated(tsoil_avg)) deallocate(tsoil_avg)
406if (allocated(tsoil_dev)) deallocate(tsoil_dev)
407if (allocated(tsoil_ts)) deallocate(tsoil_ts)
408if (allocated(tsoil_ts_old)) deallocate(tsoil_ts_old)
409if (allocated(layerings_map)) deallocate(layerings_map)
410if (allocated(h2o_soildensity_avg)) deallocate(h2o_soildensity_avg)
411if (allocated(delta_co2_ads)) deallocate(delta_co2_ads)
412if (allocated(delta_h2o_ads)) deallocate(delta_h2o_ads)
413if (allocated(h2o_ads_reg)) deallocate(h2o_ads_reg)
414if (allocated(co2_ads_reg)) deallocate(co2_ads_reg)
415if (allocated(icetable_depth)) deallocate(icetable_depth)
416if (allocated(icetable_thickness)) deallocate(icetable_thickness)
417if (allocated(ice_porefilling)) deallocate(ice_porefilling)
418if (allocated(icetable_depth_old)) deallocate(icetable_depth_old)
419if (allocated(delta_icetable)) deallocate(delta_icetable)
420if (allocated(q_co2_ts)) deallocate(q_co2_ts)
421if (allocated(q_co2_ts_ini)) deallocate(q_co2_ts_ini)
422if (allocated(q_h2o_ts)) deallocate(q_h2o_ts)
423if (allocated(d_co2ice)) deallocate(d_co2ice)
424if (allocated(d_co2ice_ini)) deallocate(d_co2ice_ini)
425if (allocated(d_h2oice)) deallocate(d_h2oice)
426if (allocated(layerings_map)) deallocate(layerings_map)
427if (allocated(flux_ssice_avg)) deallocate(flux_ssice_avg)
428
429END SUBROUTINE end_planet
430!=======================================================================
431
432END MODULE planet
Note: See TracBrowser for help on using the repository browser.