Skip to content

Commit

Permalink
Applying clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
lucbv committed Jun 12, 2024
1 parent 6a9d85e commit bc79efc
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 111 deletions.
13 changes: 6 additions & 7 deletions ode/impl/KokkosODE_RungeKutta_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ KOKKOS_FUNCTION Experimental::ode_solver_status RKSolve(
const ode_type& ode, const table_type& table,
const KokkosODE::Experimental::ODE_params& params,
const scalar_type t_start, const scalar_type t_end, const vec_type& y0,
const vec_type& y, const vec_type& temp, const mv_type& k_vecs, int* const count) {
const vec_type& y, const vec_type& temp, const mv_type& k_vecs,
int* const count) {
constexpr scalar_type error_threshold = 1;
scalar_type error_n;
bool adapt = params.adaptivity;
Expand Down Expand Up @@ -145,9 +146,8 @@ KOKKOS_FUNCTION Experimental::ode_solver_status RKSolve(
// is too large and current step
// is rejected.
if (error > 1) {
dt =
dt * Kokkos::max(
0.2, 0.8 * Kokkos::pow(error, -1.0 / table.order));
dt = dt *
Kokkos::max(0.2, 0.8 * Kokkos::pow(error, -1.0 / table.order));
dt_was_reduced = true;
}

Expand All @@ -168,9 +168,8 @@ KOKKOS_FUNCTION Experimental::ode_solver_status RKSolve(
// Compute new time increment
dt = dt *
Kokkos::min(
10.0,
Kokkos::max(
2.0, 0.9 * Kokkos::pow(error, -1.0 / table.order)));
10.0, Kokkos::max(
2.0, 0.9 * Kokkos::pow(error, -1.0 / table.order)));
}
} else {
return Experimental::ode_solver_status::SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion ode/src/KokkosODE_BDF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct BDF {

const double dt = (t_end - t_start) / num_steps;
double t = t_start;
int count = 0;
int count = 0;

// Load y0 into y_vecs(:, 0)
for (int eqIdx = 0; eqIdx < ode.neqs; ++eqIdx) {
Expand Down
5 changes: 3 additions & 2 deletions ode/src/KokkosODE_RungeKutta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ struct RungeKutta {
KOKKOS_FUNCTION static ode_solver_status Solve(
const ode_type& ode, const KokkosODE::Experimental::ODE_params& params,
const scalar_type t_start, const scalar_type t_end, const vec_type& y0,
const vec_type& y, const vec_type& temp, const mv_type& k_vecs, int* const count) {
const vec_type& y, const vec_type& temp, const mv_type& k_vecs,
int* const count) {
table_type table;
return KokkosODE::Impl::RKSolve(ode, table, params, t_start, t_end, y0, y,
temp, k_vecs, count);
temp, k_vecs, count);
}
};

Expand Down
16 changes: 9 additions & 7 deletions ode/unit_test/Test_ODE_RK.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ struct solution_wrapper {
};

template <class ode_type, KokkosODE::Experimental::RK_type rk_type,
class vec_type, class mv_type, class scalar_type,
class count_type>
class vec_type, class mv_type, class scalar_type, class count_type>
struct RKSolve_wrapper {
using ode_params = KokkosODE::Experimental::ODE_params;

Expand All @@ -102,7 +101,7 @@ struct RKSolve_wrapper {
const scalar_type tstart_, const scalar_type tend_,
const vec_type& y_old_, const vec_type& y_new_,
const vec_type& tmp_, const mv_type& kstack_,
const count_type& count_)
const count_type& count_)
: my_ode(my_ode_),
params(params_),
tstart(tstart_),
Expand All @@ -111,7 +110,7 @@ struct RKSolve_wrapper {
y_new(y_new_),
tmp(tmp_),
kstack(kstack_),
count(count_) {}
count(count_) {}

KOKKOS_FUNCTION
void operator()(const int /*idx*/) const {
Expand Down Expand Up @@ -140,7 +139,8 @@ void test_method(const std::string label, ode_type& my_ode,

Kokkos::RangePolicy<execution_space> my_policy(0, 1);
RKSolve_wrapper<ode_type, rk_type, vec_type, mv_type, scalar_type, count_type>
solve_wrapper(my_ode, params, tstart, tend, y_old, y_new, tmp, kstack, count);
solve_wrapper(my_ode, params, tstart, tend, y_old, y_new, tmp, kstack,
count);
Kokkos::parallel_for(my_policy, solve_wrapper);

auto y_new_h = Kokkos::create_mirror_view(y_new);
Expand Down Expand Up @@ -342,8 +342,10 @@ void test_rate(ode_type& my_ode, const scalar_type& tstart,
KokkosODE::Experimental::ODE_params params(num_steps(idx));
Kokkos::deep_copy(y_old, y_old_h);
Kokkos::deep_copy(y_new, y_old_h);
RKSolve_wrapper<ode_type, rk_type, vec_type, mv_type, scalar_type, count_type>
solve_wrapper(my_ode, params, tstart, tend, y_old, y_new, tmp, kstack, count);
RKSolve_wrapper<ode_type, rk_type, vec_type, mv_type, scalar_type,
count_type>
solve_wrapper(my_ode, params, tstart, tend, y_old, y_new, tmp, kstack,
count);
Kokkos::parallel_for(my_policy, solve_wrapper);

Kokkos::deep_copy(y_new_h, y_new);
Expand Down
6 changes: 4 additions & 2 deletions ode/unit_test/Test_ODE_RK_chem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ void test_chem() {
Kokkos::deep_copy(y_new, y_old_h);

Kokkos::RangePolicy<execution_space> my_policy(0, 1);
RKSolve_wrapper<chem_model_1, RK_type::RKCK, vec_type, mv_type, double, count_type>
RKSolve_wrapper<chem_model_1, RK_type::RKCK, vec_type, mv_type, double,
count_type>
solve_wrapper(chem_model, params, chem_model.tstart, chem_model.tend,
y_old, y_new, tmp, kstack, count);
Kokkos::parallel_for(my_policy, solve_wrapper);
Expand Down Expand Up @@ -165,7 +166,8 @@ void test_chem() {
Kokkos::deep_copy(y_new, y_old_h);

Kokkos::RangePolicy<execution_space> my_policy(0, 1);
RKSolve_wrapper<chem_model_2, RK_type::RKCK, vec_type, mv_type, double, count_type>
RKSolve_wrapper<chem_model_2, RK_type::RKCK, vec_type, mv_type, double,
count_type>
solve_wrapper(chem_model, params, chem_model.tstart, chem_model.tend,
y_old, y_new, tmp, kstack, count);
Kokkos::parallel_for(my_policy, solve_wrapper);
Expand Down
13 changes: 7 additions & 6 deletions ode/unit_test/Test_ODE_RK_counts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void test_RK_count() {
// First compute analytical solution as reference
// and to evaluate the error from each RK method.
auto y_ref_h = Kokkos::create_mirror(y);
y_ref_h(0) = myODE.expected_val(tend, 0);
y_ref_h(0) = myODE.expected_val(tend, 0);

vec_type tmp("tmp vector", neqs);
mv_type kstack(
Expand All @@ -65,13 +65,14 @@ void test_RK_count() {

constexpr double minStepSize = (tend - tstart) / maxSteps;
Kokkos::RangePolicy<execution_space> my_policy(0, 1);
KokkosODE::Experimental::ODE_params params(num_steps, maxSteps, absTol, relTol,
minStepSize);
KokkosODE::Experimental::ODE_params params(num_steps, maxSteps, absTol,
relTol, minStepSize);
Kokkos::deep_copy(y_old, y_old_h);
Kokkos::deep_copy(y_new, y_old_h);
RKSolve_wrapper<TestProblem::DegreeOnePoly, RK_type::RKF45, vec_type, mv_type, double, count_type>
solve_wrapper(myODE, params, tstart, tend, y_old, y_new, tmp,
kstack, count);
RKSolve_wrapper<TestProblem::DegreeOnePoly, RK_type::RKF45, vec_type, mv_type,
double, count_type>
solve_wrapper(myODE, params, tstart, tend, y_old, y_new, tmp, kstack,
count);
Kokkos::parallel_for(my_policy, solve_wrapper);

auto y_new_h = Kokkos::create_mirror(y_new);
Expand Down
150 changes: 69 additions & 81 deletions ode/unit_test/Test_ODE_TestProblems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,149 +19,137 @@

namespace TestProblem {

struct DegreeOnePoly
{
struct DegreeOnePoly {
template <typename View1, typename View2>
KOKKOS_FUNCTION void evaluate_function(double /*t*/, double /*dt*/, View1& /*y*/, View2 &dydt) const
{
for (int dofIdx = 0; dofIdx < neqs; ++dofIdx)
{
KOKKOS_FUNCTION void evaluate_function(double /*t*/, double /*dt*/,
View1& /*y*/, View2& dydt) const {
for (int dofIdx = 0; dofIdx < neqs; ++dofIdx) {
dydt(dofIdx) = 1;
}
}

template <typename View1, typename View2>
KOKKOS_FUNCTION void evaluate_jacobian(double /*t*/, double /*dt*/, View1 & /*y*/, View2 & jac) const
{
for(int rowIdx = 0; rowIdx < neqs; ++rowIdx) {
for(int colIdx = 0; colIdx < neqs; ++colIdx) {
jac(rowIdx, colIdx) = 0;
KOKKOS_FUNCTION void evaluate_jacobian(double /*t*/, double /*dt*/,
View1& /*y*/, View2& jac) const {
for (int rowIdx = 0; rowIdx < neqs; ++rowIdx) {
for (int colIdx = 0; colIdx < neqs; ++colIdx) {
jac(rowIdx, colIdx) = 0;
}
}
}

KOKKOS_FUNCTION double expected_val(const double t, const int /*n*/) const { return t + 1.0; }

KOKKOS_FUNCTION double expected_val(const double t, const int /*n*/) const {
return t + 1.0;
}
KOKKOS_FUNCTION static constexpr int num_equations() { return neqs; }
static constexpr int neqs = 1;
};

struct DegreeTwoPoly
{
struct DegreeTwoPoly {
template <typename View1, typename View2>
KOKKOS_FUNCTION void evaluate_function(double t, double /*dt*/, View1& /*y*/, View2 &dydt) const
{
for (int dofIdx = 0; dofIdx < neqs; ++dofIdx)
{
KOKKOS_FUNCTION void evaluate_function(double t, double /*dt*/, View1& /*y*/,
View2& dydt) const {
for (int dofIdx = 0; dofIdx < neqs; ++dofIdx) {
dydt(dofIdx) = t + 1;
}
}

template <typename View1, typename View2>
KOKKOS_FUNCTION void evaluate_jacobian(double /*t*/, double /*dt*/, View1 & /*y*/, View2 & jac) const
{
for(int rowIdx = 0; rowIdx < neqs; ++rowIdx) {
for(int colIdx = 0; colIdx < neqs; ++colIdx) {
jac(rowIdx, colIdx) = 0;
}
KOKKOS_FUNCTION void evaluate_jacobian(double /*t*/, double /*dt*/,
View1& /*y*/, View2& jac) const {
for (int rowIdx = 0; rowIdx < neqs; ++rowIdx) {
for (int colIdx = 0; colIdx < neqs; ++colIdx) {
jac(rowIdx, colIdx) = 0;
}
}
}

KOKKOS_FUNCTION double expected_val(const double t, const int /*n*/) const
{

KOKKOS_FUNCTION double expected_val(const double t, const int /*n*/) const {
return 0.5 * t * t + t + 1.0;
}
KOKKOS_FUNCTION static constexpr int num_equations() { return neqs; }
static constexpr int neqs = 1;
};

struct DegreeThreePoly
{
struct DegreeThreePoly {
template <typename View1, typename View2>
KOKKOS_FUNCTION void evaluate_function(double t, double /*dt*/, View1& /*y*/, View2 &dydt) const
{
for (int dofIdx = 0; dofIdx < neqs; ++dofIdx)
{
KOKKOS_FUNCTION void evaluate_function(double t, double /*dt*/, View1& /*y*/,
View2& dydt) const {
for (int dofIdx = 0; dofIdx < neqs; ++dofIdx) {
dydt(dofIdx) = (t * t) + t + 1;
}
}

template <typename View1, typename View2>
KOKKOS_FUNCTION void evaluate_jacobian(double /*t*/, double /*dt*/, View1 & /*y*/, View2 & jac) const
{
for(int rowIdx = 0; rowIdx < neqs; ++rowIdx) {
for(int colIdx = 0; colIdx < neqs; ++colIdx) {
jac(rowIdx, colIdx) = 0;
}
KOKKOS_FUNCTION void evaluate_jacobian(double /*t*/, double /*dt*/,
View1& /*y*/, View2& jac) const {
for (int rowIdx = 0; rowIdx < neqs; ++rowIdx) {
for (int colIdx = 0; colIdx < neqs; ++colIdx) {
jac(rowIdx, colIdx) = 0;
}
}
}

KOKKOS_FUNCTION double expected_val(const double t, const int /*n*/) const
{

KOKKOS_FUNCTION double expected_val(const double t, const int /*n*/) const {
return (1. / 3) * (t * t * t) + (1. / 2) * (t * t) + t + 1;
}
KOKKOS_FUNCTION static constexpr int num_equations() { return neqs; }
static constexpr int neqs = 1;
};

struct DegreeFivePoly
{
struct DegreeFivePoly {
template <typename View1, typename View2>
KOKKOS_FUNCTION void evaluate_function(double t, double /*dt*/, View1& /*y*/, View2 &dydt) const
{
for (int dofIdx = 0; dofIdx < neqs; ++dofIdx)
{
KOKKOS_FUNCTION void evaluate_function(double t, double /*dt*/, View1& /*y*/,
View2& dydt) const {
for (int dofIdx = 0; dofIdx < neqs; ++dofIdx) {
dydt(dofIdx) = (t * t * t * t) + (t * t * t) + (t * t) + t + 1;
}
}

template <typename View1, typename View2>
KOKKOS_FUNCTION void evaluate_jacobian(double /*t*/, double /*dt*/, View1 & /*y*/, View2 & jac) const
{
for(int rowIdx = 0; rowIdx < neqs; ++rowIdx) {
for(int colIdx = 0; colIdx < neqs; ++colIdx) {
jac(rowIdx, colIdx) = 0;
}
KOKKOS_FUNCTION void evaluate_jacobian(double /*t*/, double /*dt*/,
View1& /*y*/, View2& jac) const {
for (int rowIdx = 0; rowIdx < neqs; ++rowIdx) {
for (int colIdx = 0; colIdx < neqs; ++colIdx) {
jac(rowIdx, colIdx) = 0;
}
}
}

KOKKOS_FUNCTION double expected_val(const double t, const int /*n*/) const
{
return (1. / 5) * (t * t * t * t * t) + (1. / 4) * (t * t * t * t) + (1. / 3) * (t * t * t) +
(1. / 2) * (t * t) + t + 1;

KOKKOS_FUNCTION double expected_val(const double t, const int /*n*/) const {
return (1. / 5) * (t * t * t * t * t) + (1. / 4) * (t * t * t * t) +
(1. / 3) * (t * t * t) + (1. / 2) * (t * t) + t + 1;
}
KOKKOS_FUNCTION static constexpr int num_equations() { return neqs; }
static constexpr int neqs = 1;
};

struct Exponential
{
struct Exponential {
Exponential(double rate_) : rate(rate_) {}

template <typename View1, typename View2>
KOKKOS_FUNCTION void evaluate_function(double /*t*/, double /*dt*/, View1 & y, View2 & dydt) const
{
for (int dofIdx = 0; dofIdx < neqs; ++dofIdx)
{
dydt(dofIdx) = rate * y(dofIdx);
}
KOKKOS_FUNCTION void evaluate_function(double /*t*/, double /*dt*/, View1& y,
View2& dydt) const {
for (int dofIdx = 0; dofIdx < neqs; ++dofIdx) {
dydt(dofIdx) = rate * y(dofIdx);
}
}

template <typename View1, typename View2>
KOKKOS_FUNCTION void evaluate_jacobian(double /*t*/, double /*dt*/, View1 & /*y*/, View2 & jac) const
{
for(int rowIdx = 0; rowIdx < neqs; ++rowIdx) {
for(int colIdx = 0; colIdx < neqs; ++colIdx) {
jac(rowIdx, colIdx) = 0;
}
KOKKOS_FUNCTION void evaluate_jacobian(double /*t*/, double /*dt*/,
View1& /*y*/, View2& jac) const {
for (int rowIdx = 0; rowIdx < neqs; ++rowIdx) {
for (int colIdx = 0; colIdx < neqs; ++colIdx) {
jac(rowIdx, colIdx) = 0;
}
}

for(int rowIdx = 0; rowIdx < neqs; ++rowIdx) {
for (int rowIdx = 0; rowIdx < neqs; ++rowIdx) {
jac(rowIdx, rowIdx) = rate;
}
}

KOKKOS_FUNCTION double expected_val(const double t, const int /*n*/) const
{
KOKKOS_FUNCTION double expected_val(const double t, const int /*n*/) const {
return Kokkos::exp(rate * t);
}
KOKKOS_FUNCTION static constexpr int num_equations() { return neqs; }
Expand Down
Loading

0 comments on commit bc79efc

Please sign in to comment.