Skip to content

Commit

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

Co-authored-by: GitHub Actions <actions@github.com>
  • Loading branch information
github-actions[bot] and actions-user committed May 29, 2024
1 parent 369aede commit d880f32
Show file tree
Hide file tree
Showing 36 changed files with 175 additions and 268 deletions.
9 changes: 4 additions & 5 deletions include/micm/process/cuda_process_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ namespace micm
}

template<class MatrixPolicy>
requires(CudaMatrix<MatrixPolicy>&& VectorizableDense<MatrixPolicy>) inline void CudaProcessSet::
AddForcingTerms(
const MatrixPolicy& rate_constants,
const MatrixPolicy& state_variables,
MatrixPolicy& forcing) const
requires(CudaMatrix<MatrixPolicy>&& VectorizableDense<MatrixPolicy>) inline void CudaProcessSet::AddForcingTerms(
const MatrixPolicy& rate_constants,
const MatrixPolicy& state_variables,
MatrixPolicy& forcing) const
{
auto forcing_param = forcing.AsDeviceParam(); // we need to update forcing so it can't be constant and must be an lvalue
micm::cuda::AddForcingTermsKernelDriver(
Expand Down
10 changes: 3 additions & 7 deletions include/micm/process/jit_process_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ namespace micm
/// @brief Create a JITed process set calculator for a given set of processes
/// @param processes Processes to create calculator for
/// @param variable_map A mapping of species names to concentration index
JitProcessSet(
const std::vector<Process> &processes,
const std::map<std::string, std::size_t> &variable_map);
JitProcessSet(const std::vector<Process> &processes, const std::map<std::string, std::size_t> &variable_map);

~JitProcessSet();

Expand All @@ -50,10 +48,8 @@ namespace micm
/// @param state_variables Current state variable values (grid cell, state variable)
/// @param forcing Forcing terms for each state variable (grid cell, state variable)
template<class MatrixPolicy>
void AddForcingTerms(
const MatrixPolicy &rate_constants,
const MatrixPolicy &state_variables,
MatrixPolicy &forcing) const;
void AddForcingTerms(const MatrixPolicy &rate_constants, const MatrixPolicy &state_variables, MatrixPolicy &forcing)
const;

/// @brief Subtracts Jacobian terms for the set of processes for the current conditions
/// @param rate_constants Current values for the process rate constants (grid cell, process)
Expand Down
18 changes: 8 additions & 10 deletions include/micm/solver/backward_euler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace micm
{

/// @brief An implementation of the fully implicit backward euler method
template <class LinearSolverPolicy, class ProcessSetPolicy>
template<class LinearSolverPolicy, class ProcessSetPolicy>
class BackwardEuler
{
BackwardEulerSolverParameters parameters_;
Expand All @@ -41,12 +41,12 @@ namespace micm
public:
/// @brief Default constructor
BackwardEuler(
BackwardEulerSolverParameters parameters,
LinearSolverPolicy linear_solver,
ProcessSetPolicy process_set,
std::vector<std::size_t> jacobian_diagonal_elements,
std::vector<micm::Process>& processes
) : parameters_(parameters),
BackwardEulerSolverParameters parameters,
LinearSolverPolicy linear_solver,
ProcessSetPolicy process_set,
std::vector<std::size_t> jacobian_diagonal_elements,
std::vector<micm::Process>& processes)
: parameters_(parameters),
linear_solver_(linear_solver),
process_set_(process_set),
jacobian_diagonal_elements_(jacobian_diagonal_elements),
Expand All @@ -60,9 +60,7 @@ namespace micm
/// @param time_step Time [s] to advance the state by
/// @param state The state to advance
/// @return Nothing, but the state is updated
void Solve(
double time_step,
auto& state);
void Solve(double time_step, auto& state);
};

} // namespace micm
Expand Down
7 changes: 2 additions & 5 deletions include/micm/solver/backward_euler.inl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ inline std::error_code make_error_code(MicmBackwardEulerErrc e)

namespace micm
{
template <class LinearSolverPolicy, class ProcessSetPolicy>
inline void BackwardEuler<LinearSolverPolicy, ProcessSetPolicy>::Solve(
double time_step,
auto& state)
template<class LinearSolverPolicy, class ProcessSetPolicy>
inline void BackwardEuler<LinearSolverPolicy, ProcessSetPolicy>::Solve(double time_step, auto& state)
{
// A fully implicit euler implementation is given by the following equation:
// y_{n+1} = y_n + H * f(t_{n+1}, y_{n+1})
Expand All @@ -60,7 +58,6 @@ namespace micm
// if that fails, try H = H/10 once
// if that fails, accept the current H but do not update the Yn vector


double tolerance = parameters_.absolute_tolerance_[0];
double small = parameters_.small;
std::size_t max_iter = parameters_.max_number_of_steps_;
Expand Down
4 changes: 2 additions & 2 deletions include/micm/solver/backward_euler_solver_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*/
#pragma once

#include <array>
#include <cstddef>
#include <iostream>
#include <vector>
#include <array>

namespace micm
{
Expand All @@ -16,7 +16,7 @@ namespace micm
struct BackwardEulerSolverParameters
{
std::vector<double> absolute_tolerance_;
double small { 1.0e-40 };
double small{ 1.0e-40 };
size_t max_number_of_steps_{ 11 };
std::array<double, 5> time_step_reductions{ 0.5, 0.5, 0.5, 0.5, 0.1 };
};
Expand Down
4 changes: 2 additions & 2 deletions include/micm/solver/cuda_linear_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ namespace micm

template<class MatrixPolicy>
requires(
CudaMatrix<SparseMatrixPolicy>&& CudaMatrix<MatrixPolicy>&& VectorizableDense<MatrixPolicy>&&
VectorizableSparse<SparseMatrixPolicy>) void Solve(const MatrixPolicy& b, MatrixPolicy& x, const SparseMatrixPolicy& L, const SparseMatrixPolicy& U)
CudaMatrix<SparseMatrixPolicy>&& CudaMatrix<MatrixPolicy>&& VectorizableDense<MatrixPolicy>&& VectorizableSparse<
SparseMatrixPolicy>) void Solve(const MatrixPolicy& b, MatrixPolicy& x, const SparseMatrixPolicy& L, const SparseMatrixPolicy& U)
const
{
auto x_param = x.AsDeviceParam(); // we need to update x so it can't be constant and must be an lvalue
Expand Down
6 changes: 4 additions & 2 deletions include/micm/solver/cuda_lu_decomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ namespace micm
};

template<class SparseMatrixPolicy>
requires(CudaMatrix<SparseMatrixPolicy>&& VectorizableSparse<SparseMatrixPolicy>) void CudaLuDecomposition::
Decompose(const SparseMatrixPolicy& A, SparseMatrixPolicy& L, SparseMatrixPolicy& U) const
requires(CudaMatrix<SparseMatrixPolicy>&& VectorizableSparse<SparseMatrixPolicy>) void CudaLuDecomposition::Decompose(
const SparseMatrixPolicy& A,
SparseMatrixPolicy& L,
SparseMatrixPolicy& U) const
{
auto L_param = L.AsDeviceParam(); // we need to update lower matrix so it can't be constant and must be an lvalue
auto U_param = U.AsDeviceParam(); // we need to update upper matrix so it can't be constant and must be an lvalue
Expand Down
15 changes: 3 additions & 12 deletions include/micm/solver/jit_linear_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ namespace micm
/// @param compiler JIT compiler
/// @param matrix Block-diagonal sparse matrix to create solver for
/// @param initial_value Initial value for decomposed triangular matrix elements
JitLinearSolver(
const SparseMatrixPolicy& matrix,
double initial_value);
JitLinearSolver(const SparseMatrixPolicy& matrix, double initial_value);

~JitLinearSolver();

Expand All @@ -54,18 +52,11 @@ namespace micm

/// @brief Decompose the matrix into upper and lower triangular matrices and general JIT functions
/// @param matrix Matrix that will be factored into lower and upper triangular matrices
void Factor(
SparseMatrixPolicy& matrix,
SparseMatrixPolicy& lower_matrix,
SparseMatrixPolicy& upper_matrix);
void Factor(SparseMatrixPolicy& matrix, SparseMatrixPolicy& lower_matrix, SparseMatrixPolicy& upper_matrix);

/// @brief Solve for x in Ax = b
template<class MatrixPolicy>
void Solve(
const MatrixPolicy& b,
MatrixPolicy& x,
SparseMatrixPolicy& lower_matrix,
SparseMatrixPolicy& upper_matrix);
void Solve(const MatrixPolicy& b, MatrixPolicy& x, SparseMatrixPolicy& lower_matrix, SparseMatrixPolicy& upper_matrix);

private:
/// @brief Generates the JIT-ed Solve function
Expand Down
3 changes: 1 addition & 2 deletions include/micm/solver/jit_linear_solver.inl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ namespace micm
: LinearSolver<SparseMatrixPolicy, LuDecompositionPolicy>(
matrix,
initial_value,
[&](const SparseMatrixPolicy &m) -> LuDecompositionPolicy
{ return LuDecompositionPolicy(m); })
[&](const SparseMatrixPolicy &m) -> LuDecompositionPolicy { return LuDecompositionPolicy(m); })
{
solve_function_ = NULL;
if (matrix.NumberOfBlocks() != L || matrix.GroupVectorSize() != L)
Expand Down
7 changes: 2 additions & 5 deletions include/micm/solver/jit_lu_decomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ namespace micm
/// @param upper The upper triangular matrix created by decomposition
/// @param is_singular Flag that will be set to true if A is singular; false otherwise
template<class SparseMatrixPolicy>
void Decompose(
const SparseMatrixPolicy &A,
SparseMatrixPolicy &lower,
SparseMatrixPolicy &upper,
bool &is_singular) const;
void Decompose(const SparseMatrixPolicy &A, SparseMatrixPolicy &lower, SparseMatrixPolicy &upper, bool &is_singular)
const;

/// @brief Create sparse L and U matrices for a given A matrix
/// @param A Sparse matrix that will be decomposed
Expand Down
9 changes: 3 additions & 6 deletions include/micm/solver/jit_lu_decomposition.inl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ namespace micm
}

template<std::size_t L>
inline JitLuDecomposition<L>::JitLuDecomposition(
const SparseMatrix<double, SparseMatrixVectorOrdering<L>> &matrix)
inline JitLuDecomposition<L>::JitLuDecomposition(const SparseMatrix<double, SparseMatrixVectorOrdering<L>> &matrix)
: LuDecomposition(LuDecomposition::Create<SparseMatrix<double, SparseMatrixVectorOrdering<L>>>(matrix))
{
decompose_function_ = NULL;
Expand Down Expand Up @@ -198,10 +197,8 @@ namespace micm

template<std::size_t L>
template<class SparseMatrixPolicy>
void JitLuDecomposition<L>::Decompose(
const SparseMatrixPolicy &A,
SparseMatrixPolicy &lower,
SparseMatrixPolicy &upper) const
void JitLuDecomposition<L>::Decompose(const SparseMatrixPolicy &A, SparseMatrixPolicy &lower, SparseMatrixPolicy &upper)
const
{
decompose_function_(A.AsVector().data(), lower.AsVector().data(), upper.AsVector().data());
}
Expand Down
7 changes: 4 additions & 3 deletions include/micm/solver/linear_solver.inl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ namespace micm
template<class MatrixPolicy>
requires(
!VectorizableDense<MatrixPolicy> ||
!VectorizableSparse<SparseMatrixPolicy>) inline void LinearSolver<SparseMatrixPolicy, LuDecompositionPolicy>::Solve(
!VectorizableSparse<SparseMatrixPolicy>) inline void LinearSolver<SparseMatrixPolicy, LuDecompositionPolicy>::
Solve(
const MatrixPolicy& b,
MatrixPolicy& x,
const SparseMatrixPolicy& lower_matrix,
Expand Down Expand Up @@ -191,8 +192,8 @@ namespace micm

template<class SparseMatrixPolicy, class LuDecompositionPolicy>
template<class MatrixPolicy>
requires(VectorizableDense<MatrixPolicy>&& VectorizableSparse<
SparseMatrixPolicy>) inline void LinearSolver<SparseMatrixPolicy, LuDecompositionPolicy>::
requires(VectorizableDense<MatrixPolicy>&&
VectorizableSparse<SparseMatrixPolicy>) inline void LinearSolver<SparseMatrixPolicy, LuDecompositionPolicy>::
Solve(
const MatrixPolicy& b,
MatrixPolicy& x,
Expand Down
4 changes: 3 additions & 1 deletion include/micm/solver/lu_decomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ namespace micm
/// @param A Sparse matrix that will be decomposed
/// @return L and U Sparse matrices
template<class SparseMatrixPolicy>
static std::pair<SparseMatrixPolicy, SparseMatrixPolicy> GetLUMatrices(const SparseMatrixPolicy& A, typename SparseMatrixPolicy::value_type initial_value);
static std::pair<SparseMatrixPolicy, SparseMatrixPolicy> GetLUMatrices(
const SparseMatrixPolicy& A,
typename SparseMatrixPolicy::value_type initial_value);

/// @brief Perform an LU decomposition on a given A matrix
/// @param A Sparse matrix to decompose
Expand Down
3 changes: 1 addition & 2 deletions include/micm/solver/lu_decomposition.inl
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ namespace micm
}

template<class SparseMatrixPolicy>
inline void LuDecomposition::Decompose(const SparseMatrixPolicy& A, SparseMatrixPolicy& L, SparseMatrixPolicy& U)
const
inline void LuDecomposition::Decompose(const SparseMatrixPolicy& A, SparseMatrixPolicy& L, SparseMatrixPolicy& U) const
{
bool is_singular = false;
Decompose<SparseMatrixPolicy>(A, L, U, is_singular);
Expand Down
Loading

0 comments on commit d880f32

Please sign in to comment.