Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate MICM into build and start chem process structure #114

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)

project(CATChem VERSION 0.1.0 LANGUAGES Fortran)
project(CATChem VERSION 0.1.0 LANGUAGES Fortran C CXX)
Copy link
Collaborator Author

@zmoon zmoon Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just nothing that, without adding these, was getting this error:

CMake Error in src/process/chem/CMakeLists.txt:
  No known features for CXX compiler

  ""

  version .

Copy link
Collaborator Author

@zmoon zmoon Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note, it seems like really it's only necessary to add CXX to get a successful build

Copy link
Collaborator Author

@zmoon zmoon Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@K20shores do you know if there's a way to get MUSICA to build without changing this, by specifying something elsewhere instead? Just curious, as our project code is all Fortran really.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zmoon I think this is required. If not, I don't think the linker will be properly configured. I could be wrong though

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zmoon I was able to build your fork

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @K20shores , that's good to hear.


include(CMakePrintHelpers)

Expand Down
1 change: 1 addition & 0 deletions src/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ target_link_libraries(${_lib} PUBLIC CATChem_process_dust)
target_link_libraries(${_lib} PUBLIC CATChem_process_seasalt)
target_link_libraries(${_lib} PUBLIC CATChem_process_plumerise)
target_link_libraries(${_lib} PUBLIC CATChem_process_drydep)
target_link_libraries(${_lib} PUBLIC CATChem_process_chem)
set_target_properties(
${_lib}
PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include
Expand Down
2 changes: 2 additions & 0 deletions src/api/catchem.F90
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ module CATChem
use CCPr_DryDep_mod, only: cc_drydep_init => CCPr_DryDep_Init !< DryDep Process Initialization Routine
use CCPr_DryDep_mod, only: cc_drydep_run => CCPr_DryDep_Run !< DryDep Process Run Routine
use CCPr_DryDep_mod, only: cc_drydep_finalize => CCPr_DryDep_Finalize !< DryDep Process Finalization Routine
! Chemical mechanism solver
use CCPr_Chem_mod, only: cc_get_micm_version => get_micm_version

implicit none

Expand Down
29 changes: 28 additions & 1 deletion src/external/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#
# GOCART-2G Process Library
#

set(
_srcs
GOCART/Process_Library/GOCART2G_Process.F90
Expand All @@ -13,9 +17,32 @@ endif()
find_package(NetCDF REQUIRED COMPONENTS Fortran)

target_link_libraries(${_lib} NetCDF::NetCDF_Fortran)
# target_link_libraries(${_lib} PUBLIC CATChem_core)

set_target_properties(
${_lib}
PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include
)

#
# MICM Fortran API
#

include(FetchContent)

FetchContent_Declare(
musica_fortran
GIT_REPOSITORY https://github.com/NCAR/musica.git
GIT_TAG v0.9.0
)

set(MICM_ENABLE_TESTS OFF)
set(MICM_ENABLE_EXAMPLES OFF)

set(MUSICA_BUILD_C_CXX_INTERFACE ON)
zmoon marked this conversation as resolved.
Show resolved Hide resolved
set(MUSICA_BUILD_FORTRAN_INTERFACE ON)
set(MUSICA_ENABLE_INSTALL OFF)
set(MUSICA_ENABLE_TESTS OFF)
set(MUSICA_ENABLE_MICM ON)
set(MUSICA_ENABLE_TUVX OFF)

FetchContent_MakeAvailable(musica_fortran)
1 change: 1 addition & 0 deletions src/process/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ add_subdirectory(dust)
add_subdirectory(seasalt)
add_subdirectory(plumerise)
add_subdirectory(drydep)
add_subdirectory(chem)
21 changes: 21 additions & 0 deletions src/process/chem/CCPr_Chem_Mod.F90
zmoon marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module CCPr_Chem_mod
implicit none

private
public :: get_micm_version

contains

function get_micm_version() result(res)
use musica_util, only: string_t
use musica_micm, only: get_micm_version_ => get_micm_version
character(len=256) :: res

type(string_t) :: micm_version_

micm_version_ = get_micm_version_()
res = micm_version_%get_char_array()

end function get_micm_version

end module CCPr_Chem_mod
11 changes: 11 additions & 0 deletions src/process/chem/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(_lib CATChem_process_chem)

set(_srcs CCPr_Chem_Mod.F90)

add_library(${_lib} ${_srcs})
target_link_libraries(${_lib} PUBLIC CATChem_core)
target_link_libraries(${_lib} PRIVATE musica::musica-fortran)
set_target_properties(
${_lib}
PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include
)
15 changes: 9 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ set_target_properties(
test_main
PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include
)

add_test(
NAME test_main
COMMAND test_main
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_test(
NAME test_main_missing_config
COMMAND test_main
Expand All @@ -40,7 +38,6 @@ set_target_properties(
test_dust
PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include
)

add_test(
NAME test_ccpr_dust
COMMAND test_dust
Expand All @@ -56,7 +53,6 @@ set_target_properties(
test_seasalt
PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include
)

add_test(
NAME test_ccpr_seasalt
COMMAND test_seasalt
Expand All @@ -71,7 +67,6 @@ set_target_properties(
test_prise
PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include
)

add_test(
NAME test_plumerise
COMMAND test_prise
Expand All @@ -86,9 +81,17 @@ set_target_properties(
test_drydep
PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include
)

add_test(
NAME test_drydep
COMMAND test_drydep
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_executable(test_chem test_chem.f90)
target_link_libraries(test_chem PRIVATE CATChem)
target_link_libraries(test_chem PRIVATE testing)
set_target_properties(
test_chem
PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include
)
add_test(NAME test_chem COMMAND test_chem)
14 changes: 14 additions & 0 deletions tests/test_chem.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
program test_chem
use CATChem, only: cc_get_micm_version
use testing_mod, only: assert
implicit none

character(len=:), allocatable :: micm_version
character(len=*), parameter :: expected_micm_version = "3.7.0"

micm_version = trim(adjustl(cc_get_micm_version()))
print "('MICM version:', 1x, '''', a, '''')", micm_version
call assert(micm_version == expected_micm_version, &
"MICM version should be "//expected_micm_version)

end program test_chem