Skip to content

Commit

Permalink
Applying clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
lucbv committed Mar 7, 2024
1 parent 92a7f3c commit 228c55c
Show file tree
Hide file tree
Showing 8 changed files with 405 additions and 327 deletions.
8 changes: 3 additions & 5 deletions batched/dense/src/KokkosBatched_Gesv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ struct SerialGesv {
const MatrixType tmp);

template <typename MatrixType, typename VectorType>
[[deprecated]]
KOKKOS_INLINE_FUNCTION static int invoke(const MatrixType A,
const VectorType X,
const VectorType Y,
const MatrixType tmp) {
[[deprecated]] KOKKOS_INLINE_FUNCTION static int invoke(
const MatrixType A, const VectorType X, const VectorType Y,
const MatrixType tmp) {
return invoke(A, X, Y, tmp);
}
};
Expand Down
295 changes: 165 additions & 130 deletions ode/impl/KokkosODE_BDF_impl.hpp

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions ode/impl/KokkosODE_Newton_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
namespace KokkosODE {
namespace Impl {

template <class system_type, class mat_type, class ini_vec_type, class rhs_vec_type, class update_type, class scale_type>
template <class system_type, class mat_type, class ini_vec_type,
class rhs_vec_type, class update_type, class scale_type>
KOKKOS_FUNCTION KokkosODE::Experimental::newton_solver_status NewtonSolve(
system_type& sys, const KokkosODE::Experimental::Newton_params& params,
mat_type& J, mat_type& tmp, ini_vec_type& y0, rhs_vec_type& rhs, update_type& update, const scale_type& scale) {
mat_type& J, mat_type& tmp, ini_vec_type& y0, rhs_vec_type& rhs,
update_type& update, const scale_type& scale) {
using newton_solver_status = KokkosODE::Experimental::newton_solver_status;
using value_type = typename ini_vec_type::non_const_value_type;

Expand All @@ -48,8 +50,9 @@ KOKKOS_FUNCTION KokkosODE::Experimental::newton_solver_status NewtonSolve(
norm_type norm_new = Kokkos::ArithTraits<norm_type>::zero();
norm_type rate = Kokkos::ArithTraits<norm_type>::zero();

const norm_type tol = Kokkos::max(10 * Kokkos::ArithTraits<norm_type>::eps() / params.rel_tol,
Kokkos::min(0.03, Kokkos::sqrt(params.rel_tol)));
const norm_type tol =
Kokkos::max(10 * Kokkos::ArithTraits<norm_type>::eps() / params.rel_tol,
Kokkos::min(0.03, Kokkos::sqrt(params.rel_tol)));

// LBV - 07/24/2023: for now assume that we take
// a full Newton step. Eventually this value can
Expand Down Expand Up @@ -80,16 +83,18 @@ KOKKOS_FUNCTION KokkosODE::Experimental::newton_solver_status NewtonSolve(
norm = KokkosBlas::serial_nrm2(rhs);

// Compute rms norm of the scaled update
for(int idx = 0; idx < sys.neqs; ++idx) {
for (int idx = 0; idx < sys.neqs; ++idx) {
norm_new = (update(idx) * update(idx)) / (scale(idx) * scale(idx));
}
norm_new = Kokkos::sqrt(norm_new / sys.neqs);
if((it > 0) && norm_old > Kokkos::ArithTraits<norm_type>::zero()) {
if ((it > 0) && norm_old > Kokkos::ArithTraits<norm_type>::zero()) {
rate = norm_new / norm_old;
if((rate >= 1) || Kokkos::pow(rate, params.max_iters - it) / (1 - rate) * norm_new > tol) {
return newton_solver_status::NLS_DIVERGENCE;
} else if((norm_new == 0) || ((rate / (1 - rate)) * norm_new < tol)) {
return newton_solver_status::NLS_SUCCESS;
if ((rate >= 1) ||
Kokkos::pow(rate, params.max_iters - it) / (1 - rate) * norm_new >
tol) {
return newton_solver_status::NLS_DIVERGENCE;
} else if ((norm_new == 0) || ((rate / (1 - rate)) * norm_new < tol)) {
return newton_solver_status::NLS_SUCCESS;
}
}

Expand Down
41 changes: 22 additions & 19 deletions ode/src/KokkosODE_BDF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct BDF {
}
t += dt;
}
} // Solve()
} // Solve()
};

/// \brief BDF Solve integrates an ordinary differential equation
Expand All @@ -167,22 +167,24 @@ struct BDF {
/// \param temp [in]: vectors for temporary storage
/// \param temp2 [in]: vectors for temporary storage
template <class ode_type, class mat_type, class vec_type, class scalar_type>
KOKKOS_FUNCTION void BDFSolve(const ode_type& ode, const scalar_type t_start, const scalar_type t_end,
const scalar_type initial_step, const scalar_type max_step,
const vec_type& y0, const vec_type& y_new,
mat_type& temp, mat_type& temp2) {
KOKKOS_FUNCTION void BDFSolve(const ode_type& ode, const scalar_type t_start,
const scalar_type t_end,
const scalar_type initial_step,
const scalar_type max_step, const vec_type& y0,
const vec_type& y_new, mat_type& temp,
mat_type& temp2) {
using KAT = Kokkos::ArithTraits<scalar_type>;

// This needs to go away and be pulled out of temp instead...
auto rhs = Kokkos::subview(temp, Kokkos::ALL(), 0);
auto update = Kokkos::subview(temp, Kokkos::ALL(), 1);
// vec_type rhs("rhs", ode.neqs), update("update", ode.neqs);
(void) max_step;
(void)max_step;

int order = 1, num_equal_steps = 0;
constexpr scalar_type min_factor = 0.2;
scalar_type dt = initial_step;
scalar_type t = t_start;
scalar_type dt = initial_step;
scalar_type t = t_start;

constexpr int max_newton_iters = 10;
scalar_type atol = 1.0e-6, rtol = 1.0e-3;
Expand All @@ -192,31 +194,32 @@ KOKKOS_FUNCTION void BDFSolve(const ode_type& ode, const scalar_type t_start, co

// Check if we need to compute the initial
// time step size.
if(initial_step == KAT::zero()) {
KokkosODE::Impl::initial_step_size(ode, order, t_start, atol, rtol, y0, rhs, temp, dt);
if (initial_step == KAT::zero()) {
KokkosODE::Impl::initial_step_size(ode, order, t_start, atol, rtol, y0, rhs,
temp, dt);
}

// Initialize D(:, 0) = y0 and D(:, 1) = dt*rhs
auto D = Kokkos::subview(temp, Kokkos::ALL(), Kokkos::pair<int, int>(2, 10));
for(int eqIdx = 0; eqIdx < ode.neqs; ++eqIdx) {
for (int eqIdx = 0; eqIdx < ode.neqs; ++eqIdx) {
D(eqIdx, 0) = y0(eqIdx);
D(eqIdx, 1) = dt*rhs(eqIdx);
rhs(eqIdx) = 0;
D(eqIdx, 1) = dt * rhs(eqIdx);
rhs(eqIdx) = 0;
}

// Now we loop over the time interval [t_start, t_end]
// and solve our ODE.
while(t < t_end) {
KokkosODE::Impl::BDFStep(ode, t, dt, t_end, order,
num_equal_steps, max_newton_iters, atol, rtol, min_factor,
y0, y_new, rhs, update, temp, temp2);
while (t < t_end) {
KokkosODE::Impl::BDFStep(ode, t, dt, t_end, order, num_equal_steps,
max_newton_iters, atol, rtol, min_factor, y0,
y_new, rhs, update, temp, temp2);

for(int eqIdx = 0; eqIdx < ode.neqs; ++eqIdx) {
for (int eqIdx = 0; eqIdx < ode.neqs; ++eqIdx) {
y0(eqIdx) = y_new(eqIdx);
}
// printf("t=%f, dt=%f, y={%f, %f, %f}\n", t, dt, y0(0), y0(1), y0(2));
}
} // BDFSolve
} // BDFSolve

} // namespace Experimental
} // namespace KokkosODE
Expand Down
7 changes: 4 additions & 3 deletions ode/src/KokkosODE_Newton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ namespace Experimental {

/// \brief Newton solver for non-linear system of equations
struct Newton {
template <class system_type, class mat_type, class ini_vec_type, class rhs_vec_type,
class update_type, class scale_type>
template <class system_type, class mat_type, class ini_vec_type,
class rhs_vec_type, class update_type, class scale_type>
KOKKOS_FUNCTION static newton_solver_status Solve(
const system_type& sys, const Newton_params& params, const mat_type& J,
const mat_type& tmp, const ini_vec_type& y0, const rhs_vec_type& rhs,
const update_type& update, const scale_type& scale) {
return KokkosODE::Impl::NewtonSolve(sys, params, J, tmp, y0, rhs, update, scale);
return KokkosODE::Impl::NewtonSolve(sys, params, J, tmp, y0, rhs, update,
scale);
}
};

Expand Down
Loading

0 comments on commit 228c55c

Please sign in to comment.