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

90 allow api users to create and destroy instances of tuvx #96

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
936caeb
correcting fortran build
K20shores Apr 16, 2024
a872b4f
install stuff
K20shores Apr 16, 2024
2c15659
correcting python build
K20shores Apr 16, 2024
d37298d
what
K20shores Apr 16, 2024
0438304
adding lapack to containers
K20shores Apr 16, 2024
fb62208
installating lapack on ubuntu action
K20shores Apr 16, 2024
41b245a
Rename CMakelists.txt to CMakeLists.txt
K20shores Apr 16, 2024
42bd744
Merge branch 'main' into 90-allow-api-users-to-create-and-destroy-ins…
K20shores Apr 23, 2024
1420213
adding namespaces, reorganzing some tests, stubbing some tuv interfaces
K20shores Apr 24, 2024
73e5122
testing internal c api
K20shores Apr 25, 2024
02c45b1
setting error code in internal fortran interface for tuvx
K20shores Apr 25, 2024
ca762a8
adding namespaces, reorganzing some tests, stubbing some tuv interfaces
K20shores Apr 24, 2024
7c780b7
testing internal c api
K20shores Apr 25, 2024
83bc419
setting error code in internal fortran interface for tuvx
K20shores Apr 25, 2024
6604ad9
Merge branch '90-allow-api-users-to-create-and-destroy-instances-of-t…
K20shores Apr 25, 2024
c38cc28
adding back the fetch content files
K20shores Apr 25, 2024
8c9d882
removing tuvx data in favor of copying it from the fetched repository
K20shores Apr 25, 2024
01c6c22
correcting comment
K20shores Apr 25, 2024
6405196
testing tuvx fortran api
K20shores Apr 25, 2024
22dc19a
trying to use the homebrew pip in github actions
K20shores Apr 25, 2024
83616c9
trying to specify the python path
K20shores Apr 25, 2024
38977c0
adding compile options
K20shores Apr 25, 2024
fee939c
adding compile definitions for fortran
K20shores Apr 25, 2024
741aabf
removing parallel build temporarily
K20shores Apr 25, 2024
b32a0bd
adding verbose flag
K20shores Apr 25, 2024
cd3af4e
trying a user install
K20shores Apr 25, 2024
d4ec8ec
verbose build
K20shores Apr 25, 2024
3cdd726
using a list of compile definitions specific to targets
K20shores Apr 25, 2024
c9692ce
going back to compile features for c++ version
K20shores Apr 25, 2024
8fad4d5
removing parallel build
K20shores Apr 25, 2024
d5c67e2
setting link options
K20shores Apr 25, 2024
0261cd7
going back to compile options
K20shores Apr 25, 2024
cfc4135
undoing change
K20shores Apr 25, 2024
9515d6e
setting c++ version on python wrapper
K20shores Apr 25, 2024
418d384
maybe this
K20shores Apr 25, 2024
8fe56a2
making fortran work
K20shores Apr 25, 2024
23350f1
adding 20 second test timeout
K20shores Apr 26, 2024
888cd95
excluding fortran tuv tests for mac
K20shores Apr 26, 2024
e10664a
handling merge conflicts
K20shores Apr 26, 2024
d144afc
adding parallel build
K20shores Apr 26, 2024
df13dd6
adding namespace options
K20shores Apr 26, 2024
d95a954
resolving typos, incorrect comments
K20shores Apr 30, 2024
9dd03d7
Update fortran/tuvx_core.F90
K20shores Apr 30, 2024
bee0666
Update fortran/test/fetch_content_integration/test_tuvx_api.F90
K20shores Apr 30, 2024
1add8a5
correcting placement of ifdef for error functions
K20shores Apr 30, 2024
ad51c4b
removing comment
K20shores May 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ jobs:
- name: Run Cmake
run: |
PYTHON_PATH=$(which python)
cmake -S . -B build -D CMAKE_CXX_FLAGS=-Wl,-ld_classic -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D MUSICA_ENABLE_PYTHON_LIBRARY=ON -D Python3_EXECUTABLE=${PYTHON_PATH}
cmake -S . -B build -D CMAKE_CXX_FLAGS=-Wl,-ld_classic -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D MUSICA_ENABLE_PYTHON_LIBRARY=ON -D Python3_EXECUTABLE=$PYTHON_PATH

- name: Build
run: cmake --build build --parallel
run: cmake --build build --verbose --parallel 10

- name: Run tests
run: |
Expand All @@ -63,9 +63,9 @@ jobs:
run: cmake -S . -B build -D CMAKE_CXX_FLAGS=-Wl,-ld_classic -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D MUSICA_BUILD_FORTRAN_INTERFACE=ON

- name: Build
run: cmake --build build --parallel
run: cmake --build build --verbose --parallel 10

- name: Run tests
run: |
cd build
ctest -C ${{ matrix.build_type }} --rerun-failed --output-on-failure . --verbose -j 10
ctest -E "tuvx_c_api|tuvx_fortran_api" -C ${{ matrix.build_type }} --rerun-failed --output-on-failure . --verbose -j 10
4 changes: 2 additions & 2 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D MUSICA_ENABLE_PYTHON_LIBRARY=ON

- name: Build
run: cmake --build build --verbose --parallel
run: cmake --build build --verbose --parallel 10

- name: Run tests
run: |
Expand All @@ -68,7 +68,7 @@ jobs:
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D MUSICA_BUILD_FORTRAN_INTERFACE=ON

- name: Build
run: cmake --build build --parallel
run: cmake --build build --verbose --parallel 10

- name: Run tests
run: |
Expand Down
20 changes: 11 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,30 @@ set(MUSICA_MOD_DIR ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR})
set(MUSICA_LIB_DIR ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(MUSICA_FORTRAN_SRC_DIR ${CMAKE_SOURCE_DIR}/fortran)

set(musica_compile_definitions "")

# Add flags for various compilers
if(${CMAKE_Fortran_COMPILER_ID} MATCHES "Intel")
add_definitions(-DMUSICA_USING_INTEL)
list(APPEND musica_compile_definitions MUSICA_USING_INTEL)
elseif(${CMAKE_Fortran_COMPILER_ID} MATCHES "GNU")
add_definitions(-DMUSICA_USING_GNU)
list(APPEND musica_compile_definitions MUSICA_USING_GNU)
elseif(${CMAKE_Fortran_COMPILER_ID} MATCHES "PGI")
add_definitions(-DMUSICA_USING_PGI)
endif()

# Add flags when using the ClangCL toolset
if(CMAKE_GENERATOR_TOOLSET STREQUAL "ClangCL")
add_definitions(-DMUSICA_USING_CLANGCL)
list(APPEND musica_compile_definitions MUSICA_USING_PGI)
endif()

if(MUSICA_BUILD_C_CXX_INTERFACE)
# must be global so that it also applies to dependencies like google test, unless we want
# to set it for each target
# on ubuntu with clang, an incorrect version of the c++ standard library was being linked
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux" AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# If the compiler is Clang, use libc++
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
endif()

set(CMAKE_CXX_STANDARD 20)
# Add flags when using the ClangCL toolset
if(CMAKE_GENERATOR_TOOLSET STREQUAL "ClangCL")
list(APPEND musica_compile_definitions MUSICA_USING_CLANGCL)
endif()

################################################################################
Expand Down
1 change: 1 addition & 0 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ endif()
# TUV-x

if (MUSICA_ENABLE_TUVX)
set(ENABLE_TESTS OFF CACHE BOOL "" FORCE)
FetchContent_Declare(tuvx
GIT_REPOSITORY https://github.com/NCAR/tuv-x.git
GIT_TAG v0.8.0
Expand Down
1 change: 1 addition & 0 deletions cmake/test_util.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function(add_musica_test test_name test_binary test_args working_dir)
add_test(NAME ${test_name}
COMMAND ${test_binary} ${test_args}
WORKING_DIRECTORY ${working_dir})
set_tests_properties(${test_name} PROPERTIES TIMEOUT 20)
endif()
set(MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1 --trace-children=yes --leak-check=full --gen-suppressions=all ${MEMCHECK_SUPPRESS}")
set(memcheck "${MEMORYCHECK_COMMAND} ${MEMORYCHECK_COMMAND_OPTIONS}")
Expand Down
17 changes: 1 addition & 16 deletions fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,14 @@ target_link_libraries(musica-fortran
target_sources(musica-fortran
PRIVATE
micm_core.F90
util.F90
tuvx_core.F90
)

# Add flags for gfortran
if(${CMAKE_Fortran_COMPILER_ID} MATCHES "GNU")
add_compile_options($<$<COMPILE_LANGUAGE:Fortran>:-ffree-line-length-none>)
endif()

####################
# TUV-x
if (MUSICA_ENABLE_TUVX)
# add the sources to musica
target_sources(musica-fortran
PRIVATE
$<TARGET_OBJECTS:tuvx_object>
)
target_link_libraries(musica-fortran
PUBLIC
tuvx
)
endif()


################################################################################
# testing

Expand Down
5 changes: 3 additions & 2 deletions fortran/micm_core.F90
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module micm_core
module musica_micm_core

use iso_c_binding, only: c_ptr, c_char, c_int, c_bool, c_double, c_null_char, &
c_size_t, c_f_pointer, c_funptr, c_null_ptr, c_associated
use musica_util, only: error_t_c, is_success
Expand Down Expand Up @@ -224,4 +225,4 @@ subroutine finalize(this)
this%ptr = c_null_ptr
end subroutine finalize

end module micm_core
end module musica_micm_core
2 changes: 0 additions & 2 deletions fortran/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
create_standard_test_fortran(NAME musica_fortran_interface SOURCES fetch_content_integration/test_micm_fort_api.F90)
create_standard_test_fortran(NAME musica_fortran_interface_invalid SOURCES fetch_content_integration/test_micm_fort_api_invalid.F90)
add_subdirectory(unit)
21 changes: 11 additions & 10 deletions fortran/test/fetch_content_integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pkg_check_modules(netcdff IMPORTED_TARGET REQUIRED netcdf-fortran)
enable_testing()

# API Test
add_executable(test_micm_fort_api test_micm_fort_api.F90)
add_executable(test_micm_core_api test_micm_api.F90)

target_link_libraries(test_micm_fort_api
PRIVATE
Expand All @@ -46,20 +46,21 @@ add_test(
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)

add_executable(test_micm_fort_api_invalid test_micm_fort_api_invalid.F90)
# API Test
add_executable(test_tuvx_core_api test_tuvx_api.F90)

target_link_libraries(test_micm_fort_api_invalid
target_link_libraries(test_tuvx_fort_api
PRIVATE
musica::musica-fortran
)

add_test(
NAME test_micm_fort_api_invalid
COMMAND $<TARGET_FILE:test_micm_fort_api_invalid>
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)

set_target_properties(test_micm_fort_api_invalid
set_target_properties(test_tuvx_fort_api
PROPERTIES
LINKER_LANGUAGE Fortran
)

add_test(
NAME test_tuvx_fort_api
COMMAND $<TARGET_FILE:test_tuvx_fort_api>
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
131 changes: 131 additions & 0 deletions fortran/test/fetch_content_integration/test_micm_api.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
program combined_micm_tests
use iso_c_binding
use musica_micm_core, only: micm_t, mapping_t
use musica_util, only: assert, error_t_c, is_error, is_success

implicit none

#include "micm/util/error.hpp"

#define ASSERT( expr ) call assert( expr, __FILE__, __LINE__ )
#define ASSERT_EQ( a, b ) call assert( a == b, __FILE__, __LINE__ )
#define ASSERT_NE( a, b ) call assert( a /= b, __FILE__, __LINE__ )

! Declarations
type(micm_t), pointer :: micm
real(c_double) :: time_step
real(c_double) :: temperature
real(c_double) :: pressure
integer(c_int) :: num_concentrations, num_user_defined_reaction_rates
real(c_double), dimension(5) :: concentrations
real(c_double), dimension(3) :: user_defined_reaction_rates
integer :: errcode

! Main program
time_step = 200
temperature = 272.5
pressure = 101253.4
num_concentrations = 5
concentrations = (/ 0.75, 0.4, 0.8, 0.01, 0.02 /)
num_user_defined_reaction_rates = 3
user_defined_reaction_rates = (/ 0.1, 0.2, 0.3 /)

! Call the valid test subroutine
call test_micm_fort_api()

! Call the invalid test subroutine
call test_micm_fort_api_invalid()

contains

! Valid MICM solver creation test
subroutine test_micm_fort_api()
type(mapping_t) :: the_mapping
character(len=:), allocatable :: string_value
real(c_double) :: double_value
integer(c_int) :: int_value
logical(c_bool) :: bool_value
type(error_t_c) :: error
character(len=256) :: config_path
integer :: i

config_path = "configs/chapman"

write(*,*) "[test micm fort api] Creating MICM solver..."
micm => micm_t(config_path, error)
ASSERT( is_success( error ) )

do i = 1, micm%species_ordering_length
the_mapping = micm%species_ordering(i)
print *, "Species Name:", the_mapping%name(:the_mapping%string_length), ", Index:", the_mapping%index
end do
do i = 1, micm%user_defined_reaction_rates_length
the_mapping = micm%user_defined_reaction_rates(i)
print *, "User Defined Reaction Rate Name:", the_mapping%name(:the_mapping%string_length), ", Index:", the_mapping%index
end do

write(*,*) "[test micm fort api] Initial concentrations", concentrations

write(*,*) "[test micm fort api] Solving starts..."
call micm%solve(time_step, temperature, pressure, num_concentrations, concentrations, &
num_user_defined_reaction_rates, user_defined_reaction_rates, error)
ASSERT( is_success( error ) )

write(*,*) "[test micm fort api] After solving, concentrations", concentrations

string_value = micm%get_species_property_string( "O3", "__long name", error )
ASSERT( is_success( error ) )
ASSERT_EQ( string_value, "ozone" )
double_value = micm%get_species_property_double( "O3", "molecular weight [kg mol-1]", error )
ASSERT( is_success( error ) )
ASSERT_EQ( double_value, 0.048_c_double )
int_value = micm%get_species_property_int( "O3", "__atoms", error )
ASSERT( is_success( error ) )
ASSERT_EQ( int_value, 3_c_int )
bool_value = micm%get_species_property_bool( "O3", "__do advect", error )
ASSERT( is_success( error ) )
ASSERT( logical( bool_value ) )

string_value = micm%get_species_property_string( "O3", "missing property", error )
ASSERT( is_error( error, MICM_ERROR_CATEGORY_SPECIES, \
MICM_SPECIES_ERROR_CODE_PROPERTY_NOT_FOUND ) )
double_value = micm%get_species_property_double( "O3", "missing property", error )
ASSERT( is_error( error, MICM_ERROR_CATEGORY_SPECIES, \
MICM_SPECIES_ERROR_CODE_PROPERTY_NOT_FOUND ) )
int_value = micm%get_species_property_int( "O3", "missing property", error )
ASSERT( is_error( error, MICM_ERROR_CATEGORY_SPECIES, \
MICM_SPECIES_ERROR_CODE_PROPERTY_NOT_FOUND ) )
bool_value = micm%get_species_property_bool( "O3", "missing property", error )
ASSERT( is_error( error, MICM_ERROR_CATEGORY_SPECIES, \
MICM_SPECIES_ERROR_CODE_PROPERTY_NOT_FOUND ) )
deallocate( micm )
micm => micm_t( "configs/invalid", error )
ASSERT( is_error( error, MICM_ERROR_CATEGORY_CONFIGURATION, \
MICM_CONFIGURATION_ERROR_CODE_INVALID_FILE_PATH ) )
ASSERT( .not. associated( micm ) )

write(*,*) "[test micm fort api] Finished."

end subroutine test_micm_fort_api

! Invalid MICM solver creation test
subroutine test_micm_fort_api_invalid()
use musica_util, only: error_t_c
use musica_micm_core, only: micm_t

implicit none

type(micm_t), pointer :: micm
character(len=7) :: config_path
type(error_t_c) :: error

config_path = "invalid_config"

write(*,*) "[test micm fort api] Creating MICM solver..."
micm => micm_t(config_path, error)
ASSERT( is_error( error, MICM_ERROR_CATEGORY_CONFIGURATION, \
MICM_CONFIGURATION_ERROR_CODE_INVALID_FILE_PATH ) )

end subroutine test_micm_fort_api_invalid

end program combined_micm_tests