Skip to content

Commit

Permalink
Auto-format code changes (#470)
Browse files Browse the repository at this point in the history
Auto-format code using Clang-Format

Co-authored-by: GitHub Actions <[email protected]>
  • Loading branch information
github-actions[bot] and actions-user authored Apr 24, 2024
1 parent 0212b85 commit d73f052
Show file tree
Hide file tree
Showing 30 changed files with 557 additions and 364 deletions.
85 changes: 37 additions & 48 deletions include/micm/configure/solver_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <system_error>
#include <micm/process/arrhenius_rate_constant.hpp>
#include <micm/process/branched_rate_constant.hpp>
#include <micm/process/process.hpp>
Expand All @@ -25,6 +24,7 @@
#include <micm/util/error.hpp>
#include <nlohmann/json.hpp>
#include <sstream>
#include <system_error>

enum class MicmConfigErrc
{
Expand All @@ -45,56 +45,45 @@ enum class MicmConfigErrc

namespace std
{
template <>
template<>
struct is_error_condition_enum<MicmConfigErrc> : true_type
{
};
} // namespace std
} // namespace std

namespace {
namespace
{
class MicmConfigErrorCategory : public std::error_category
{
public:
const char* name() const noexcept override { return MICM_ERROR_CATEGORY_CONFIGURATION; }
public:
const char* name() const noexcept override
{
return MICM_ERROR_CATEGORY_CONFIGURATION;
}
std::string message(int ev) const override
{
switch (static_cast<MicmConfigErrc>(ev))
{
case MicmConfigErrc::InvalidKey:
return "Invalid key";
case MicmConfigErrc::UnknownKey:
return "Unknown key";
case MicmConfigErrc::InvalidFilePath:
return "Invalid file path";
case MicmConfigErrc::NoConfigFilesFound:
return "No config files found";
case MicmConfigErrc::CAMPFilesNotFound:
return "CAMP files not found";
case MicmConfigErrc::CAMPDataNotFound:
return "CAMP data not found";
case MicmConfigErrc::InvalidSpecies:
return "Invalid species";
case MicmConfigErrc::InvalidMechanism:
return "Invalid mechanism";
case MicmConfigErrc::InvalidType:
return "Invalid type";
case MicmConfigErrc::ObjectTypeNotFound:
return "Object type not found";
case MicmConfigErrc::RequiredKeyNotFound:
return "Required key not found";
case MicmConfigErrc::ContainsNonStandardKey:
return "Contains non-standard key";
case MicmConfigErrc::MutuallyExclusiveOption:
return "Mutually exclusive option";
default:
return "Unknown error";
case MicmConfigErrc::InvalidKey: return "Invalid key";
case MicmConfigErrc::UnknownKey: return "Unknown key";
case MicmConfigErrc::InvalidFilePath: return "Invalid file path";
case MicmConfigErrc::NoConfigFilesFound: return "No config files found";
case MicmConfigErrc::CAMPFilesNotFound: return "CAMP files not found";
case MicmConfigErrc::CAMPDataNotFound: return "CAMP data not found";
case MicmConfigErrc::InvalidSpecies: return "Invalid species";
case MicmConfigErrc::InvalidMechanism: return "Invalid mechanism";
case MicmConfigErrc::InvalidType: return "Invalid type";
case MicmConfigErrc::ObjectTypeNotFound: return "Object type not found";
case MicmConfigErrc::RequiredKeyNotFound: return "Required key not found";
case MicmConfigErrc::ContainsNonStandardKey: return "Contains non-standard key";
case MicmConfigErrc::MutuallyExclusiveOption: return "Mutually exclusive option";
default: return "Unknown error";
}

}
};

const MicmConfigErrorCategory micmConfigErrorCategory{};
} // namespace
} // namespace

std::error_code make_error_code(MicmConfigErrc e)
{
Expand Down Expand Up @@ -271,7 +260,7 @@ namespace micm

// Parse species object array
ParseSpeciesArray(species_objects);

// Assign the parsed 'Species' to 'Phase'
gas_phase_ = Phase(species_arr_);

Expand Down Expand Up @@ -481,7 +470,7 @@ namespace micm
const std::string PRODUCTS = "products";

ValidateSchema(object, { "type", REACTANTS, PRODUCTS }, { "A", "B", "C", "D", "E", "Ea", "MUSICA name" });

auto reactants = ParseReactants(object[REACTANTS]);
auto products = ParseProducts(object[PRODUCTS]);

Expand Down Expand Up @@ -511,15 +500,15 @@ namespace micm
{
if (parameters.C_ != 0)
{
throw std::system_error{ make_error_code(MicmConfigErrc::MutuallyExclusiveOption), "Ea is specified when C is also specified for an Arrhenius reaction. Pick one." };
throw std::system_error{ make_error_code(MicmConfigErrc::MutuallyExclusiveOption),
"Ea is specified when C is also specified for an Arrhenius reaction. Pick one." };
}
// Calculate 'C' using 'Ea'
parameters.C_ = -1 * object["Ea"].get<double>() / BOLTZMANN_CONSTANT;
}
arrhenius_rate_arr_.push_back(ArrheniusRateConstant(parameters));
std::unique_ptr<ArrheniusRateConstant> rate_ptr = std::make_unique<ArrheniusRateConstant>(parameters);
processes_.push_back(Process(reactants, products, std::move(rate_ptr), gas_phase_));

}

void ParseTroe(const json& object)
Expand All @@ -529,7 +518,7 @@ namespace micm

ValidateSchema(
object, { "type", REACTANTS, PRODUCTS }, { "k0_A", "k0_B", "k0_C", "kinf_A", "kinf_B", "kinf_C", "Fc", "N" });

auto reactants = ParseReactants(object[REACTANTS]);
auto products = ParseProducts(object[PRODUCTS]);

Expand Down Expand Up @@ -582,7 +571,7 @@ namespace micm

ValidateSchema(
object, { "type", REACTANTS, PRODUCTS }, { "k0_A", "k0_B", "k0_C", "kinf_A", "kinf_B", "kinf_C", "Fc", "N" });

auto reactants = ParseReactants(object[REACTANTS]);
auto products = ParseProducts(object[PRODUCTS]);

Expand Down Expand Up @@ -641,7 +630,7 @@ namespace micm
const std::string N = "n";

ValidateSchema(object, { "type", REACTANTS, ALKOXY_PRODUCTS, NITRATE_PRODUCTS, X, Y, A0, N }, {});

auto reactants = ParseReactants(object[REACTANTS]);
auto alkoxy_products = ParseProducts(object[ALKOXY_PRODUCTS]);
auto nitrate_products = ParseProducts(object[NITRATE_PRODUCTS]);
Expand Down Expand Up @@ -673,7 +662,7 @@ namespace micm
const std::string PRODUCTS = "products";

ValidateSchema(object, { "type", REACTANTS, PRODUCTS }, { "A", "B", "C" });

auto reactants = ParseReactants(object[REACTANTS]);
auto products = ParseProducts(object[PRODUCTS]);

Expand Down Expand Up @@ -706,7 +695,7 @@ namespace micm
const std::string SCALING_FACTOR = "scaling factor";

ValidateSchema(object, { "type", SPECIES, MUSICA_NAME }, { SCALING_FACTOR, PRODUCTS });

std::string species = object["species"].get<std::string>();
json reactants_object{};
json products_object{};
Expand All @@ -729,7 +718,7 @@ namespace micm
const std::string SCALING_FACTOR = "scaling factor";

ValidateSchema(object, { "type", SPECIES, MUSICA_NAME }, { SCALING_FACTOR });

std::string species = object["species"].get<std::string>();
json reactants_object{};
json products_object{};
Expand All @@ -753,7 +742,7 @@ namespace micm
const std::string SCALING_FACTOR = "scaling factor";

ValidateSchema(object, { "type", REACTANTS, PRODUCTS, MUSICA_NAME }, { SCALING_FACTOR });

auto reactants = ParseReactants(object[REACTANTS]);
auto products = ParseProducts(object[PRODUCTS]);
double scaling_factor = object.contains(SCALING_FACTOR) ? object[SCALING_FACTOR].get<double>() : 1.0;
Expand All @@ -773,7 +762,7 @@ namespace micm
const std::string PROBABILITY = "reaction probability";

ValidateSchema(object, { "type", REACTANTS, PRODUCTS, MUSICA_NAME }, { PROBABILITY });

std::string species_name = object[REACTANTS].get<std::string>();
json reactants_object{};
reactants_object[species_name] = {};
Expand Down
19 changes: 9 additions & 10 deletions include/micm/jit/jit_compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include <memory>
#include <micm/util/error.hpp>

#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/LoopAccessAnalysis.h"
Expand All @@ -33,7 +34,6 @@
#include "llvm/Transforms/Scalar/GVN.h"
#include "llvm/Transforms/Utils.h"
#include "llvm/Transforms/Vectorize.h"
#include <micm/util/error.hpp>

enum class MicmJitErrc
{
Expand All @@ -43,18 +43,18 @@ enum class MicmJitErrc

namespace std
{
template <>
template<>
struct is_error_condition_enum<MicmJitErrc> : true_type
{
};
} // namespace std
} // namespace std

namespace
{
class JitErrorCategory : public std::error_category
{
public:
const char* name() const noexcept override
const char *name() const noexcept override
{
return MICM_ERROR_CATEGORY_JIT;
}
Expand All @@ -63,17 +63,16 @@ namespace
switch (static_cast<MicmJitErrc>(ev))
{
case MicmJitErrc::InvalidMatrix:
return "Invalid matrix for JIT compiled operation. Ensure matrix is Vector-ordered with vector dimension equal to the nubmer of grid cells.";
case MicmJitErrc::MissingJitFunction:
return "Missing JIT-compiled function";
default:
return "Unknown error";
return "Invalid matrix for JIT compiled operation. Ensure matrix is Vector-ordered with vector dimension equal to "
"the nubmer of grid cells.";
case MicmJitErrc::MissingJitFunction: return "Missing JIT-compiled function";
default: return "Unknown error";
}
}
};

const JitErrorCategory jitErrorCategory{};
} // namespace micm
} // namespace

std::error_code make_error_code(MicmJitErrc e)
{
Expand Down
13 changes: 6 additions & 7 deletions include/micm/process/process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ enum class MicmProcessErrc

namespace std
{
template <>
template<>
struct is_error_condition_enum<MicmProcessErrc> : true_type
{
};
} // namespace std

namespace {
namespace
{
class MicmProcessErrorCategory : public std::error_category
{
public:
Expand All @@ -46,16 +47,14 @@ namespace {
{
switch (static_cast<MicmProcessErrc>(ev))
{
case MicmProcessErrc::TooManyReactantsForSurfaceReaction:
return "A surface reaction can only have one reactant";
default:
return "Unknown error";
case MicmProcessErrc::TooManyReactantsForSurfaceReaction: return "A surface reaction can only have one reactant";
default: return "Unknown error";
}
}
};

const MicmProcessErrorCategory micmProcessErrorCategory{};
}
} // namespace

std::error_code make_error_code(MicmProcessErrc e)
{
Expand Down
18 changes: 9 additions & 9 deletions include/micm/process/process_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum class MicmProcessSetErrc

namespace std
{
template <>
template<>
struct is_error_condition_enum<MicmProcessSetErrc> : true_type
{
};
Expand All @@ -30,17 +30,17 @@ namespace
class MicmProcessSetErrorCategory : public std::error_category
{
public:
const char* name() const noexcept override { return MICM_ERROR_CATEGORY_PROCESS_SET; }
const char* name() const noexcept override
{
return MICM_ERROR_CATEGORY_PROCESS_SET;
}
std::string message(int ev) const override
{
switch (static_cast<MicmProcessSetErrc>(ev))
{
case MicmProcessSetErrc::ReactantDoesNotExist:
return "Reactant does not exist";
case MicmProcessSetErrc::ProductDoesNotExist:
return "Product does not exist";
default:
return "Unknown error";
case MicmProcessSetErrc::ReactantDoesNotExist: return "Reactant does not exist";
case MicmProcessSetErrc::ProductDoesNotExist: return "Product does not exist";
default: return "Unknown error";
}
}
};
Expand All @@ -50,7 +50,7 @@ namespace

std::error_code make_error_code(MicmProcessSetErrc e)
{
return {static_cast<int>(e), micmProcessSetErrorCategory};
return { static_cast<int>(e), micmProcessSetErrorCategory };
}

namespace micm
Expand Down
12 changes: 5 additions & 7 deletions include/micm/process/rate_constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ enum class MicmRateConstantErrc

namespace std
{
template <>
template<>
struct is_error_condition_enum<MicmRateConstantErrc> : true_type
{
};
} // namespace std
} // namespace std

namespace
{
Expand All @@ -38,18 +38,16 @@ namespace
{
switch (static_cast<MicmRateConstantErrc>(ev))
{
case MicmRateConstantErrc::MissingArgumentsForSurfaceRateConstant:
return "Missing arguments for surface reaction";
case MicmRateConstantErrc::MissingArgumentsForSurfaceRateConstant: return "Missing arguments for surface reaction";
case MicmRateConstantErrc::MissingArgumentsForUserDefinedRateConstant:
return "Missing arguments for user-defined rate constant";
default:
return "Unknown error";
default: return "Unknown error";
}
}
};

const RateConstantErrorCategory rateConstantErrorCategory{};
} // namespace micm
} // namespace

std::error_code make_error_code(MicmRateConstantErrc e)
{
Expand Down
5 changes: 4 additions & 1 deletion include/micm/solver/jit_linear_solver.inl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ namespace micm
solve_function_ = NULL;
if (matrix.Size() != L || matrix.GroupVectorSize() != L)
{
std::string msg = "JIT functions require the number of grid cells solved together to match the vector dimension template parameter, currently: " + std::to_string(L);
std::string msg =
"JIT functions require the number of grid cells solved together to match the vector dimension template parameter, "
"currently: " +
std::to_string(L);
throw std::system_error(make_error_code(MicmJitErrc::InvalidMatrix), msg);
}
GenerateSolveFunction();
Expand Down
Loading

0 comments on commit d73f052

Please sign in to comment.