Repository navigation
Feat req: Refactor wrf model_mod and models/wrf directory, unify WRF/WRF-CHEM #404
Description
Use case
Refactor the wrf model_mod to make it easier/possible to:
- add state variables
- swap between wrf v3 and v4
- not assume the structure of the state variable in model_mod.
Is your feature request related to a problem?
The WRF model_mod has wrf_static_data_for_dart which is replicating functionality available in state_structure_mod.
-
Adding variable X to the state means altering the model_mod code to have a
wrf%dom(id)%type_X, rather than simply adding a line in the model_nml::wrf_state_variables. -
WRF has its own integer types (qtys), replicating (but not quite) the DART qty functionality.
Lines 323 to 332 in 7ee9ed9
! JPH local variables to hold type indices integer :: type_u, type_v, type_w, type_t, type_qv, type_qr, type_hdiab, & type_qndrp, type_qnsnow, type_qnrain, type_qngraupel, type_qnice, & type_qc, type_qg, type_qi, type_qs, type_gz, type_refl, type_fall_spd, & type_dref, type_spdp, type_qh, type_qnhail, type_qhvol, type_qgvol, & type_cldfra integer :: type_u10, type_v10, type_t2, type_th2, type_q2, & type_ps, type_mu, type_tsk, type_tslb, type_sh2o, & type_smois, type_2dflash
so you see code like this:
Lines 889 to 890 in 7ee9ed9
var_type = wrf%dom(id)%var_type(var_id) dart_type = wrf%dom(id)%dart_kind(var_id) -
WRF v3 vs. v4 - it is not clear for users what to change when moving from WRF v3 to v4. If possible, it would be good for the model_mod to be able to check the WRF version from the netcdf file.
-
Wider issue Model_mods which use their own structure to keep track of state variables #389. Moving control of the state vector to core dart modules allows us to have general solutions for things like compression, removing missing values (so dart core code can assume every element of the state is valid), and other cool stuff.
Describe your preferred solution
Remove the state vector information from wrf_static_data_for_dart
Describe any alternatives you have considered
I think the wrf_static_data_for_dart is a road block for core dart development, however wrf-dart is widely used and has a lot of additional user developed code in circulation. There is 8000 lines of code in for wrf model_mod (+ unknown user modifications) so the refactoring needs to be approached with this in mind.
I think it is possible to simplify the bounds checks for each grid (staggered and various flavors of periodic), but I do not think the bounds check affects development of core dart.
Activity
[-]Feature request: Refactor wrf model_mod[/-][+]Feature request: Refactor wrf model_mod and models/wrf directory[/+]hkershaw-brown commentedon Oct 21, 2022
edit:
https://github.com/hkershaw-brown/DART/tree/wrf-refactor is the initial attempt, having a go at updating the wrf model_mod
https://github.com/NCAR/DART/tree/wrf-fresh is starting from scratch redoing the wrf model_mod
hkershaw-brown commentedon May 26, 2023
wrf model_mod get_close has a test for missing_r8
https://github.com/NCAR/DART/blob/72e5740b71ef6c7cde4c6f946e2c1df2019365fb/models/wrf/model_mod.f90#L6419C3-L6428
should check for verti_is_undefined before doing this (or not have the missing_r8 check)
hkershaw-brown commentedon May 30, 2023
Vertical Convertion
There are several references to the vertical location of state being converted in get_state_meta_data. This is incorrect, get_state_meta_data does not do vertical conversion. For example:
DART/models/wrf/model_mod.f90
Lines 6406 to 6417 in 72e5740
get_close_obs and get_close_state are identical - they both call get_close.
get_close calls vert_convert
convert_vertical_obs calls vert_convert
convert_vertical_state - builds columns from the state
unneeded call to get horizontal location, the location is passed into convert_vertical_state
DART/models/wrf/model_mod.f90
Lines 3026 to 3027 in 70e6af8
🐛 Bug: convert_vertical_state is using the module localization coord, not the which_vert passed into convert_vertical_state.
DART/models/wrf/model_mod.f90
Line 3030 in 70e6af8
issue for this bug bug: wrf convert_vertical_state does not use which_vert, #1038
check all surface variables, model_pressure_distrib
DART/models/wrf/model_mod.f90
Lines 4807 to 4812 in 70e6af8
hkershaw-brown commentedon Aug 2, 2023
To do:
wrf has a namelist option for calendar type. Are there observations not in GREGORIAN (2d?)
variable_is_on_domain- assuming <10 domains (i1):DART/models/wrf/model_mod.f90
Lines 7745 to 7746 in f996f26
check whether map utils varies between WRF versions module_map_utils.F misc_definitions_module.F
restrict_polar is hardcoded in two places (and is not a namelist option)
DART/models/wrf/model_mod.f90
Line 938 in 9729d78
hkershaw-brown commentedon Aug 9, 2023
For VERTISLEVEL we have:
DART/models/wrf/model_mod.f90
Lines 895 to 900 in 9729d78
bottom_top = 29 ;
bottom_top_stag = 30 ;
float W(Time, bottom_top_stag, south_north, west_east) ;
Edit: then this:
DART/models/wrf/model_mod.f90
Lines 1857 to 1858 in 9729d78
hkershaw-brown commentedon Aug 10, 2023
note in the code about latlon project settings only valid for global domains
DART/models/wrf/model_mod.f90
Lines 7307 to 7316 in 9729d78
nancycollins commentedon Aug 10, 2023
for help with the acronyms:
comments on these particular few lines:
'global' doesn't seem to be the opposite of single column, but i'm also sure i don't understand exactly what projection settings are needed to use the wrf code that converts a location into an index into the wrf grid (which is how this model_mod works). most wrf cases are NOT global - they are regional grids. perhaps latinc and loninc aren't used in the regional case.
hkershaw-brown commentedon Aug 14, 2023
Mask variables: XLAND, QTY_SURFACE_TYPE
Should you be interpolating a mask?
edit: rounded to the nearest integer in rttov obs_def:
DART/observations/forward_operators/obs_def_rttov13_mod.f90
Line 2065 in 9729d78
wrf netcdf file XLAND:description = "LAND MASK (1 FOR LAND, 2 FOR WATER)" ;
comment and QTY_SURFACE_TYPE
! 0 = land, 1 = water, 2 = sea ice (not yet supported)edit:
wrf 1 for land, rttov forward operator expecting 0 for land.
QTY_SURFACE_TYPE has the -1, QTY_LAND_MASK does not.
DART/models/wrf/model_mod.f90
Lines 2825 to 2843 in 9729d78
DART/models/wrf/model_mod.f90
Lines 2801 to 2823 in 9729d78
hkershaw-brown commentedon Aug 15, 2023
I'm not sure what is not allowed here
DART/models/wrf/model_mod.f90
Lines 6738 to 6740 in 9729d78
There are some notes in the code about periodic_x,y and polar
DART/models/wrf/model_mod.f90
Line 7092 in 9729d78
It is looking like these are still wrf namelist options and not in the wrf output netcdf file:
namelist_variables
wrfoutput
hkershaw-brown commentedon Aug 15, 2023
Boundary condition options:
The boundary conditions periodic_x,y, polar in model_mod.f90 only apply to domain 1. I guess this is why it is a namelist option rather than part of the wrf netcdf metadata(?). There is a lot of checking for in model_mod for (id)%periodic but periodic is only allowed to be true for domain1.
DART/models/wrf/model_mod.f90
Lines 7114 to 7124 in 9729d78
Edit: the wrf namelist has periodic_x,y polar for each domain - namelist (max_dom)
The wrf docs has
polarasuse polar boundary condition(see table). The model_mod.f90 haslogical :: polar = .false. ! wrap over the polesAre these the same thing?Edit: What is the difference between polar and periodic_y?
Can you have periodic_y and not polar?
no
.not. wrf%dom(id)%periodic_x .and. wrf%dom(id)%periodic_yoptionJust polar:
DART/models/wrf/model_mod.f90
Lines 6275 to 6277 in 70e6af8
hkershaw-brown commentedon Aug 18, 2023
Do we like the results?
DART/models/wrf/model_mod.f90
Line 5144 in 9729d78
DART/models/wrf/model_mod.f90
Line 5215 in 9729d78
39 remaining items
hkershaw-brown commentedon Nov 11, 2024
Note on extrapolation 2D vs 3D: see discussion on #773, #768
2D fields (e.g. 2m temp) seem to be temperature rather than potential temperature, so be aware that testing that the code is (or is not) doing the pot_temp -> temp conversion appropriately.
hkershaw-brown commentedon Nov 17, 2024
NSF NCAR MMM statement "Given the extensive use of WRF in the U.S. and international atmospheric modeling communities, we are not planning to retire WRF or step away from its support and maintenance in the foreseeable future."
https://www.mmm.ucar.edu/about/wrf-mpas-support
hkershaw-brown commentedon Jun 10, 2025
In the namelist section, not actually in the namelist:
DART/models/wrf/model_mod.f90
Lines 229 to 231 in d908222
hkershaw-brown commentedon Aug 29, 2025
support mete and chem output in different files?
415GB mete and chem:
/glade/derecho/scratch/hkershaw/DART/WRF-CHEM/29Aug2025
hkershaw-brown commentedon Sep 2, 2025
Cloud water units:
https://github.com/NCAR/DART/pull/896/files#diff-e12d14ed6b47c2ee908ccf4ad30e45a718ebd9e26297e77254a978e8804d7403R1430-R1435
hkershaw-brown commentedon Nov 26, 2025
Separate mete and chem files: 9091f62
hkershaw-brown commentedon Dec 1, 2025
This is just a note, on QTY_POTENTIAL_TEMPERATURE interpolate
This will give different answers at O2:
fld(1, e) = ts0 + dym*( dxmx_ill(e) + dxx_ilr(e)) + dy*( dxmx_iul(e) + dxx_iur(e) )
fld(1, e) = dym*( dxmx_ill(e) + dxx_ilr(e)) + dy*( dxmx_iul(e) + dxx_iur(e) ) + ts0
DART/models/wrf/model_mod.f90
Line 1824 in a32ab03
hkershaw-brown commentedon Jan 9, 2026
refactored uses a function for the interpolation, so you do not get bitwise differences between 00, 01, 02
t0 + func()
func() + t0
I think these interpolation lines are (one reason) why dart-wrf has need -fp model precise for bitwise testing. With the function the compiler has to materialize the function result before using it in a calculation.
hkershaw-brown commentedon Jan 9, 2026
Note wrf_unified currently not doing the case for observation in scaleheight, convert to a different vertical.
I don't think observations come in scaleheight, but it is in the wrf model mod.
hkershaw-brown commentedon Jan 12, 2026
WRF
model interpolate does:
horizontal interpolation on the quad, then vertical interpolation between two levels
vert_convert does:
vertical interpolation at each quad point, then horizontal interpolation on the quad
model_interpolate:
DART/models/wrf/model_mod.f90
Lines 1343 to 1346 in 4c89e64
vert_convert:
DART/models/wrf/model_mod.f90
Lines 3445 to 3458 in 4c89e64
fix-bitwise: vertical conversion of obs vertical then horiz interp
hkershaw-brown commentedon Jan 30, 2026
WRF has biliear interpolation all over the place: #860 (comment)
and then clamps to zero in model interpolate.
Refactor - not put bilinear interpolation as a function. Maybe worth doing this to switch out bilinear to idw in one step if needed.