Skip to content

Commit

Permalink
Configure clang-tidy to uniformise the style in naming classes, class…
Browse files Browse the repository at this point in the history
… data members and variables (#511)

* name functions in  camel case for rate const, process

* camel clase

* change size function in sparse matrix

* clang tidy for camel case

* fix bugs in llvm, nvhpc

* Add Set prefix to distinguish the same function name

* add check option for class

* clang tidy for member data

* update clang tidy

* fix llvm tests

* allow anycase for naming variables
  • Loading branch information
boulderdaze committed May 13, 2024
1 parent d123e9c commit 9ad706b
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 125 deletions.
12 changes: 12 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ CheckOptions:
value: CamelCase
- key: readability-identifier-naming.FunctionIgnoredRegexp
value: 'name|message|make_error_code'
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.ClassIgnoredRegexp
value: 'is_error_condition_enum'
- key: readability-identifier-naming.MemberCase
value: aNy_CasE
- key: readability-identifier-naming.MemberSuffix
value: _
- key: readability-identifier-naming.ClassConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.GlobalConstantCase
value: UPPER_CASE
- key: readability-implicit-bool-conversion.AllowIntegerConditions
value: 1
- key: readability-implicit-bool-conversion.AllowPointerConditions
Expand Down
28 changes: 14 additions & 14 deletions include/micm/configure/solver_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ namespace
}
};

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

inline std::error_code make_error_code(MicmConfigErrc e)
{
return { static_cast<int>(e), micmConfigErrorCategory };
return { static_cast<int>(e), MICM_CONFIG_ERROR };
}

namespace micm
{

constexpr double MolesM3ToMoleculesCm3 = 1.0e-6 * 6.02214076e23;
constexpr double MOLES_M3_TO_MOLECULES_CM3 = 1.0e-6 * 6.02214076e23;

// Solver parameters
struct SolverParameters
Expand Down Expand Up @@ -141,10 +141,10 @@ namespace micm
RosenbrockSolverParameters parameters_;

// Common JSON
static const inline std::string DEFAULT_CONFIG_FILE = "config.json";
static const inline std::string CAMP_FILES = "camp-files";
static const inline std::string CAMP_DATA = "camp-data";
static const inline std::string TYPE = "type";
inline static const std::string DEFAULT_CONFIG_FILE = "config.json";
inline static const std::string CAMP_FILES = "camp-files";
inline static const std::string CAMP_DATA = "camp-data";
inline static const std::string TYPE = "type";

// Error string
std::stringstream last_json_object_;
Expand Down Expand Up @@ -481,7 +481,7 @@ namespace micm
{
parameters.A_ = object["A"].get<double>();
}
parameters.A_ *= std::pow(MolesM3ToMoleculesCm3, reactants.size() - 1);
parameters.A_ *= std::pow(MOLES_M3_TO_MOLECULES_CM3, reactants.size() - 1);
if (object.contains("B"))
{
parameters.B_ = object["B"].get<double>();
Expand Down Expand Up @@ -530,7 +530,7 @@ namespace micm
parameters.k0_A_ = object["k0_A"].get<double>();
}
// Account for the conversion of reactant concentrations (including M) to molecules cm-3
parameters.k0_A_ *= std::pow(MolesM3ToMoleculesCm3, reactants.size());
parameters.k0_A_ *= std::pow(MOLES_M3_TO_MOLECULES_CM3, reactants.size());
if (object.contains("k0_B"))
{
parameters.k0_B_ = object["k0_B"].get<double>();
Expand All @@ -544,7 +544,7 @@ namespace micm
parameters.kinf_A_ = object["kinf_A"].get<double>();
}
// Account for terms in denominator and exponent that include [M] but not other reactants
parameters.kinf_A_ *= std::pow(MolesM3ToMoleculesCm3, reactants.size() - 1);
parameters.kinf_A_ *= std::pow(MOLES_M3_TO_MOLECULES_CM3, reactants.size() - 1);
if (object.contains("kinf_B"))
{
parameters.kinf_B_ = object["kinf_B"].get<double>();
Expand Down Expand Up @@ -583,7 +583,7 @@ namespace micm
parameters.k0_A_ = object["k0_A"].get<double>();
}
// Account for the conversion of reactant concentrations (including M) to molecules cm-3
parameters.k0_A_ *= std::pow(MolesM3ToMoleculesCm3, reactants.size() - 1);
parameters.k0_A_ *= std::pow(MOLES_M3_TO_MOLECULES_CM3, reactants.size() - 1);
if (object.contains("k0_B"))
{
parameters.k0_B_ = object["k0_B"].get<double>();
Expand All @@ -597,7 +597,7 @@ namespace micm
parameters.kinf_A_ = object["kinf_A"].get<double>();
}
// Account for terms in denominator and exponent that include [M] but not other reactants
parameters.kinf_A_ *= std::pow(MolesM3ToMoleculesCm3, reactants.size() - 2);
parameters.kinf_A_ *= std::pow(MOLES_M3_TO_MOLECULES_CM3, reactants.size() - 2);
if (object.contains("kinf_B"))
{
parameters.kinf_B_ = object["kinf_B"].get<double>();
Expand Down Expand Up @@ -640,7 +640,7 @@ namespace micm
BranchedRateConstantParameters parameters;
parameters.X_ = object[X].get<double>();
// Account for the conversion of reactant concentrations to molecules cm-3
parameters.X_ *= std::pow(MolesM3ToMoleculesCm3, reactants.size() - 1);
parameters.X_ *= std::pow(MOLES_M3_TO_MOLECULES_CM3, reactants.size() - 1);
parameters.Y_ = object[Y].get<double>();
parameters.a0_ = object[A0].get<double>();
parameters.n_ = object[N].get<int>();
Expand Down Expand Up @@ -674,7 +674,7 @@ namespace micm
parameters.A_ = object["A"].get<double>();
}
// Account for the conversion of reactant concentrations to molecules cm-3
parameters.A_ *= std::pow(MolesM3ToMoleculesCm3, reactants.size() - 1);
parameters.A_ *= std::pow(MOLES_M3_TO_MOLECULES_CM3, reactants.size() - 1);
if (object.contains("B"))
{
parameters.B_ = object["B"].get<double>();
Expand Down
4 changes: 2 additions & 2 deletions include/micm/jit/jit_compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ namespace
}
};

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

inline std::error_code make_error_code(MicmJitErrc e)
{
return { static_cast<int>(e), jitErrorCategory };
return { static_cast<int>(e), JIT_ERROR };
}

namespace micm
Expand Down
3 changes: 1 addition & 2 deletions include/micm/jit/jit_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ namespace micm
return builder_->CreateLoad(GetType(type), elem, array_ptr.name_ + " load elem");
}

void
JitFunction::SetArrayElement(JitArgument array_ptr, llvm::ArrayRef<llvm::Value*> index, JitType type, llvm::Value* value)
void JitFunction::SetArrayElement(JitArgument array_ptr, llvm::ArrayRef<llvm::Value*> index, JitType type, llvm::Value* value)
{
llvm::Value* elem = builder_->CreateGEP(GetType(type), array_ptr.ptr_, index, array_ptr.name_ + " set elem");
builder_->CreateStore(value, elem);
Expand Down
4 changes: 2 additions & 2 deletions include/micm/process/process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ namespace
}
};

const MicmProcessErrorCategory micmProcessErrorCategory{};
const MicmProcessErrorCategory MICM_PROCESS_ERROR{};
} // namespace

inline std::error_code make_error_code(MicmProcessErrc e)
{
return { static_cast<int>(e), micmProcessErrorCategory };
return { static_cast<int>(e), MICM_PROCESS_ERROR };
}

namespace micm
Expand Down
4 changes: 2 additions & 2 deletions include/micm/process/process_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ namespace
}
};

const MicmProcessSetErrorCategory micmProcessSetErrorCategory{};
const MicmProcessSetErrorCategory MICM_PROCESS_SET_ERROR{};
} // namespace

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

namespace micm
Expand Down
4 changes: 2 additions & 2 deletions include/micm/process/rate_constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ namespace
}
};

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

inline std::error_code make_error_code(MicmRateConstantErrc e)
{
return { static_cast<int>(e), rateConstantErrorCategory };
return { static_cast<int>(e), RATE_CONSTANT_ERROR };
}

namespace micm
Expand Down
26 changes: 13 additions & 13 deletions include/micm/profiler/instrumentation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ namespace micm

struct ProfileResult
{
std::string name;
FloatingPointMicroseconds start;
std::chrono::microseconds elapsed_time;
std::thread::id threadID;
std::string name_;
FloatingPointMicroseconds start_;
std::chrono::microseconds elapsed_time_;
std::thread::id thread_id_;
};

struct InstrumentationSession
{
std::string name;
std::string name_;
};

class Instrumentor
Expand All @@ -44,7 +44,7 @@ namespace micm
std::lock_guard lock(mutex_);
if (current_session_)
{
std::cerr << "Instrumentor::BeginSession('" << name << "') when session '" << current_session_->name
std::cerr << "Instrumentor::BeginSession('" << name << "') when session '" << current_session_->name_
<< "' already open." << std::endl;
InternalEndSession();
}
Expand Down Expand Up @@ -75,12 +75,12 @@ namespace micm
json << std::setprecision(3) << std::fixed;
json << ",{";
json << "\"cat\":\"function\",";
json << "\"dur\":" << (result.elapsed_time.count()) << ',';
json << "\"name\":\"" << result.name << "\",";
json << "\"dur\":" << (result.elapsed_time_.count()) << ',';
json << "\"name\":\"" << result.name_ << "\",";
json << "\"ph\":\"X\",";
json << "\"pid\":0,";
json << "\"tid\":\"" << result.threadID << "\",";
json << "\"ts\":" << result.start.count();
json << "\"tid\":\"" << result.thread_id_ << "\",";
json << "\"ts\":" << result.start_.count();
json << "}";

std::lock_guard lock(mutex_);
Expand Down Expand Up @@ -175,7 +175,7 @@ namespace micm
template<size_t N>
struct ChangeResult
{
char Data[N];
char data_[N];
};

template<size_t N, size_t K>
Expand All @@ -192,7 +192,7 @@ namespace micm
matchIndex++;
if (matchIndex == K - 1)
srcIndex += matchIndex;
result.Data[dstIndex++] = expr[srcIndex] == '"' ? '\'' : expr[srcIndex];
result.data_[dstIndex++] = expr[srcIndex] == '"' ? '\'' : expr[srcIndex];
srcIndex++;
}

Expand All @@ -217,7 +217,7 @@ namespace micm
# define MICM_PROFILE_END_SESSION() ::micm::Instrumentor::Get().EndSession()
# define MICM_PROFILE_SCOPE_LINE2(name, line) \
constexpr auto fixedName##line = ::micm::InstrumentorUtils::CleanupOutputString(name, "__cdecl "); \
::micm::InstrumentationTimer timer##line(fixedName##line.Data)
::micm::InstrumentationTimer timer##line(fixedName##line.data_)
# define MICM_PROFILE_SCOPE_LINE(name, line) MICM_PROFILE_SCOPE_LINE2(name, line)
# define MICM_PROFILE_SCOPE(name) MICM_PROFILE_SCOPE_LINE(name, __LINE__)
# define MICM_PROFILE_FUNCTION() MICM_PROFILE_SCOPE(MICM_FUNC_SIG)
Expand Down
18 changes: 9 additions & 9 deletions include/micm/solver/rosenbrock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ namespace micm
struct SolverStats
{
/// @brief The number of forcing function calls
uint64_t function_calls{};
uint64_t function_calls_{};
/// @brief The number of jacobian function calls
uint64_t jacobian_updates{};
uint64_t jacobian_updates_{};
/// @brief The total number of internal time steps taken
uint64_t number_of_steps{};
uint64_t number_of_steps_{};
/// @brief The number of accepted integrations
uint64_t accepted{};
uint64_t accepted_{};
/// @brief The number of rejected integrations
uint64_t rejected{};
uint64_t rejected_{};
/// @brief The number of LU decompositions
uint64_t decompositions{};
uint64_t decompositions_{};
/// @brief The number of linear solves
uint64_t solves{};
uint64_t solves_{};
/// @brief The number of times a singular matrix is detected. For now, this will always be zero as we assume the matrix
/// is never singular
uint64_t singular{};
uint64_t singular_{};

/// @brief Set all member variables to zero
void Reset();
Expand Down Expand Up @@ -116,7 +116,7 @@ namespace micm
ProcessSetPolicy process_set_;
LinearSolverPolicy linear_solver_;

static constexpr double delta_min_ = 1.0e-6;
static constexpr double DELTA_MIN = 1.0e-6;

/// @brief Default constructor
RosenbrockSolver();
Expand Down
Loading

0 comments on commit 9ad706b

Please sign in to comment.