Skip to content

Commit 6f87301

Browse files
feat: update wind components in update_mpas_states
This was a subroutine update_wind_components in model_mod that was called by statevector_to_analysis_file untested
1 parent 9954b92 commit 6f87301

File tree

2 files changed

+78
-14
lines changed

2 files changed

+78
-14
lines changed

models/mpas_atm/model_mod.f90

+3-2
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ module model_mod
165165
public :: update_u_from_reconstruct, &
166166
set_lbc_variables, &
167167
force_u_into_state, &
168+
use_increments_for_u_update, &
168169
statevector_to_boundary_file
169170

170171
! set_lbc_variables sets the lbc_variables string array
@@ -550,11 +551,11 @@ subroutine static_init_model()
550551
if (use_increments_for_u_update) then
551552
write(string1,*) 'edge normal winds (u) in MPAS file will be updated based on the difference'
552553
write(string2,*) 'between the original U/V reconstructed winds and the updated values'
553-
write(string3,*) 'because use_increment_for_u_update is True'
554+
write(string3,*) 'because use_increments_for_u_update is True'
554555
else
555556
write(string1,*) 'edge normal winds (u) in MPAS file will be updated by averaging the'
556557
write(string2,*) 'updated U/V reconstructed winds at the corresponding cell centers'
557-
write(string3,*) 'because use_increment_for_u_update is False'
558+
write(string3,*) 'because use_increments_for_u_update is False'
558559
endif
559560
call error_handler(E_MSG,'static_init_model',string1,source, &
560561
text2=string2, text3=string3)

models/mpas_atm/update_mpas_states.f90

+75-12
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ program update_mpas_states
3030
get_time, get_date, operator(/=)
3131
use model_mod, only : static_init_model, &
3232
get_model_size, &
33-
get_analysis_time, update_u_from_reconstruct
33+
get_analysis_time, update_u_from_reconstruct, &
34+
use_increments_for_u_update, uv_cell_to_edges
3435

3536
use state_structure_mod, only : get_num_variables, get_variable_name, &
36-
get_variable_size, get_varid_from_varname
37+
get_variable_size, get_varid_from_varname, &
38+
get_dim_lengths
3739

3840
use netcdf_utilities_mod, only : nc_open_file_readonly, &
3941
nc_open_file_readwrite, &
@@ -62,6 +64,10 @@ program update_mpas_states
6264
real(r8), allocatable :: variable(:)
6365
type(time_type) :: model_time
6466
type(time_type) :: state_time
67+
integer :: dims(2) !(nVertLevels, nEdges | nCells)
68+
real(r8), allocatable :: u(:,:), ucell(:,:), vcell(:,:)
69+
real(r8), allocatable :: ucell_dart(:,:), vcell_dart(:,:), increments(:,:)
70+
integer :: dom_id = 1 ! HK @todo
6571
!----------------------------------------------------------------------
6672

6773
call initialize_utilities(progname=source)
@@ -85,8 +91,8 @@ program update_mpas_states
8591
next_outfile = get_next_filename(update_output_file_list, filenum)
8692
if (next_infile == '' .or. next_outfile == '') exit fileloop
8793

88-
ncAnlID = nc_open_file_readonly(next_infile, 'update_mpas_states - open readonly')
89-
ncBckID = nc_open_file_readwrite(next_outfile, 'update_mpas_states - open readwrite')
94+
ncAnlID = nc_open_file_readonly(next_infile, 'update_mpas_states - open readonly') ! analysis from DART
95+
ncBckID = nc_open_file_readwrite(next_outfile, 'update_mpas_states - open readwrite') ! background, original mpas file
9096

9197
model_time = get_analysis_time(ncBckID, next_outfile)
9298
state_time = get_analysis_time(ncAnlID, next_infile)
@@ -105,24 +111,81 @@ program update_mpas_states
105111

106112
allocate(variable(get_variable_size(1, i)))
107113

108-
if (get_variable_name(1,i) == 'uReconstructZonal' .or. &
109-
get_variable_name(1,i) == 'uReconstructMeridional'.or. &
110-
get_variable_name(1,i) == 'u') cycle varloop
114+
if (get_variable_name(dom_id,i) == 'uReconstructZonal' .or. &
115+
get_variable_name(dom_id,i) == 'uReconstructMeridional'.or. &
116+
get_variable_name(dom_id,i) == 'u') cycle varloop
111117

112-
call nc_get_variable(ncAnlID, get_variable_name(1,i), variable)
113-
call nc_put_variable(ncBckID, get_variable_name(1,i), variable)
118+
call nc_get_variable(ncAnlID, get_variable_name(dom_id,i), variable)
119+
call nc_put_variable(ncBckID, get_variable_name(dom_id,i), variable)
114120

115121
deallocate(variable)
116122

117123
enddo varloop
118124

119125
! deal with wind
120126
if (update_u_from_reconstruct) then
121-
! reconstruct u
122-
call error_handler(E_ERR,'update_mpas_states','update_u_from_reconstruct is not implemented',source)
127+
128+
if (use_increments_for_u_update) then
129+
! Read in the previous reconstructed winds from the original mpas netcdf file
130+
! and compute what increments (changes in values) were added by the assimilation.
131+
! Read in the original edge normal wind 'u' field from that same mpas netcdf
132+
! file and add the interpolated increments to compute the updated 'u' values.
133+
134+
! read in u, uReconstrtuctZonal, uReconstructMeridional from background
135+
! read in uReconstrtuctZonal, uReconstructMeridional from analysis
136+
137+
dims = get_dim_lengths(dom_id, get_varid_from_varname(dom_id, 'u'))
138+
allocate(u(dims(1), dims(2)), increments(dims(1), dims(2)))
139+
call nc_get_variable(ncBckID, 'u', u)
140+
141+
dims = get_dim_lengths(dom_id, get_varid_from_varname(dom_id, 'uReconstructZonal'))
142+
allocate(ucell(dims(1), dims(2)), ucell_dart(dims(1), dims(2)))
143+
call nc_get_variable(ncBckID, 'uReconstructZonal', ucell)
144+
call nc_get_variable(ncAnlID, 'uReconstructZonal', ucell_dart)
145+
ucell = ucell_dart - ucell ! u increments
146+
147+
dims = get_dim_lengths(dom_id, get_varid_from_varname(dom_id, 'uReconstructMeridional'))
148+
allocate(vcell(dims(1), dims(2)), vcell_dart(dims(1), dims(2)))
149+
call nc_get_variable(ncBckID, 'uReconstructMeridional', vcell)
150+
call nc_get_variable(ncAnlID, 'uReconstructMeridional', vcell_dart)
151+
vcell = vcell_dart - vcell ! v increments
152+
153+
call uv_cell_to_edges(ucell, vcell, increments) !
154+
155+
u = u + increments
156+
157+
call nc_put_variable(ncBckID, 'u', u)
158+
call nc_put_variable(ncBckID, 'uReconstructZonal', ucell_dart)
159+
call nc_put_variable(ncBckID, 'uReconstructMeridional', vcell_dart)
160+
161+
deallocate(u, increments, ucell, vcell, ucell_dart, vcell_dart)
162+
163+
else
164+
! The state vector has updated zonal and meridional wind components.
165+
! put them directly into the arrays. These are the full values, not
166+
! just increments.
167+
dims = get_dim_lengths(dom_id, get_varid_from_varname(dom_id, 'u'))
168+
allocate(u(dims(1), dims(2)))
169+
dims = get_dim_lengths(dom_id, get_varid_from_varname(dom_id, 'uReconstructZonal'))
170+
allocate(ucell_dart(dims(1), dims(2)))
171+
call nc_get_variable(ncAnlID, 'uReconstructZonal', ucell_dart)
172+
dims = get_dim_lengths(dom_id, get_varid_from_varname(dom_id, 'uReconstructMeridional'))
173+
allocate(vcell_dart(dims(1), dims(2)))
174+
call nc_get_variable(ncAnlID, 'uReconstructMeridional', vcell_dart)
175+
176+
call uv_cell_to_edges(ucell_dart, vcell_dart, u, .true.)
177+
178+
call nc_put_variable(ncBckID, 'u', variable)
179+
call nc_put_variable(ncBckID, 'uReconstructZonal', variable)
180+
call nc_put_variable(ncBckID, 'uReconstructMeridional', variable)
181+
182+
deallocate(u, ucell_dart, vcell_dart)
183+
184+
endif
185+
123186
else
124187
! copy u from analysis to background
125-
allocate(variable(get_variable_size(1, get_varid_from_varname(1, 'u'))))
188+
allocate(variable(get_variable_size(1, get_varid_from_varname(dom_id, 'u'))))
126189

127190
call nc_get_variable(ncAnlID, 'u', variable)
128191
call nc_put_variable(ncBckID, 'u', variable)

0 commit comments

Comments
 (0)