Skip to content

Commit 4641e70

Browse files
authored
eCLM-PDAF with local filters (#16)
* CLMSA: Use `cradius` in km in `init_dim_obs_l_pdaf` * LESTKF/LETKF: no deallocation of observations lat/lon arrays * init_dim_l_clm: dependent on domain_p Flexibility needed for different dimensions of local domains * local filter for eCLM: flexible index handling with index trafo - STATE_LOC2CLM_C_P: Returns the CLM-column c for the local domain domain_p (from the column, the gridcell can be derived) * local filters: INIT_DIM_L_CLM, add hydrologically-active condition
1 parent c1071f4 commit 4641e70

File tree

13 files changed

+441
-93
lines changed

13 files changed

+441
-93
lines changed

interface/framework/g2l_state_pdaf.F90

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,10 @@ SUBROUTINE g2l_state_pdaf(step, domain_p, dim_p, state_p, dim_l, state_l)
5252
USE mod_tsmp, &
5353
ONLY: nx_local, ny_local
5454
#if defined CLMSA
55-
#if defined CLMFIVE
56-
USE decompMod, ONLY: get_proc_bounds
57-
#else
58-
USE decompMod, ONLY: get_proc_bounds_atm
59-
#endif
55+
USE enkf_clm_mod, ONLY: g2l_state_clm
6056
#endif
6157

62-
USE iso_c_binding, ONLY: c_loc
58+
! USE iso_c_binding, ONLY: c_loc
6359

6460
IMPLICIT NONE
6561

@@ -94,17 +90,7 @@ SUBROUTINE g2l_state_pdaf(step, domain_p, dim_p, state_p, dim_l, state_l)
9490
end if
9591
!call g2l_state(domain_p, c_loc(state_p), dim_l, c_loc(state_l))
9692
#else
97-
! beg and end gridcell for atm
98-
#if defined CLMFIVE
99-
call get_proc_bounds(begg, endg)
100-
#else
101-
call get_proc_bounds_atm(begg, endg)
102-
#endif
103-
n_domain = endg - begg + 1
104-
DO i = 0, dim_l-1
105-
nshift_p = domain_p + i * n_domain
106-
state_l(i+1) = state_p(nshift_p)
107-
ENDDO
93+
call g2l_state_clm(domain_p, dim_p, state_p, dim_l, state_l)
10894
#endif
10995

11096
END SUBROUTINE g2l_state_pdaf

interface/framework/init_dim_l_pdaf.F90

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ SUBROUTINE init_dim_l_pdaf(step, domain_p, dim_l)
4848
USE mod_tsmp, ONLY: tag_model_parflow, &
4949
tag_model_clm, model
5050
USE mod_tsmp, &
51-
ONLY: init_parf_l_size
51+
ONLY: init_dim_l_pfl
5252
#ifdef CLMSA
53-
USE enkf_clm_mod, &
54-
ONLY: init_clm_l_size
53+
USE enkf_clm_mod, ONLY: init_dim_l_clm
5554
#endif
5655
IMPLICIT NONE
5756

@@ -69,22 +68,27 @@ SUBROUTINE init_dim_l_pdaf(step, domain_p, dim_l)
6968
! ****************************************
7069
! *** Initialize local state dimension ***
7170
! ****************************************
72-
#if (defined PARFLOW_STAND_ALONE || defined COUP_OAS_PFL)
73-
if (model.eq.tag_model_parflow) then
71+
#if defined PARFLOW_STAND_ALONE
72+
! Set the size of the local analysis domain
73+
call init_dim_l_pfl(dim_l)
74+
#endif
75+
76+
#if defined COUP_OAS_PFL
77+
if (model == tag_model_parflow) then
7478
! Set the size of the local analysis domain
75-
call init_parf_l_size(dim_l)
79+
call init_dim_l_pfl(dim_l)
7680
end if
77-
#endif
78-
79-
#ifndef CLMSA
80-
if (model.eq.tag_model_clm) then
81+
if (model == tag_model_clm) then
8182
! Set the size of the local analysis domain
8283
dim_l = 1
8384
end if
84-
#else
85+
#endif
86+
87+
#if defined CLMSA
8588
! Set the size of the local analysis domain
8689
! for clm stand alone mode only
87-
call init_clm_l_size(dim_l)
90+
91+
call init_dim_l_clm(domain_p, dim_l)
8892
#endif
8993

9094
END SUBROUTINE init_dim_l_pdaf

interface/framework/init_dim_obs_l_pdaf.F90

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ SUBROUTINE init_dim_obs_l_pdaf(domain_p, step, dim_obs_f, dim_obs_l)
7171
point_obs, model
7272
#endif
7373

74+
#if defined CLMSA
75+
USE enkf_clm_mod, ONLY: state_loc2clm_c_p
76+
use shr_kind_mod, only: r8 => shr_kind_r8
77+
78+
#ifdef CLMFIVE
79+
USE GridcellType, ONLY: grc
80+
USE ColumnType, ONLY : col
81+
#else
82+
USE clmtype, ONLY : clm3
83+
#endif
84+
#endif
85+
7486
USE, INTRINSIC :: iso_c_binding, ONLY: C_F_POINTER
7587

7688
IMPLICIT NONE
@@ -95,11 +107,26 @@ SUBROUTINE init_dim_obs_l_pdaf(domain_p, step, dim_obs_f, dim_obs_l)
95107
INTEGER :: domain_p_coord ! Current local analysis domain for coord arrays
96108

97109
!kuw
98-
integer :: dx,dy, max_var_id, ierror
110+
#if defined CLMSA
111+
real :: dx,dy
112+
#else
113+
integer :: dx,dy
114+
#endif
115+
integer :: max_var_id, ierror
99116
integer :: obsind(dim_obs)
100117
real :: obsdist(dim_obs)
101118
! kuw end
102119

120+
#if defined CLMSA
121+
! INTEGER :: dim_l
122+
! INTEGER :: ncellxy
123+
! INTEGER :: k
124+
real(r8), pointer :: lon(:)
125+
real(r8), pointer :: lat(:)
126+
integer, pointer :: mycgridcell(:) !Pointer for CLM3.5/CLM5.0 col->gridcell index arrays
127+
REAL :: yhalf
128+
#endif
129+
103130
! **********************************************
104131
! *** Initialize local observation dimension ***
105132
! **********************************************
@@ -241,10 +268,44 @@ SUBROUTINE init_dim_obs_l_pdaf(domain_p, step, dim_obs_f, dim_obs_l)
241268
end if
242269
else
243270
if(model == tag_model_clm) THEN
271+
272+
#ifdef CLMSA
273+
! Lon/Lat information from CLM
274+
#ifdef CLMFIVE
275+
! Obtain CLM lon/lat information
276+
lon => grc%londeg
277+
lat => grc%latdeg
278+
! Obtain CLM column-gridcell information
279+
mycgridcell => col%gridcell
280+
#else
281+
lon => clm3%g%londeg
282+
lat => clm3%g%latdeg
283+
mycgridcell => clm3%g%l%c%gridcell
284+
#endif
285+
#endif
286+
244287
do i = 1,dim_obs
288+
#ifdef CLMSA
289+
! Units: lat/lon (degrees)
290+
! More doc on following lines: See `localize_covar_pdaf`
291+
292+
! Compared to LOCALIZE_COVAR_PDAF: No OBS_PDAF2NC. This is in
293+
! order to have OBS_INDEX_L return a NC-ordered array, not
294+
! PDAF-ordered array.
295+
dx = abs(clmobs_lon(i) - lon(mycgridcell(state_loc2clm_c_p(domain_p))))
296+
dy = abs(clmobs_lat(i) - lat(mycgridcell(state_loc2clm_c_p(domain_p))))
297+
IF (dx > 180.0) THEN
298+
dx = 360.0 - dx
299+
END IF
300+
yhalf = ( clmobs_lat(i) + lat(mycgridcell(state_loc2clm_c_p(domain_p))) ) / 2.0
301+
dx = dx * cos(yhalf * 3.14159265358979323846 / 180.0)
302+
dist = 111.19492664455873 * sqrt(real(dx)**2 + real(dy)**2)
303+
#else
304+
! Units: Index numbering
245305
dx = abs(longxy_obs(i) - longxy(domain_p))
246306
dy = abs(latixy_obs(i) - latixy(domain_p))
247307
dist = sqrt(real(dx)**2 + real(dy)**2)
308+
#endif
248309
obsdist(i) = dist
249310
if (dist <= real(cradius)) then
250311
dim_obs_l = dim_obs_l + 1

interface/framework/init_n_domains_pdaf.F90

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,16 @@ SUBROUTINE init_n_domains_pdaf(step, n_domains_p)
5151
USE mod_assimilation, &
5252
ONLY: dim_state_p
5353
USE mod_tsmp, &
54-
ONLY: init_n_domains_size
54+
ONLY: init_n_domains_pfl
5555
#if defined CLMSA
56-
#if defined CLMFIVE
57-
USE decompMod, ONLY: get_proc_bounds
58-
#else
59-
USE decompMod, ONLY: get_proc_bounds_atm
60-
#endif
56+
USE enkf_clm_mod, ONLY: init_n_domains_clm
6157
#endif
6258

6359
IMPLICIT NONE
6460

6561
! !ARGUMENTS:
6662
INTEGER, INTENT(in) :: step ! Current time step
6763
INTEGER, INTENT(out) :: n_domains_p ! PE-local number of analysis domains
68-
#if defined CLMSA
69-
INTEGER :: begg, endg ! per-proc gridcell ending gridcell indices
70-
#endif
7164

7265
! !CALLING SEQUENCE:
7366
! Called by: PDAF_lseik_update (as U_init_n_domains)
@@ -78,27 +71,22 @@ SUBROUTINE init_n_domains_pdaf(step, n_domains_p)
7871
! ************************************
7972
! *** Initialize number of domains ***
8073
! ************************************
81-
#if (defined PARFLOW_STAND_ALONE || defined COUP_OAS_PFL)
82-
if (model.eq.tag_model_parflow) then
83-
! Here simply the process-local state dimension
84-
call init_n_domains_size(n_domains_p)
85-
end if
74+
#if defined PARFLOW_STAND_ALONE
75+
call init_n_domains_pfl(n_domains_p)
8676
#endif
8777

88-
#ifndef CLMSA
78+
#if defined COUP_OAS_PFL
79+
if (model == tag_model_parflow) then
80+
call init_n_domains_pfl(n_domains_p)
81+
end if
8982
if (model == tag_model_clm) then
90-
! Here simply the process-local state dimension
83+
! For CLM coupled with ParFlow, use the process-local state dimension
9184
n_domains_p = dim_state_p
92-
end if
93-
#else
94-
! beg and end gridcell for atm
95-
#if defined CLMFIVE
96-
call get_proc_bounds(begg, endg)
97-
#else
98-
call get_proc_bounds_atm(begg, endg)
85+
end if
9986
#endif
100-
! Here simply the process-local state dimension
101-
n_domains_p = endg - begg + 1
87+
88+
#if defined CLMSA
89+
call init_n_domains_clm(n_domains_p)
10290
#endif
10391

10492
END SUBROUTINE init_n_domains_pdaf

interface/framework/init_obs_l_pdaf.F90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ SUBROUTINE init_obs_l_pdaf(domain_p, step, dim_obs_l, observation_l)
7474
observation_l(:) = 0.0
7575

7676
!#ifndef CLMSA
77+
! Index array OBS_INDEX_L (returns nc-ordered index) set in subroutine INIT_DIM_OBS_L_PDAF
7778
do i=1,dim_obs_l
7879
observation_l(i) = obs(obs_index_l(i))
7980
end do

interface/framework/l2g_state_pdaf.F90

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ SUBROUTINE l2g_state_pdaf(step, domain_p, dim_l, state_l, dim_p, state_p)
5555
USE iso_c_binding, ONLY: c_loc
5656

5757
#if defined CLMSA
58-
#if defined CLMFIVE
59-
USE decompMod, ONLY: get_proc_bounds
60-
#else
61-
USE decompMod, ONLY: get_proc_bounds_atm
62-
#endif
58+
use enkf_clm_mod, ONLY: l2g_state_clm
6359
#endif
6460

6561
IMPLICIT NONE
@@ -95,17 +91,7 @@ SUBROUTINE l2g_state_pdaf(step, domain_p, dim_l, state_l, dim_p, state_p)
9591
end if
9692
!call l2g_state(domain_p, c_loc(state_p), dim_l, c_loc(state_l))
9793
#else
98-
! beg and end gridcell for atm
99-
#if defined CLMFIVE
100-
call get_proc_bounds(begg, endg)
101-
#else
102-
call get_proc_bounds_atm(begg, endg)
103-
#endif
104-
n_domain = endg - begg + 1
105-
DO i = 0, dim_l-1
106-
nshift_p = domain_p + i * n_domain
107-
state_p(nshift_p) = state_l(i+1)
108-
ENDDO
94+
call l2g_state_clm(domain_p, dim_l, state_l, dim_p, state_p)
10995
#endif
11096

11197
END SUBROUTINE l2g_state_pdaf

interface/framework/localize_covar_pdaf.F90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ SUBROUTINE localize_covar_pdaf(dim_p, dim_obs, HP, HPH)
3838
USE shr_kind_mod , only : r8 => shr_kind_r8
3939
USE mod_read_obs, ONLY: clmobs_lon
4040
USE mod_read_obs, ONLY: clmobs_lat
41-
USE enkf_clm_mod, ONLY: init_clm_l_size, clmupdate_T
41+
USE enkf_clm_mod, ONLY: clmupdate_T
4242
USE enkf_clm_mod, ONLY: clm_begc
4343
USE enkf_clm_mod, ONLY: clm_endc
4444
USE enkf_clm_mod, ONLY: state_pdaf2clm_c_p
@@ -226,7 +226,7 @@ SUBROUTINE localize_covar_pdaf(dim_p, dim_obs, HP, HPH)
226226
! dx = abs(longxy_obs(j) - longxy(state_pdaf2clm_c_p(i)))
227227
! dy = abs(latixy_obs(j) - latixy(state_pdaf2clm_c_p(i)))
228228

229-
! Units: lat/lon
229+
! Units: lat/lon (degrees)
230230
dx = abs(clmobs_lon(obs_pdaf2nc(j)) - lon(mycgridcell(state_pdaf2clm_c_p(i))))
231231
dy = abs(clmobs_lat(obs_pdaf2nc(j)) - lat(mycgridcell(state_pdaf2clm_c_p(i))))
232232

@@ -267,7 +267,7 @@ SUBROUTINE localize_covar_pdaf(dim_p, dim_obs, HP, HPH)
267267
! dx = abs(longxy_obs(j) - longxy_obs(i))
268268
! dy = abs(latixy_obs(j) - latixy_obs(i))
269269

270-
! Units: lat/lon
270+
! Units: lat/lon (degrees)
271271
dx = abs(clmobs_lon(obs_pdaf2nc(j)) - clmobs_lon(obs_pdaf2nc(i)))
272272
dy = abs(clmobs_lat(obs_pdaf2nc(j)) - clmobs_lat(obs_pdaf2nc(i)))
273273

interface/framework/mod_read_obs.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ subroutine clean_obs_nc()
517517
!if(allocated(y_idx_obs_nc))deallocate(y_idx_obs_nc)
518518
!if(allocated(z_idx_obs_nc))deallocate(z_idx_obs_nc)
519519
!kuw: clean clm observations
520-
IF (.NOT. filtertype == 8) THEN
521-
! For LEnKF lat/lon are used
520+
IF (.NOT. filtertype == 5 .AND. .NOT. filtertype == 7 .AND. .NOT. filtertype == 8) THEN
521+
! For LETKF, LESTKF, LEnKF lat/lon are used
522522
if(allocated(clmobs_lon))deallocate(clmobs_lon)
523523
if(allocated(clmobs_lat))deallocate(clmobs_lat)
524524
END IF

interface/framework/mod_tsmp.F90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,19 @@ end subroutine update_tsmp
9191
end interface
9292

9393
interface
94-
subroutine init_n_domains_size(n_domains_p) bind(c)
94+
subroutine init_n_domains_pfl(n_domains_p) bind(c)
9595
use iso_c_binding
9696
import
9797
INTEGER(c_int) :: n_domains_p ! PE-local number of analysis domains
98-
end subroutine init_n_domains_size
98+
end subroutine init_n_domains_pfl
9999
end interface
100100

101101
interface
102-
subroutine init_parf_l_size(dim_l) bind(c)
102+
subroutine init_dim_l_pfl(dim_l) bind(c)
103103
use iso_c_binding
104104
import
105105
INTEGER(c_int) :: dim_l ! Local state dimension
106-
end subroutine init_parf_l_size
106+
end subroutine init_dim_l_pfl
107107
end interface
108108

109109
!!$ interface

0 commit comments

Comments
 (0)