Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 190 additions & 26 deletions hydro/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# additions that WRF-Hydro's top CMakeLists.txt handles
add_compile_options( "${PROJECT_COMPILE_OPTIONS}" )
add_compile_definitions( "${PROJECT_COMPILE_DEFINITIONS}" )
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/hydro/mods)
add_definitions(-DMPP_LAND)
if (WRF_HYDRO_NUDGING STREQUAL "1")
add_definitions(-DWRF_HYDRO_NUDGING=1)
if(${PROJECT_NAME} STREQUAL "WRF")
# additions that WRF-Hydro's top CMakeLists.txt handles
add_compile_options( "${PROJECT_COMPILE_OPTIONS}" )
add_compile_definitions( "${PROJECT_COMPILE_DEFINITIONS}" )
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/hydro/mods)
add_definitions(-DMPP_LAND)
if (WRF_HYDRO_NUDGING STREQUAL "1")
add_definitions(-DWRF_HYDRO_NUDGING=1)
endif()
if (OUTPUT_CHAN_CONN STREQUAL "1" )
add_definitions(-DOUTPUT_CHAN_CONN)
# requires nudging io module
set(WRF_HYDRO_NUDGING_IO "1")
endif()
endif()


# build the various sup-projects
add_subdirectory("MPP")
add_subdirectory("utils")
Expand All @@ -16,17 +24,30 @@ add_subdirectory("Debug_Utilities")
add_subdirectory("Routing/Overland")
add_subdirectory("Routing/Subsurface")
add_subdirectory("Routing/Reservoirs")
add_subdirectory("Routing/Diversions")
add_subdirectory("Data_Rec")
add_subdirectory("Routing")
add_subdirectory("HYDRO_drv")
add_subdirectory("CPL/WRF_cpl")
if(${PROJECT_NAME} STREQUAL "WRF")
add_subdirectory("CPL/WRF_cpl")
endif()

if (WRF_HYDRO_NUDGING_IO STREQUAL "1" OR
WRF_HYDRO_NUDGING STREQUAL "1")
add_subdirectory("nudging/io")
add_dependencies(hydro_routing hydro_nudging_io)
endif()

if (WRF_HYDRO_NUDGING STREQUAL "1")
add_subdirectory("nudging")
add_dependencies(hydro_routing hydro_nudging)
add_dependencies(hydro_driver hydro_nudging)
endif()

if (WRF_HYDRO_NUOPC STREQUAL "1")
add_subdirectory("CPL/NUOPC_cpl")
endif()

# add module dependencies
add_dependencies(hydro_debug_utils hydro_mpp)
add_dependencies(hydro_utils hydro_mpp)
Expand Down Expand Up @@ -75,21 +96,164 @@ add_dependencies(hydro_data_rec
hydro_routing_reservoirs
)

add_library(wrfhydro INTERFACE)
target_link_libraries(wrfhydro INTERFACE
hydro_utils
hydro_mpp
hydro_debug_utils
hydro_routing_overland
hydro_routing_subsurface
hydro_data_rec
hydro_routing
hydro_routing_reservoirs_levelpool
hydro_routing_reservoirs_hybrid
hydro_routing_reservoirs_rfc
hydro_routing_reservoirs
hydro_wrf_cpl
hydro_orchestrator
hydro_netcdf_layer
hydro_driver
)
if (HYDRO_LSM MATCHES "NoahMP")
message("-- Building NoahMP LSM")
add_subdirectory("Land_models/NoahMP")

add_subdirectory("CPL/NoahMP_cpl")
add_dependencies(hydro_noahmp_cpl hydro_routing)
add_dependencies(hydro_noahmp_cpl hydro_mpp )
add_dependencies(hydro_noahmp_cpl hydro_driver )

add_executable(wrfhydro
Land_models/NoahMP/IO_code/main_hrldas_driver.F
Land_models/NoahMP/IO_code/module_hrldas_netcdf_io.F
Land_models/NoahMP/IO_code/module_NoahMP_hrldas_driver.F
)

target_include_directories(wrfhydro BEFORE PUBLIC ${PROJECT_BINARY_DIR}/mods)

target_link_libraries(wrfhydro
hydro_utils
hydro_mpp
hydro_debug_utils
hydro_routing_overland
hydro_routing_subsurface
hydro_data_rec
hydro_routing
hydro_routing_reservoirs_levelpool
hydro_routing_reservoirs_hybrid
hydro_routing_reservoirs_rfc
hydro_routing_reservoirs
hydro_driver
noahmp_util
noahmp_phys
noahmp_data
hydro_noahmp_cpl
${NETCDF_LIBRARIES}
# hydro_routing_groundwater
# hydro_routing_groundwater_bucket
# hydro_routing_groundwater_nhd
# hydro_routing_groundwater_simple
)

if (WRF_HYDRO_NUDGING_IO STREQUAL "1")
target_link_libraries(wrfhydro hydro_nudging_io)
add_dependencies(wrfhydro hydro_nudging_io)
endif()

if (WRF_HYDRO_NUDGING STREQUAL "1")
target_link_libraries(wrfhydro hydro_nudging)
target_link_libraries(wrfhydro hydro_routing_diversions)
add_dependencies(wrfhydro hydro_nudging)
add_dependencies(wrfhydro hydro_routing_diversions)
endif()

# bash commands to copy namelists to the Run directory
set(BASH_CP_HRLDAS_NML "if [[ ! -f ${CMAKE_BINARY_DIR}/Run/namelist.hrldas ]]\; then cp ${PROJECT_SOURCE_DIR}/src/template/NoahMP/namelist.hrldas ${CMAKE_BINARY_DIR}/Run \; fi\;")
set(BASH_CP_HYDRO_NML "if [[ ! -f ${CMAKE_BINARY_DIR}/Run/hydro.namelist ]]\; then cp ${PROJECT_SOURCE_DIR}/src/template/HYDRO/hydro.namelist ${CMAKE_BINARY_DIR}/Run \; fi\;")

add_custom_command(TARGET wrfhydro POST_BUILD
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/Run
COMMAND cp ${PROJECT_SOURCE_DIR}/tests/ctests/run_dir_makefile.mk ${CMAKE_BINARY_DIR}/Run/Makefile
# copy tables
COMMAND cp ${PROJECT_SOURCE_DIR}/src/template/HYDRO/CHANPARM.TBL ${CMAKE_BINARY_DIR}/Run
COMMAND cp ${PROJECT_SOURCE_DIR}/src/template/HYDRO/HYDRO.TBL ${CMAKE_BINARY_DIR}/Run
COMMAND cp ${PROJECT_SOURCE_DIR}/src/Land_models/NoahMP/run/*.TBL ${CMAKE_BINARY_DIR}/Run
# copy namelists
COMMAND bash -c "${BASH_CP_HRLDAS_NML}"
COMMAND bash -c "${BASH_CP_HYDRO_NML}"
# copy and setup executables
COMMAND rm -f ${CMAKE_BINARY_DIR}/Run/wrf_hydro
COMMAND rm -f ${CMAKE_BINARY_DIR}/Run/wrf_hydro_NoahMP
COMMAND cp ${PROJECT_BINARY_DIR}/src/wrfhydro ${CMAKE_BINARY_DIR}/Run/wrf_hydro
COMMAND ln -sf ${CMAKE_BINARY_DIR}/Run/wrf_hydro ${CMAKE_BINARY_DIR}/Run/wrf_hydro_NoahMP
COMMAND rm ${PROJECT_BINARY_DIR}/src/wrfhydro
)
if(WRF_HYDRO_CREATE_EXE_SYMLINK)
add_custom_command(TARGET wrfhydro POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/Run/wrf_hydro ${CMAKE_BINARY_DIR}/Run/wrf_hydro.exe
)
endif()

elseif (HYDRO_LSM MATCHES "Noah")
message("-- Building Noah LSM")
add_subdirectory("Land_models/Noah")
add_subdirectory("CPL/Noah_cpl")

add_dependencies(hydro_noah_cpl hydro_routing)
add_dependencies(hydro_noah_cpl hydro_mpp )
add_dependencies(hydro_noah_cpl hydro_driver )

add_executable(wrfhydro
Land_models/Noah/IO_code/module_hrldas_netcdf_io.F
Land_models/Noah/IO_code/Noah_hrldas_driver.F
)

target_include_directories(wrfhydro BEFORE PUBLIC ${PROJECT_BINARY_DIR}/mods)

target_link_libraries(wrfhydro
hydro_utils
hydro_mpp
hydro_debug_utils
hydro_routing_overland
hydro_routing_subsurface
hydro_data_rec
hydro_routing
hydro_driver
hydro_routing_reservoirs_levelpool
hydro_routing_reservoirs_hybrid
hydro_routing_reservoirs_rfc
hydro_routing_reservoirs
noah_util
noah
hydro_noah_cpl
${NETCDF_LIBRARIES}
${MPI_Fortran_LIBRARIES}
# hydro_routing_groundwater
# hydro_routing_groundwater_bucket
# hydro_routing_groundwater_nhd
# hydro_routing_groundwater_simple
)

if (WRF_HYDRO_NUDGING STREQUAL "1")
target_link_libraries(wrfhydro hydro_nudging)
add_dependencies(wrfhydro hydro_nudging)
endif()

add_custom_command(TARGET wrfhydro POST_BUILD
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/Run
COMMAND rm -f ${CMAKE_BINARY_DIR}/Run/*
COMMAND cp ${PROJECT_BINARY_DIR}/src/wrfhydro ${CMAKE_BINARY_DIR}/Run/wrf_hydro_Noah
COMMAND cp ${PROJECT_SOURCE_DIR}/src/template/Noah/* ${CMAKE_BINARY_DIR}/Run
COMMAND cp ${PROJECT_SOURCE_DIR}/src/template/HYDRO/CHANPARM.TBL ${CMAKE_BINARY_DIR}/Run
COMMAND cp ${PROJECT_SOURCE_DIR}/src/template/HYDRO/hydro.namelist ${CMAKE_BINARY_DIR}/Run
COMMAND cp ${PROJECT_SOURCE_DIR}/src/template/HYDRO/HYDRO.TBL ${CMAKE_BINARY_DIR}/Run
COMMAND cp ${PROJECT_SOURCE_DIR}/src/Land_models/Noah/Run/*.TBL ${CMAKE_BINARY_DIR}/Run
COMMAND ln -sf ${CMAKE_BINARY_DIR}/Run/wrf_hydro_Noah ${CMAKE_BINARY_DIR}/Run/wrf_hydro
COMMAND ln -sf ${CMAKE_BINARY_DIR}/Run/wrf_hydro_Noah ${CMAKE_BINARY_DIR}/Run/wrf_hydro.exe
COMMAND rm ${PROJECT_BINARY_DIR}/src/wrfhydro
)

elseif(${PROJECT_NAME} STREQUAL "WRF")
add_library(wrfhydro INTERFACE)
target_link_libraries(wrfhydro INTERFACE
hydro_utils
hydro_mpp
hydro_debug_utils
hydro_routing_overland
hydro_routing_subsurface
hydro_data_rec
hydro_routing
hydro_routing_reservoirs_levelpool
hydro_routing_reservoirs_hybrid
hydro_routing_reservoirs_rfc
hydro_routing_reservoirs
hydro_wrf_cpl
hydro_orchestrator
hydro_netcdf_layer
hydro_driver
)
else()
message("Unknown land surface model:" ${HYDRO_LSM} )
endif()
2 changes: 1 addition & 1 deletion hydro/CPL/WRF_cpl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ add_dependencies(hydro_wrf_cpl
MPI::MPI_Fortran
)

target_link_libraries( hydro_wrf_cpl PRIVATE hydro_driver )
target_link_libraries(hydro_wrf_cpl PRIVATE hydro_driver)

target_include_directories(hydro_wrf_cpl
PRIVATE
Expand Down
6 changes: 4 additions & 2 deletions hydro/Data_Rec/module_namelist.F90
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ subroutine read_rt_nlst(nlst)
character(len=256) :: route_lake_f=""
character(len=256) :: route_direction_f=""
character(len=256) :: route_order_f=""
character(len=256) :: diversions_file=""
logical :: reservoir_persistence_usgs
logical :: reservoir_persistence_usace
character(len=256) :: reservoir_parameter_file=""
Expand Down Expand Up @@ -105,8 +106,8 @@ subroutine read_rt_nlst(nlst)
RT_OPTION, CHANRTSWCRT, channel_option, &
SUBRTSWCRT,OVRTSWCRT,AGGFACTRT, dtrt_ter,dtrt_ch,dxrt,&
GwSpinCycles, GwPreCycles, GwSpinUp, GwPreDiag, GwPreDiagInterval, gwIhShift, &
GWBASESWCRT, gwChanCondSw, gwChanCondConstIn, gwChanCondConstOut , &
route_topo_f,route_chan_f,route_link_f, compound_channel, route_lake_f, &
GWBASESWCRT, gwChanCondSw, gwChanCondConstIn, gwChanCondConstOut, &
route_topo_f,route_chan_f,route_link_f, compound_channel, route_lake_f, diversions_file, &
reservoir_persistence_usgs, reservoir_persistence_usace, reservoir_parameter_file, reservoir_usgs_timeslice_path, &
reservoir_usace_timeslice_path, reservoir_observation_lookback_hours, reservoir_observation_update_time_interval_seconds, &
reservoir_rfc_forecasts, reservoir_rfc_forecasts_time_series_path, reservoir_rfc_forecasts_lookback_hours, &
Expand Down Expand Up @@ -248,6 +249,7 @@ subroutine read_rt_nlst(nlst)
nlst%DEEPGWSPIN = DEEPGWSPIN
nlst%SOLVEG_INITSWC = SOLVEG_INITSWC
nlst%reservoir_obs_dir = "testDirectory"
nlst%diversions_file = diversions_file
nlst%reservoir_persistence_usgs = reservoir_persistence_usgs
nlst%reservoir_persistence_usace = reservoir_persistence_usace
nlst%reservoir_parameter_file = reservoir_parameter_file
Expand Down
1 change: 1 addition & 0 deletions hydro/Data_Rec/module_namelist_inc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module module_namelist_inc
character(len=256) :: route_chan_f=""
character(len=256) :: route_link_f=""
character(len=256) :: route_lake_f=""
character(len=256) :: diversions_file=""
logical :: reservoir_persistence_usgs
logical :: reservoir_persistence_usace
character(len=256) :: reservoir_parameter_file=""
Expand Down
6 changes: 6 additions & 0 deletions hydro/HYDRO_drv/module_HYDRO_drv.F90
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module module_HYDRO_drv
#endif
use module_hydro_stop, only: HYDRO_stop
use module_UDMAP, only: get_basn_area_nhd
use module_channel_diversions, only: init_diversions
use netcdf

implicit none
Expand Down Expand Up @@ -1583,6 +1584,11 @@ subroutine HYDRO_ini(ntime, did,ix0,jx0, vegtyp,soltyp)
if(nlst(did)%CHANRTSWCRT .ne. 0) call init_stream_nudging
#endif

!#ifdef WRF_HYDRO_DIVERSIONS
! TODO: should this check to make sure we have nudging on too? [RC]
call init_diversions(nlst(did)%diversions_file, nlst(did)%timeSlicePath)
!#endif


! if (trim(nlst_rt(did)%restart_file) == "") then
! output at the initial time
Expand Down
23 changes: 12 additions & 11 deletions hydro/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Makefile
# Makefile
#
CMD = Run/wrf_hydro.exe
CMD = Run/wrf_hydro
.PHONY: $(CMD)

all: $(CMD)

$(CMD):
@if [ ! -d "Run" ]; then \
(mkdir Run);\
fi
(rm -f Run/wrf_hydro.exe )
(rm -f Run/wrf_hydro )
(make -f Makefile.comm BASIC)
@if [ -d "LandModel_cpl" ]; then \
(cd LandModel_cpl; make) \
Expand All @@ -24,16 +25,16 @@ $(CMD):
(cd LandModel; make ) \
fi

debug::
@echo 'F90FLAGS := $$(DEBUGFLAGS) $$(F90FLAGS)' >> ./macros
debug::
@echo 'F90FLAGS := $$(DEBUGFLAGS) $$(F90FLAGS)' >> ./macros
@echo 'F90FLAGS := $$(DEBUGFLAGS) $$(F90FLAGS)' >> ./LandModel/user_build_options
debug:: $(CMD)

install:
-rm -f ./Run/wrf_hydro.exe; \
mv LandModel/run/hrldas.exe ./Run/wrf_hydro.exe
-rm -f ./Run/wrf_hydro
mv LandModel/run/hrldas.exe ./Run/wrf_hydro
test:
@echo "No libraries or utilities are built, skip testing."
@echo "No libraries or utilities are built, skip testing."
clean:
@if [ -d "LandModel_cpl" ]; then \
(cd LandModel_cpl; make clean) \
Expand All @@ -42,7 +43,7 @@ clean:
@if [ -d "LandModel" ]; then \
(cd LandModel; make clean) \
fi
if [ $(WRF_HYDRO_RAPID) -eq 1 ]; then \
(cd Rapid_routing; make -f makefile.cpl clean); \
@if [ "$(WRF_HYDRO_RAPID)" = "1" ]; then \
(cd Rapid_routing; make -f makefile.cpl clean); \
fi
(rm -f */*.mod */*.o lib/*.a Run/wrf_hydro.exe)
(rm -f */*.mod */*.o lib/*.a Run/wrf_hydro)
Loading