Skip to content

Commit

Permalink
Auto-format code changes (#708)
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 Jan 14, 2025
1 parent 71302b7 commit 51ddf39
Show file tree
Hide file tree
Showing 21 changed files with 200 additions and 118 deletions.
17 changes: 12 additions & 5 deletions include/micm/configure/solver_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace micm
System system_;
std::vector<Process> processes_;
RosenbrockSolverParameters parameters_;
double relative_tolerance_;
double relative_tolerance_;

SolverParameters(const System& system, std::vector<Process>&& processes, const RosenbrockSolverParameters&& parameters)
: system_(system),
Expand All @@ -119,10 +119,14 @@ namespace micm
relative_tolerance_(0)
{
}
SolverParameters(System&& system, std::vector<Process>&& processes, RosenbrockSolverParameters&& parameters, double relative_tolerance)
SolverParameters(
System&& system,
std::vector<Process>&& processes,
RosenbrockSolverParameters&& parameters,
double relative_tolerance)
: system_(system),
processes_(processes),
parameters_(parameters),
parameters_(parameters),
relative_tolerance_(relative_tolerance)
{
}
Expand Down Expand Up @@ -284,7 +288,7 @@ namespace micm
processes_.clear();

// Parse species object array
ParseSpeciesArray(species_objects);
ParseSpeciesArray(species_objects);

// Assign the parsed 'Species' to 'Phase'
std::vector<Species> species_arr;
Expand Down Expand Up @@ -970,7 +974,10 @@ namespace micm
SolverParameters GetSolverParams()
{
return SolverParameters(
std::move(System(this->gas_phase_, this->phases_)), std::move(this->processes_), std::move(this->parameters_), this->relative_tolerance_);
std::move(System(this->gas_phase_, this->phases_)),
std::move(this->processes_),
std::move(this->parameters_),
this->relative_tolerance_);
}
};
} // namespace micm
10 changes: 7 additions & 3 deletions include/micm/cuda/solver/cuda_rosenbrock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,18 @@ namespace micm
/// @param errors The computed errors
/// @return The scaled norm of the errors
template<class DenseMatrixPolicy>
double NormalizedError(const DenseMatrixPolicy& y_old, const DenseMatrixPolicy& y_new, const DenseMatrixPolicy& errors, auto& state)
const requires(CudaMatrix<DenseMatrixPolicy>&& VectorizableDense<DenseMatrixPolicy>)
double NormalizedError(
const DenseMatrixPolicy& y_old,
const DenseMatrixPolicy& y_new,
const DenseMatrixPolicy& errors,
auto& state) const
requires(CudaMatrix<DenseMatrixPolicy> && VectorizableDense<DenseMatrixPolicy>)
{
return micm::cuda::NormalizedErrorDriver(
y_old.AsDeviceParam(),
y_new.AsDeviceParam(),
errors.AsDeviceParam(),
state.absolute_tolerance_param_,
state.absolute_tolerance_param_,
state.relative_tolerance_,
this->devstruct_);
}
Expand Down
7 changes: 5 additions & 2 deletions include/micm/cuda/solver/cuda_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ namespace micm
absolute_tolerance_param_.number_of_elements_ = atol.size();
absolute_tolerance_param_.number_of_grid_cells_ = 1;

CHECK_CUDA_ERROR(micm::cuda::MallocVector<double>(absolute_tolerance_param_, absolute_tolerance_param_.number_of_elements_), "cudaMalloc");
CHECK_CUDA_ERROR(
micm::cuda::MallocVector<double>(absolute_tolerance_param_, absolute_tolerance_param_.number_of_elements_),
"cudaMalloc");
CHECK_CUDA_ERROR(micm::cuda::CopyToDevice<double>(absolute_tolerance_param_, atol), "cudaMemcpyHostToDevice");
};

Expand All @@ -61,7 +63,8 @@ namespace micm
void SetAbsoluteTolerances(const std::vector<double>& absoluteTolerance) override
{
State<DenseMatrixPolicy, SparseMatrixPolicy, LuDecompositionPolicy>::SetAbsoluteTolerances(absoluteTolerance);
CHECK_CUDA_ERROR(micm::cuda::CopyToDevice<double>(absolute_tolerance_param_, absoluteTolerance), "cudaMemcpyHostToDevice");
CHECK_CUDA_ERROR(
micm::cuda::CopyToDevice<double>(absolute_tolerance_param_, absoluteTolerance), "cudaMemcpyHostToDevice");
}

/// @brief Copy input variables to the device
Expand Down
9 changes: 3 additions & 6 deletions include/micm/jit/solver/jit_rosenbrock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,12 @@ namespace micm
/// @param linear_solver Linear solver
/// @param rates Rates calculator
/// @param jacobian Jacobian matrix
JitRosenbrockSolver(
LinearSolverPolicy linear_solver,
RatesPolicy rates,
auto& jacobian,
const size_t number_of_species)
JitRosenbrockSolver(LinearSolverPolicy linear_solver, RatesPolicy rates, auto& jacobian, const size_t number_of_species)
: AbstractRosenbrockSolver<RatesPolicy, LinearSolverPolicy, JitRosenbrockSolver<RatesPolicy, LinearSolverPolicy>>(
std::move(linear_solver),
std::move(rates),
jacobian, number_of_species)
jacobian,
number_of_species)
{
this->GenerateAlphaMinusJacobian(jacobian);
}
Expand Down
24 changes: 13 additions & 11 deletions include/micm/solver/backward_euler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ namespace micm
/// @param linear_solver Linear solver
/// @param rates Rates calculator
/// @param jacobian Jacobian matrix
BackwardEuler(
LinearSolverPolicy&& linear_solver,
RatesPolicy&& rates,
auto& jacobian,
const size_t number_of_species)
BackwardEuler(LinearSolverPolicy&& linear_solver, RatesPolicy&& rates, auto& jacobian, const size_t number_of_species)
: linear_solver_(std::move(linear_solver)),
rates_(std::move(rates)),
jacobian_diagonal_elements_(jacobian.DiagonalIndices(0))
Expand All @@ -74,14 +70,20 @@ namespace micm
/// @return true if the residual is small enough to stop the iteration
template<class DenseMatrixPolicy>
static bool IsConverged(
const BackwardEulerSolverParameters& parameters,
const DenseMatrixPolicy& residual,
const DenseMatrixPolicy& Yn1, const std::vector<double>& absolute_tolerance, double relative_tolerance) requires(!VectorizableDense<DenseMatrixPolicy>);
const BackwardEulerSolverParameters& parameters,
const DenseMatrixPolicy& residual,
const DenseMatrixPolicy& Yn1,
const std::vector<double>& absolute_tolerance,
double relative_tolerance)
requires(!VectorizableDense<DenseMatrixPolicy>);
template<class DenseMatrixPolicy>
static bool IsConverged(
const BackwardEulerSolverParameters& parameters,
const DenseMatrixPolicy& residual,
const DenseMatrixPolicy& Yn1, const std::vector<double>& absolute_tolerance, double relative_tolerance) requires(VectorizableDense<DenseMatrixPolicy>);
const BackwardEulerSolverParameters& parameters,
const DenseMatrixPolicy& residual,
const DenseMatrixPolicy& Yn1,
const std::vector<double>& absolute_tolerance,
double relative_tolerance)
requires(VectorizableDense<DenseMatrixPolicy>);
};

} // namespace micm
Expand Down
15 changes: 12 additions & 3 deletions include/micm/solver/backward_euler.inl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ inline std::error_code make_error_code(MicmBackwardEulerErrc e)
namespace micm
{
template<class RatesPolicy, class LinearSolverPolicy>
inline SolverResult BackwardEuler<RatesPolicy, LinearSolverPolicy>::Solve(double time_step, auto& state, const BackwardEulerSolverParameters& parameters) const
inline SolverResult BackwardEuler<RatesPolicy, LinearSolverPolicy>::Solve(
double time_step,
auto& state,
const BackwardEulerSolverParameters& parameters) const
{
// 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 Down Expand Up @@ -195,7 +198,10 @@ namespace micm
inline bool BackwardEuler<RatesPolicy, LinearSolverPolicy>::IsConverged(
const BackwardEulerSolverParameters& parameters,
const DenseMatrixPolicy& residual,
const DenseMatrixPolicy& Yn1, const std::vector<double>& absolute_tolerance, double relative_tolerance) requires(!VectorizableDense<DenseMatrixPolicy>)
const DenseMatrixPolicy& Yn1,
const std::vector<double>& absolute_tolerance,
double relative_tolerance)
requires(!VectorizableDense<DenseMatrixPolicy>)
{
double small = parameters.small_;
double rel_tol = relative_tolerance;
Expand All @@ -221,7 +227,10 @@ namespace micm
inline bool BackwardEuler<RatesPolicy, LinearSolverPolicy>::IsConverged(
const BackwardEulerSolverParameters& parameters,
const DenseMatrixPolicy& residual,
const DenseMatrixPolicy& Yn1, const std::vector<double>& absolute_tolerance, double relative_tolerance) requires(VectorizableDense<DenseMatrixPolicy>)
const DenseMatrixPolicy& Yn1,
const std::vector<double>& absolute_tolerance,
double relative_tolerance)
requires(VectorizableDense<DenseMatrixPolicy>)
{
double small = parameters.small_;
double rel_tol = relative_tolerance;
Expand Down
22 changes: 13 additions & 9 deletions include/micm/solver/rosenbrock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,19 @@ namespace micm
/// @param errors The computed errors
/// @return
template<class DenseMatrixPolicy>
double NormalizedError(const DenseMatrixPolicy& y, const DenseMatrixPolicy& y_new, const DenseMatrixPolicy& errors, auto& state) const
requires(!VectorizableDense<DenseMatrixPolicy>);
double NormalizedError(
const DenseMatrixPolicy& y,
const DenseMatrixPolicy& y_new,
const DenseMatrixPolicy& errors,
auto& state) const
requires(!VectorizableDense<DenseMatrixPolicy>);
template<class DenseMatrixPolicy>
double NormalizedError(const DenseMatrixPolicy& y, const DenseMatrixPolicy& y_new, const DenseMatrixPolicy& errors, auto& state) const
requires(VectorizableDense<DenseMatrixPolicy>);
double NormalizedError(
const DenseMatrixPolicy& y,
const DenseMatrixPolicy& y_new,
const DenseMatrixPolicy& errors,
auto& state) const
requires(VectorizableDense<DenseMatrixPolicy>);
}; // end of Abstract Rosenbrock Solver

template<class RatesPolicy, class LinearSolverPolicy>
Expand All @@ -130,11 +138,7 @@ namespace micm
/// @param jacobian Jacobian matrix
///
/// Note: This constructor is not intended to be used directly. Instead, use the SolverBuilder to create a solver
RosenbrockSolver(
LinearSolverPolicy&& linear_solver,
RatesPolicy&& rates,
auto& jacobian,
const size_t number_of_species)
RosenbrockSolver(LinearSolverPolicy&& linear_solver, RatesPolicy&& rates, auto& jacobian, const size_t number_of_species)
: AbstractRosenbrockSolver<RatesPolicy, LinearSolverPolicy, RosenbrockSolver<RatesPolicy, LinearSolverPolicy>>(
std::move(linear_solver),
std::move(rates),
Expand Down
25 changes: 12 additions & 13 deletions include/micm/solver/rosenbrock.inl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace micm
template<class RatesPolicy, class LinearSolverPolicy, class Derived>
inline SolverResult AbstractRosenbrockSolver<RatesPolicy, LinearSolverPolicy, Derived>::Solve(
double time_step,
auto& state, const RosenbrockSolverParameters& parameters) const noexcept
auto& state,
const RosenbrockSolverParameters& parameters) const noexcept
{
MICM_PROFILE_FUNCTION();
using MatrixPolicy = decltype(state.variables_);
Expand Down Expand Up @@ -248,8 +249,9 @@ namespace micm
inline double AbstractRosenbrockSolver<RatesPolicy, LinearSolverPolicy, Derived>::NormalizedError(
const DenseMatrixPolicy& Y,
const DenseMatrixPolicy& Ynew,
const DenseMatrixPolicy& errors,
auto& state) const requires(!VectorizableDense<DenseMatrixPolicy>)
const DenseMatrixPolicy& errors,
auto& state) const
requires(!VectorizableDense<DenseMatrixPolicy>)
{
// Solving Ordinary Differential Equations II, page 123
// https://link-springer-com.cuucar.idm.oclc.org/book/10.1007/978-3-642-05221-7
Expand All @@ -271,8 +273,7 @@ namespace micm
for (std::size_t i = 0; i < N; ++i)
{
ymax = std::max(std::abs(_y[i]), std::abs(_ynew[i]));
errors_over_scale =
_errors[i] / (atol[i % n_vars] + rtol * ymax);
errors_over_scale = _errors[i] / (atol[i % n_vars] + rtol * ymax);
error += errors_over_scale * errors_over_scale;
}

Expand All @@ -286,8 +287,9 @@ namespace micm
inline double AbstractRosenbrockSolver<RatesPolicy, LinearSolverPolicy, Derived>::NormalizedError(
const DenseMatrixPolicy& Y,
const DenseMatrixPolicy& Ynew,
const DenseMatrixPolicy& errors,
auto& state) const requires(VectorizableDense<DenseMatrixPolicy>)
const DenseMatrixPolicy& errors,
auto& state) const
requires(VectorizableDense<DenseMatrixPolicy>)
{
// Solving Ordinary Differential Equations II, page 123
// https://link-springer-com.cuucar.idm.oclc.org/book/10.1007/978-3-642-05221-7
Expand All @@ -310,9 +312,7 @@ namespace micm
// compute the error over the blocks which fit exactly into the L parameter
for (std::size_t i = 0; i < whole_blocks; ++i)
{
errors_over_scale =
*errors_iter / (atol[(i / L) % n_vars] +
rtol * std::max(std::abs(*y_iter), std::abs(*ynew_iter)));
errors_over_scale = *errors_iter / (atol[(i / L) % n_vars] + rtol * std::max(std::abs(*y_iter), std::abs(*ynew_iter)));
error += errors_over_scale * errors_over_scale;
++y_iter;
++ynew_iter;
Expand All @@ -329,9 +329,8 @@ namespace micm
for (std::size_t x = 0; x < remaining_rows; ++x)
{
const std::size_t idx = y * L + x;
errors_over_scale = errors_iter[idx] /
(atol[y] +
rtol * std::max(std::abs(y_iter[idx]), std::abs(ynew_iter[idx])));
errors_over_scale =
errors_iter[idx] / (atol[y] + rtol * std::max(std::abs(y_iter[idx]), std::abs(ynew_iter[idx])));
error += errors_over_scale * errors_over_scale;
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/micm/solver/solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace micm
{
return state_parameters_.number_of_rate_constants_;
}

StatePolicy GetState() const
{
auto state = std::move(StatePolicy(state_parameters_));
Expand Down
6 changes: 3 additions & 3 deletions include/micm/solver/solver_builder.inl
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ namespace micm
}
}
}
}
}

template<
class SolverParametersPolicy,
Expand Down Expand Up @@ -404,7 +404,7 @@ namespace micm
}

this->UnusedSpeciesCheck();

RatesPolicy rates(this->reactions_, species_map);
auto nonzero_elements = rates.NonZeroJacobianElements();
auto jacobian = BuildJacobian<SparseMatrixPolicy>(nonzero_elements, this->number_of_grid_cells_, number_of_species);
Expand All @@ -422,7 +422,7 @@ namespace micm
.variable_names_ = variable_names,
.custom_rate_parameter_labels_ = labels,
.nonzero_jacobian_elements_ = nonzero_elements };

this->SetAbsoluteTolerances(state_parameters.absolute_tolerance_, species_map);

return Solver<SolverPolicy, StatePolicy>(
Expand Down
4 changes: 2 additions & 2 deletions include/micm/solver/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace micm
std::vector<std::string> custom_rate_parameter_labels_{};
std::set<std::pair<std::size_t, std::size_t>> nonzero_jacobian_elements_{};
double relative_tolerance_{ 1e-06 };
std::vector<double> absolute_tolerance_ {};
std::vector<double> absolute_tolerance_{};
};

template<
Expand Down Expand Up @@ -68,7 +68,7 @@ namespace micm
double relative_tolerance_;
std::vector<double> absolute_tolerance_;

public:
public:
/// @brief Default constructor
/// Only defined to be used to create default values in types, but a default constructed state is not useable
State();
Expand Down
10 changes: 7 additions & 3 deletions include/micm/solver/state.inl
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,16 @@ namespace micm
for (std::size_t i = 0; i < custom_rate_parameters_.NumRows(); ++i)
custom_rate_parameters_[i][param->second] = values[i];
}

template<
class DenseMatrixPolicy,
class SparseMatrixPolicy,
class LuDecompositionPolicy,
class LMatrixPolicy,
class UMatrixPolicy>
inline void State<DenseMatrixPolicy, SparseMatrixPolicy, LuDecompositionPolicy, LMatrixPolicy, UMatrixPolicy>::SetRelativeTolerance(double relativeTolerance)
inline void
State<DenseMatrixPolicy, SparseMatrixPolicy, LuDecompositionPolicy, LMatrixPolicy, UMatrixPolicy>::SetRelativeTolerance(
double relativeTolerance)
{
this->relative_tolerance_ = relativeTolerance;
}
Expand All @@ -270,7 +272,9 @@ namespace micm
class LuDecompositionPolicy,
class LMatrixPolicy,
class UMatrixPolicy>
inline void State<DenseMatrixPolicy, SparseMatrixPolicy, LuDecompositionPolicy, LMatrixPolicy, UMatrixPolicy>::SetAbsoluteTolerances(const std::vector<double>& absoluteTolerance)
inline void
State<DenseMatrixPolicy, SparseMatrixPolicy, LuDecompositionPolicy, LMatrixPolicy, UMatrixPolicy>::SetAbsoluteTolerances(
const std::vector<double>& absoluteTolerance)
{
this->absolute_tolerance_ = absoluteTolerance;
}
Expand Down
Loading

0 comments on commit 51ddf39

Please sign in to comment.