Skip to content

Commit

Permalink
Auto-format code using Clang-Format (#150)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Actions <[email protected]>
  • Loading branch information
github-actions[bot] and actions-user authored Jun 18, 2024
1 parent 5aa6e75 commit fad439f
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 74 deletions.
5 changes: 3 additions & 2 deletions include/musica/micm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include <musica/util.hpp>

#include <micm/configure/solver_config.hpp>
#include <micm/process/process_set.hpp>
#include <micm/solver/rosenbrock.hpp>
#include <micm/solver/rosenbrock_solver_parameters.hpp>
#include <micm/solver/solver.hpp>
#include <micm/util/matrix.hpp>
#include <micm/process/process_set.hpp>

#include <memory>
#include <string>
Expand Down Expand Up @@ -102,7 +102,8 @@ namespace musica
private:
using DenseMatrixPolicy = micm::Matrix<double>;
using SparseMatrixPolicy = micm::SparseMatrix<double, micm::SparseMatrixStandardOrdering>;
using SolverPolicy = typename micm::RosenbrockSolverParameters::template SolverType<micm::ProcessSet, micm::LinearSolver<SparseMatrixPolicy, micm::LuDecomposition>>;
using SolverPolicy = typename micm::RosenbrockSolverParameters::
template SolverType<micm::ProcessSet, micm::LinearSolver<SparseMatrixPolicy, micm::LuDecomposition>>;
using Rosenbrock = micm::Solver<SolverPolicy, micm::State<DenseMatrixPolicy, SparseMatrixPolicy>>;

std::unique_ptr<Rosenbrock> solver_;
Expand Down
12 changes: 9 additions & 3 deletions include/musica/tuvx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions src/micm/micm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// creating and deleting MICM instances, creating solvers, and solving the model.
#include <musica/micm.hpp>

#include <micm/version.hpp>
#include <micm/solver/rosenbrock_solver_parameters.hpp>
#include <micm/solver/solver_builder.hpp>
#include <micm/system/species.hpp>
#include <micm/version.hpp>

#include <cmath>
#include <filesystem>
Expand Down Expand Up @@ -171,12 +171,13 @@ namespace musica
solver_config.ReadAndParse(std::filesystem::path(config_path));
solver_parameters_ = std::make_unique<micm::SolverParameters>(solver_config.GetSolverParams());

solver_ = std::make_unique<Rosenbrock>(micm::CpuSolverBuilder<micm::RosenbrockSolverParameters>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters())
.SetSystem(solver_parameters_->system_)
.SetReactions(solver_parameters_->processes_)
.SetNumberOfGridCells(NUM_GRID_CELLS)
.SetIgnoreUnusedSpecies(true)
.Build());
solver_ = std::make_unique<Rosenbrock>(micm::CpuSolverBuilder<micm::RosenbrockSolverParameters>(
micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters())
.SetSystem(solver_parameters_->system_)
.SetReactions(solver_parameters_->processes_)
.SetNumberOfGridCells(NUM_GRID_CELLS)
.SetIgnoreUnusedSpecies(true)
.Build());

DeleteError(error);
*error = NoError();
Expand Down
120 changes: 63 additions & 57 deletions src/test/unit/tuvx/tuvx_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> edges = {0.0, 1.0, 2.0};
ASSERT_NO_THROW(
SetEdges(grid, edges.data(), edges.size(), &error);
);
std::vector<double> 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<double> edges = { 0.0, 1.0, 2.0 };
ASSERT_NO_THROW(SetEdges(grid, edges.data(), edges.size(), &error););
std::vector<double> midpoints = { 0.5, 1.5 };
ASSERT_NO_THROW(SetMidpoints(grid, midpoints.data(), midpoints.size(), &error););
DeleteError(&error);
}
12 changes: 7 additions & 5 deletions src/tuvx/tuvx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// reactive transport model. It also includes functions for creating and deleting TUVX instances.
#include <musica/tuvx.hpp>

#include <cstring>
#include <filesystem>
#include <iostream>
#include <cstring>

namespace musica
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand All @@ -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>(grid));
}
}
Expand Down

0 comments on commit fad439f

Please sign in to comment.