From fad439fe7a0eefdd27d3468102ed0829452674c2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 11:39:33 -0500 Subject: [PATCH] Auto-format code using Clang-Format (#150) Co-authored-by: GitHub Actions --- include/musica/micm.hpp | 5 +- include/musica/tuvx.hpp | 12 ++- src/micm/micm.cpp | 15 ++-- src/test/unit/tuvx/tuvx_c_api.cpp | 120 ++++++++++++++++-------------- src/tuvx/tuvx.cpp | 12 +-- 5 files changed, 90 insertions(+), 74 deletions(-) diff --git a/include/musica/micm.hpp b/include/musica/micm.hpp index 31f50d18..02266906 100644 --- a/include/musica/micm.hpp +++ b/include/musica/micm.hpp @@ -8,11 +8,11 @@ #include #include +#include #include #include #include #include -#include #include #include @@ -102,7 +102,8 @@ namespace musica private: using DenseMatrixPolicy = micm::Matrix; using SparseMatrixPolicy = micm::SparseMatrix; - using SolverPolicy = typename micm::RosenbrockSolverParameters::template SolverType>; + using SolverPolicy = typename micm::RosenbrockSolverParameters:: + template SolverType>; using Rosenbrock = micm::Solver>; std::unique_ptr solver_; diff --git a/include/musica/tuvx.hpp b/include/musica/tuvx.hpp index 8b7b81bc..249ec6ec 100644 --- a/include/musica/tuvx.hpp +++ b/include/musica/tuvx.hpp @@ -80,10 +80,16 @@ 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, int *error_code); void InternalDeleteTuvx(void *tuvx, int *error_code); void *InternalGetGridMap(void *tuvx, int *error_code); - void *InternalGetGrid(void *grid_map, const char* grid_name, std::size_t grid_name_length, const char* grid_units, std::size_t grid_units_length, int *error_code); + void *InternalGetGrid( + void *grid_map, + const char *grid_name, + std::size_t grid_name_length, + const char *grid_units, + std::size_t grid_units_length, + int *error_code); void InternalDeleteGrid(void *grid, int *error_code); void InternalSetEdges(void *grid, double edges[], std::size_t num_edges, int *error_code); void InternalSetMidpoints(void *grid, double midpoints[], std::size_t num_midpoints, int *error_code); @@ -100,7 +106,7 @@ namespace musica /// @brief Create an instance of tuvx from a configuration file /// @param config_path Path to configuration file or directory containing configuration file /// @param error Error struct to indicate success or failure - void Create(const char* config_path, Error *error); + void Create(const char *config_path, 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 diff --git a/src/micm/micm.cpp b/src/micm/micm.cpp index c25374b9..39472577 100644 --- a/src/micm/micm.cpp +++ b/src/micm/micm.cpp @@ -6,10 +6,10 @@ // creating and deleting MICM instances, creating solvers, and solving the model. #include -#include #include #include #include +#include #include #include @@ -171,12 +171,13 @@ namespace musica solver_config.ReadAndParse(std::filesystem::path(config_path)); solver_parameters_ = std::make_unique(solver_config.GetSolverParams()); - solver_ = std::make_unique(micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()) - .SetSystem(solver_parameters_->system_) - .SetReactions(solver_parameters_->processes_) - .SetNumberOfGridCells(NUM_GRID_CELLS) - .SetIgnoreUnusedSpecies(true) - .Build()); + solver_ = std::make_unique(micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()) + .SetSystem(solver_parameters_->system_) + .SetReactions(solver_parameters_->processes_) + .SetNumberOfGridCells(NUM_GRID_CELLS) + .SetIgnoreUnusedSpecies(true) + .Build()); DeleteError(error); *error = NoError(); diff --git a/src/test/unit/tuvx/tuvx_c_api.cpp b/src/test/unit/tuvx/tuvx_c_api.cpp index 68cb1a1b..c91c1ebe 100644 --- a/src/test/unit/tuvx/tuvx_c_api.cpp +++ b/src/test/unit/tuvx/tuvx_c_api.cpp @@ -5,74 +5,80 @@ using namespace musica; // Test fixture for the TUVX C API -class TuvxCApiTest : public ::testing::Test { -protected: - TUVX* tuvx; +class TuvxCApiTest : public ::testing::Test +{ + protected: + TUVX* tuvx; - // the function that google test actually calls before each test - void SetUp() override { - tuvx = nullptr; - } + // the function that google test actually calls before each test + void SetUp() override + { + tuvx = nullptr; + } - void SetUp(const char* config_path) { - Error error; - tuvx = CreateTuvx(config_path, &error); - if (!IsSuccess(error)) { - std::cerr << "Error creating TUVX instance: " << error.message_.value_ << std::endl; - } - ASSERT_TRUE(IsSuccess(error)); - DeleteError(&error); + void SetUp(const char* config_path) + { + Error error; + tuvx = CreateTuvx(config_path, &error); + if (!IsSuccess(error)) + { + std::cerr << "Error creating TUVX instance: " << error.message_.value_ << std::endl; } + ASSERT_TRUE(IsSuccess(error)); + DeleteError(&error); + } - void TearDown() override { - if (tuvx == nullptr) { - return; - } - Error error; - DeleteTuvx(tuvx, &error); - ASSERT_TRUE(IsSuccess(error)); - DeleteError(&error); - tuvx = nullptr; + void TearDown() override + { + if (tuvx == nullptr) + { + return; } + Error error; + DeleteTuvx(tuvx, &error); + ASSERT_TRUE(IsSuccess(error)); + DeleteError(&error); + tuvx = nullptr; + } }; -TEST_F(TuvxCApiTest, CreateTuvxInstanceWithYamlConfig) { - const char* yaml_config_path = "examples/ts1_tsmlt.yml"; - SetUp(yaml_config_path); - ASSERT_NE(tuvx, nullptr); +TEST_F(TuvxCApiTest, CreateTuvxInstanceWithYamlConfig) +{ + const char* yaml_config_path = "examples/ts1_tsmlt.yml"; + SetUp(yaml_config_path); + ASSERT_NE(tuvx, nullptr); } -TEST_F(TuvxCApiTest, CreateTuvxInstanceWithJsonConfig) { - const char* json_config_path = "examples/ts1_tsmlt.json"; - SetUp(json_config_path); - ASSERT_NE(tuvx, nullptr); +TEST_F(TuvxCApiTest, CreateTuvxInstanceWithJsonConfig) +{ + const char* json_config_path = "examples/ts1_tsmlt.json"; + SetUp(json_config_path); + ASSERT_NE(tuvx, nullptr); } -TEST_F(TuvxCApiTest, DetectsNonexistentConfigFile) { - const char* config_path = "nonexisting.yml"; - Error error; - TUVX* tuvx = CreateTuvx(config_path, &error); - ASSERT_FALSE(IsSuccess(error)); - DeleteError(&error); +TEST_F(TuvxCApiTest, DetectsNonexistentConfigFile) +{ + const char* config_path = "nonexisting.yml"; + Error error; + TUVX* tuvx = CreateTuvx(config_path, &error); + ASSERT_FALSE(IsSuccess(error)); + DeleteError(&error); } -TEST_F(TuvxCApiTest, CanGetGrid) { - const char* yaml_config_path = "examples/ts1_tsmlt.yml"; - SetUp(yaml_config_path); - Error error; - GridMap* grid_map = GetGridMap(tuvx, &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(grid_map, nullptr); - Grid* grid = GetGrid(grid_map, "height", "km", &error); - ASSERT_TRUE(IsSuccess(error)); - ASSERT_NE(grid, nullptr); - std::vector edges = {0.0, 1.0, 2.0}; - ASSERT_NO_THROW( - SetEdges(grid, edges.data(), edges.size(), &error); - ); - std::vector midpoints = {0.5, 1.5}; - ASSERT_NO_THROW( - SetMidpoints(grid, midpoints.data(), midpoints.size(), &error); - ); - DeleteError(&error); +TEST_F(TuvxCApiTest, CanGetGrid) +{ + const char* yaml_config_path = "examples/ts1_tsmlt.yml"; + SetUp(yaml_config_path); + Error error; + GridMap* grid_map = GetGridMap(tuvx, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(grid_map, nullptr); + Grid* grid = GetGrid(grid_map, "height", "km", &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(grid, nullptr); + std::vector edges = { 0.0, 1.0, 2.0 }; + ASSERT_NO_THROW(SetEdges(grid, edges.data(), edges.size(), &error);); + std::vector midpoints = { 0.5, 1.5 }; + ASSERT_NO_THROW(SetMidpoints(grid, midpoints.data(), midpoints.size(), &error);); + DeleteError(&error); } diff --git a/src/tuvx/tuvx.cpp b/src/tuvx/tuvx.cpp index 63191cbd..924054c2 100644 --- a/src/tuvx/tuvx.cpp +++ b/src/tuvx/tuvx.cpp @@ -5,9 +5,9 @@ // reactive transport model. It also includes functions for creating and deleting TUVX instances. #include +#include #include #include -#include namespace musica { @@ -108,7 +108,7 @@ namespace musica tuvx_ = nullptr; } - void TUVX::Create(const char* config_path, Error *error) + void TUVX::Create(const char *config_path, Error *error) { int parsing_status = 0; // 0 on success, 1 on failure try @@ -171,9 +171,10 @@ namespace musica } int error_code = 0; - Grid* grid = nullptr; + Grid *grid = nullptr; - try { + try + { *error = NoError(); grid = new Grid(InternalGetGrid(grid_map_, grid_name, strlen(grid_name), grid_units, strlen(grid_units), &error_code)); @@ -184,7 +185,8 @@ namespace musica grid = nullptr; *error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to create grid map") }; } - else { + else + { grids_.push_back(std::unique_ptr(grid)); } }