Skip to content

Commit

Permalink
Add NUOPC cap to parflow
Browse files Browse the repository at this point in the history
* cmake option -DPARFLOW_ENABLE_NUOPC=ON
* pass MPI communicator from cap to amps layer
* add amps_EmbeddedInitFComm to convert fortran communicator to c for embedded applications
* set amps coupler logging to stdout
* fix target_link_libraries for pfsimulator
* update target_include_directories to specify BUILD_INTERFACE
* add PF NUOPC cap ESMX testing application
* fork wrf_parflow.c to cpl_parflow.c
* add solver_mask in cpl_parflow.c
* add cplparflowexport function
* export specific and zmulit from cplparflowadvance
* add ExportRichards function
* add GetGrid2DRichards to solver_richards.c
* add GetMaskRichards to solver_richards.c
* add sphdeg coords to NUOPC cap from clm vegtf
* add python3 scripting to pfnuopc cap
* nuopc import fields default to fill value
* nuopc export fields default to model data
* export ParFlow libraries to ParFlow.cmake file
* update to cmake source dirs to project
  • Loading branch information
danrosen25 committed Nov 6, 2023
1 parent de3a26d commit 8ade66f
Show file tree
Hide file tree
Showing 41 changed files with 10,347 additions and 41 deletions.
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.14)

project (PARFLOW LANGUAGES C Fortran CXX)

set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")

#-----------------------------------------------------------------------------
# Set standard compiler flagsx
Expand Down Expand Up @@ -524,7 +524,7 @@ else(PARFLOW_ENABLE_PROFILING)
set (PARFLOW_PROFILE_OPTS "")
endif(PARFLOW_ENABLE_PROFILING)

include_directories ("${CMAKE_SOURCE_DIR}/pfsimulator/parflow_lib")
include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/pfsimulator/parflow_lib")

include_directories ("${PROJECT_SOURCE_DIR}/pfsimulator/amps/${PARFLOW_AMPS_LAYER}")
include_directories ("${PROJECT_SOURCE_DIR}/pfsimulator/amps/common")
Expand Down Expand Up @@ -574,6 +574,12 @@ if ( ${PARFLOW_ENABLE_TOOLS} )
add_subdirectory (pftools)
endif ()

# Optionally build the NUOPC cap
option(PARFLOW_ENABLE_NUOPC "Enable building of the Parflow nuopc" "False")
if ( ${PARFLOW_ENABLE_NUOPC} )
add_subdirectory (pfnuopc)
endif ()

#-----------------------------------------------------------------------------
# Setup CTEST environment
#-----------------------------------------------------------------------------
Expand All @@ -584,7 +590,7 @@ if (PARFLOW_ENABLE_LATEX)
add_subdirectory(docs/manuals)
endif()

install (DIRECTORY ${CMAKE_BINARY_DIR}/config/ DESTINATION config)
install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/config/ DESTINATION config)

#-----------------------------------------------------------------------------
# Doxygen
Expand Down
12 changes: 6 additions & 6 deletions cmake/modules/ParflowTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ function (pf_add_parallel_test inputfile topology)
separate_arguments(targs UNIX_COMMAND ${topology})
list(APPEND args ${targs})

add_test (NAME ${testname}_${postfix} COMMAND ${CMAKE_COMMAND} "-DPARFLOW_TEST=${args}" -DMPIEXEC=${MPIEXEC} -DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} "-DMPIEXEC_PREFLAGS=${MPIEXEC_PREFLAGS}" "-DMPIEXEC_POSTFLAGS=${MPIEXEC_POSTFLAGS}" -DPARFLOW_HAVE_OAS3={PARFLOW_HAVE_OAS3} -P ${CMAKE_SOURCE_DIR}/cmake/modules/RunParallelTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test (NAME ${testname}_${postfix} COMMAND ${CMAKE_COMMAND} "-DPARFLOW_TEST=${args}" -DMPIEXEC=${MPIEXEC} -DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} "-DMPIEXEC_PREFLAGS=${MPIEXEC_PREFLAGS}" "-DMPIEXEC_POSTFLAGS=${MPIEXEC_POSTFLAGS}" -DPARFLOW_HAVE_OAS3={PARFLOW_HAVE_OAS3} -P ${PROJECT_SOURCE_DIR}/cmake/modules/RunParallelTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set_tests_properties(${testname}_${postfix} PROPERTIES TIMEOUT 3600)

if( ${PARFLOW_HAVE_MEMORYCHECK} )
add_test (NAME ${testname}_${postfix}_memcheck COMMAND ${CMAKE_COMMAND} -DPARFLOW_HAVE_MEMORYCHECK=${PARFLOW_HAVE_MEMORYCHECK} -DPARFLOW_MEMORYCHECK_COMMAND=${PARFLOW_MEMORYCHECK_COMMAND} -DPARFLOW_MEMORYCHECK_COMMAND_OPTIONS=${PARFLOW_MEMORYCHECK_COMMAND_OPTIONS} "-DPARFLOW_TEST=${args}" -DMPIEXEC=${MPIEXEC} -DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} "-DMPIEXEC_PREFLAGS=${MPIEXEC_PREFLAGS}" "-DMPIEXEC_POSTFLAGS=${MPIEXEC_POSTFLAGS}" -DPARFLOW_HAVE_OAS3=${PARFLOW_HAVE_OAS3} -P ${CMAKE_SOURCE_DIR}/cmake/modules/RunParallelTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test (NAME ${testname}_${postfix}_memcheck COMMAND ${CMAKE_COMMAND} -DPARFLOW_HAVE_MEMORYCHECK=${PARFLOW_HAVE_MEMORYCHECK} -DPARFLOW_MEMORYCHECK_COMMAND=${PARFLOW_MEMORYCHECK_COMMAND} -DPARFLOW_MEMORYCHECK_COMMAND_OPTIONS=${PARFLOW_MEMORYCHECK_COMMAND_OPTIONS} "-DPARFLOW_TEST=${args}" -DMPIEXEC=${MPIEXEC} -DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} "-DMPIEXEC_PREFLAGS=${MPIEXEC_PREFLAGS}" "-DMPIEXEC_POSTFLAGS=${MPIEXEC_POSTFLAGS}" -DPARFLOW_HAVE_OAS3=${PARFLOW_HAVE_OAS3} -P ${PROJECT_SOURCE_DIR}/cmake/modules/RunParallelTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif ()

endfunction()
Expand All @@ -42,11 +42,11 @@ function (pf_add_sequential_test inputfile)
list(APPEND args ${inputfile})
list(APPEND args 1 1 1)

add_test (NAME ${testname} COMMAND ${CMAKE_COMMAND} "-DPARFLOW_TEST=${args}" -DPARFLOW_HAVE_OAS3=${PARFLOW_HAVE_OAS3} -P ${CMAKE_SOURCE_DIR}/cmake/modules/RunParallelTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test (NAME ${testname} COMMAND ${CMAKE_COMMAND} "-DPARFLOW_TEST=${args}" -DPARFLOW_HAVE_OAS3=${PARFLOW_HAVE_OAS3} -P ${PROJECT_SOURCE_DIR}/cmake/modules/RunParallelTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set_tests_properties(${testname} PROPERTIES TIMEOUT 3600)

if( ${PARFLOW_HAVE_MEMORYCHECK} )
add_test (NAME ${testname}_memcheck COMMAND ${CMAKE_COMMAND} -DPARFLOW_HAVE_MEMORYCHECK=${PARFLOW_HAVE_MEMORYCHECK} -DPARFLOW_MEMORYCHECK_COMMAND=${PARFLOW_MEMORYCHECK_COMMAND} -DPARFLOW_MEMORYCHECK_COMMAND_OPTIONS=${PARFLOW_MEMORYCHECK_COMMAND_OPTIONS} "-DPARFLOW_TEST=${args}" -DMPIEXEC=${MPIEXEC} -DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} "-DMPIEXEC_PREFLAGS=${MPIEXEC_PREFLAGS}" "-DMPIEXEC_POSTFLAGS=${MPIEXEC_POSTFLAGS}" -DPARFLOW_HAVE_OAS3=${PARFLOW_HAVE_OAS3} -P ${CMAKE_SOURCE_DIR}/cmake/modules/RunParallelTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test (NAME ${testname}_memcheck COMMAND ${CMAKE_COMMAND} -DPARFLOW_HAVE_MEMORYCHECK=${PARFLOW_HAVE_MEMORYCHECK} -DPARFLOW_MEMORYCHECK_COMMAND=${PARFLOW_MEMORYCHECK_COMMAND} -DPARFLOW_MEMORYCHECK_COMMAND_OPTIONS=${PARFLOW_MEMORYCHECK_COMMAND_OPTIONS} "-DPARFLOW_TEST=${args}" -DMPIEXEC=${MPIEXEC} -DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} "-DMPIEXEC_PREFLAGS=${MPIEXEC_PREFLAGS}" "-DMPIEXEC_POSTFLAGS=${MPIEXEC_POSTFLAGS}" -DPARFLOW_HAVE_OAS3=${PARFLOW_HAVE_OAS3} -P ${PROJECT_SOURCE_DIR}/cmake/modules/RunParallelTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()

endfunction()
Expand All @@ -59,10 +59,10 @@ endfunction()
function (pf_add_amps_parallel_test test ranks loops)
set (testname amps-${test}-${ranks}-${loops})

add_test (NAME ${testname} COMMAND ${CMAKE_COMMAND} -DPARFLOW_TEST=${test} -DPARFLOW_RANKS=${ranks} -DPARFLOW_ARGS=${loops} -DMPIEXEC=${MPIEXEC} -DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} "-DMPIEXEC_PREFLAGS=${MPIEXEC_PREFLAGS}" "-DMPIEXEC_POSTFLAGS=${MPIEXEC_POSTFLAGS}" -DPARFLOW_HAVE_OAS3=${PARFLOW_HAVE_OAS3} -P ${CMAKE_SOURCE_DIR}/cmake/modules/RunAmpsTest.cmake)
add_test (NAME ${testname} COMMAND ${CMAKE_COMMAND} -DPARFLOW_TEST=${test} -DPARFLOW_RANKS=${ranks} -DPARFLOW_ARGS=${loops} -DMPIEXEC=${MPIEXEC} -DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} "-DMPIEXEC_PREFLAGS=${MPIEXEC_PREFLAGS}" "-DMPIEXEC_POSTFLAGS=${MPIEXEC_POSTFLAGS}" -DPARFLOW_HAVE_OAS3=${PARFLOW_HAVE_OAS3} -P ${PROJECT_SOURCE_DIR}/cmake/modules/RunAmpsTest.cmake)

if( ${PARFLOW_HAVE_MEMORYCHECK} )
add_test (NAME ${testname}_memcheck COMMAND ${CMAKE_COMMAND} -DPARFLOW_HAVE_MEMORYCHECK=${PARFLOW_HAVE_MEMORYCHECK} -DPARFLOW_MEMORYCHECK_COMMAND=${PARFLOW_MEMORYCHECK_COMMAND} -DPARFLOW_MEMORYCHECK_COMMAND_OPTIONS=${PARFLOW_MEMORYCHECK_COMMAND_OPTIONS} -DPARFLOW_TEST=${test} -DPARFLOW_RANKS=${ranks} -DPARFLOW_ARGS=${loops} -DMPIEXEC=${MPIEXEC} -DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} "-DMPIEXEC_PREFLAGS=${MPIEXEC_PREFLAGS}" "-DMPIEXEC_POSTFLAGS=${MPIEXEC_POSTFLAGS}" -DPARFLOW_HAVE_OAS3=${PARFLOW_HAVE_OAS3} -P ${CMAKE_SOURCE_DIR}/cmake/modules/RunAmpsTest.cmake)
add_test (NAME ${testname}_memcheck COMMAND ${CMAKE_COMMAND} -DPARFLOW_HAVE_MEMORYCHECK=${PARFLOW_HAVE_MEMORYCHECK} -DPARFLOW_MEMORYCHECK_COMMAND=${PARFLOW_MEMORYCHECK_COMMAND} -DPARFLOW_MEMORYCHECK_COMMAND_OPTIONS=${PARFLOW_MEMORYCHECK_COMMAND_OPTIONS} -DPARFLOW_TEST=${test} -DPARFLOW_RANKS=${ranks} -DPARFLOW_ARGS=${loops} -DMPIEXEC=${MPIEXEC} -DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} "-DMPIEXEC_PREFLAGS=${MPIEXEC_PREFLAGS}" "-DMPIEXEC_POSTFLAGS=${MPIEXEC_POSTFLAGS}" -DPARFLOW_HAVE_OAS3=${PARFLOW_HAVE_OAS3} -P ${PROJECT_SOURCE_DIR}/cmake/modules/RunAmpsTest.cmake)
endif()
endfunction()

Expand Down
6 changes: 3 additions & 3 deletions cmake/modules/PftoolsTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
function (pf_add_filecompare_test testname cmd comparefile)

add_test (NAME ${testname} COMMAND ${CMAKE_COMMAND} "-DPFCMD=${cmd}" -P ${CMAKE_SOURCE_DIR}/cmake/modules/RunFileCompareTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test (NAME ${testname} COMMAND ${CMAKE_COMMAND} "-DPFCMD=${cmd}" -P ${PROJECT_SOURCE_DIR}/cmake/modules/RunFileCompareTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

endfunction()

Expand Down Expand Up @@ -39,7 +39,7 @@ function (pf_add_mask_test testname inputfile)

list(APPEND files "${pfsolname}" "${vtkname}")

add_test (NAME ${testname} COMMAND ${CMAKE_COMMAND} "-DPFCMD=${cmd}" "-DPFFILES=${files}" -P ${CMAKE_SOURCE_DIR}/cmake/modules/RunFileCompareTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test (NAME ${testname} COMMAND ${CMAKE_COMMAND} "-DPFCMD=${cmd}" "-DPFFILES=${files}" -P ${PROJECT_SOURCE_DIR}/cmake/modules/RunFileCompareTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

endfunction()

Expand Down Expand Up @@ -69,7 +69,7 @@ function (pf_add_multi_mask_test testname inputfile)

list(APPEND files "${pfsolname}" "${vtkname}")

add_test (NAME ${testname} COMMAND ${CMAKE_COMMAND} "-DPFCMD=${cmd}" "-DPFFILES=${files}" -P ${CMAKE_SOURCE_DIR}/cmake/modules/RunFileCompareTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test (NAME ${testname} COMMAND ${CMAKE_COMMAND} "-DPFCMD=${cmd}" "-DPFFILES=${files}" -P ${PROJECT_SOURCE_DIR}/cmake/modules/RunFileCompareTest.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

endfunction()

46 changes: 46 additions & 0 deletions pfnuopc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required (VERSION 3.5.2)

### Build Flags
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO} -fbacktrace")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -O0 -fbacktrace -fcheck=all" )
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO} -traceback")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -O0 -traceback -check all")
endif()

### Find and Include ESMF
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
find_package(ESMF MODULE REQUIRED)

### Include ESMF Compiler Options
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${ESMF_F90COMPILEOPTS}")

set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include)

### Library Files
list(APPEND pf_nuopc_files
src/pf_nuopc_cap.F90
src/pf_nuopc_fields.F90
src/pf_nuopc_grid.F90
src/pf_nuopc_flags.F90
)

### New Library: parflow_nuopc
add_library(parflow_nuopc STATIC ${pf_nuopc_files})
add_dependencies(parflow_nuopc pfsimulator)
include_directories(parflow_nuopc include)
target_link_libraries(parflow_nuopc PUBLIC ESMF)
target_link_libraries(parflow_nuopc PUBLIC pfsimulator)

### Install Library
install(TARGETS parflow_nuopc
EXPORT ParFlow
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
INCLUDES DESTINATION include
)
install(FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/parflow_nuopc.mod
DESTINATION include
)

13 changes: 13 additions & 0 deletions pfnuopc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ParFlow NUOPC Cap

The ParFlow NUOPC Cap is a ParFlow interface wrapper for the National Unified
Operational Prediction Capability (NUOPC) coupling framework.

[NUOPC Documentation](http://earthsystemmodeling.org/nuopc/)

## Build
Include -DPARFLOW\_ENABLE\_NUOPC=ON in cmake build
```
cmake <PARFLOW_SOURCE> \
-DPARFLOW_ENABLE_NUOPC=ON
```
142 changes: 142 additions & 0 deletions pfnuopc/cmake/modules/FindESMF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# - Try to find ESMF
#
# Uses ESMFMKFILE to find the filepath of esmf.mk. If this is NOT set, then this
# module will attempt to find esmf.mk. If ESMFMKFILE exists, then
# ESMF_FOUND=TRUE and all ESMF makefile variables will be set in the global
# scope. Optionally, set ESMF_MKGLOBALS to a string list to filter makefile
# variables. For example, to globally scope only ESMF_LIBSDIR and ESMF_APPSDIR
# variables, use this CMake command in CMakeLists.txt:
#
# set(ESMF_MKGLOBALS "LIBSDIR" "APPSDIR")

# Set ESMFMKFILE as defined by system env variable. If it's not explicitly set
# try to find esmf.mk file in default locations (ESMF_ROOT, CMAKE_PREFIX_PATH,
# etc)
if(NOT DEFINED ESMFMKFILE)
if(NOT DEFINED ENV{ESMFMKFILE})
find_path(ESMFMKFILE_PATH esmf.mk PATH_SUFFIXES lib lib64)
if(ESMFMKFILE_PATH)
set(ESMFMKFILE ${ESMFMKFILE_PATH}/esmf.mk)
message(STATUS "Found esmf.mk file ${ESMFMKFILE}")
endif()
else()
set(ESMFMKFILE $ENV{ESMFMKFILE})
endif()
endif()

# Only parse the mk file if it is found
if(EXISTS ${ESMFMKFILE})
set(ESMFMKFILE ${ESMFMKFILE} CACHE FILEPATH "Path to esmf.mk file")
set(ESMF_FOUND TRUE CACHE BOOL "esmf.mk file found" FORCE)

# Read the mk file
file(STRINGS "${ESMFMKFILE}" esmfmkfile_contents)
# Parse each line in the mk file
foreach(str ${esmfmkfile_contents})
# Only consider uncommented lines
string(REGEX MATCH "^[^#]" def ${str})
# Line is not commented
if(def)
# Extract the variable name
string(REGEX MATCH "^[^=]+" esmf_varname ${str})
# Extract the variable's value
string(REGEX MATCH "=.+$" esmf_vardef ${str})
# Only for variables with a defined value
if(esmf_vardef)
# Get rid of the assignment string
string(SUBSTRING ${esmf_vardef} 1 -1 esmf_vardef)
# Remove whitespace
string(STRIP ${esmf_vardef} esmf_vardef)
# A string or single-valued list
if(NOT DEFINED ESMF_MKGLOBALS)
# Set in global scope
set(${esmf_varname} ${esmf_vardef})
# Don't display by default in GUI
mark_as_advanced(esmf_varname)
else() # Need to filter global promotion
foreach(m ${ESMF_MKGLOBALS})
string(FIND ${esmf_varname} ${m} match)
# Found the string
if(NOT ${match} EQUAL -1)
# Promote to global scope
set(${esmf_varname} ${esmf_vardef})
# Don't display by default in the GUI
mark_as_advanced(esmf_varname)
# No need to search for the current string filter
break()
endif()
endforeach()
endif()
endif()
endif()
endforeach()

# Construct ESMF_VERSION from ESMF_VERSION_STRING_GIT
# ESMF_VERSION_MAJOR and ESMF_VERSION_MINOR are defined in ESMFMKFILE
set(ESMF_VERSION 0)
set(ESMF_VERSION_PATCH ${ESMF_VERSION_REVISION})
set(ESMF_BETA_RELEASE FALSE)
if(ESMF_VERSION_BETASNAPSHOT MATCHES "^('T')$")
set(ESMF_BETA_RELEASE TRUE)
if(ESMF_VERSION_STRING_GIT MATCHES "^ESMF.*beta_snapshot")
set(ESMF_BETA_SNAPSHOT ${ESMF_VERSION_STRING_GIT})
elseif(ESMF_VERSION_STRING_GIT MATCHES "^v.\..\..b")
set(ESMF_BETA_SNAPSHOT ${ESMF_VERSION_STRING_GIT})
else()
set(ESMF_BETA_SNAPSHOT 0)
endif()
message(STATUS "Detected ESMF Beta snapshot: ${ESMF_BETA_SNAPSHOT}")
endif()
set(ESMF_VERSION "${ESMF_VERSION_MAJOR}.${ESMF_VERSION_MINOR}.${ESMF_VERSION_PATCH}")

# Find the ESMF library
if(USE_ESMF_STATIC_LIBS)
find_library(ESMF_LIBRARY_LOCATION NAMES libesmf.a PATHS ${ESMF_LIBSDIR} NO_DEFAULT_PATH)
if(ESMF_LIBRARY_LOCATION MATCHES "ESMF_LIBRARY_LOCATION-NOTFOUND")
message(WARNING "Static ESMF library (libesmf.a) not found in \
${ESMF_LIBSDIR}. Try setting USE_ESMF_STATIC_LIBS=OFF")
endif()
if(NOT TARGET ESMF)
add_library(ESMF STATIC IMPORTED)
endif()
else()
find_library(ESMF_LIBRARY_LOCATION NAMES esmf PATHS ${ESMF_LIBSDIR} NO_DEFAULT_PATH)
if(ESMF_LIBRARY_LOCATION MATCHES "ESMF_LIBRARY_LOCATION-NOTFOUND")
message(WARNING "ESMF library not found in ${ESMF_LIBSDIR}.")
endif()
if(NOT TARGET ESMF)
add_library(ESMF UNKNOWN IMPORTED)
endif()
endif()

# Add ESMF include directories
set(ESMF_INCLUDE_DIRECTORIES "")
separate_arguments(_ESMF_F90COMPILEPATHS UNIX_COMMAND ${ESMF_F90COMPILEPATHS})
foreach(_ITEM ${_ESMF_F90COMPILEPATHS})
string(REGEX REPLACE "^-I" "" _ITEM "${_ITEM}")
list(APPEND ESMF_INCLUDE_DIRECTORIES ${_ITEM})
endforeach()

# Add ESMF link libraries
string(STRIP "${ESMF_F90LINKRPATHS} ${ESMF_F90ESMFLINKRPATHS} ${ESMF_F90ESMFLINKPATHS} ${ESMF_F90LINKPATHS} ${ESMF_F90LINKLIBS} ${ESMF_F90LINKOPTS}" ESMF_INTERFACE_LINK_LIBRARIES)

# Finalize find_package
include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(
${CMAKE_FIND_PACKAGE_NAME}
REQUIRED_VARS ESMF_LIBRARY_LOCATION
ESMF_INTERFACE_LINK_LIBRARIES
ESMF_F90COMPILEPATHS
VERSION_VAR ESMF_VERSION)

set_target_properties(ESMF PROPERTIES
IMPORTED_LOCATION "${ESMF_LIBRARY_LOCATION}"
INTERFACE_INCLUDE_DIRECTORIES "${ESMF_INCLUDE_DIRECTORIES}"
INTERFACE_LINK_LIBRARIES "${ESMF_INTERFACE_LINK_LIBRARIES}")

else()
set(ESMF_FOUND FALSE CACHE BOOL "esmf.mk file NOT found" FORCE)
message(WARNING "ESMFMKFILE ${ESMFMKFILE} not found. Try setting ESMFMKFILE \
to esmf.mk location.")
endif()
30 changes: 30 additions & 0 deletions pfnuopc/include/pf_nuopc_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
!-------------------------------------------------------------------------------
! Define Defaults
!-------------------------------------------------------------------------------
#define CONTEXT line=__LINE__,file=__FILE__
#define PASSTHRU msg=ESMF_LOGERR_PASSTHRU,CONTEXT
#define ESMF_STDERRORCHECK(rc) ESMF_LogFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)

!-------------------------------------------------------------------------------
! Define ESMF real kind to match Appplications single/double precision
!-------------------------------------------------------------------------------
#if defined(REAL4)
#define ESMF_KIND_FIELD ESMF_KIND_R4
#define ESMF_KIND_COORD ESMF_KIND_R4
#define ESMF_DEFAULT_VALUE 9.99e20_ESMF_KIND_R8
#define ESMF_TYPEKIND_FIELD ESMF_TYPEKIND_R4
#define ESMF_TYPEKIND_COORD ESMF_TYPEKIND_R4
#elif defined(REAL8)
#define ESMF_KIND_FIELD ESMF_KIND_R8
#define ESMF_KIND_COORD ESMF_KIND_R8
#define ESMF_DEFAULT_VALUE 9.99e20_ESMF_KIND_R8
#define ESMF_TYPEKIND_FIELD ESMF_TYPEKIND_R8
#define ESMF_TYPEKIND_COORD ESMF_TYPEKIND_R8
#else
#define ESMF_KIND_FIELD ESMF_KIND_R4
#define ESMF_KIND_COORD ESMF_KIND_R8
#define ESMF_DEFAULT_VALUE 9.99e20_ESMF_KIND_R8
#define ESMF_TYPEKIND_FIELD ESMF_TYPEKIND_R4
#define ESMF_TYPEKIND_COORD ESMF_TYPEKIND_R8
#endif

Loading

0 comments on commit 8ade66f

Please sign in to comment.