From b157477591c10388001314d022694cfe70b64c80 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Thu, 29 Aug 2024 12:58:08 -0600 Subject: [PATCH 01/10] update tuvx cstor --- .../test_tuvx_api.F90 | 60 +++++++++++++++---- fortran/tuvx/tuvx.F90 | 37 ++++++++---- include/musica/tuvx/tuvx.hpp | 13 +++- src/tuvx/tuvx.cpp | 10 ++-- 4 files changed, 88 insertions(+), 32 deletions(-) diff --git a/fortran/test/fetch_content_integration/test_tuvx_api.F90 b/fortran/test/fetch_content_integration/test_tuvx_api.F90 index 7dfdddff..534e9794 100644 --- a/fortran/test/fetch_content_integration/test_tuvx_api.F90 +++ b/fortran/test/fetch_content_integration/test_tuvx_api.F90 @@ -26,30 +26,57 @@ program combined_tuvx_tests ! Valid tuvx solver creation test subroutine test_tuvx_api() - character(len=256) :: config_path - logical(c_bool) :: bool_value - type(tuvx_t), pointer :: tuvx - type(error_t) :: error - + character(len=256) :: config_path + type(grid_map_t), pointer :: grids + type(profile_map_t), pointer :: profiles + type(radiator_map_t), pointer :: radiators + type(tuvx_t), pointer :: tuvx + type(error_t) :: error config_path = "examples/ts1_tsmlt.json" - tuvx => tuvx_t(config_path, error) + grids => grid_map_t( error ) + ASSERT( error%is_success() ) + + profiles => profile_map_t( error ) + ASSERT( error%is_success() ) + + radiators => radiator_map_t( error ) + ASSERT( error%is_success() ) + + tuvx => tuvx_t(config_path, grids, profiles, radiators, error) ASSERT( error%is_success() ) + deallocate( grids ) + deallocate( profiles ) + deallocate( radiators ) deallocate( tuvx ) end subroutine test_tuvx_api ! Invalid tuvx solver creation test subroutine test_tuvx_api_invalid_config() - type(tuvx_t), pointer :: tuvx - type(error_t) :: error - character(len=256) :: config_path - + character(len=256) :: config_path + type(grid_map_t), pointer :: grids + type(profile_map_t), pointer :: profiles + type(radiator_map_t), pointer :: radiators + type(tuvx_t), pointer :: tuvx + type(error_t) :: error config_path = "invalid_config" - tuvx => tuvx_t(config_path, error) + grids => grid_map_t( error ) + ASSERT( error%is_success() ) + + profiles => profile_map_t( error ) + ASSERT( error%is_success() ) + + radiators => radiator_map_t( error ) + ASSERT( error%is_success() ) + + tuvx => tuvx_t(config_path, grids, profiles, radiators, error) + ASSERT( error%is_success() ) + + tuvx => tuvx_t(config_path, grids, profiles, radiators, error) ASSERT( .not. error%is_success() ) end subroutine test_tuvx_api_invalid_config @@ -89,7 +116,16 @@ subroutine test_tuvx_solve() config_path = "examples/ts1_tsmlt.json" - tuvx => tuvx_t( config_path, error ) + grids => grid_map_t( error ) + ASSERT( error%is_success() ) + + profiles => profile_map_t( error ) + ASSERT( error%is_success() ) + + radiators => radiator_map_t( error ) + ASSERT( error%is_success() ) + + tuvx => tuvx_t(config_path, grids, profiles, radiators, error) ASSERT( error%is_success() ) grids => tuvx%get_grids( error ) ASSERT( error%is_success() ) diff --git a/fortran/tuvx/tuvx.F90 b/fortran/tuvx/tuvx.F90 index 36a58d79..8cb2173c 100644 --- a/fortran/tuvx/tuvx.F90 +++ b/fortran/tuvx/tuvx.F90 @@ -21,12 +21,15 @@ module musica_tuvx !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! interface - function create_tuvx_c(config_path, error) bind(C, name="CreateTuvx") + function create_tuvx_c(config_path, grids, profiles, radiators, error) bind(C, name="CreateTuvx") use musica_util, only: error_t_c use iso_c_binding, only: c_ptr, c_int, c_char - character(len=1, kind=c_char), intent(in) :: config_path(*) - type(error_t_c), intent(inout) :: error - type(c_ptr) :: create_tuvx_c + character(len=1, kind=c_char), intent(in) :: config_path(*) + type(c_ptr), intent(in) :: grids + type(c_ptr), intent(in) :: profiles + type(c_ptr), intent(in) :: radiators + type(error_t_c), intent(inout) :: error + type(c_ptr), :: create_tuvx_c end function create_tuvx_c subroutine delete_tuvx_c(tuvx, error) bind(C, name="DeleteTuvx") @@ -87,18 +90,24 @@ end function get_radiator_map_c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Construct a tuvx instance - function constructor(config_path, error) result( this ) + function constructor(config_path, grids, profiles, radiators, error) result( this ) use iso_c_binding, only: c_char, c_null_char use musica_util, only: error_t_c, error_t ! Arguments - type(error_t), intent(inout) :: error - character(len=*), intent(in) :: config_path + character(len=*), intent(in) :: config_path + type(grid_map_t), intent(in) :: grids + type(profile_map_t), intent(in) :: profiles + type(radiator_map_t), intent(in) :: radiators + type(error_t), intent(inout) :: error ! Local variables - character(len=1, kind=c_char) :: c_config_path(len_trim(config_path)+1) - integer :: n, i + character(len=1, kind=c_char) :: config_path_c(len_trim(config_path)+1) + type(c_ptr) :: grids_c + type(c_ptr) :: profiles_c + type(c_ptr) :: radiators_c type(error_t_c) :: error_c + integer :: n, i ! Return value type(tuvx_t), pointer :: this @@ -107,11 +116,15 @@ function constructor(config_path, error) result( this ) n = len_trim(config_path) do i = 1, n - c_config_path(i) = config_path(i:i) + config_path_c(i) = config_path(i:i) end do - c_config_path(n+1) = c_null_char + config_path_c(n+1) = c_null_char + + grids_c = c_loc(grids) + profiles_c = c_loc(profiles) + radiators_c = c_loc(radiators) - this%ptr_ = create_tuvx_c(c_config_path, error_c) + this%ptr_ = create_tuvx_c(config_path_c, grids_c, profiles_c, radiators_c, error_c) error = error_t(error_c) if (.not. error%is_success()) then diff --git a/include/musica/tuvx/tuvx.hpp b/include/musica/tuvx/tuvx.hpp index bd862fde..08920431 100644 --- a/include/musica/tuvx/tuvx.hpp +++ b/include/musica/tuvx/tuvx.hpp @@ -24,8 +24,9 @@ namespace musica /// @brief Create an instance of tuvx from a configuration file /// @param config_path Path to configuration file + /// @param TODO(jiwon) /// @param error Error struct to indicate success or failure - void Create(const char *config_path, Error *error); + void Create(const char *config_path, GridMap *grids, ProfileMap *profiles, RadiatorMap *radiators, Error *error); /// @brief Create a grid map. For now, this calls the interal tuvx fortran api, but will allow the change to c++ later on /// to be transparent to downstream projects @@ -58,7 +59,7 @@ namespace musica // The external C API for TUVX // callable by wrappers in other languages - TUVX *CreateTuvx(const char *config_path, Error *error); + TUVX *CreateTuvx(const char *config_path, GridMap *grids, ProfileMap *profiles, RadiatorMap *radiators, Error *error); void DeleteTuvx(const TUVX *tuvx, Error *error); GridMap *GetGridMap(TUVX *tuvx, Error *error); ProfileMap *GetProfileMap(TUVX *tuvx, Error *error); @@ -67,7 +68,13 @@ namespace musica // for use by musica interanlly. If tuvx ever gets rewritten in C++, these functions will // go away but the C API will remain the same and downstream projects (like CAM-SIMA) will // not need to change - void *InternalCreateTuvx(const char *config_path, std::size_t config_path_length, int *error_code); + void *InternalCreateTuvx( + const char *config_path, + std::size_t config_path_length, + GridMap *grids, + ProfileMap *profiles, + RadiatorMap *radiators, + int *error_code); void InternalDeleteTuvx(void *tuvx, int *error_code); void *InternalGetGridMap(void *tuvx, int *error_code); void *InternalGetProfileMap(void *tuvx, int *error_code); diff --git a/src/tuvx/tuvx.cpp b/src/tuvx/tuvx.cpp index 9abd977d..83e11bd9 100644 --- a/src/tuvx/tuvx.cpp +++ b/src/tuvx/tuvx.cpp @@ -13,12 +13,12 @@ namespace musica { // TUVX external C API functions - - TUVX *CreateTuvx(const char *config_path, Error *error) + TUVX *CreateTuvx(const char *config_path, GridMap *grids, ProfileMap *profiles, RadiatorMap *radiators, Error *error) { DeleteError(error); TUVX *tuvx = new TUVX(); - tuvx->Create(config_path, error); + + tuvx->Create(config_path, grids, profiles, radiators, error); if (!IsSuccess(*error)) { delete tuvx; @@ -79,7 +79,7 @@ namespace musica tuvx_ = nullptr; } - void TUVX::Create(const char *config_path, Error *error) + void TUVX::Create(const char *config_path, GridMap *grids, ProfileMap *profiles, RadiatorMap *radiators, Error *error) { int parsing_status = 0; // 0 on success, 1 on failure try @@ -91,7 +91,7 @@ namespace musica return; } - tuvx_ = InternalCreateTuvx(config_path, strlen(config_path), &parsing_status); + tuvx_ = InternalCreateTuvx(config_path, strlen(config_path), grids, profiles, radiators, &parsing_status); if (parsing_status == 1) { *error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to create tuvx instance") }; From 0cce5c274c99c800dba96a30e59d52ece151b223 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Thu, 29 Aug 2024 13:01:49 -0600 Subject: [PATCH 02/10] git stash --- CMakeLists.txt | 2 +- docker/Dockerfile | 1 + .../test_tuvx_api.F90 | 7 +- src/test/unit/tuvx/tuvx_c_api.cpp | 1269 +++++++++-------- src/tuvx/interface.F90 | 4 +- src/tuvx/tuvx.cpp | 1 + 6 files changed, 654 insertions(+), 630 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d416647e..0ed5dc85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ option(MUSICA_ENABLE_MPI "Enable MPI parallel support" OFF) option(MUSICA_ENABLE_OPENMP "Enable OpemMP support" OFF) option(MUSICA_ENABLE_MEMCHECK "Enable memory checking" OFF) option(MUSICA_BUILD_DOCS "Build the documentation" OFF) -option(MUSICA_ENABLE_MICM "Enable MICM" ON) +option(MUSICA_ENABLE_MICM "Enable MICM" OFF) option(MUSICA_ENABLE_TUVX "Enable TUV-x" ON) set(MUSICA_SET_MICM_VECTOR_MATRIX_SIZE "1" CACHE STRING "Set MICM vector-ordered matrix dimension") diff --git a/docker/Dockerfile b/docker/Dockerfile index 31f319f2..bc5f01db 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -15,6 +15,7 @@ RUN dnf -y update \ json-devel \ python \ valgrind \ + tree \ && dnf clean all # Copy the musica code diff --git a/fortran/test/fetch_content_integration/test_tuvx_api.F90 b/fortran/test/fetch_content_integration/test_tuvx_api.F90 index 534e9794..d32e4b8e 100644 --- a/fortran/test/fetch_content_integration/test_tuvx_api.F90 +++ b/fortran/test/fetch_content_integration/test_tuvx_api.F90 @@ -118,15 +118,16 @@ subroutine test_tuvx_solve() grids => grid_map_t( error ) ASSERT( error%is_success() ) - profiles => profile_map_t( error ) ASSERT( error%is_success() ) - radiators => radiator_map_t( error ) ASSERT( error%is_success() ) - tuvx => tuvx_t(config_path, grids, profiles, radiators, error) ASSERT( error%is_success() ) + + !!!! + !!!! Jiwon + !!!! grids => tuvx%get_grids( error ) ASSERT( error%is_success() ) diff --git a/src/test/unit/tuvx/tuvx_c_api.cpp b/src/test/unit/tuvx/tuvx_c_api.cpp index 91dbbc93..dc43d9f1 100644 --- a/src/test/unit/tuvx/tuvx_c_api.cpp +++ b/src/test/unit/tuvx/tuvx_c_api.cpp @@ -9,17 +9,29 @@ class TuvxCApiTest : public ::testing::Test { protected: TUVX* tuvx; + GridMap* grids; + ProfileMap* profiles; + RadiatorMap* radiators; // the function that google test actually calls before each test void SetUp() override { tuvx = nullptr; + grids = nullptr; + profiles = nullptr; + radiators = nullptr; } void SetUp(const char* config_path) { Error error; - tuvx = CreateTuvx(config_path, &error); + grids = CreateGridMap(&error); + ASSERT_TRUE(IsSuccess(error)); + profiles = CreateProfileMap(&error); + ASSERT_TRUE(IsSuccess(error)); + radiators = CreateRadiatorMap(&error); + ASSERT_TRUE(IsSuccess(error)); + tuvx = CreateTuvx(config_path, grids, profiles, radiators, &error); if (!IsSuccess(error)) { std::cerr << "Error creating TUVX instance: " << error.message_.value_ << std::endl; @@ -35,6 +47,12 @@ class TuvxCApiTest : public ::testing::Test return; } Error error; + DeleteGridMap(grids, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteProfileMap(profiles, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteRadiatorMap(radiators, &error); + ASSERT_TRUE(IsSuccess(error)); DeleteTuvx(tuvx, &error); ASSERT_TRUE(IsSuccess(error)); DeleteError(&error); @@ -60,7 +78,10 @@ TEST_F(TuvxCApiTest, DetectsNonexistentConfigFile) { const char* config_path = "nonexisting.yml"; Error error; - TUVX* tuvx = CreateTuvx(config_path, &error); + GridMap* grids = CreateGridMap(&error); + ProfileMap* profiles = CreateProfileMap(&error); + RadiatorMap* radiators = CreateRadiatorMap(&error); + TUVX* tuvx = CreateTuvx(config_path, grids, profiles, radiators, &error); ASSERT_FALSE(IsSuccess(error)); DeleteError(&error); } @@ -81,644 +102,644 @@ TEST_F(TuvxCApiTest, CannotGetConfiguredGrid) DeleteError(&error); } -TEST_F(TuvxCApiTest, CanCreateGrid) -{ - Error error; - Grid* grid = CreateGrid("foo", "m", 2, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(grid, nullptr); - std::vector edges = { 0.0, 100.0, 200.0 }; - SetGridEdges(grid, edges.data(), edges.size(), &error); - ASSERT_TRUE(IsSuccess(error)); - for (auto& edge : edges) - { - edge = -100.0; - } - GetGridEdges(grid, edges.data(), edges.size(), &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(edges[0], 0.0); - ASSERT_EQ(edges[1], 100.0); - ASSERT_EQ(edges[2], 200.0); - std::vector midpoints = { 50.0, 150.0 }; - SetGridMidpoints(grid, midpoints.data(), midpoints.size(), &error); - ASSERT_TRUE(IsSuccess(error)); - for (auto& midpoint : midpoints) - { - midpoint = -100.0; - } - GetGridMidpoints(grid, midpoints.data(), midpoints.size(), &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(midpoints[0], 50.0); - ASSERT_EQ(midpoints[1], 150.0); - DeleteGrid(grid, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteError(&error); -} +// TEST_F(TuvxCApiTest, CanCreateGrid) +// { +// Error error; +// Grid* grid = CreateGrid("foo", "m", 2, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(grid, nullptr); +// std::vector edges = { 0.0, 100.0, 200.0 }; +// SetGridEdges(grid, edges.data(), edges.size(), &error); +// ASSERT_TRUE(IsSuccess(error)); +// for (auto& edge : edges) +// { +// edge = -100.0; +// } +// GetGridEdges(grid, edges.data(), edges.size(), &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(edges[0], 0.0); +// ASSERT_EQ(edges[1], 100.0); +// ASSERT_EQ(edges[2], 200.0); +// std::vector midpoints = { 50.0, 150.0 }; +// SetGridMidpoints(grid, midpoints.data(), midpoints.size(), &error); +// ASSERT_TRUE(IsSuccess(error)); +// for (auto& midpoint : midpoints) +// { +// midpoint = -100.0; +// } +// GetGridMidpoints(grid, midpoints.data(), midpoints.size(), &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(midpoints[0], 50.0); +// ASSERT_EQ(midpoints[1], 150.0); +// DeleteGrid(grid, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteError(&error); +// } -TEST_F(TuvxCApiTest, CanCreateGridMap) -{ - Error error; - GridMap* grid_map = CreateGridMap(&error); - ASSERT_TRUE(IsSuccess(error)); - Grid* foo_grid = CreateGrid("foo", "m", 2, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(foo_grid, nullptr); - AddGrid(grid_map, foo_grid, &error); - ASSERT_TRUE(IsSuccess(error)); - Grid* bar_grid = CreateGrid("bar", "m", 3, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(bar_grid, nullptr); - AddGrid(grid_map, bar_grid, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(grid_map, nullptr); - double edge_values[] = { 0.0, 1.0, 2.0 }; - double midpoint_values[] = { 0.5, 1.5 }; - SetGridEdges(foo_grid, edge_values, 3, &error); - SetGridMidpoints(foo_grid, midpoint_values, 2, &error); - ASSERT_TRUE(IsSuccess(error)); - for (auto& edge : edge_values) - { - edge = -100.0; - } - for (auto& midpoint : midpoint_values) - { - midpoint = -100.0; - } - GetGridEdges(foo_grid, edge_values, 3, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(edge_values[0], 0.0); - ASSERT_EQ(edge_values[1], 1.0); - ASSERT_EQ(edge_values[2], 2.0); - GetGridMidpoints(foo_grid, midpoint_values, 2, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(midpoint_values[0], 0.5); - ASSERT_EQ(midpoint_values[1], 1.5); - Grid* foo_copy = GetGrid(grid_map, "foo", "m", &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(foo_copy, nullptr); - for (auto& edge : edge_values) - { - edge = -100.0; - } - for (auto& midpoint : midpoint_values) - { - midpoint = -100.0; - } - GetGridEdges(foo_copy, edge_values, 3, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(edge_values[0], 0.0); - ASSERT_EQ(edge_values[1], 1.0); - ASSERT_EQ(edge_values[2], 2.0); - GetGridMidpoints(foo_copy, midpoint_values, 2, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(midpoint_values[0], 0.5); - ASSERT_EQ(midpoint_values[1], 1.5); - DeleteGrid(foo_grid, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteGrid(bar_grid, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteGrid(foo_copy, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteGridMap(grid_map, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteError(&error); -} +// TEST_F(TuvxCApiTest, CanCreateGridMap) +// { +// Error error; +// GridMap* grid_map = CreateGridMap(&error); +// ASSERT_TRUE(IsSuccess(error)); +// Grid* foo_grid = CreateGrid("foo", "m", 2, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(foo_grid, nullptr); +// AddGrid(grid_map, foo_grid, &error); +// ASSERT_TRUE(IsSuccess(error)); +// Grid* bar_grid = CreateGrid("bar", "m", 3, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(bar_grid, nullptr); +// AddGrid(grid_map, bar_grid, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(grid_map, nullptr); +// double edge_values[] = { 0.0, 1.0, 2.0 }; +// double midpoint_values[] = { 0.5, 1.5 }; +// SetGridEdges(foo_grid, edge_values, 3, &error); +// SetGridMidpoints(foo_grid, midpoint_values, 2, &error); +// ASSERT_TRUE(IsSuccess(error)); +// for (auto& edge : edge_values) +// { +// edge = -100.0; +// } +// for (auto& midpoint : midpoint_values) +// { +// midpoint = -100.0; +// } +// GetGridEdges(foo_grid, edge_values, 3, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(edge_values[0], 0.0); +// ASSERT_EQ(edge_values[1], 1.0); +// ASSERT_EQ(edge_values[2], 2.0); +// GetGridMidpoints(foo_grid, midpoint_values, 2, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(midpoint_values[0], 0.5); +// ASSERT_EQ(midpoint_values[1], 1.5); +// Grid* foo_copy = GetGrid(grid_map, "foo", "m", &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(foo_copy, nullptr); +// for (auto& edge : edge_values) +// { +// edge = -100.0; +// } +// for (auto& midpoint : midpoint_values) +// { +// midpoint = -100.0; +// } +// GetGridEdges(foo_copy, edge_values, 3, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(edge_values[0], 0.0); +// ASSERT_EQ(edge_values[1], 1.0); +// ASSERT_EQ(edge_values[2], 2.0); +// GetGridMidpoints(foo_copy, midpoint_values, 2, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(midpoint_values[0], 0.5); +// ASSERT_EQ(midpoint_values[1], 1.5); +// DeleteGrid(foo_grid, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteGrid(bar_grid, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteGrid(foo_copy, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteGridMap(grid_map, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteError(&error); +// } -TEST_F(TuvxCApiTest, CannotGetConfiguredProfile) -{ - const char* yaml_config_path = "examples/ts1_tsmlt.yml"; - SetUp(yaml_config_path); - Error error; - ProfileMap* profile_map = GetProfileMap(tuvx, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(profile_map, nullptr); - Profile* profile = GetProfile(profile_map, "air", "molecule cm-3", &error); - ASSERT_FALSE(IsSuccess(error)); // non-host profile - ASSERT_EQ(profile, nullptr); - DeleteProfileMap(profile_map, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteError(&error); -} +// TEST_F(TuvxCApiTest, CannotGetConfiguredProfile) +// { +// const char* yaml_config_path = "examples/ts1_tsmlt.yml"; +// SetUp(yaml_config_path); +// Error error; +// ProfileMap* profile_map = GetProfileMap(tuvx, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(profile_map, nullptr); +// Profile* profile = GetProfile(profile_map, "air", "molecule cm-3", &error); +// ASSERT_FALSE(IsSuccess(error)); // non-host profile +// ASSERT_EQ(profile, nullptr); +// DeleteProfileMap(profile_map, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteError(&error); +// } -TEST_F(TuvxCApiTest, CanCreateProfile) -{ - Error error; - Grid* grid = CreateGrid("foo", "m", 2, &error); - ASSERT_TRUE(IsSuccess(error)); - Profile* profile = CreateProfile("bar", "molecule cm-3", grid, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(profile, nullptr); - std::vector edge_values = { 0.0, 1.0, 2.0 }; - SetProfileEdgeValues(profile, edge_values.data(), edge_values.size(), &error); - ASSERT_TRUE(IsSuccess(error)); - for (auto& edge : edge_values) - { - edge = -100.0; - } - GetProfileEdgeValues(profile, edge_values.data(), edge_values.size(), &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(edge_values[0], 0.0); - ASSERT_EQ(edge_values[1], 1.0); - ASSERT_EQ(edge_values[2], 2.0); - std::vector midpoint_values = { 0.5, 1.5 }; - SetProfileMidpointValues(profile, midpoint_values.data(), midpoint_values.size(), &error); - ASSERT_TRUE(IsSuccess(error)); - for (auto& midpoint : midpoint_values) - { - midpoint = -100.0; - } - GetProfileMidpointValues(profile, midpoint_values.data(), midpoint_values.size(), &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(midpoint_values[0], 0.5); - ASSERT_EQ(midpoint_values[1], 1.5); - std::vector densities = { 1.0, 2.0 }; - SetProfileLayerDensities(profile, densities.data(), densities.size(), &error); - ASSERT_TRUE(IsSuccess(error)); - for (auto& density : densities) - { - density = -100.0; - } - GetProfileLayerDensities(profile, densities.data(), densities.size(), &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(densities[0], 1.0); - ASSERT_EQ(densities[1], 2.0); - SetProfileExoLayerDensity(profile, 3.0, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(GetProfileExoLayerDensity(profile, &error), 3.0); - GetProfileLayerDensities(profile, densities.data(), densities.size(), &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(densities[0], 1.0); - ASSERT_EQ(densities[1], 2.0 + 3.0); - CalculateProfileExoLayerDensity(profile, 1.0, &error); - ASSERT_TRUE(IsSuccess(error)); - // This should be updated once we do all conversions to/from non-SI units - // in the internal TUV-x functions - ASSERT_EQ(GetProfileExoLayerDensity(profile, &error), 200.0); - GetProfileLayerDensities(profile, densities.data(), densities.size(), &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(densities[0], 1.0); - // This should be updated once we do all conversions to/from non-SI units - // in the internal TUV-x functions - ASSERT_EQ(densities[1], 2.0 + 200.0); - DeleteProfile(profile, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteGrid(grid, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteError(&error); -} +// TEST_F(TuvxCApiTest, CanCreateProfile) +// { +// Error error; +// Grid* grid = CreateGrid("foo", "m", 2, &error); +// ASSERT_TRUE(IsSuccess(error)); +// Profile* profile = CreateProfile("bar", "molecule cm-3", grid, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(profile, nullptr); +// std::vector edge_values = { 0.0, 1.0, 2.0 }; +// SetProfileEdgeValues(profile, edge_values.data(), edge_values.size(), &error); +// ASSERT_TRUE(IsSuccess(error)); +// for (auto& edge : edge_values) +// { +// edge = -100.0; +// } +// GetProfileEdgeValues(profile, edge_values.data(), edge_values.size(), &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(edge_values[0], 0.0); +// ASSERT_EQ(edge_values[1], 1.0); +// ASSERT_EQ(edge_values[2], 2.0); +// std::vector midpoint_values = { 0.5, 1.5 }; +// SetProfileMidpointValues(profile, midpoint_values.data(), midpoint_values.size(), &error); +// ASSERT_TRUE(IsSuccess(error)); +// for (auto& midpoint : midpoint_values) +// { +// midpoint = -100.0; +// } +// GetProfileMidpointValues(profile, midpoint_values.data(), midpoint_values.size(), &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(midpoint_values[0], 0.5); +// ASSERT_EQ(midpoint_values[1], 1.5); +// std::vector densities = { 1.0, 2.0 }; +// SetProfileLayerDensities(profile, densities.data(), densities.size(), &error); +// ASSERT_TRUE(IsSuccess(error)); +// for (auto& density : densities) +// { +// density = -100.0; +// } +// GetProfileLayerDensities(profile, densities.data(), densities.size(), &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(densities[0], 1.0); +// ASSERT_EQ(densities[1], 2.0); +// SetProfileExoLayerDensity(profile, 3.0, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(GetProfileExoLayerDensity(profile, &error), 3.0); +// GetProfileLayerDensities(profile, densities.data(), densities.size(), &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(densities[0], 1.0); +// ASSERT_EQ(densities[1], 2.0 + 3.0); +// CalculateProfileExoLayerDensity(profile, 1.0, &error); +// ASSERT_TRUE(IsSuccess(error)); +// // This should be updated once we do all conversions to/from non-SI units +// // in the internal TUV-x functions +// ASSERT_EQ(GetProfileExoLayerDensity(profile, &error), 200.0); +// GetProfileLayerDensities(profile, densities.data(), densities.size(), &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(densities[0], 1.0); +// // This should be updated once we do all conversions to/from non-SI units +// // in the internal TUV-x functions +// ASSERT_EQ(densities[1], 2.0 + 200.0); +// DeleteProfile(profile, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteGrid(grid, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteError(&error); +// } -TEST_F(TuvxCApiTest, CanCreateProfileMap) -{ - Error error; - ProfileMap* profile_map = CreateProfileMap(&error); - ASSERT_TRUE(IsSuccess(error)); - Grid* foo_grid = CreateGrid("foo", "m", 2, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(foo_grid, nullptr); - Profile* foo_profile = CreateProfile("foo", "molecule cm-3", foo_grid, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(foo_profile, nullptr); - AddProfile(profile_map, foo_profile, &error); - ASSERT_TRUE(IsSuccess(error)); - Grid* bar_grid = CreateGrid("bar", "m", 3, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(bar_grid, nullptr); - Profile* bar_profile = CreateProfile("bar", "molecule cm-3", bar_grid, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(bar_profile, nullptr); - AddProfile(profile_map, bar_profile, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(profile_map, nullptr); - double edge_values[] = { 0.0, 1.0, 2.0 }; - double midpoint_values[] = { 0.5, 1.5 }; - SetProfileEdgeValues(foo_profile, edge_values, 3, &error); - SetProfileMidpointValues(foo_profile, midpoint_values, 2, &error); - ASSERT_TRUE(IsSuccess(error)); - for (auto& edge : edge_values) - { - edge = -100.0; - } - for (auto& midpoint : midpoint_values) - { - midpoint = -100.0; - } - GetProfileEdgeValues(foo_profile, edge_values, 3, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(edge_values[0], 0.0); - ASSERT_EQ(edge_values[1], 1.0); - ASSERT_EQ(edge_values[2], 2.0); - GetProfileMidpointValues(foo_profile, midpoint_values, 2, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(midpoint_values[0], 0.5); - ASSERT_EQ(midpoint_values[1], 1.5); - Profile* foo_copy = GetProfile(profile_map, "foo", "molecule cm-3", &error); - for (auto& edge : edge_values) - { - edge = -100.0; - } - for (auto& midpoint : midpoint_values) - { - midpoint = -100.0; - } - GetProfileEdgeValues(foo_copy, edge_values, 3, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(edge_values[0], 0.0); - ASSERT_EQ(edge_values[1], 1.0); - ASSERT_EQ(edge_values[2], 2.0); - GetProfileMidpointValues(foo_copy, midpoint_values, 2, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(midpoint_values[0], 0.5); - ASSERT_EQ(midpoint_values[1], 1.5); - edge_values[0] = 5.0; - edge_values[1] = 10.0; - edge_values[2] = 20.0; - midpoint_values[0] = 7.5; - midpoint_values[1] = 15.0; - SetProfileEdgeValues(foo_copy, edge_values, 3, &error); - SetProfileMidpointValues(foo_copy, midpoint_values, 2, &error); - ASSERT_TRUE(IsSuccess(error)); - for (auto& edge : edge_values) - { - edge = -100.0; - } - for (auto& midpoint : midpoint_values) - { - midpoint = -100.0; - } - GetProfileEdgeValues(foo_copy, edge_values, 3, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(edge_values[0], 5.0); - ASSERT_EQ(edge_values[1], 10.0); - ASSERT_EQ(edge_values[2], 20.0); - GetProfileMidpointValues(foo_copy, midpoint_values, 2, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(midpoint_values[0], 7.5); - ASSERT_EQ(midpoint_values[1], 15.0); - for (auto& edge : edge_values) - { - edge = -100.0; - } - for (auto& midpoint : midpoint_values) - { - midpoint = -100.0; - } - GetProfileEdgeValues(foo_profile, edge_values, 3, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(edge_values[0], 5.0); - ASSERT_EQ(edge_values[1], 10.0); - ASSERT_EQ(edge_values[2], 20.0); - GetProfileMidpointValues(foo_profile, midpoint_values, 2, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(midpoint_values[0], 7.5); - ASSERT_EQ(midpoint_values[1], 15.0); - DeleteProfile(foo_profile, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteProfile(bar_profile, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteProfile(foo_copy, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteGrid(foo_grid, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteGrid(bar_grid, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteProfileMap(profile_map, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteError(&error); -} +// TEST_F(TuvxCApiTest, CanCreateProfileMap) +// { +// Error error; +// ProfileMap* profile_map = CreateProfileMap(&error); +// ASSERT_TRUE(IsSuccess(error)); +// Grid* foo_grid = CreateGrid("foo", "m", 2, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(foo_grid, nullptr); +// Profile* foo_profile = CreateProfile("foo", "molecule cm-3", foo_grid, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(foo_profile, nullptr); +// AddProfile(profile_map, foo_profile, &error); +// ASSERT_TRUE(IsSuccess(error)); +// Grid* bar_grid = CreateGrid("bar", "m", 3, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(bar_grid, nullptr); +// Profile* bar_profile = CreateProfile("bar", "molecule cm-3", bar_grid, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(bar_profile, nullptr); +// AddProfile(profile_map, bar_profile, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(profile_map, nullptr); +// double edge_values[] = { 0.0, 1.0, 2.0 }; +// double midpoint_values[] = { 0.5, 1.5 }; +// SetProfileEdgeValues(foo_profile, edge_values, 3, &error); +// SetProfileMidpointValues(foo_profile, midpoint_values, 2, &error); +// ASSERT_TRUE(IsSuccess(error)); +// for (auto& edge : edge_values) +// { +// edge = -100.0; +// } +// for (auto& midpoint : midpoint_values) +// { +// midpoint = -100.0; +// } +// GetProfileEdgeValues(foo_profile, edge_values, 3, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(edge_values[0], 0.0); +// ASSERT_EQ(edge_values[1], 1.0); +// ASSERT_EQ(edge_values[2], 2.0); +// GetProfileMidpointValues(foo_profile, midpoint_values, 2, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(midpoint_values[0], 0.5); +// ASSERT_EQ(midpoint_values[1], 1.5); +// Profile* foo_copy = GetProfile(profile_map, "foo", "molecule cm-3", &error); +// for (auto& edge : edge_values) +// { +// edge = -100.0; +// } +// for (auto& midpoint : midpoint_values) +// { +// midpoint = -100.0; +// } +// GetProfileEdgeValues(foo_copy, edge_values, 3, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(edge_values[0], 0.0); +// ASSERT_EQ(edge_values[1], 1.0); +// ASSERT_EQ(edge_values[2], 2.0); +// GetProfileMidpointValues(foo_copy, midpoint_values, 2, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(midpoint_values[0], 0.5); +// ASSERT_EQ(midpoint_values[1], 1.5); +// edge_values[0] = 5.0; +// edge_values[1] = 10.0; +// edge_values[2] = 20.0; +// midpoint_values[0] = 7.5; +// midpoint_values[1] = 15.0; +// SetProfileEdgeValues(foo_copy, edge_values, 3, &error); +// SetProfileMidpointValues(foo_copy, midpoint_values, 2, &error); +// ASSERT_TRUE(IsSuccess(error)); +// for (auto& edge : edge_values) +// { +// edge = -100.0; +// } +// for (auto& midpoint : midpoint_values) +// { +// midpoint = -100.0; +// } +// GetProfileEdgeValues(foo_copy, edge_values, 3, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(edge_values[0], 5.0); +// ASSERT_EQ(edge_values[1], 10.0); +// ASSERT_EQ(edge_values[2], 20.0); +// GetProfileMidpointValues(foo_copy, midpoint_values, 2, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(midpoint_values[0], 7.5); +// ASSERT_EQ(midpoint_values[1], 15.0); +// for (auto& edge : edge_values) +// { +// edge = -100.0; +// } +// for (auto& midpoint : midpoint_values) +// { +// midpoint = -100.0; +// } +// GetProfileEdgeValues(foo_profile, edge_values, 3, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(edge_values[0], 5.0); +// ASSERT_EQ(edge_values[1], 10.0); +// ASSERT_EQ(edge_values[2], 20.0); +// GetProfileMidpointValues(foo_profile, midpoint_values, 2, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(midpoint_values[0], 7.5); +// ASSERT_EQ(midpoint_values[1], 15.0); +// DeleteProfile(foo_profile, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteProfile(bar_profile, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteProfile(foo_copy, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteGrid(foo_grid, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteGrid(bar_grid, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteProfileMap(profile_map, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteError(&error); +// } -TEST_F(TuvxCApiTest, CannotGetConfiguredRadiator) -{ - const char* yaml_config_path = "examples/ts1_tsmlt.yml"; - SetUp(yaml_config_path); - Error error; - RadiatorMap* radiator_map = GetRadiatorMap(tuvx, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(radiator_map, nullptr); - Radiator* radiator = GetRadiator(radiator_map, "foo", &error); - ASSERT_FALSE(IsSuccess(error)); // non-host grid - ASSERT_EQ(radiator, nullptr); - DeleteRadiatorMap(radiator_map, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteError(&error); -} +// TEST_F(TuvxCApiTest, CannotGetConfiguredRadiator) +// { +// const char* yaml_config_path = "examples/ts1_tsmlt.yml"; +// SetUp(yaml_config_path); +// Error error; +// RadiatorMap* radiator_map = GetRadiatorMap(tuvx, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(radiator_map, nullptr); +// Radiator* radiator = GetRadiator(radiator_map, "foo", &error); +// ASSERT_FALSE(IsSuccess(error)); // non-host grid +// ASSERT_EQ(radiator, nullptr); +// DeleteRadiatorMap(radiator_map, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteError(&error); +// } -TEST_F(TuvxCApiTest, CanCreateRadiator) -{ - Error error; - Grid* height = CreateGrid("height", "km", 3, &error); - Grid* wavelength = CreateGrid("wavelength", "nm", 2, &error); - Radiator* radiator = CreateRadiator("foo", height, wavelength, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(radiator, nullptr); +// TEST_F(TuvxCApiTest, CanCreateRadiator) +// { +// Error error; +// Grid* height = CreateGrid("height", "km", 3, &error); +// Grid* wavelength = CreateGrid("wavelength", "nm", 2, &error); +// Radiator* radiator = CreateRadiator("foo", height, wavelength, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(radiator, nullptr); - // Test for optical depths - std::size_t num_vertical_layers = 3; - std::size_t num_wavelength_bins = 2; - // Allocate array as 1D - double* optical_depths_1D = new double[num_wavelength_bins * num_vertical_layers]; - // Allocate an array of pointers to each row - double** optical_depths = new double*[num_vertical_layers]; - // Fill in the pointers to the rows - for (int row = 0; row < num_vertical_layers; row++) - { - optical_depths[row] = &optical_depths_1D[row * num_wavelength_bins]; - } - int i = 1; - for (int row = 0; row < num_vertical_layers; row++) - { - for (int col = 0; col < num_wavelength_bins; col++) - { - optical_depths[row][col] = 10 * i; - i++; - } - } - SetRadiatorOpticalDepths(radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); - ASSERT_TRUE(IsSuccess(error)); - for (int row = 0; row < num_vertical_layers; row++) - { - for (int col = 0; col < num_wavelength_bins; col++) - { - optical_depths[row][col] = -999.0; - } - } - GetRadiatorOpticalDepths(radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(optical_depths[0][0], 10.0); - ASSERT_EQ(optical_depths[0][1], 20.0); - ASSERT_EQ(optical_depths[1][0], 30.0); - ASSERT_EQ(optical_depths[1][1], 40.0); - ASSERT_EQ(optical_depths[2][0], 50.0); - ASSERT_EQ(optical_depths[2][1], 60.0); +// // Test for optical depths +// std::size_t num_vertical_layers = 3; +// std::size_t num_wavelength_bins = 2; +// // Allocate array as 1D +// double* optical_depths_1D = new double[num_wavelength_bins * num_vertical_layers]; +// // Allocate an array of pointers to each row +// double** optical_depths = new double*[num_vertical_layers]; +// // Fill in the pointers to the rows +// for (int row = 0; row < num_vertical_layers; row++) +// { +// optical_depths[row] = &optical_depths_1D[row * num_wavelength_bins]; +// } +// int i = 1; +// for (int row = 0; row < num_vertical_layers; row++) +// { +// for (int col = 0; col < num_wavelength_bins; col++) +// { +// optical_depths[row][col] = 10 * i; +// i++; +// } +// } +// SetRadiatorOpticalDepths(radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); +// ASSERT_TRUE(IsSuccess(error)); +// for (int row = 0; row < num_vertical_layers; row++) +// { +// for (int col = 0; col < num_wavelength_bins; col++) +// { +// optical_depths[row][col] = -999.0; +// } +// } +// GetRadiatorOpticalDepths(radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(optical_depths[0][0], 10.0); +// ASSERT_EQ(optical_depths[0][1], 20.0); +// ASSERT_EQ(optical_depths[1][0], 30.0); +// ASSERT_EQ(optical_depths[1][1], 40.0); +// ASSERT_EQ(optical_depths[2][0], 50.0); +// ASSERT_EQ(optical_depths[2][1], 60.0); - // Test for single scattering albedos - double* albedos_1D = new double[num_wavelength_bins * num_vertical_layers]; - double** albedos = new double*[num_vertical_layers]; - for (int row = 0; row < num_vertical_layers; row++) - { - albedos[row] = &albedos_1D[row * num_wavelength_bins]; - } - i = 1; - for (int row = 0; row < num_vertical_layers; row++) - { - for (int col = 0; col < num_wavelength_bins; col++) - { - albedos[row][col] = 100 * i; - i++; - } - } - SetRadiatorSingleScatteringAlbedos(radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); - ASSERT_TRUE(IsSuccess(error)); - for (int row = 0; row < num_vertical_layers; row++) - { - for (int col = 0; col < num_wavelength_bins; col++) - { - albedos[row][col] = -999.0; - } - } - GetRadiatorSingleScatteringAlbedos(radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(albedos[0][0], 100.0); - ASSERT_EQ(albedos[0][1], 200.0); - ASSERT_EQ(albedos[1][0], 300.0); - ASSERT_EQ(albedos[1][1], 400.0); - ASSERT_EQ(albedos[2][0], 500.0); - ASSERT_EQ(albedos[2][1], 600.0); +// // Test for single scattering albedos +// double* albedos_1D = new double[num_wavelength_bins * num_vertical_layers]; +// double** albedos = new double*[num_vertical_layers]; +// for (int row = 0; row < num_vertical_layers; row++) +// { +// albedos[row] = &albedos_1D[row * num_wavelength_bins]; +// } +// i = 1; +// for (int row = 0; row < num_vertical_layers; row++) +// { +// for (int col = 0; col < num_wavelength_bins; col++) +// { +// albedos[row][col] = 100 * i; +// i++; +// } +// } +// SetRadiatorSingleScatteringAlbedos(radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); +// ASSERT_TRUE(IsSuccess(error)); +// for (int row = 0; row < num_vertical_layers; row++) +// { +// for (int col = 0; col < num_wavelength_bins; col++) +// { +// albedos[row][col] = -999.0; +// } +// } +// GetRadiatorSingleScatteringAlbedos(radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(albedos[0][0], 100.0); +// ASSERT_EQ(albedos[0][1], 200.0); +// ASSERT_EQ(albedos[1][0], 300.0); +// ASSERT_EQ(albedos[1][1], 400.0); +// ASSERT_EQ(albedos[2][0], 500.0); +// ASSERT_EQ(albedos[2][1], 600.0); - // Test for asymmetery factors - double* factors_1D = new double[num_wavelength_bins * num_vertical_layers]; - double** factors = new double*[num_vertical_layers]; - for (int row = 0; row < num_vertical_layers; row++) - { - factors[row] = &factors_1D[row * num_wavelength_bins]; - } - i = 1; - for (int row = 0; row < num_vertical_layers; row++) - { - for (int col = 0; col < num_wavelength_bins; col++) - { - factors[row][col] = 1 * i; - i++; - } - } - std::size_t num_streams = 1; - SetRadiatorAsymmetryFactors(radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); - ASSERT_TRUE(IsSuccess(error)); - for (int row = 0; row < num_vertical_layers; row++) - { - for (int col = 0; col < num_wavelength_bins; col++) - { - factors[row][col] = -999.0; - } - } - GetRadiatorAsymmetryFactors(radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(factors[0][0], 1); - ASSERT_EQ(factors[0][1], 2); - ASSERT_EQ(factors[1][0], 3); - ASSERT_EQ(factors[1][1], 4); - ASSERT_EQ(factors[2][0], 5); - ASSERT_EQ(factors[2][1], 6); +// // Test for asymmetery factors +// double* factors_1D = new double[num_wavelength_bins * num_vertical_layers]; +// double** factors = new double*[num_vertical_layers]; +// for (int row = 0; row < num_vertical_layers; row++) +// { +// factors[row] = &factors_1D[row * num_wavelength_bins]; +// } +// i = 1; +// for (int row = 0; row < num_vertical_layers; row++) +// { +// for (int col = 0; col < num_wavelength_bins; col++) +// { +// factors[row][col] = 1 * i; +// i++; +// } +// } +// std::size_t num_streams = 1; +// SetRadiatorAsymmetryFactors(radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); +// ASSERT_TRUE(IsSuccess(error)); +// for (int row = 0; row < num_vertical_layers; row++) +// { +// for (int col = 0; col < num_wavelength_bins; col++) +// { +// factors[row][col] = -999.0; +// } +// } +// GetRadiatorAsymmetryFactors(radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(factors[0][0], 1); +// ASSERT_EQ(factors[0][1], 2); +// ASSERT_EQ(factors[1][0], 3); +// ASSERT_EQ(factors[1][1], 4); +// ASSERT_EQ(factors[2][0], 5); +// ASSERT_EQ(factors[2][1], 6); - // Clean up - DeleteRadiator(radiator, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteGrid(height, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteGrid(wavelength, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteError(&error); - delete[] optical_depths; - delete[] optical_depths_1D; - delete[] albedos; - delete[] albedos_1D; - delete[] factors; - delete[] factors_1D; -} +// // Clean up +// DeleteRadiator(radiator, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteGrid(height, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteGrid(wavelength, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteError(&error); +// delete[] optical_depths; +// delete[] optical_depths_1D; +// delete[] albedos; +// delete[] albedos_1D; +// delete[] factors; +// delete[] factors_1D; +// } -TEST_F(TuvxCApiTest, CanCreateRadiatorMap) -{ - Error error; - RadiatorMap* radiator_map = CreateRadiatorMap(&error); - ASSERT_TRUE(IsSuccess(error)); - Grid* height = CreateGrid("height", "km", 3, &error); - Grid* wavelength = CreateGrid("wavelength", "nm", 2, &error); - Radiator* foo_radiator = CreateRadiator("foo", height, wavelength, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(foo_radiator, nullptr); - AddRadiator(radiator_map, foo_radiator, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(radiator_map, nullptr); - Grid* bar_height = CreateGrid("bar_height", "km", 3, &error); - Grid* bar_wavelength = CreateGrid("bar_wavelength", "nm", 2, &error); - Radiator* bar_radiator = CreateRadiator("bar", bar_height, bar_wavelength, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(bar_radiator, nullptr); - AddRadiator(radiator_map, bar_radiator, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(radiator_map, nullptr); +// TEST_F(TuvxCApiTest, CanCreateRadiatorMap) +// { +// Error error; +// RadiatorMap* radiator_map = CreateRadiatorMap(&error); +// ASSERT_TRUE(IsSuccess(error)); +// Grid* height = CreateGrid("height", "km", 3, &error); +// Grid* wavelength = CreateGrid("wavelength", "nm", 2, &error); +// Radiator* foo_radiator = CreateRadiator("foo", height, wavelength, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(foo_radiator, nullptr); +// AddRadiator(radiator_map, foo_radiator, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(radiator_map, nullptr); +// Grid* bar_height = CreateGrid("bar_height", "km", 3, &error); +// Grid* bar_wavelength = CreateGrid("bar_wavelength", "nm", 2, &error); +// Radiator* bar_radiator = CreateRadiator("bar", bar_height, bar_wavelength, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(bar_radiator, nullptr); +// AddRadiator(radiator_map, bar_radiator, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(radiator_map, nullptr); - // Test for optical depths - std::size_t num_vertical_layers = 3; - std::size_t num_wavelength_bins = 2; - double* optical_depths_1D = new double[num_wavelength_bins * num_vertical_layers]; - double** optical_depths = new double*[num_vertical_layers]; - for (int row = 0; row < num_vertical_layers; row++) - { - optical_depths[row] = &optical_depths_1D[row * num_wavelength_bins]; - } - int i = 1; - for (int row = 0; row < num_vertical_layers; row++) - { - for (int col = 0; col < num_wavelength_bins; col++) - { - optical_depths[row][col] = 10 * i; - i++; - } - } - SetRadiatorOpticalDepths(foo_radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); - ASSERT_TRUE(IsSuccess(error)); +// // Test for optical depths +// std::size_t num_vertical_layers = 3; +// std::size_t num_wavelength_bins = 2; +// double* optical_depths_1D = new double[num_wavelength_bins * num_vertical_layers]; +// double** optical_depths = new double*[num_vertical_layers]; +// for (int row = 0; row < num_vertical_layers; row++) +// { +// optical_depths[row] = &optical_depths_1D[row * num_wavelength_bins]; +// } +// int i = 1; +// for (int row = 0; row < num_vertical_layers; row++) +// { +// for (int col = 0; col < num_wavelength_bins; col++) +// { +// optical_depths[row][col] = 10 * i; +// i++; +// } +// } +// SetRadiatorOpticalDepths(foo_radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); +// ASSERT_TRUE(IsSuccess(error)); - // Test for single scattering albedos - double* albedos_1D = new double[num_wavelength_bins * num_vertical_layers]; - double** albedos = new double*[num_vertical_layers]; - for (int row = 0; row < num_vertical_layers; row++) - { - albedos[row] = &albedos_1D[row * num_wavelength_bins]; - } - i = 1; - for (int row = 0; row < num_vertical_layers; row++) - { - for (int col = 0; col < num_wavelength_bins; col++) - { - albedos[row][col] = 100 * i; - i++; - } - } - SetRadiatorSingleScatteringAlbedos(foo_radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); - ASSERT_TRUE(IsSuccess(error)); +// // Test for single scattering albedos +// double* albedos_1D = new double[num_wavelength_bins * num_vertical_layers]; +// double** albedos = new double*[num_vertical_layers]; +// for (int row = 0; row < num_vertical_layers; row++) +// { +// albedos[row] = &albedos_1D[row * num_wavelength_bins]; +// } +// i = 1; +// for (int row = 0; row < num_vertical_layers; row++) +// { +// for (int col = 0; col < num_wavelength_bins; col++) +// { +// albedos[row][col] = 100 * i; +// i++; +// } +// } +// SetRadiatorSingleScatteringAlbedos(foo_radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); +// ASSERT_TRUE(IsSuccess(error)); - // Test for asymmetery factors - std::size_t num_streams = 1; - double* factors_1D = new double[num_wavelength_bins * num_vertical_layers]; - double** factors = new double*[num_vertical_layers]; - for (int row = 0; row < num_vertical_layers; row++) - { - factors[row] = &factors_1D[row * num_wavelength_bins]; - } - i = 1; - for (int row = 0; row < num_vertical_layers; row++) - { - for (int col = 0; col < num_wavelength_bins; col++) - { - factors[row][col] = 1 * i; - i++; - } - } - SetRadiatorAsymmetryFactors(foo_radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); - ASSERT_TRUE(IsSuccess(error)); +// // Test for asymmetery factors +// std::size_t num_streams = 1; +// double* factors_1D = new double[num_wavelength_bins * num_vertical_layers]; +// double** factors = new double*[num_vertical_layers]; +// for (int row = 0; row < num_vertical_layers; row++) +// { +// factors[row] = &factors_1D[row * num_wavelength_bins]; +// } +// i = 1; +// for (int row = 0; row < num_vertical_layers; row++) +// { +// for (int col = 0; col < num_wavelength_bins; col++) +// { +// factors[row][col] = 1 * i; +// i++; +// } +// } +// SetRadiatorAsymmetryFactors(foo_radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); +// ASSERT_TRUE(IsSuccess(error)); - // Test for optical depths - for (int row = 0; row < num_vertical_layers; row++) - { - for (int col = 0; col < num_wavelength_bins; col++) - { - optical_depths[row][col] = -999.0; - } - } - GetRadiatorOpticalDepths(foo_radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(optical_depths[0][0], 10.0); - ASSERT_EQ(optical_depths[0][1], 20.0); - ASSERT_EQ(optical_depths[1][0], 30.0); - ASSERT_EQ(optical_depths[1][1], 40.0); - ASSERT_EQ(optical_depths[2][0], 50.0); - ASSERT_EQ(optical_depths[2][1], 60.0); +// // Test for optical depths +// for (int row = 0; row < num_vertical_layers; row++) +// { +// for (int col = 0; col < num_wavelength_bins; col++) +// { +// optical_depths[row][col] = -999.0; +// } +// } +// GetRadiatorOpticalDepths(foo_radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(optical_depths[0][0], 10.0); +// ASSERT_EQ(optical_depths[0][1], 20.0); +// ASSERT_EQ(optical_depths[1][0], 30.0); +// ASSERT_EQ(optical_depths[1][1], 40.0); +// ASSERT_EQ(optical_depths[2][0], 50.0); +// ASSERT_EQ(optical_depths[2][1], 60.0); - // Test for single scattering albedos - for (int row = 0; row < num_vertical_layers; row++) - { - for (int col = 0; col < num_wavelength_bins; col++) - { - albedos[row][col] = -999.0; - } - } - GetRadiatorSingleScatteringAlbedos(foo_radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(albedos[0][0], 100.0); - ASSERT_EQ(albedos[0][1], 200.0); - ASSERT_EQ(albedos[1][0], 300.0); - ASSERT_EQ(albedos[1][1], 400.0); - ASSERT_EQ(albedos[2][0], 500.0); - ASSERT_EQ(albedos[2][1], 600.0); +// // Test for single scattering albedos +// for (int row = 0; row < num_vertical_layers; row++) +// { +// for (int col = 0; col < num_wavelength_bins; col++) +// { +// albedos[row][col] = -999.0; +// } +// } +// GetRadiatorSingleScatteringAlbedos(foo_radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(albedos[0][0], 100.0); +// ASSERT_EQ(albedos[0][1], 200.0); +// ASSERT_EQ(albedos[1][0], 300.0); +// ASSERT_EQ(albedos[1][1], 400.0); +// ASSERT_EQ(albedos[2][0], 500.0); +// ASSERT_EQ(albedos[2][1], 600.0); - // Test for asymmetry factors - for (int row = 0; row < num_vertical_layers; row++) - { - for (int col = 0; col < num_wavelength_bins; col++) - { - factors[row][col] = -999.0; - } - } - GetRadiatorAsymmetryFactors(foo_radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(factors[0][0], 1); - ASSERT_EQ(factors[0][1], 2); - ASSERT_EQ(factors[1][0], 3); - ASSERT_EQ(factors[1][1], 4); - ASSERT_EQ(factors[2][0], 5); - ASSERT_EQ(factors[2][1], 6); +// // Test for asymmetry factors +// for (int row = 0; row < num_vertical_layers; row++) +// { +// for (int col = 0; col < num_wavelength_bins; col++) +// { +// factors[row][col] = -999.0; +// } +// } +// GetRadiatorAsymmetryFactors(foo_radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(factors[0][0], 1); +// ASSERT_EQ(factors[0][1], 2); +// ASSERT_EQ(factors[1][0], 3); +// ASSERT_EQ(factors[1][1], 4); +// ASSERT_EQ(factors[2][0], 5); +// ASSERT_EQ(factors[2][1], 6); - // Test copy for radiator map - Radiator* foo_copy = GetRadiator(radiator_map, "foo", &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(foo_copy, nullptr); - GetRadiatorOpticalDepths(foo_copy, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(optical_depths[0][0], 10.0); - ASSERT_EQ(optical_depths[0][1], 20.0); - ASSERT_EQ(optical_depths[1][0], 30.0); - ASSERT_EQ(optical_depths[1][1], 40.0); - ASSERT_EQ(optical_depths[2][0], 50.0); - ASSERT_EQ(optical_depths[2][1], 60.0); - GetRadiatorSingleScatteringAlbedos(foo_copy, albedos[0], num_vertical_layers, num_wavelength_bins, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(albedos[0][0], 100.0); - ASSERT_EQ(albedos[0][1], 200.0); - ASSERT_EQ(albedos[1][0], 300.0); - ASSERT_EQ(albedos[1][1], 400.0); - ASSERT_EQ(albedos[2][0], 500.0); - ASSERT_EQ(albedos[2][1], 600.0); - GetRadiatorAsymmetryFactors(foo_copy, factors[0], num_vertical_layers, num_wavelength_bins, 1, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_EQ(factors[0][0], 1); - ASSERT_EQ(factors[0][1], 2); - ASSERT_EQ(factors[1][0], 3); - ASSERT_EQ(factors[1][1], 4); - ASSERT_EQ(factors[2][0], 5); - ASSERT_EQ(factors[2][1], 6); +// // Test copy for radiator map +// Radiator* foo_copy = GetRadiator(radiator_map, "foo", &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_NE(foo_copy, nullptr); +// GetRadiatorOpticalDepths(foo_copy, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(optical_depths[0][0], 10.0); +// ASSERT_EQ(optical_depths[0][1], 20.0); +// ASSERT_EQ(optical_depths[1][0], 30.0); +// ASSERT_EQ(optical_depths[1][1], 40.0); +// ASSERT_EQ(optical_depths[2][0], 50.0); +// ASSERT_EQ(optical_depths[2][1], 60.0); +// GetRadiatorSingleScatteringAlbedos(foo_copy, albedos[0], num_vertical_layers, num_wavelength_bins, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(albedos[0][0], 100.0); +// ASSERT_EQ(albedos[0][1], 200.0); +// ASSERT_EQ(albedos[1][0], 300.0); +// ASSERT_EQ(albedos[1][1], 400.0); +// ASSERT_EQ(albedos[2][0], 500.0); +// ASSERT_EQ(albedos[2][1], 600.0); +// GetRadiatorAsymmetryFactors(foo_copy, factors[0], num_vertical_layers, num_wavelength_bins, 1, &error); +// ASSERT_TRUE(IsSuccess(error)); +// ASSERT_EQ(factors[0][0], 1); +// ASSERT_EQ(factors[0][1], 2); +// ASSERT_EQ(factors[1][0], 3); +// ASSERT_EQ(factors[1][1], 4); +// ASSERT_EQ(factors[2][0], 5); +// ASSERT_EQ(factors[2][1], 6); - // Clean up - DeleteRadiator(foo_radiator, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteRadiator(bar_radiator, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteRadiator(foo_copy, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteRadiatorMap(radiator_map, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteGrid(height, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteGrid(wavelength, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteGrid(bar_height, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteGrid(bar_wavelength, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteError(&error); - delete[] optical_depths; - delete[] optical_depths_1D; - delete[] albedos; - delete[] albedos_1D; - delete[] factors; - delete[] factors_1D; -} \ No newline at end of file +// // Clean up +// DeleteRadiator(foo_radiator, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteRadiator(bar_radiator, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteRadiator(foo_copy, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteRadiatorMap(radiator_map, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteGrid(height, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteGrid(wavelength, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteGrid(bar_height, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteGrid(bar_wavelength, &error); +// ASSERT_TRUE(IsSuccess(error)); +// DeleteError(&error); +// delete[] optical_depths; +// delete[] optical_depths_1D; +// delete[] albedos; +// delete[] albedos_1D; +// delete[] factors; +// delete[] factors_1D; +// } \ No newline at end of file diff --git a/src/tuvx/interface.F90 b/src/tuvx/interface.F90 index 48ca85db..ff040ce8 100644 --- a/src/tuvx/interface.F90 +++ b/src/tuvx/interface.F90 @@ -19,8 +19,8 @@ module tuvx_interface !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - function internal_create_tuvx(c_config_path, config_path_length, error_code) & - bind(C, name="InternalCreateTuvx") + function internal_create_tuvx(c_config_path, config_path_length, grids, & + profiles, radiators, error_code) bind(C, name="InternalCreateTuvx") use iso_c_binding, only: c_ptr, c_f_pointer ! arguments diff --git a/src/tuvx/tuvx.cpp b/src/tuvx/tuvx.cpp index 83e11bd9..d7c59805 100644 --- a/src/tuvx/tuvx.cpp +++ b/src/tuvx/tuvx.cpp @@ -115,6 +115,7 @@ namespace musica { *error = NoError(); int error_code = 0; + // TODO (jiwon) remove this new operation? GridMap *grid_map = new GridMap(InternalGetGridMap(tuvx_, &error_code)); if (error_code != 0) { From 1c8c237547056222c9f5f1fb48bbd73c3c3d33c2 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Thu, 29 Aug 2024 15:08:07 -0600 Subject: [PATCH 03/10] remove unused arguments --- include/musica/tuvx/tuvx.hpp | 9 +- src/test/unit/tuvx/tuvx_c_api.cpp | 1253 ++++++++++++++--------------- src/tuvx/interface.F90 | 4 +- src/tuvx/tuvx.cpp | 13 +- 4 files changed, 637 insertions(+), 642 deletions(-) diff --git a/include/musica/tuvx/tuvx.hpp b/include/musica/tuvx/tuvx.hpp index 08920431..ebe1ef67 100644 --- a/include/musica/tuvx/tuvx.hpp +++ b/include/musica/tuvx/tuvx.hpp @@ -25,6 +25,7 @@ namespace musica /// @brief Create an instance of tuvx from a configuration file /// @param config_path Path to configuration file /// @param TODO(jiwon) + /// @param TODO(jiwon) /// @param error Error struct to indicate success or failure void Create(const char *config_path, GridMap *grids, ProfileMap *profiles, RadiatorMap *radiators, Error *error); @@ -68,13 +69,7 @@ namespace musica // for use by musica interanlly. If tuvx ever gets rewritten in C++, these functions will // go away but the C API will remain the same and downstream projects (like CAM-SIMA) will // not need to change - void *InternalCreateTuvx( - const char *config_path, - std::size_t config_path_length, - GridMap *grids, - ProfileMap *profiles, - RadiatorMap *radiators, - int *error_code); + void *InternalCreateTuvx(const char *config_path, std::size_t config_path_length, int *error_code); void InternalDeleteTuvx(void *tuvx, int *error_code); void *InternalGetGridMap(void *tuvx, int *error_code); void *InternalGetProfileMap(void *tuvx, int *error_code); diff --git a/src/test/unit/tuvx/tuvx_c_api.cpp b/src/test/unit/tuvx/tuvx_c_api.cpp index dc43d9f1..f8c11db9 100644 --- a/src/test/unit/tuvx/tuvx_c_api.cpp +++ b/src/test/unit/tuvx/tuvx_c_api.cpp @@ -26,11 +26,8 @@ class TuvxCApiTest : public ::testing::Test { Error error; grids = CreateGridMap(&error); - ASSERT_TRUE(IsSuccess(error)); profiles = CreateProfileMap(&error); - ASSERT_TRUE(IsSuccess(error)); radiators = CreateRadiatorMap(&error); - ASSERT_TRUE(IsSuccess(error)); tuvx = CreateTuvx(config_path, grids, profiles, radiators, &error); if (!IsSuccess(error)) { @@ -47,12 +44,6 @@ class TuvxCApiTest : public ::testing::Test return; } Error error; - DeleteGridMap(grids, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteProfileMap(profiles, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteRadiatorMap(radiators, &error); - ASSERT_TRUE(IsSuccess(error)); DeleteTuvx(tuvx, &error); ASSERT_TRUE(IsSuccess(error)); DeleteError(&error); @@ -102,644 +93,644 @@ TEST_F(TuvxCApiTest, CannotGetConfiguredGrid) DeleteError(&error); } -// TEST_F(TuvxCApiTest, CanCreateGrid) -// { -// Error error; -// Grid* grid = CreateGrid("foo", "m", 2, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(grid, nullptr); -// std::vector edges = { 0.0, 100.0, 200.0 }; -// SetGridEdges(grid, edges.data(), edges.size(), &error); -// ASSERT_TRUE(IsSuccess(error)); -// for (auto& edge : edges) -// { -// edge = -100.0; -// } -// GetGridEdges(grid, edges.data(), edges.size(), &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(edges[0], 0.0); -// ASSERT_EQ(edges[1], 100.0); -// ASSERT_EQ(edges[2], 200.0); -// std::vector midpoints = { 50.0, 150.0 }; -// SetGridMidpoints(grid, midpoints.data(), midpoints.size(), &error); -// ASSERT_TRUE(IsSuccess(error)); -// for (auto& midpoint : midpoints) -// { -// midpoint = -100.0; -// } -// GetGridMidpoints(grid, midpoints.data(), midpoints.size(), &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(midpoints[0], 50.0); -// ASSERT_EQ(midpoints[1], 150.0); -// DeleteGrid(grid, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteError(&error); -// } +TEST_F(TuvxCApiTest, CanCreateGrid) +{ + Error error; + Grid* grid = CreateGrid("foo", "m", 2, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(grid, nullptr); + std::vector edges = { 0.0, 100.0, 200.0 }; + SetGridEdges(grid, edges.data(), edges.size(), &error); + ASSERT_TRUE(IsSuccess(error)); + for (auto& edge : edges) + { + edge = -100.0; + } + GetGridEdges(grid, edges.data(), edges.size(), &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(edges[0], 0.0); + ASSERT_EQ(edges[1], 100.0); + ASSERT_EQ(edges[2], 200.0); + std::vector midpoints = { 50.0, 150.0 }; + SetGridMidpoints(grid, midpoints.data(), midpoints.size(), &error); + ASSERT_TRUE(IsSuccess(error)); + for (auto& midpoint : midpoints) + { + midpoint = -100.0; + } + GetGridMidpoints(grid, midpoints.data(), midpoints.size(), &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(midpoints[0], 50.0); + ASSERT_EQ(midpoints[1], 150.0); + DeleteGrid(grid, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteError(&error); +} -// TEST_F(TuvxCApiTest, CanCreateGridMap) -// { -// Error error; -// GridMap* grid_map = CreateGridMap(&error); -// ASSERT_TRUE(IsSuccess(error)); -// Grid* foo_grid = CreateGrid("foo", "m", 2, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(foo_grid, nullptr); -// AddGrid(grid_map, foo_grid, &error); -// ASSERT_TRUE(IsSuccess(error)); -// Grid* bar_grid = CreateGrid("bar", "m", 3, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(bar_grid, nullptr); -// AddGrid(grid_map, bar_grid, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(grid_map, nullptr); -// double edge_values[] = { 0.0, 1.0, 2.0 }; -// double midpoint_values[] = { 0.5, 1.5 }; -// SetGridEdges(foo_grid, edge_values, 3, &error); -// SetGridMidpoints(foo_grid, midpoint_values, 2, &error); -// ASSERT_TRUE(IsSuccess(error)); -// for (auto& edge : edge_values) -// { -// edge = -100.0; -// } -// for (auto& midpoint : midpoint_values) -// { -// midpoint = -100.0; -// } -// GetGridEdges(foo_grid, edge_values, 3, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(edge_values[0], 0.0); -// ASSERT_EQ(edge_values[1], 1.0); -// ASSERT_EQ(edge_values[2], 2.0); -// GetGridMidpoints(foo_grid, midpoint_values, 2, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(midpoint_values[0], 0.5); -// ASSERT_EQ(midpoint_values[1], 1.5); -// Grid* foo_copy = GetGrid(grid_map, "foo", "m", &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(foo_copy, nullptr); -// for (auto& edge : edge_values) -// { -// edge = -100.0; -// } -// for (auto& midpoint : midpoint_values) -// { -// midpoint = -100.0; -// } -// GetGridEdges(foo_copy, edge_values, 3, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(edge_values[0], 0.0); -// ASSERT_EQ(edge_values[1], 1.0); -// ASSERT_EQ(edge_values[2], 2.0); -// GetGridMidpoints(foo_copy, midpoint_values, 2, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(midpoint_values[0], 0.5); -// ASSERT_EQ(midpoint_values[1], 1.5); -// DeleteGrid(foo_grid, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteGrid(bar_grid, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteGrid(foo_copy, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteGridMap(grid_map, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteError(&error); -// } +TEST_F(TuvxCApiTest, CanCreateGridMap) +{ + Error error; + GridMap* grid_map = CreateGridMap(&error); + ASSERT_TRUE(IsSuccess(error)); + Grid* foo_grid = CreateGrid("foo", "m", 2, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(foo_grid, nullptr); + AddGrid(grid_map, foo_grid, &error); + ASSERT_TRUE(IsSuccess(error)); + Grid* bar_grid = CreateGrid("bar", "m", 3, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(bar_grid, nullptr); + AddGrid(grid_map, bar_grid, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(grid_map, nullptr); + double edge_values[] = { 0.0, 1.0, 2.0 }; + double midpoint_values[] = { 0.5, 1.5 }; + SetGridEdges(foo_grid, edge_values, 3, &error); + SetGridMidpoints(foo_grid, midpoint_values, 2, &error); + ASSERT_TRUE(IsSuccess(error)); + for (auto& edge : edge_values) + { + edge = -100.0; + } + for (auto& midpoint : midpoint_values) + { + midpoint = -100.0; + } + GetGridEdges(foo_grid, edge_values, 3, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(edge_values[0], 0.0); + ASSERT_EQ(edge_values[1], 1.0); + ASSERT_EQ(edge_values[2], 2.0); + GetGridMidpoints(foo_grid, midpoint_values, 2, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(midpoint_values[0], 0.5); + ASSERT_EQ(midpoint_values[1], 1.5); + Grid* foo_copy = GetGrid(grid_map, "foo", "m", &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(foo_copy, nullptr); + for (auto& edge : edge_values) + { + edge = -100.0; + } + for (auto& midpoint : midpoint_values) + { + midpoint = -100.0; + } + GetGridEdges(foo_copy, edge_values, 3, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(edge_values[0], 0.0); + ASSERT_EQ(edge_values[1], 1.0); + ASSERT_EQ(edge_values[2], 2.0); + GetGridMidpoints(foo_copy, midpoint_values, 2, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(midpoint_values[0], 0.5); + ASSERT_EQ(midpoint_values[1], 1.5); + DeleteGrid(foo_grid, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteGrid(bar_grid, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteGrid(foo_copy, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteGridMap(grid_map, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteError(&error); +} -// TEST_F(TuvxCApiTest, CannotGetConfiguredProfile) -// { -// const char* yaml_config_path = "examples/ts1_tsmlt.yml"; -// SetUp(yaml_config_path); -// Error error; -// ProfileMap* profile_map = GetProfileMap(tuvx, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(profile_map, nullptr); -// Profile* profile = GetProfile(profile_map, "air", "molecule cm-3", &error); -// ASSERT_FALSE(IsSuccess(error)); // non-host profile -// ASSERT_EQ(profile, nullptr); -// DeleteProfileMap(profile_map, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteError(&error); -// } +TEST_F(TuvxCApiTest, CannotGetConfiguredProfile) +{ + const char* yaml_config_path = "examples/ts1_tsmlt.yml"; + SetUp(yaml_config_path); + Error error; + ProfileMap* profile_map = GetProfileMap(tuvx, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(profile_map, nullptr); + Profile* profile = GetProfile(profile_map, "air", "molecule cm-3", &error); + ASSERT_FALSE(IsSuccess(error)); // non-host profile + ASSERT_EQ(profile, nullptr); + DeleteProfileMap(profile_map, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteError(&error); +} -// TEST_F(TuvxCApiTest, CanCreateProfile) -// { -// Error error; -// Grid* grid = CreateGrid("foo", "m", 2, &error); -// ASSERT_TRUE(IsSuccess(error)); -// Profile* profile = CreateProfile("bar", "molecule cm-3", grid, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(profile, nullptr); -// std::vector edge_values = { 0.0, 1.0, 2.0 }; -// SetProfileEdgeValues(profile, edge_values.data(), edge_values.size(), &error); -// ASSERT_TRUE(IsSuccess(error)); -// for (auto& edge : edge_values) -// { -// edge = -100.0; -// } -// GetProfileEdgeValues(profile, edge_values.data(), edge_values.size(), &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(edge_values[0], 0.0); -// ASSERT_EQ(edge_values[1], 1.0); -// ASSERT_EQ(edge_values[2], 2.0); -// std::vector midpoint_values = { 0.5, 1.5 }; -// SetProfileMidpointValues(profile, midpoint_values.data(), midpoint_values.size(), &error); -// ASSERT_TRUE(IsSuccess(error)); -// for (auto& midpoint : midpoint_values) -// { -// midpoint = -100.0; -// } -// GetProfileMidpointValues(profile, midpoint_values.data(), midpoint_values.size(), &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(midpoint_values[0], 0.5); -// ASSERT_EQ(midpoint_values[1], 1.5); -// std::vector densities = { 1.0, 2.0 }; -// SetProfileLayerDensities(profile, densities.data(), densities.size(), &error); -// ASSERT_TRUE(IsSuccess(error)); -// for (auto& density : densities) -// { -// density = -100.0; -// } -// GetProfileLayerDensities(profile, densities.data(), densities.size(), &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(densities[0], 1.0); -// ASSERT_EQ(densities[1], 2.0); -// SetProfileExoLayerDensity(profile, 3.0, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(GetProfileExoLayerDensity(profile, &error), 3.0); -// GetProfileLayerDensities(profile, densities.data(), densities.size(), &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(densities[0], 1.0); -// ASSERT_EQ(densities[1], 2.0 + 3.0); -// CalculateProfileExoLayerDensity(profile, 1.0, &error); -// ASSERT_TRUE(IsSuccess(error)); -// // This should be updated once we do all conversions to/from non-SI units -// // in the internal TUV-x functions -// ASSERT_EQ(GetProfileExoLayerDensity(profile, &error), 200.0); -// GetProfileLayerDensities(profile, densities.data(), densities.size(), &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(densities[0], 1.0); -// // This should be updated once we do all conversions to/from non-SI units -// // in the internal TUV-x functions -// ASSERT_EQ(densities[1], 2.0 + 200.0); -// DeleteProfile(profile, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteGrid(grid, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteError(&error); -// } +TEST_F(TuvxCApiTest, CanCreateProfile) +{ + Error error; + Grid* grid = CreateGrid("foo", "m", 2, &error); + ASSERT_TRUE(IsSuccess(error)); + Profile* profile = CreateProfile("bar", "molecule cm-3", grid, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(profile, nullptr); + std::vector edge_values = { 0.0, 1.0, 2.0 }; + SetProfileEdgeValues(profile, edge_values.data(), edge_values.size(), &error); + ASSERT_TRUE(IsSuccess(error)); + for (auto& edge : edge_values) + { + edge = -100.0; + } + GetProfileEdgeValues(profile, edge_values.data(), edge_values.size(), &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(edge_values[0], 0.0); + ASSERT_EQ(edge_values[1], 1.0); + ASSERT_EQ(edge_values[2], 2.0); + std::vector midpoint_values = { 0.5, 1.5 }; + SetProfileMidpointValues(profile, midpoint_values.data(), midpoint_values.size(), &error); + ASSERT_TRUE(IsSuccess(error)); + for (auto& midpoint : midpoint_values) + { + midpoint = -100.0; + } + GetProfileMidpointValues(profile, midpoint_values.data(), midpoint_values.size(), &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(midpoint_values[0], 0.5); + ASSERT_EQ(midpoint_values[1], 1.5); + std::vector densities = { 1.0, 2.0 }; + SetProfileLayerDensities(profile, densities.data(), densities.size(), &error); + ASSERT_TRUE(IsSuccess(error)); + for (auto& density : densities) + { + density = -100.0; + } + GetProfileLayerDensities(profile, densities.data(), densities.size(), &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(densities[0], 1.0); + ASSERT_EQ(densities[1], 2.0); + SetProfileExoLayerDensity(profile, 3.0, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(GetProfileExoLayerDensity(profile, &error), 3.0); + GetProfileLayerDensities(profile, densities.data(), densities.size(), &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(densities[0], 1.0); + ASSERT_EQ(densities[1], 2.0 + 3.0); + CalculateProfileExoLayerDensity(profile, 1.0, &error); + ASSERT_TRUE(IsSuccess(error)); + // This should be updated once we do all conversions to/from non-SI units + // in the internal TUV-x functions + ASSERT_EQ(GetProfileExoLayerDensity(profile, &error), 200.0); + GetProfileLayerDensities(profile, densities.data(), densities.size(), &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(densities[0], 1.0); + // This should be updated once we do all conversions to/from non-SI units + // in the internal TUV-x functions + ASSERT_EQ(densities[1], 2.0 + 200.0); + DeleteProfile(profile, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteGrid(grid, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteError(&error); +} -// TEST_F(TuvxCApiTest, CanCreateProfileMap) -// { -// Error error; -// ProfileMap* profile_map = CreateProfileMap(&error); -// ASSERT_TRUE(IsSuccess(error)); -// Grid* foo_grid = CreateGrid("foo", "m", 2, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(foo_grid, nullptr); -// Profile* foo_profile = CreateProfile("foo", "molecule cm-3", foo_grid, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(foo_profile, nullptr); -// AddProfile(profile_map, foo_profile, &error); -// ASSERT_TRUE(IsSuccess(error)); -// Grid* bar_grid = CreateGrid("bar", "m", 3, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(bar_grid, nullptr); -// Profile* bar_profile = CreateProfile("bar", "molecule cm-3", bar_grid, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(bar_profile, nullptr); -// AddProfile(profile_map, bar_profile, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(profile_map, nullptr); -// double edge_values[] = { 0.0, 1.0, 2.0 }; -// double midpoint_values[] = { 0.5, 1.5 }; -// SetProfileEdgeValues(foo_profile, edge_values, 3, &error); -// SetProfileMidpointValues(foo_profile, midpoint_values, 2, &error); -// ASSERT_TRUE(IsSuccess(error)); -// for (auto& edge : edge_values) -// { -// edge = -100.0; -// } -// for (auto& midpoint : midpoint_values) -// { -// midpoint = -100.0; -// } -// GetProfileEdgeValues(foo_profile, edge_values, 3, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(edge_values[0], 0.0); -// ASSERT_EQ(edge_values[1], 1.0); -// ASSERT_EQ(edge_values[2], 2.0); -// GetProfileMidpointValues(foo_profile, midpoint_values, 2, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(midpoint_values[0], 0.5); -// ASSERT_EQ(midpoint_values[1], 1.5); -// Profile* foo_copy = GetProfile(profile_map, "foo", "molecule cm-3", &error); -// for (auto& edge : edge_values) -// { -// edge = -100.0; -// } -// for (auto& midpoint : midpoint_values) -// { -// midpoint = -100.0; -// } -// GetProfileEdgeValues(foo_copy, edge_values, 3, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(edge_values[0], 0.0); -// ASSERT_EQ(edge_values[1], 1.0); -// ASSERT_EQ(edge_values[2], 2.0); -// GetProfileMidpointValues(foo_copy, midpoint_values, 2, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(midpoint_values[0], 0.5); -// ASSERT_EQ(midpoint_values[1], 1.5); -// edge_values[0] = 5.0; -// edge_values[1] = 10.0; -// edge_values[2] = 20.0; -// midpoint_values[0] = 7.5; -// midpoint_values[1] = 15.0; -// SetProfileEdgeValues(foo_copy, edge_values, 3, &error); -// SetProfileMidpointValues(foo_copy, midpoint_values, 2, &error); -// ASSERT_TRUE(IsSuccess(error)); -// for (auto& edge : edge_values) -// { -// edge = -100.0; -// } -// for (auto& midpoint : midpoint_values) -// { -// midpoint = -100.0; -// } -// GetProfileEdgeValues(foo_copy, edge_values, 3, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(edge_values[0], 5.0); -// ASSERT_EQ(edge_values[1], 10.0); -// ASSERT_EQ(edge_values[2], 20.0); -// GetProfileMidpointValues(foo_copy, midpoint_values, 2, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(midpoint_values[0], 7.5); -// ASSERT_EQ(midpoint_values[1], 15.0); -// for (auto& edge : edge_values) -// { -// edge = -100.0; -// } -// for (auto& midpoint : midpoint_values) -// { -// midpoint = -100.0; -// } -// GetProfileEdgeValues(foo_profile, edge_values, 3, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(edge_values[0], 5.0); -// ASSERT_EQ(edge_values[1], 10.0); -// ASSERT_EQ(edge_values[2], 20.0); -// GetProfileMidpointValues(foo_profile, midpoint_values, 2, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(midpoint_values[0], 7.5); -// ASSERT_EQ(midpoint_values[1], 15.0); -// DeleteProfile(foo_profile, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteProfile(bar_profile, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteProfile(foo_copy, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteGrid(foo_grid, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteGrid(bar_grid, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteProfileMap(profile_map, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteError(&error); -// } +TEST_F(TuvxCApiTest, CanCreateProfileMap) +{ + Error error; + ProfileMap* profile_map = CreateProfileMap(&error); + ASSERT_TRUE(IsSuccess(error)); + Grid* foo_grid = CreateGrid("foo", "m", 2, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(foo_grid, nullptr); + Profile* foo_profile = CreateProfile("foo", "molecule cm-3", foo_grid, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(foo_profile, nullptr); + AddProfile(profile_map, foo_profile, &error); + ASSERT_TRUE(IsSuccess(error)); + Grid* bar_grid = CreateGrid("bar", "m", 3, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(bar_grid, nullptr); + Profile* bar_profile = CreateProfile("bar", "molecule cm-3", bar_grid, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(bar_profile, nullptr); + AddProfile(profile_map, bar_profile, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(profile_map, nullptr); + double edge_values[] = { 0.0, 1.0, 2.0 }; + double midpoint_values[] = { 0.5, 1.5 }; + SetProfileEdgeValues(foo_profile, edge_values, 3, &error); + SetProfileMidpointValues(foo_profile, midpoint_values, 2, &error); + ASSERT_TRUE(IsSuccess(error)); + for (auto& edge : edge_values) + { + edge = -100.0; + } + for (auto& midpoint : midpoint_values) + { + midpoint = -100.0; + } + GetProfileEdgeValues(foo_profile, edge_values, 3, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(edge_values[0], 0.0); + ASSERT_EQ(edge_values[1], 1.0); + ASSERT_EQ(edge_values[2], 2.0); + GetProfileMidpointValues(foo_profile, midpoint_values, 2, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(midpoint_values[0], 0.5); + ASSERT_EQ(midpoint_values[1], 1.5); + Profile* foo_copy = GetProfile(profile_map, "foo", "molecule cm-3", &error); + for (auto& edge : edge_values) + { + edge = -100.0; + } + for (auto& midpoint : midpoint_values) + { + midpoint = -100.0; + } + GetProfileEdgeValues(foo_copy, edge_values, 3, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(edge_values[0], 0.0); + ASSERT_EQ(edge_values[1], 1.0); + ASSERT_EQ(edge_values[2], 2.0); + GetProfileMidpointValues(foo_copy, midpoint_values, 2, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(midpoint_values[0], 0.5); + ASSERT_EQ(midpoint_values[1], 1.5); + edge_values[0] = 5.0; + edge_values[1] = 10.0; + edge_values[2] = 20.0; + midpoint_values[0] = 7.5; + midpoint_values[1] = 15.0; + SetProfileEdgeValues(foo_copy, edge_values, 3, &error); + SetProfileMidpointValues(foo_copy, midpoint_values, 2, &error); + ASSERT_TRUE(IsSuccess(error)); + for (auto& edge : edge_values) + { + edge = -100.0; + } + for (auto& midpoint : midpoint_values) + { + midpoint = -100.0; + } + GetProfileEdgeValues(foo_copy, edge_values, 3, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(edge_values[0], 5.0); + ASSERT_EQ(edge_values[1], 10.0); + ASSERT_EQ(edge_values[2], 20.0); + GetProfileMidpointValues(foo_copy, midpoint_values, 2, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(midpoint_values[0], 7.5); + ASSERT_EQ(midpoint_values[1], 15.0); + for (auto& edge : edge_values) + { + edge = -100.0; + } + for (auto& midpoint : midpoint_values) + { + midpoint = -100.0; + } + GetProfileEdgeValues(foo_profile, edge_values, 3, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(edge_values[0], 5.0); + ASSERT_EQ(edge_values[1], 10.0); + ASSERT_EQ(edge_values[2], 20.0); + GetProfileMidpointValues(foo_profile, midpoint_values, 2, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(midpoint_values[0], 7.5); + ASSERT_EQ(midpoint_values[1], 15.0); + DeleteProfile(foo_profile, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteProfile(bar_profile, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteProfile(foo_copy, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteGrid(foo_grid, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteGrid(bar_grid, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteProfileMap(profile_map, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteError(&error); +} -// TEST_F(TuvxCApiTest, CannotGetConfiguredRadiator) -// { -// const char* yaml_config_path = "examples/ts1_tsmlt.yml"; -// SetUp(yaml_config_path); -// Error error; -// RadiatorMap* radiator_map = GetRadiatorMap(tuvx, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(radiator_map, nullptr); -// Radiator* radiator = GetRadiator(radiator_map, "foo", &error); -// ASSERT_FALSE(IsSuccess(error)); // non-host grid -// ASSERT_EQ(radiator, nullptr); -// DeleteRadiatorMap(radiator_map, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteError(&error); -// } +TEST_F(TuvxCApiTest, CannotGetConfiguredRadiator) +{ + const char* yaml_config_path = "examples/ts1_tsmlt.yml"; + SetUp(yaml_config_path); + Error error; + RadiatorMap* radiator_map = GetRadiatorMap(tuvx, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(radiator_map, nullptr); + Radiator* radiator = GetRadiator(radiator_map, "foo", &error); + ASSERT_FALSE(IsSuccess(error)); // non-host grid + ASSERT_EQ(radiator, nullptr); + DeleteRadiatorMap(radiator_map, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteError(&error); +} -// TEST_F(TuvxCApiTest, CanCreateRadiator) -// { -// Error error; -// Grid* height = CreateGrid("height", "km", 3, &error); -// Grid* wavelength = CreateGrid("wavelength", "nm", 2, &error); -// Radiator* radiator = CreateRadiator("foo", height, wavelength, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(radiator, nullptr); +TEST_F(TuvxCApiTest, CanCreateRadiator) +{ + Error error; + Grid* height = CreateGrid("height", "km", 3, &error); + Grid* wavelength = CreateGrid("wavelength", "nm", 2, &error); + Radiator* radiator = CreateRadiator("foo", height, wavelength, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(radiator, nullptr); -// // Test for optical depths -// std::size_t num_vertical_layers = 3; -// std::size_t num_wavelength_bins = 2; -// // Allocate array as 1D -// double* optical_depths_1D = new double[num_wavelength_bins * num_vertical_layers]; -// // Allocate an array of pointers to each row -// double** optical_depths = new double*[num_vertical_layers]; -// // Fill in the pointers to the rows -// for (int row = 0; row < num_vertical_layers; row++) -// { -// optical_depths[row] = &optical_depths_1D[row * num_wavelength_bins]; -// } -// int i = 1; -// for (int row = 0; row < num_vertical_layers; row++) -// { -// for (int col = 0; col < num_wavelength_bins; col++) -// { -// optical_depths[row][col] = 10 * i; -// i++; -// } -// } -// SetRadiatorOpticalDepths(radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); -// ASSERT_TRUE(IsSuccess(error)); -// for (int row = 0; row < num_vertical_layers; row++) -// { -// for (int col = 0; col < num_wavelength_bins; col++) -// { -// optical_depths[row][col] = -999.0; -// } -// } -// GetRadiatorOpticalDepths(radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(optical_depths[0][0], 10.0); -// ASSERT_EQ(optical_depths[0][1], 20.0); -// ASSERT_EQ(optical_depths[1][0], 30.0); -// ASSERT_EQ(optical_depths[1][1], 40.0); -// ASSERT_EQ(optical_depths[2][0], 50.0); -// ASSERT_EQ(optical_depths[2][1], 60.0); + // Test for optical depths + std::size_t num_vertical_layers = 3; + std::size_t num_wavelength_bins = 2; + // Allocate array as 1D + double* optical_depths_1D = new double[num_wavelength_bins * num_vertical_layers]; + // Allocate an array of pointers to each row + double** optical_depths = new double*[num_vertical_layers]; + // Fill in the pointers to the rows + for (int row = 0; row < num_vertical_layers; row++) + { + optical_depths[row] = &optical_depths_1D[row * num_wavelength_bins]; + } + int i = 1; + for (int row = 0; row < num_vertical_layers; row++) + { + for (int col = 0; col < num_wavelength_bins; col++) + { + optical_depths[row][col] = 10 * i; + i++; + } + } + SetRadiatorOpticalDepths(radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); + ASSERT_TRUE(IsSuccess(error)); + for (int row = 0; row < num_vertical_layers; row++) + { + for (int col = 0; col < num_wavelength_bins; col++) + { + optical_depths[row][col] = -999.0; + } + } + GetRadiatorOpticalDepths(radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(optical_depths[0][0], 10.0); + ASSERT_EQ(optical_depths[0][1], 20.0); + ASSERT_EQ(optical_depths[1][0], 30.0); + ASSERT_EQ(optical_depths[1][1], 40.0); + ASSERT_EQ(optical_depths[2][0], 50.0); + ASSERT_EQ(optical_depths[2][1], 60.0); -// // Test for single scattering albedos -// double* albedos_1D = new double[num_wavelength_bins * num_vertical_layers]; -// double** albedos = new double*[num_vertical_layers]; -// for (int row = 0; row < num_vertical_layers; row++) -// { -// albedos[row] = &albedos_1D[row * num_wavelength_bins]; -// } -// i = 1; -// for (int row = 0; row < num_vertical_layers; row++) -// { -// for (int col = 0; col < num_wavelength_bins; col++) -// { -// albedos[row][col] = 100 * i; -// i++; -// } -// } -// SetRadiatorSingleScatteringAlbedos(radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); -// ASSERT_TRUE(IsSuccess(error)); -// for (int row = 0; row < num_vertical_layers; row++) -// { -// for (int col = 0; col < num_wavelength_bins; col++) -// { -// albedos[row][col] = -999.0; -// } -// } -// GetRadiatorSingleScatteringAlbedos(radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(albedos[0][0], 100.0); -// ASSERT_EQ(albedos[0][1], 200.0); -// ASSERT_EQ(albedos[1][0], 300.0); -// ASSERT_EQ(albedos[1][1], 400.0); -// ASSERT_EQ(albedos[2][0], 500.0); -// ASSERT_EQ(albedos[2][1], 600.0); + // Test for single scattering albedos + double* albedos_1D = new double[num_wavelength_bins * num_vertical_layers]; + double** albedos = new double*[num_vertical_layers]; + for (int row = 0; row < num_vertical_layers; row++) + { + albedos[row] = &albedos_1D[row * num_wavelength_bins]; + } + i = 1; + for (int row = 0; row < num_vertical_layers; row++) + { + for (int col = 0; col < num_wavelength_bins; col++) + { + albedos[row][col] = 100 * i; + i++; + } + } + SetRadiatorSingleScatteringAlbedos(radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); + ASSERT_TRUE(IsSuccess(error)); + for (int row = 0; row < num_vertical_layers; row++) + { + for (int col = 0; col < num_wavelength_bins; col++) + { + albedos[row][col] = -999.0; + } + } + GetRadiatorSingleScatteringAlbedos(radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(albedos[0][0], 100.0); + ASSERT_EQ(albedos[0][1], 200.0); + ASSERT_EQ(albedos[1][0], 300.0); + ASSERT_EQ(albedos[1][1], 400.0); + ASSERT_EQ(albedos[2][0], 500.0); + ASSERT_EQ(albedos[2][1], 600.0); -// // Test for asymmetery factors -// double* factors_1D = new double[num_wavelength_bins * num_vertical_layers]; -// double** factors = new double*[num_vertical_layers]; -// for (int row = 0; row < num_vertical_layers; row++) -// { -// factors[row] = &factors_1D[row * num_wavelength_bins]; -// } -// i = 1; -// for (int row = 0; row < num_vertical_layers; row++) -// { -// for (int col = 0; col < num_wavelength_bins; col++) -// { -// factors[row][col] = 1 * i; -// i++; -// } -// } -// std::size_t num_streams = 1; -// SetRadiatorAsymmetryFactors(radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); -// ASSERT_TRUE(IsSuccess(error)); -// for (int row = 0; row < num_vertical_layers; row++) -// { -// for (int col = 0; col < num_wavelength_bins; col++) -// { -// factors[row][col] = -999.0; -// } -// } -// GetRadiatorAsymmetryFactors(radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(factors[0][0], 1); -// ASSERT_EQ(factors[0][1], 2); -// ASSERT_EQ(factors[1][0], 3); -// ASSERT_EQ(factors[1][1], 4); -// ASSERT_EQ(factors[2][0], 5); -// ASSERT_EQ(factors[2][1], 6); + // Test for asymmetery factors + double* factors_1D = new double[num_wavelength_bins * num_vertical_layers]; + double** factors = new double*[num_vertical_layers]; + for (int row = 0; row < num_vertical_layers; row++) + { + factors[row] = &factors_1D[row * num_wavelength_bins]; + } + i = 1; + for (int row = 0; row < num_vertical_layers; row++) + { + for (int col = 0; col < num_wavelength_bins; col++) + { + factors[row][col] = 1 * i; + i++; + } + } + std::size_t num_streams = 1; + SetRadiatorAsymmetryFactors(radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); + ASSERT_TRUE(IsSuccess(error)); + for (int row = 0; row < num_vertical_layers; row++) + { + for (int col = 0; col < num_wavelength_bins; col++) + { + factors[row][col] = -999.0; + } + } + GetRadiatorAsymmetryFactors(radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(factors[0][0], 1); + ASSERT_EQ(factors[0][1], 2); + ASSERT_EQ(factors[1][0], 3); + ASSERT_EQ(factors[1][1], 4); + ASSERT_EQ(factors[2][0], 5); + ASSERT_EQ(factors[2][1], 6); -// // Clean up -// DeleteRadiator(radiator, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteGrid(height, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteGrid(wavelength, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteError(&error); -// delete[] optical_depths; -// delete[] optical_depths_1D; -// delete[] albedos; -// delete[] albedos_1D; -// delete[] factors; -// delete[] factors_1D; -// } + // Clean up + DeleteRadiator(radiator, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteGrid(height, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteGrid(wavelength, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteError(&error); + delete[] optical_depths; + delete[] optical_depths_1D; + delete[] albedos; + delete[] albedos_1D; + delete[] factors; + delete[] factors_1D; +} -// TEST_F(TuvxCApiTest, CanCreateRadiatorMap) -// { -// Error error; -// RadiatorMap* radiator_map = CreateRadiatorMap(&error); -// ASSERT_TRUE(IsSuccess(error)); -// Grid* height = CreateGrid("height", "km", 3, &error); -// Grid* wavelength = CreateGrid("wavelength", "nm", 2, &error); -// Radiator* foo_radiator = CreateRadiator("foo", height, wavelength, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(foo_radiator, nullptr); -// AddRadiator(radiator_map, foo_radiator, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(radiator_map, nullptr); -// Grid* bar_height = CreateGrid("bar_height", "km", 3, &error); -// Grid* bar_wavelength = CreateGrid("bar_wavelength", "nm", 2, &error); -// Radiator* bar_radiator = CreateRadiator("bar", bar_height, bar_wavelength, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(bar_radiator, nullptr); -// AddRadiator(radiator_map, bar_radiator, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(radiator_map, nullptr); +TEST_F(TuvxCApiTest, CanCreateRadiatorMap) +{ + Error error; + RadiatorMap* radiator_map = CreateRadiatorMap(&error); + ASSERT_TRUE(IsSuccess(error)); + Grid* height = CreateGrid("height", "km", 3, &error); + Grid* wavelength = CreateGrid("wavelength", "nm", 2, &error); + Radiator* foo_radiator = CreateRadiator("foo", height, wavelength, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(foo_radiator, nullptr); + AddRadiator(radiator_map, foo_radiator, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(radiator_map, nullptr); + Grid* bar_height = CreateGrid("bar_height", "km", 3, &error); + Grid* bar_wavelength = CreateGrid("bar_wavelength", "nm", 2, &error); + Radiator* bar_radiator = CreateRadiator("bar", bar_height, bar_wavelength, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(bar_radiator, nullptr); + AddRadiator(radiator_map, bar_radiator, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(radiator_map, nullptr); -// // Test for optical depths -// std::size_t num_vertical_layers = 3; -// std::size_t num_wavelength_bins = 2; -// double* optical_depths_1D = new double[num_wavelength_bins * num_vertical_layers]; -// double** optical_depths = new double*[num_vertical_layers]; -// for (int row = 0; row < num_vertical_layers; row++) -// { -// optical_depths[row] = &optical_depths_1D[row * num_wavelength_bins]; -// } -// int i = 1; -// for (int row = 0; row < num_vertical_layers; row++) -// { -// for (int col = 0; col < num_wavelength_bins; col++) -// { -// optical_depths[row][col] = 10 * i; -// i++; -// } -// } -// SetRadiatorOpticalDepths(foo_radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); -// ASSERT_TRUE(IsSuccess(error)); + // Test for optical depths + std::size_t num_vertical_layers = 3; + std::size_t num_wavelength_bins = 2; + double* optical_depths_1D = new double[num_wavelength_bins * num_vertical_layers]; + double** optical_depths = new double*[num_vertical_layers]; + for (int row = 0; row < num_vertical_layers; row++) + { + optical_depths[row] = &optical_depths_1D[row * num_wavelength_bins]; + } + int i = 1; + for (int row = 0; row < num_vertical_layers; row++) + { + for (int col = 0; col < num_wavelength_bins; col++) + { + optical_depths[row][col] = 10 * i; + i++; + } + } + SetRadiatorOpticalDepths(foo_radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); + ASSERT_TRUE(IsSuccess(error)); -// // Test for single scattering albedos -// double* albedos_1D = new double[num_wavelength_bins * num_vertical_layers]; -// double** albedos = new double*[num_vertical_layers]; -// for (int row = 0; row < num_vertical_layers; row++) -// { -// albedos[row] = &albedos_1D[row * num_wavelength_bins]; -// } -// i = 1; -// for (int row = 0; row < num_vertical_layers; row++) -// { -// for (int col = 0; col < num_wavelength_bins; col++) -// { -// albedos[row][col] = 100 * i; -// i++; -// } -// } -// SetRadiatorSingleScatteringAlbedos(foo_radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); -// ASSERT_TRUE(IsSuccess(error)); + // Test for single scattering albedos + double* albedos_1D = new double[num_wavelength_bins * num_vertical_layers]; + double** albedos = new double*[num_vertical_layers]; + for (int row = 0; row < num_vertical_layers; row++) + { + albedos[row] = &albedos_1D[row * num_wavelength_bins]; + } + i = 1; + for (int row = 0; row < num_vertical_layers; row++) + { + for (int col = 0; col < num_wavelength_bins; col++) + { + albedos[row][col] = 100 * i; + i++; + } + } + SetRadiatorSingleScatteringAlbedos(foo_radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); + ASSERT_TRUE(IsSuccess(error)); -// // Test for asymmetery factors -// std::size_t num_streams = 1; -// double* factors_1D = new double[num_wavelength_bins * num_vertical_layers]; -// double** factors = new double*[num_vertical_layers]; -// for (int row = 0; row < num_vertical_layers; row++) -// { -// factors[row] = &factors_1D[row * num_wavelength_bins]; -// } -// i = 1; -// for (int row = 0; row < num_vertical_layers; row++) -// { -// for (int col = 0; col < num_wavelength_bins; col++) -// { -// factors[row][col] = 1 * i; -// i++; -// } -// } -// SetRadiatorAsymmetryFactors(foo_radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); -// ASSERT_TRUE(IsSuccess(error)); + // Test for asymmetery factors + std::size_t num_streams = 1; + double* factors_1D = new double[num_wavelength_bins * num_vertical_layers]; + double** factors = new double*[num_vertical_layers]; + for (int row = 0; row < num_vertical_layers; row++) + { + factors[row] = &factors_1D[row * num_wavelength_bins]; + } + i = 1; + for (int row = 0; row < num_vertical_layers; row++) + { + for (int col = 0; col < num_wavelength_bins; col++) + { + factors[row][col] = 1 * i; + i++; + } + } + SetRadiatorAsymmetryFactors(foo_radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); + ASSERT_TRUE(IsSuccess(error)); -// // Test for optical depths -// for (int row = 0; row < num_vertical_layers; row++) -// { -// for (int col = 0; col < num_wavelength_bins; col++) -// { -// optical_depths[row][col] = -999.0; -// } -// } -// GetRadiatorOpticalDepths(foo_radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(optical_depths[0][0], 10.0); -// ASSERT_EQ(optical_depths[0][1], 20.0); -// ASSERT_EQ(optical_depths[1][0], 30.0); -// ASSERT_EQ(optical_depths[1][1], 40.0); -// ASSERT_EQ(optical_depths[2][0], 50.0); -// ASSERT_EQ(optical_depths[2][1], 60.0); + // Test for optical depths + for (int row = 0; row < num_vertical_layers; row++) + { + for (int col = 0; col < num_wavelength_bins; col++) + { + optical_depths[row][col] = -999.0; + } + } + GetRadiatorOpticalDepths(foo_radiator, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(optical_depths[0][0], 10.0); + ASSERT_EQ(optical_depths[0][1], 20.0); + ASSERT_EQ(optical_depths[1][0], 30.0); + ASSERT_EQ(optical_depths[1][1], 40.0); + ASSERT_EQ(optical_depths[2][0], 50.0); + ASSERT_EQ(optical_depths[2][1], 60.0); -// // Test for single scattering albedos -// for (int row = 0; row < num_vertical_layers; row++) -// { -// for (int col = 0; col < num_wavelength_bins; col++) -// { -// albedos[row][col] = -999.0; -// } -// } -// GetRadiatorSingleScatteringAlbedos(foo_radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(albedos[0][0], 100.0); -// ASSERT_EQ(albedos[0][1], 200.0); -// ASSERT_EQ(albedos[1][0], 300.0); -// ASSERT_EQ(albedos[1][1], 400.0); -// ASSERT_EQ(albedos[2][0], 500.0); -// ASSERT_EQ(albedos[2][1], 600.0); + // Test for single scattering albedos + for (int row = 0; row < num_vertical_layers; row++) + { + for (int col = 0; col < num_wavelength_bins; col++) + { + albedos[row][col] = -999.0; + } + } + GetRadiatorSingleScatteringAlbedos(foo_radiator, albedos[0], num_vertical_layers, num_wavelength_bins, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(albedos[0][0], 100.0); + ASSERT_EQ(albedos[0][1], 200.0); + ASSERT_EQ(albedos[1][0], 300.0); + ASSERT_EQ(albedos[1][1], 400.0); + ASSERT_EQ(albedos[2][0], 500.0); + ASSERT_EQ(albedos[2][1], 600.0); -// // Test for asymmetry factors -// for (int row = 0; row < num_vertical_layers; row++) -// { -// for (int col = 0; col < num_wavelength_bins; col++) -// { -// factors[row][col] = -999.0; -// } -// } -// GetRadiatorAsymmetryFactors(foo_radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(factors[0][0], 1); -// ASSERT_EQ(factors[0][1], 2); -// ASSERT_EQ(factors[1][0], 3); -// ASSERT_EQ(factors[1][1], 4); -// ASSERT_EQ(factors[2][0], 5); -// ASSERT_EQ(factors[2][1], 6); + // Test for asymmetry factors + for (int row = 0; row < num_vertical_layers; row++) + { + for (int col = 0; col < num_wavelength_bins; col++) + { + factors[row][col] = -999.0; + } + } + GetRadiatorAsymmetryFactors(foo_radiator, factors[0], num_vertical_layers, num_wavelength_bins, num_streams, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(factors[0][0], 1); + ASSERT_EQ(factors[0][1], 2); + ASSERT_EQ(factors[1][0], 3); + ASSERT_EQ(factors[1][1], 4); + ASSERT_EQ(factors[2][0], 5); + ASSERT_EQ(factors[2][1], 6); -// // Test copy for radiator map -// Radiator* foo_copy = GetRadiator(radiator_map, "foo", &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_NE(foo_copy, nullptr); -// GetRadiatorOpticalDepths(foo_copy, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(optical_depths[0][0], 10.0); -// ASSERT_EQ(optical_depths[0][1], 20.0); -// ASSERT_EQ(optical_depths[1][0], 30.0); -// ASSERT_EQ(optical_depths[1][1], 40.0); -// ASSERT_EQ(optical_depths[2][0], 50.0); -// ASSERT_EQ(optical_depths[2][1], 60.0); -// GetRadiatorSingleScatteringAlbedos(foo_copy, albedos[0], num_vertical_layers, num_wavelength_bins, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(albedos[0][0], 100.0); -// ASSERT_EQ(albedos[0][1], 200.0); -// ASSERT_EQ(albedos[1][0], 300.0); -// ASSERT_EQ(albedos[1][1], 400.0); -// ASSERT_EQ(albedos[2][0], 500.0); -// ASSERT_EQ(albedos[2][1], 600.0); -// GetRadiatorAsymmetryFactors(foo_copy, factors[0], num_vertical_layers, num_wavelength_bins, 1, &error); -// ASSERT_TRUE(IsSuccess(error)); -// ASSERT_EQ(factors[0][0], 1); -// ASSERT_EQ(factors[0][1], 2); -// ASSERT_EQ(factors[1][0], 3); -// ASSERT_EQ(factors[1][1], 4); -// ASSERT_EQ(factors[2][0], 5); -// ASSERT_EQ(factors[2][1], 6); + // Test copy for radiator map + Radiator* foo_copy = GetRadiator(radiator_map, "foo", &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(foo_copy, nullptr); + GetRadiatorOpticalDepths(foo_copy, optical_depths[0], num_vertical_layers, num_wavelength_bins, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(optical_depths[0][0], 10.0); + ASSERT_EQ(optical_depths[0][1], 20.0); + ASSERT_EQ(optical_depths[1][0], 30.0); + ASSERT_EQ(optical_depths[1][1], 40.0); + ASSERT_EQ(optical_depths[2][0], 50.0); + ASSERT_EQ(optical_depths[2][1], 60.0); + GetRadiatorSingleScatteringAlbedos(foo_copy, albedos[0], num_vertical_layers, num_wavelength_bins, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(albedos[0][0], 100.0); + ASSERT_EQ(albedos[0][1], 200.0); + ASSERT_EQ(albedos[1][0], 300.0); + ASSERT_EQ(albedos[1][1], 400.0); + ASSERT_EQ(albedos[2][0], 500.0); + ASSERT_EQ(albedos[2][1], 600.0); + GetRadiatorAsymmetryFactors(foo_copy, factors[0], num_vertical_layers, num_wavelength_bins, 1, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_EQ(factors[0][0], 1); + ASSERT_EQ(factors[0][1], 2); + ASSERT_EQ(factors[1][0], 3); + ASSERT_EQ(factors[1][1], 4); + ASSERT_EQ(factors[2][0], 5); + ASSERT_EQ(factors[2][1], 6); -// // Clean up -// DeleteRadiator(foo_radiator, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteRadiator(bar_radiator, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteRadiator(foo_copy, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteRadiatorMap(radiator_map, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteGrid(height, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteGrid(wavelength, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteGrid(bar_height, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteGrid(bar_wavelength, &error); -// ASSERT_TRUE(IsSuccess(error)); -// DeleteError(&error); -// delete[] optical_depths; -// delete[] optical_depths_1D; -// delete[] albedos; -// delete[] albedos_1D; -// delete[] factors; -// delete[] factors_1D; -// } \ No newline at end of file + // Clean up + DeleteRadiator(foo_radiator, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteRadiator(bar_radiator, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteRadiator(foo_copy, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteRadiatorMap(radiator_map, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteGrid(height, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteGrid(wavelength, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteGrid(bar_height, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteGrid(bar_wavelength, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteError(&error); + delete[] optical_depths; + delete[] optical_depths_1D; + delete[] albedos; + delete[] albedos_1D; + delete[] factors; + delete[] factors_1D; +} \ No newline at end of file diff --git a/src/tuvx/interface.F90 b/src/tuvx/interface.F90 index ff040ce8..48ca85db 100644 --- a/src/tuvx/interface.F90 +++ b/src/tuvx/interface.F90 @@ -19,8 +19,8 @@ module tuvx_interface !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - function internal_create_tuvx(c_config_path, config_path_length, grids, & - profiles, radiators, error_code) bind(C, name="InternalCreateTuvx") + function internal_create_tuvx(c_config_path, config_path_length, error_code) & + bind(C, name="InternalCreateTuvx") use iso_c_binding, only: c_ptr, c_f_pointer ! arguments diff --git a/src/tuvx/tuvx.cpp b/src/tuvx/tuvx.cpp index d7c59805..ee1e0db9 100644 --- a/src/tuvx/tuvx.cpp +++ b/src/tuvx/tuvx.cpp @@ -49,6 +49,7 @@ namespace musica GridMap *GetGridMap(TUVX *tuvx, Error *error) { DeleteError(error); + // TODO(jiwon) return tuvx->CreateGridMap(error); } @@ -67,7 +68,7 @@ namespace musica // TUVX class functions TUVX::TUVX() - : tuvx_() + : tuvx_(nullptr) { } @@ -79,6 +80,7 @@ namespace musica tuvx_ = nullptr; } + // TODO(jiwon) remove things and create grid back void TUVX::Create(const char *config_path, GridMap *grids, ProfileMap *profiles, RadiatorMap *radiators, Error *error) { int parsing_status = 0; // 0 on success, 1 on failure @@ -91,7 +93,7 @@ namespace musica return; } - tuvx_ = InternalCreateTuvx(config_path, strlen(config_path), grids, profiles, radiators, &parsing_status); + tuvx_ = InternalCreateTuvx(config_path, strlen(config_path), &parsing_status); if (parsing_status == 1) { *error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to create tuvx instance") }; @@ -100,6 +102,12 @@ namespace musica { *error = NoError(); } + + // TODO(jiwon) check error msg? + // deallocate the grid, profile and radiator map after you pass it to the constructor + DeleteGridMap(grids, error); + DeleteProfileMap(profiles, error); + DeleteRadiatorMap(radiators, error); } catch (const std::system_error &e) { @@ -116,6 +124,7 @@ namespace musica *error = NoError(); int error_code = 0; // TODO (jiwon) remove this new operation? + GridMap *grid_map = new GridMap(InternalGetGridMap(tuvx_, &error_code)); if (error_code != 0) { From efbfa317d975ab529bf872435669059948015a68 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 30 Aug 2024 11:32:42 -0600 Subject: [PATCH 04/10] add value attribute --- .../test_tuvx_api.F90 | 20 ++++-------- fortran/tuvx/tuvx.F90 | 32 ++++++++----------- src/tuvx/tuvx.cpp | 2 -- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/fortran/test/fetch_content_integration/test_tuvx_api.F90 b/fortran/test/fetch_content_integration/test_tuvx_api.F90 index d32e4b8e..e2ec007b 100644 --- a/fortran/test/fetch_content_integration/test_tuvx_api.F90 +++ b/fortran/test/fetch_content_integration/test_tuvx_api.F90 @@ -47,9 +47,6 @@ subroutine test_tuvx_api() tuvx => tuvx_t(config_path, grids, profiles, radiators, error) ASSERT( error%is_success() ) - deallocate( grids ) - deallocate( profiles ) - deallocate( radiators ) deallocate( tuvx ) end subroutine test_tuvx_api @@ -86,11 +83,11 @@ subroutine test_tuvx_solve() type(tuvx_t), pointer :: tuvx type(error_t) :: error character(len=256) :: config_path - type(grid_map_t), pointer :: grids + type(grid_map_t), pointer :: grids, grids_from_host type(grid_t), pointer :: grid, height_grid, wavelength_grid - type(profile_map_t), pointer :: profiles + type(profile_map_t), pointer :: profiles, profiles_from_host type(profile_t), pointer :: profile, profile_copy - type(radiator_map_t), pointer :: radiators + type(radiator_map_t), pointer :: radiators, radiators_from_host type(radiator_t), pointer :: radiator, radiator_copy real*8, dimension(5), target :: edges, edge_values, temp_edge real*8, dimension(4), target :: midpoints, midpoint_values, layer_densities, temp_midpoint @@ -116,18 +113,15 @@ subroutine test_tuvx_solve() config_path = "examples/ts1_tsmlt.json" - grids => grid_map_t( error ) + grids_from_host => grid_map_t( error ) ASSERT( error%is_success() ) - profiles => profile_map_t( error ) + profiles_from_host => profile_map_t( error ) ASSERT( error%is_success() ) - radiators => radiator_map_t( error ) + radiators_from_host => radiator_map_t( error ) ASSERT( error%is_success() ) - tuvx => tuvx_t(config_path, grids, profiles, radiators, error) + tuvx => tuvx_t(config_path, grids_from_host, profiles_from_host, radiators_from_host, error) ASSERT( error%is_success() ) - !!!! - !!!! Jiwon - !!!! grids => tuvx%get_grids( error ) ASSERT( error%is_success() ) diff --git a/fortran/tuvx/tuvx.F90 b/fortran/tuvx/tuvx.F90 index 8cb2173c..ff64f0fe 100644 --- a/fortran/tuvx/tuvx.F90 +++ b/fortran/tuvx/tuvx.F90 @@ -25,11 +25,11 @@ function create_tuvx_c(config_path, grids, profiles, radiators, error) bind(C, n use musica_util, only: error_t_c use iso_c_binding, only: c_ptr, c_int, c_char character(len=1, kind=c_char), intent(in) :: config_path(*) - type(c_ptr), intent(in) :: grids - type(c_ptr), intent(in) :: profiles - type(c_ptr), intent(in) :: radiators + type(c_ptr), value, intent(in) :: grids + type(c_ptr), value, intent(in) :: profiles + type(c_ptr), value, intent(in) :: radiators type(error_t_c), intent(inout) :: error - type(c_ptr), :: create_tuvx_c + type(c_ptr) :: create_tuvx_c end function create_tuvx_c subroutine delete_tuvx_c(tuvx, error) bind(C, name="DeleteTuvx") @@ -90,22 +90,20 @@ end function get_radiator_map_c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Construct a tuvx instance - function constructor(config_path, grids, profiles, radiators, error) result( this ) - use iso_c_binding, only: c_char, c_null_char + function constructor(config_path, grids, profiles, radiators, error) & + result( this ) + use iso_c_binding, only: c_char, c_null_char, c_loc use musica_util, only: error_t_c, error_t ! Arguments - character(len=*), intent(in) :: config_path - type(grid_map_t), intent(in) :: grids - type(profile_map_t), intent(in) :: profiles - type(radiator_map_t), intent(in) :: radiators - type(error_t), intent(inout) :: error + character(len=*), intent(in) :: config_path + type(grid_map_t), target, intent(in) :: grids + type(profile_map_t), target, intent(in) :: profiles + type(radiator_map_t), target, intent(in) :: radiators + type(error_t), intent(inout) :: error ! Local variables character(len=1, kind=c_char) :: config_path_c(len_trim(config_path)+1) - type(c_ptr) :: grids_c - type(c_ptr) :: profiles_c - type(c_ptr) :: radiators_c type(error_t_c) :: error_c integer :: n, i @@ -120,11 +118,7 @@ function constructor(config_path, grids, profiles, radiators, error) result( th end do config_path_c(n+1) = c_null_char - grids_c = c_loc(grids) - profiles_c = c_loc(profiles) - radiators_c = c_loc(radiators) - - this%ptr_ = create_tuvx_c(config_path_c, grids_c, profiles_c, radiators_c, error_c) + this%ptr_ = create_tuvx_c(config_path_c, c_loc(grids), c_loc(profiles), c_loc(radiators), error_c) error = error_t(error_c) if (.not. error%is_success()) then diff --git a/src/tuvx/tuvx.cpp b/src/tuvx/tuvx.cpp index ee1e0db9..49d380d5 100644 --- a/src/tuvx/tuvx.cpp +++ b/src/tuvx/tuvx.cpp @@ -80,7 +80,6 @@ namespace musica tuvx_ = nullptr; } - // TODO(jiwon) remove things and create grid back void TUVX::Create(const char *config_path, GridMap *grids, ProfileMap *profiles, RadiatorMap *radiators, Error *error) { int parsing_status = 0; // 0 on success, 1 on failure @@ -123,7 +122,6 @@ namespace musica { *error = NoError(); int error_code = 0; - // TODO (jiwon) remove this new operation? GridMap *grid_map = new GridMap(InternalGetGridMap(tuvx_, &error_code)); if (error_code != 0) From ab577b5eb3a51ac4a9117dc05963a6cdfca77333 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 30 Aug 2024 14:23:44 -0600 Subject: [PATCH 05/10] fix memory leak --- .../test_tuvx_api.F90 | 19 ++++---- include/musica/tuvx/tuvx.hpp | 5 ++- src/test/unit/tuvx/tuvx_c_api.cpp | 43 +++++++++++++------ src/tuvx/tuvx.cpp | 8 +--- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/fortran/test/fetch_content_integration/test_tuvx_api.F90 b/fortran/test/fetch_content_integration/test_tuvx_api.F90 index e2ec007b..66a6d316 100644 --- a/fortran/test/fetch_content_integration/test_tuvx_api.F90 +++ b/fortran/test/fetch_content_integration/test_tuvx_api.F90 @@ -37,16 +37,16 @@ subroutine test_tuvx_api() grids => grid_map_t( error ) ASSERT( error%is_success() ) - profiles => profile_map_t( error ) ASSERT( error%is_success() ) - radiators => radiator_map_t( error ) ASSERT( error%is_success() ) - tuvx => tuvx_t(config_path, grids, profiles, radiators, error) ASSERT( error%is_success() ) + deallocate( grids ) + deallocate( profiles ) + deallocate( radiators ) deallocate( tuvx ) end subroutine test_tuvx_api @@ -63,19 +63,17 @@ subroutine test_tuvx_api_invalid_config() grids => grid_map_t( error ) ASSERT( error%is_success() ) - profiles => profile_map_t( error ) ASSERT( error%is_success() ) - radiators => radiator_map_t( error ) ASSERT( error%is_success() ) - - tuvx => tuvx_t(config_path, grids, profiles, radiators, error) - ASSERT( error%is_success() ) - tuvx => tuvx_t(config_path, grids, profiles, radiators, error) ASSERT( .not. error%is_success() ) + deallocate( grids ) + deallocate( profiles ) + deallocate( radiators ) + end subroutine test_tuvx_api_invalid_config subroutine test_tuvx_solve() @@ -498,6 +496,9 @@ subroutine test_tuvx_solve() deallocate( radiators ) deallocate( height_grid ) deallocate( wavelength_grid ) + deallocate( grids_from_host ) + deallocate( profiles_from_host ) + deallocate( radiators_from_host ) deallocate( tuvx ) end subroutine test_tuvx_solve diff --git a/include/musica/tuvx/tuvx.hpp b/include/musica/tuvx/tuvx.hpp index ebe1ef67..560ffbda 100644 --- a/include/musica/tuvx/tuvx.hpp +++ b/include/musica/tuvx/tuvx.hpp @@ -24,8 +24,9 @@ namespace musica /// @brief Create an instance of tuvx from a configuration file /// @param config_path Path to configuration file - /// @param TODO(jiwon) - /// @param TODO(jiwon) + /// @param grids Grid map from host application + /// @param profiles Profile map from host application + /// @param radiators Radiator map from host application /// @param error Error struct to indicate success or failure void Create(const char *config_path, GridMap *grids, ProfileMap *profiles, RadiatorMap *radiators, Error *error); diff --git a/src/test/unit/tuvx/tuvx_c_api.cpp b/src/test/unit/tuvx/tuvx_c_api.cpp index f8c11db9..96b74497 100644 --- a/src/test/unit/tuvx/tuvx_c_api.cpp +++ b/src/test/unit/tuvx/tuvx_c_api.cpp @@ -9,26 +9,26 @@ class TuvxCApiTest : public ::testing::Test { protected: TUVX* tuvx; - GridMap* grids; - ProfileMap* profiles; - RadiatorMap* radiators; + GridMap* grids_from_host; + ProfileMap* profiles_from_host; + RadiatorMap* radiators_from_host; // the function that google test actually calls before each test void SetUp() override { tuvx = nullptr; - grids = nullptr; - profiles = nullptr; - radiators = nullptr; + grids_from_host = nullptr; + profiles_from_host = nullptr; + radiators_from_host = nullptr; } void SetUp(const char* config_path) { Error error; - grids = CreateGridMap(&error); - profiles = CreateProfileMap(&error); - radiators = CreateRadiatorMap(&error); - tuvx = CreateTuvx(config_path, grids, profiles, radiators, &error); + grids_from_host = CreateGridMap(&error); + profiles_from_host = CreateProfileMap(&error); + radiators_from_host = CreateRadiatorMap(&error); + tuvx = CreateTuvx(config_path, grids_from_host, profiles_from_host, radiators_from_host, &error); if (!IsSuccess(error)) { std::cerr << "Error creating TUVX instance: " << error.message_.value_ << std::endl; @@ -46,8 +46,17 @@ class TuvxCApiTest : public ::testing::Test Error error; DeleteTuvx(tuvx, &error); ASSERT_TRUE(IsSuccess(error)); + DeleteGridMap(grids_from_host, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteProfileMap(profiles_from_host, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteRadiatorMap(radiators_from_host, &error); + ASSERT_TRUE(IsSuccess(error)); DeleteError(&error); tuvx = nullptr; + grids_from_host = nullptr; + profiles_from_host = nullptr; + radiators_from_host = nullptr; } }; @@ -69,11 +78,17 @@ TEST_F(TuvxCApiTest, DetectsNonexistentConfigFile) { const char* config_path = "nonexisting.yml"; Error error; - GridMap* grids = CreateGridMap(&error); - ProfileMap* profiles = CreateProfileMap(&error); - RadiatorMap* radiators = CreateRadiatorMap(&error); - TUVX* tuvx = CreateTuvx(config_path, grids, profiles, radiators, &error); + GridMap* grids_from_host = CreateGridMap(&error); + ProfileMap* profiles_from_host = CreateProfileMap(&error); + RadiatorMap* radiators_from_host = CreateRadiatorMap(&error); + TUVX* tuvx = CreateTuvx(config_path, grids_from_host, profiles_from_host, radiators_from_host, &error); ASSERT_FALSE(IsSuccess(error)); + DeleteGridMap(grids_from_host, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteProfileMap(profiles_from_host, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteRadiatorMap(radiators_from_host, &error); + ASSERT_TRUE(IsSuccess(error)); DeleteError(&error); } diff --git a/src/tuvx/tuvx.cpp b/src/tuvx/tuvx.cpp index 49d380d5..4cf63733 100644 --- a/src/tuvx/tuvx.cpp +++ b/src/tuvx/tuvx.cpp @@ -49,7 +49,7 @@ namespace musica GridMap *GetGridMap(TUVX *tuvx, Error *error) { DeleteError(error); - // TODO(jiwon) + return tuvx->CreateGridMap(error); } @@ -101,12 +101,6 @@ namespace musica { *error = NoError(); } - - // TODO(jiwon) check error msg? - // deallocate the grid, profile and radiator map after you pass it to the constructor - DeleteGridMap(grids, error); - DeleteProfileMap(profiles, error); - DeleteRadiatorMap(radiators, error); } catch (const std::system_error &e) { From 766f4b92a1a4160b49fb52e9dce9ead43ab82bcc Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 30 Aug 2024 14:32:04 -0600 Subject: [PATCH 06/10] enable micm --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ed5dc85..d416647e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ option(MUSICA_ENABLE_MPI "Enable MPI parallel support" OFF) option(MUSICA_ENABLE_OPENMP "Enable OpemMP support" OFF) option(MUSICA_ENABLE_MEMCHECK "Enable memory checking" OFF) option(MUSICA_BUILD_DOCS "Build the documentation" OFF) -option(MUSICA_ENABLE_MICM "Enable MICM" OFF) +option(MUSICA_ENABLE_MICM "Enable MICM" ON) option(MUSICA_ENABLE_TUVX "Enable TUV-x" ON) set(MUSICA_SET_MICM_VECTOR_MATRIX_SIZE "1" CACHE STRING "Set MICM vector-ordered matrix dimension") From ad61ad08b5900918d52db432f5f6d36574dec432 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 30 Aug 2024 14:56:32 -0600 Subject: [PATCH 07/10] code cleanup --- fortran/tuvx/tuvx.F90 | 8 ++++---- src/test/unit/tuvx/tuvx_c_api.cpp | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/fortran/tuvx/tuvx.F90 b/fortran/tuvx/tuvx.F90 index ff64f0fe..146f2a50 100644 --- a/fortran/tuvx/tuvx.F90 +++ b/fortran/tuvx/tuvx.F90 @@ -103,7 +103,7 @@ function constructor(config_path, grids, profiles, radiators, error) & type(error_t), intent(inout) :: error ! Local variables - character(len=1, kind=c_char) :: config_path_c(len_trim(config_path)+1) + character(len=1, kind=c_char) :: c_config_path(len_trim(config_path)+1) type(error_t_c) :: error_c integer :: n, i @@ -114,11 +114,11 @@ function constructor(config_path, grids, profiles, radiators, error) & n = len_trim(config_path) do i = 1, n - config_path_c(i) = config_path(i:i) + c_config_path(i) = config_path(i:i) end do - config_path_c(n+1) = c_null_char + c_config_path(n+1) = c_null_char - this%ptr_ = create_tuvx_c(config_path_c, c_loc(grids), c_loc(profiles), c_loc(radiators), error_c) + this%ptr_ = create_tuvx_c(c_config_path, c_loc(grids), c_loc(profiles), c_loc(radiators), error_c) error = error_t(error_c) if (.not. error%is_success()) then diff --git a/src/test/unit/tuvx/tuvx_c_api.cpp b/src/test/unit/tuvx/tuvx_c_api.cpp index 96b74497..42e33b9c 100644 --- a/src/test/unit/tuvx/tuvx_c_api.cpp +++ b/src/test/unit/tuvx/tuvx_c_api.cpp @@ -53,10 +53,6 @@ class TuvxCApiTest : public ::testing::Test DeleteRadiatorMap(radiators_from_host, &error); ASSERT_TRUE(IsSuccess(error)); DeleteError(&error); - tuvx = nullptr; - grids_from_host = nullptr; - profiles_from_host = nullptr; - radiators_from_host = nullptr; } }; From 3950d6b6a23db2e74a2ebd6885b94c68eee905f7 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 30 Aug 2024 15:07:43 -0600 Subject: [PATCH 08/10] formatting --- fortran/tuvx/tuvx.F90 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fortran/tuvx/tuvx.F90 b/fortran/tuvx/tuvx.F90 index 146f2a50..51364f8a 100644 --- a/fortran/tuvx/tuvx.F90 +++ b/fortran/tuvx/tuvx.F90 @@ -21,7 +21,8 @@ module musica_tuvx !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! interface - function create_tuvx_c(config_path, grids, profiles, radiators, error) bind(C, name="CreateTuvx") + function create_tuvx_c(config_path, grids, profiles, radiators, error) % + bind(C, name="CreateTuvx") use musica_util, only: error_t_c use iso_c_binding, only: c_ptr, c_int, c_char character(len=1, kind=c_char), intent(in) :: config_path(*) @@ -118,7 +119,8 @@ function constructor(config_path, grids, profiles, radiators, error) & end do c_config_path(n+1) = c_null_char - this%ptr_ = create_tuvx_c(c_config_path, c_loc(grids), c_loc(profiles), c_loc(radiators), error_c) + this%ptr_ = create_tuvx_c(c_config_path, c_loc(grids), c_loc(profiles), & + c_loc(radiators), error_c) error = error_t(error_c) if (.not. error%is_success()) then From 80c8b6c506b9447f9ff75833a826431ae44ebc99 Mon Sep 17 00:00:00 2001 From: Jiwon Gim Date: Fri, 30 Aug 2024 15:15:06 -0600 Subject: [PATCH 09/10] fix a bug --- fortran/tuvx/tuvx.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fortran/tuvx/tuvx.F90 b/fortran/tuvx/tuvx.F90 index 51364f8a..1b7d4e47 100644 --- a/fortran/tuvx/tuvx.F90 +++ b/fortran/tuvx/tuvx.F90 @@ -21,7 +21,7 @@ module musica_tuvx !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! interface - function create_tuvx_c(config_path, grids, profiles, radiators, error) % + function create_tuvx_c(config_path, grids, profiles, radiators, error) & bind(C, name="CreateTuvx") use musica_util, only: error_t_c use iso_c_binding, only: c_ptr, c_int, c_char From 8e3bcdd50626147b5fab8f49db234f88f91ccd09 Mon Sep 17 00:00:00 2001 From: Matt Dawson Date: Tue, 3 Sep 2024 11:04:38 -0700 Subject: [PATCH 10/10] update TUV-x ctor args in fortran wrapper --- fortran/tuvx/tuvx.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fortran/tuvx/tuvx.F90 b/fortran/tuvx/tuvx.F90 index 1b7d4e47..d0d9b452 100644 --- a/fortran/tuvx/tuvx.F90 +++ b/fortran/tuvx/tuvx.F90 @@ -119,8 +119,8 @@ function constructor(config_path, grids, profiles, radiators, error) & end do c_config_path(n+1) = c_null_char - this%ptr_ = create_tuvx_c(c_config_path, c_loc(grids), c_loc(profiles), & - c_loc(radiators), error_c) + this%ptr_ = create_tuvx_c(c_config_path, grids%ptr_, profiles%ptr_, & + radiators%ptr_, error_c) error = error_t(error_c) if (.not. error%is_success()) then