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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ stream_list.*
*.i90

src/core_*/inc
/build-cmake-colm-debug
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ option(MPAS_PROFILE "Enable GPTL profiling" OFF)
option(MPAS_OPENMP "Enable OpenMP" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(MPAS_USE_PIO "Build with PIO I/O library" OFF)
option(MPAS_COLM2024 "Build atmosphere core with embedded CoLM2024 land-surface physics" OFF)

if(MPAS_COLM2024 AND NOT DO_PHYSICS)
message(FATAL_ERROR "MPAS_COLM2024 requires DO_PHYSICS=ON because CoLM2024 is built into the atmosphere physics driver.")
endif()

message(STATUS "[OPTION] MPAS_CORES: ${MPAS_CORES}")
message(STATUS "[OPTION] MPAS_DOUBLE_PRECISION: ${MPAS_DOUBLE_PRECISION}")
message(STATUS "[OPTION] MPAS_PROFILE: ${MPAS_PROFILE}")
message(STATUS "[OPTION] MPAS_OPENMP: ${MPAS_OPENMP}")
message(STATUS "[OPTION] BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
message(STATUS "[OPTION] MPAS_USE_PIO: ${MPAS_USE_PIO}")
message(STATUS "[OPTION] MPAS_COLM2024: ${MPAS_COLM2024}")

# Build product output locations
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
Expand All @@ -43,8 +49,11 @@ if(NOT CMAKE_BUILD_TYPE)
endif()

# Detect MPAS git version
if(DEFINED GIT_EXECUTABLE AND NOT EXISTS "${GIT_EXECUTABLE}")
unset(GIT_EXECUTABLE CACHE)
endif()
find_package(Git QUIET)
if(NOT MPAS_GIT_VERSION)
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
Expand All @@ -68,9 +77,11 @@ endif()
find_package(MPI REQUIRED COMPONENTS Fortran)

find_package(PnetCDF REQUIRED COMPONENTS Fortran)
if(MPAS_USE_PIO OR MPAS_COLM2024)
find_package(NetCDF REQUIRED COMPONENTS Fortran C)
endif()
if(MPAS_USE_PIO)
find_package(PIO REQUIRED COMPONENTS Fortran C)
find_package(NetCDF REQUIRED COMPONENTS Fortran C)
endif()
if(MPAS_PROFILE)
find_package(GPTL REQUIRED)
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,13 @@ endif # END OF GIT DESCRIBE VERSION
####################################################
# Section for adding external libraries and includes
####################################################
ifeq "$(COLM2024)" "true"
COLM2024_DIR ?= $(PWD)/src/core_atmosphere/physics/physics_colm2024
override CPPFLAGS += -DMPAS_COLM2024
COLM2024_MESSAGE = "MPAS was built with CoLM2024 from $(COLM2024_DIR)."
else
COLM2024_MESSAGE = "MPAS was not built with CoLM2024."
endif
ifdef MPAS_EXTERNAL_LIBS
override LIBS += $(MPAS_EXTERNAL_LIBS)
endif
Expand Down Expand Up @@ -1573,6 +1580,7 @@ mpas_main: $(MAIN_DEPS)
@echo $(OPENMP_OFFLOAD_MESSAGE)
@echo $(OPENACC_MESSAGE)
@echo $(MUSICA_MESSAGE)
@echo $(COLM2024_MESSAGE)
@echo $(SCOTCH_MESSAGE)
@echo $(SHAREDLIB_MESSAGE)
ifeq "$(AUTOCLEAN)" "true"
Expand Down Expand Up @@ -1648,4 +1656,3 @@ errmsg:
ifdef CORE
exit 1
endif

25 changes: 14 additions & 11 deletions cmake/Functions/MPAS_Functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ function(mpas_fortran_target target)
endfunction()


# mpas_core_target(CORE <core-name> TARGET <cmake-target-name> INCLUDE <file1.inc, ...> )
# mpas_core_target(CORE <core-name> TARGET <cmake-target-name>
# INCLUDES <file1.inc, ...> REGISTRY_DEPENDS <file1.xml, ...> )
#
# Common configuration and properties for `MPAS::core::<core_name>` targets.
# * Calls mpas_fortran_target() for common Fortran target configuration.
Expand All @@ -164,9 +165,10 @@ endfunction()
# CORE - Name of core
# TARGET - Name of core_target (without namespace)
# INCLUDES - List of generated include files
# REGISTRY_DEPENDS - Files included by the core Registry.xml preprocessor input
#
function(mpas_core_target)
cmake_parse_arguments(ARG "" "CORE;TARGET" "INCLUDES" ${ARGN})
cmake_parse_arguments(ARG "" "CORE;TARGET" "INCLUDES;REGISTRY_DEPENDS" ${ARGN})

mpas_fortran_target(${ARG_TARGET})

Expand Down Expand Up @@ -214,25 +216,26 @@ function(mpas_core_target)
if (${DO_PHYSICS})
set(CPP_EXTRA_FLAGS ${CPP_EXTRA_FLAGS} -DDO_PHYSICS)
endif()
set(REGISTRY_PROCESSED_XML ${CMAKE_CURRENT_BINARY_DIR}/Registry_processed.xml)

add_custom_command(OUTPUT Registry_processed.xml
COMMAND ${CPP_EXECUTABLE} -E -P ${CPP_EXTRA_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/Registry.xml > Registry_processed.xml
add_custom_command(OUTPUT ${REGISTRY_PROCESSED_XML}
COMMAND ${CPP_EXECUTABLE} -E -P ${CPP_EXTRA_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/Registry.xml > ${REGISTRY_PROCESSED_XML}
COMMENT "CORE ${ARG_CORE}: Pre-Process Registry"
DEPENDS Registry.xml)
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Registry.xml ${ARG_REGISTRY_DEPENDS})
add_custom_command(OUTPUT ${ARG_INCLUDES}
COMMAND mpas_parse_${ARG_CORE} Registry_processed.xml ${CPP_EXTRA_FLAGS}
COMMAND mpas_parse_${ARG_CORE} ${REGISTRY_PROCESSED_XML} ${CPP_EXTRA_FLAGS}
COMMENT "CORE ${ARG_CORE}: Parse Registry"
DEPENDS mpas_parse_${ARG_CORE} Registry_processed.xml)
DEPENDS mpas_parse_${ARG_CORE} ${REGISTRY_PROCESSED_XML})
add_custom_command(OUTPUT namelist.${ARG_CORE}
WORKING_DIRECTORY ${CORE_DATADIR}
COMMAND mpas_namelist_gen ${CMAKE_CURRENT_BINARY_DIR}/Registry_processed.xml namelist.${ARG_CORE} in_defaults=true
COMMAND mpas_namelist_gen ${REGISTRY_PROCESSED_XML} namelist.${ARG_CORE} in_defaults=true
COMMENT "CORE ${ARG_CORE}: Generate Namelist"
DEPENDS mpas_namelist_gen Registry_processed.xml)
DEPENDS mpas_namelist_gen ${REGISTRY_PROCESSED_XML})
add_custom_command(OUTPUT streams.${ARG_CORE}
WORKING_DIRECTORY ${CORE_DATADIR}
COMMAND mpas_streams_gen ${CMAKE_CURRENT_BINARY_DIR}/Registry_processed.xml streams.${ARG_CORE} stream_list.${ARG_CORE}. listed
COMMAND mpas_streams_gen ${REGISTRY_PROCESSED_XML} streams.${ARG_CORE} stream_list.${ARG_CORE}. listed
COMMENT "CORE ${ARG_CORE}: Generate Streams"
DEPENDS mpas_streams_gen Registry_processed.xml)
DEPENDS mpas_streams_gen ${REGISTRY_PROCESSED_XML})
add_custom_target(gen_${ARG_CORE} DEPENDS ${ARG_INCLUDES} namelist.${ARG_CORE} streams.${ARG_CORE})
add_dependencies(${ARG_TARGET} gen_${ARG_CORE})

Expand Down
170 changes: 169 additions & 1 deletion src/core_atmosphere/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set(ATMOSPHERE_CORE_PHYSICS_SOURCES
mpas_atmphys_driver_sfclayer.F
mpas_atmphys_init.F
mpas_atmphys_lsm_shared.F
mpas_atmphys_driver_lsm_colm2024.F
mpas_atmphys_packages.F
mpas_atmphys_todynamics.F
mpas_atmphys_vars.F
Expand Down Expand Up @@ -298,6 +299,146 @@ set(ATMOSPHERE_CORE_PHYSICS_NOAMP_SRC_SOURCES
)
list(TRANSFORM ATMOSPHERE_CORE_PHYSICS_NOAMP_SRC_SOURCES PREPEND physics/physics_noahmp/src/)

if(MPAS_COLM2024)
set(COLM2024_SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/physics/physics_colm2024)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
${COLM2024_SOURCE_ROOT}/include/define.h)
set(COLM2024_SOURCE_SEARCH_DIRS
share
main
main/HYDRO
main/BGC
main/URBAN
main/DA
main/ParaOpt
drivers/mpas
)
foreach(_colm2024_dir IN LISTS COLM2024_SOURCE_SEARCH_DIRS)
file(GLOB _colm2024_dir_sources CONFIGURE_DEPENDS
${COLM2024_SOURCE_ROOT}/${_colm2024_dir}/*.F90)
list(APPEND COLM2024_SOURCE_CANDIDATES ${_colm2024_dir_sources})
endforeach()
list(REMOVE_DUPLICATES COLM2024_SOURCE_CANDIDATES)
list(SORT COLM2024_SOURCE_CANDIDATES)
foreach(_colm2024_src IN LISTS COLM2024_SOURCE_CANDIDATES)
file(RELATIVE_PATH _colm2024_src_rel ${CMAKE_CURRENT_SOURCE_DIR} ${_colm2024_src})
execute_process(
COMMAND ${CPP_EXECUTABLE} -traditional-cpp -P -I${COLM2024_SOURCE_ROOT}/include ${_colm2024_src}
OUTPUT_VARIABLE _colm2024_preprocessed_src
ERROR_VARIABLE _colm2024_preprocess_error
RESULT_VARIABLE _colm2024_preprocess_result
)
if(NOT _colm2024_preprocess_result EQUAL 0)
message(FATAL_ERROR "Could not preprocess CoLM2024 source ${_colm2024_src}: ${_colm2024_preprocess_error}")
endif()
string(TOUPPER "${_colm2024_preprocessed_src}" _colm2024_preprocessed_src_upper)
if(NOT "${_colm2024_preprocessed_src_upper}" MATCHES "(^|\n)[ \t]*(MODULE|SUBROUTINE|FUNCTION|PROGRAM)[ \t]+[A-Z0-9_]+")
list(APPEND ATMOSPHERE_CORE_PHYSICS_COLM2024_SKIPPED_EMPTY_SOURCES ${_colm2024_src_rel})
continue()
endif()
list(APPEND COLM2024_AVAILABLE_SOURCES ${_colm2024_src_rel})
string(REGEX MATCHALL "(^|\n)[ \t]*MODULE[ \t]+[A-Z][A-Z0-9_]*" _colm2024_module_lines
"${_colm2024_preprocessed_src_upper}")
foreach(_colm2024_module_line IN LISTS _colm2024_module_lines)
if(_colm2024_module_line MATCHES "MODULE[ \t]+PROCEDURE")
continue()
endif()
string(REGEX REPLACE ".*MODULE[ \t]+([A-Z][A-Z0-9_]*).*" "\\1" _colm2024_module_name
"${_colm2024_module_line}")
set(COLM2024_MODULE_SOURCE_${_colm2024_module_name} ${_colm2024_src_rel})
endforeach()
string(REGEX MATCHALL "(^|\n)[ \t]*USE[^\n]*" _colm2024_use_lines
"${_colm2024_preprocessed_src_upper}")
set(_colm2024_source_uses)
foreach(_colm2024_use_line IN LISTS _colm2024_use_lines)
if(_colm2024_use_line MATCHES "INTRINSIC")
continue()
endif()
if(_colm2024_use_line MATCHES "USE[ \t]*(,[^:]*)?(::)?[ \t]*([A-Z][A-Z0-9_]*)")
list(APPEND _colm2024_source_uses ${CMAKE_MATCH_3})
endif()
endforeach()
if(_colm2024_source_uses)
list(REMOVE_DUPLICATES _colm2024_source_uses)
endif()
string(MAKE_C_IDENTIFIER "${_colm2024_src_rel}" _colm2024_src_key)
set(COLM2024_SOURCE_USES_${_colm2024_src_key} ${_colm2024_source_uses})
endforeach()
set(ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES
physics/physics_colm2024/drivers/mpas/MOD_CoLM_MPAS_Interface.F90
physics/physics_colm2024/main/CoLMDRIVER.F90
physics/physics_colm2024/main/CoLMMAIN.F90
physics/physics_colm2024/main/MOD_MonthlyinSituCO2MaunaLoa.F90
)
foreach(_colm2024_root IN LISTS ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES)
if(NOT "${_colm2024_root}" IN_LIST COLM2024_AVAILABLE_SOURCES)
message(FATAL_ERROR "Required embedded CoLM2024 source is unavailable: ${_colm2024_root}")
endif()
endforeach()

set(_colm2024_previous_source_count -1)
list(LENGTH ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES _colm2024_source_count)
while(NOT _colm2024_previous_source_count EQUAL _colm2024_source_count)
set(_colm2024_previous_source_count ${_colm2024_source_count})
foreach(_colm2024_src IN LISTS ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES)
string(MAKE_C_IDENTIFIER "${_colm2024_src}" _colm2024_src_key)
foreach(_colm2024_use IN LISTS COLM2024_SOURCE_USES_${_colm2024_src_key})
if(DEFINED COLM2024_MODULE_SOURCE_${_colm2024_use})
list(APPEND ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES
${COLM2024_MODULE_SOURCE_${_colm2024_use}})
endif()
endforeach()
endforeach()
list(REMOVE_DUPLICATES ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES)
list(LENGTH ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES _colm2024_source_count)
endwhile()
list(SORT ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES)

list(LENGTH ATMOSPHERE_CORE_PHYSICS_COLM2024_SKIPPED_EMPTY_SOURCES _colm2024_skipped_empty_count)
list(LENGTH COLM2024_AVAILABLE_SOURCES _colm2024_available_source_count)
message(STATUS "CoLM2024 embedded CMake sources: ${_colm2024_source_count} of ${_colm2024_available_source_count}")
message(STATUS "CoLM2024 embedded CMake skipped empty sources: ${_colm2024_skipped_empty_count}")

function(_colm2024_object_path out source)
set(${out} "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/core_atmosphere.dir/${source}.o" PARENT_SCOPE)
endfunction()

function(_colm2024_source_depends source)
if(NOT "${source}" IN_LIST ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES)
return()
endif()
set(_colm2024_deps)
foreach(_colm2024_dep IN LISTS ARGN)
if(NOT "${_colm2024_dep}" IN_LIST ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES)
continue()
endif()
_colm2024_object_path(_colm2024_dep_obj ${_colm2024_dep})
list(APPEND _colm2024_deps ${_colm2024_dep_obj})
endforeach()
if(_colm2024_deps)
set_property(SOURCE ${source} APPEND PROPERTY OBJECT_DEPENDS "${_colm2024_deps}")
endif()
endfunction()

foreach(_colm2024_src IN LISTS ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES)
string(MAKE_C_IDENTIFIER "${_colm2024_src}" _colm2024_src_key)
set(_colm2024_dep_sources)
set(_colm2024_source_uses ${COLM2024_SOURCE_USES_${_colm2024_src_key}})
foreach(_colm2024_use IN LISTS _colm2024_source_uses)
if(DEFINED COLM2024_MODULE_SOURCE_${_colm2024_use})
set(_colm2024_dep_source ${COLM2024_MODULE_SOURCE_${_colm2024_use}})
if(NOT _colm2024_dep_source STREQUAL _colm2024_src)
list(APPEND _colm2024_dep_sources ${_colm2024_dep_source})
endif()
endif()
endforeach()
if(_colm2024_dep_sources)
list(REMOVE_DUPLICATES _colm2024_dep_sources)
_colm2024_source_depends(${_colm2024_src} ${_colm2024_dep_sources})
endif()
endforeach()
endif()

# diagnostics/
set(ATMOSPHERE_CORE_DIAGNOSTIC_SOURCES
mpas_atm_diagnostic_template.F
Expand Down Expand Up @@ -351,6 +492,7 @@ add_library(core_atmosphere ${ATMOSPHERE_CORE_SOURCES}
${ATMOSPHERE_CORE_PHYSICS_NOAMP_UTILITY_SOURCES}
${ATMOSPHERE_CORE_PHYSICS_NOAMP_MPAS_DRIVER_SOURCES}
${ATMOSPHERE_CORE_PHYSICS_NOAMP_SRC_SOURCES}
${ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES}
${ATMOSPHERE_CORE_PHYSICS_SOURCES}
${ATMOSPHERE_CORE_PHYSICS_MMM_SOURCES}
${ATMOSPHERE_CORE_PHYSICS_WRF_SOURCES}
Expand All @@ -365,9 +507,35 @@ set(CORE_ATMOSPHERE_COMPILE_DEFINITIONS
if (${DO_PHYSICS})
list(APPEND CORE_ATMOSPHERE_COMPILE_DEFINITIONS DO_PHYSICS)
endif ()
if (MPAS_COLM2024)
list(APPEND CORE_ATMOSPHERE_COMPILE_DEFINITIONS MPAS_COLM2024)
endif ()
target_compile_definitions(core_atmosphere PRIVATE ${CORE_ATMOSPHERE_COMPILE_DEFINITIONS})
if (MPAS_COLM2024)
target_include_directories(core_atmosphere PRIVATE ${COLM2024_SOURCE_ROOT}/include)
target_link_libraries(core_atmosphere PUBLIC NetCDF::NetCDF_Fortran NetCDF::NetCDF_C)
set_property(SOURCE ${ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES}
PROPERTY Fortran_PREPROCESS ON)
if(CMAKE_Fortran_COMPILER_ID MATCHES GNU)
set(_colm2024_compile_options -fdefault-real-8 -ffree-line-length-none)
elseif(CMAKE_Fortran_COMPILER_ID MATCHES Intel)
set(_colm2024_compile_options -real-size 64)
elseif(CMAKE_Fortran_COMPILER_ID MATCHES NVHPC)
set(_colm2024_compile_options -r8)
endif()
if(_colm2024_compile_options)
set_property(SOURCE ${ATMOSPHERE_CORE_PHYSICS_COLM2024_SOURCES}
APPEND PROPERTY COMPILE_OPTIONS ${_colm2024_compile_options})
endif()
endif ()
set_MPAS_DEBUG_flag(core_atmosphere)
mpas_core_target(CORE atmosphere TARGET core_atmosphere INCLUDES ${ATMOSPHERE_CORE_INCLUDES})
set(ATMOSPHERE_REGISTRY_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/diagnostics/Registry_diagnostics.xml
${CMAKE_CURRENT_SOURCE_DIR}/physics/Registry_noahmp.xml
${CMAKE_CURRENT_SOURCE_DIR}/physics/Registry_colm2024.xml)
mpas_core_target(CORE atmosphere TARGET core_atmosphere
INCLUDES ${ATMOSPHERE_CORE_INCLUDES}
REGISTRY_DEPENDS ${ATMOSPHERE_REGISTRY_DEPENDS})

#Get physics_wrf tables from MPAS-Data
include(FetchContent)
Expand Down
3 changes: 3 additions & 0 deletions src/core_atmosphere/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ post_build:

physcore: mpas_atm_dimensions.o
( cd physics; $(MAKE) all )
$(RM) -r libphys
( mkdir libphys; cd libphys; ar -x ../physics/libphys.a )
( cd ../..; ln -sf ./src/core_atmosphere/physics/physics_wrf/files/*TBL .)
( cd ../..; ln -sf ./src/core_atmosphere/physics/physics_wrf/files/*DATA* .)
( cd ../..; ln -sf ./src/core_atmosphere/physics/physics_noahmp/parameters/*TBL .)

chemcore:
( cd chemistry; $(MAKE) all CHEMISTRY="$(CHEMISTRY)" )
$(RM) -r libchem
( mkdir libchem; cd libchem; ar -x ../chemistry/libchem.a )

dycore: mpas_atm_dimensions.o $(PHYSCORE) $(CHEMCORE)
Expand All @@ -67,6 +69,7 @@ utilities: $(PHYSCORE)
( cd utils; $(MAKE) all PHYSICS="$(PHYSICS)" )

atmcore: $(PHYSCORE) dycore diagcore $(OBJS)
$(RM) libdycore.a
ar -ru libdycore.a $(OBJS) dynamics/*.o $(PHYS_OBJS) $(CHEM_OBJS) diagnostics/*.o

mpas_atm_core_interface.o: mpas_atm_core.o
Expand Down
Loading