Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename some of the time steppers #4366

Merged
merged 5 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

#include "Time/TimeSteppers/AdamsBashforthN.hpp"
#include "Time/TimeSteppers/AdamsBashforth.hpp"

#include <algorithm>
#include <boost/container/static_vector.hpp>
Expand Down Expand Up @@ -71,7 +71,7 @@ struct ApproximateTime {
// A vector holding one entry per order of integration.
template <typename T>
using OrderVector =
boost::container::static_vector<T, AdamsBashforthN::maximum_order>;
boost::container::static_vector<T, AdamsBashforth::maximum_order>;

OrderVector<double> constant_coefficients(const size_t order) {
switch (order) {
Expand Down Expand Up @@ -176,20 +176,20 @@ OrderVector<double> get_coefficients(const Iterator& times_begin,
}
} // namespace

AdamsBashforthN::AdamsBashforthN(const size_t order) : order_(order) {
AdamsBashforth::AdamsBashforth(const size_t order) : order_(order) {
if (order_ < 1 or order_ > maximum_order) {
ERROR("The order for Adams-Bashforth Nth order must be 1 <= order <= "
<< maximum_order);
}
}

size_t AdamsBashforthN::order() const { return order_; }
size_t AdamsBashforth::order() const { return order_; }

size_t AdamsBashforthN::error_estimate_order() const { return order_ - 1; }
size_t AdamsBashforth::error_estimate_order() const { return order_ - 1; }

size_t AdamsBashforthN::number_of_past_steps() const { return order_ - 1; }
size_t AdamsBashforth::number_of_past_steps() const { return order_ - 1; }

double AdamsBashforthN::stable_step() const {
double AdamsBashforth::stable_step() const {
if (order_ == 1) {
return 1.;
}
Expand All @@ -207,20 +207,20 @@ double AdamsBashforthN::stable_step() const {
return 1. / invstep;
}

TimeStepId AdamsBashforthN::next_time_id(const TimeStepId& current_id,
const TimeDelta& time_step) const {
TimeStepId AdamsBashforth::next_time_id(const TimeStepId& current_id,
const TimeDelta& time_step) const {
ASSERT(current_id.substep() == 0, "Adams-Bashforth should not have substeps");
return {current_id.time_runs_forward(), current_id.slab_number(),
current_id.step_time() + time_step};
}

void AdamsBashforthN::pup(PUP::er& p) {
void AdamsBashforth::pup(PUP::er& p) {
LtsTimeStepper::pup(p);
p | order_;
}

template <typename T>
void AdamsBashforthN::update_u_impl(
void AdamsBashforth::update_u_impl(
const gsl::not_null<T*> u, const gsl::not_null<UntypedHistory<T>*> history,
const TimeDelta& time_step) const {
ASSERT(history->size() >= history->integration_order(),
Expand All @@ -235,7 +235,7 @@ void AdamsBashforthN::update_u_impl(
}

template <typename T>
bool AdamsBashforthN::update_u_impl(
bool AdamsBashforth::update_u_impl(
const gsl::not_null<T*> u, const gsl::not_null<T*> u_error,
const gsl::not_null<UntypedHistory<T>*> history,
const TimeDelta& time_step) const {
Expand All @@ -258,19 +258,19 @@ bool AdamsBashforthN::update_u_impl(
}

template <typename T>
bool AdamsBashforthN::dense_update_u_impl(const gsl::not_null<T*> u,
const UntypedHistory<T>& history,
const double time) const {
bool AdamsBashforth::dense_update_u_impl(const gsl::not_null<T*> u,
const UntypedHistory<T>& history,
const double time) const {
const ApproximateTimeDelta time_step{time - history.back().value()};
update_u_common(u, history, time_step, history.integration_order());
return true;
}

template <typename T, typename Delta>
void AdamsBashforthN::update_u_common(const gsl::not_null<T*> u,
const UntypedHistory<T>& history,
const Delta& time_step,
const size_t order) const {
void AdamsBashforth::update_u_common(const gsl::not_null<T*> u,
const UntypedHistory<T>& history,
const Delta& time_step,
const size_t order) const {
ASSERT(
history.size() > 0,
"Cannot meaningfully update the evolved variables with an empty history");
Expand All @@ -292,7 +292,7 @@ void AdamsBashforthN::update_u_common(const gsl::not_null<T*> u,
}

template <typename T>
bool AdamsBashforthN::can_change_step_size_impl(
bool AdamsBashforth::can_change_step_size_impl(
const TimeStepId& time_id, const UntypedHistory<T>& history) const {
// We need to forbid local time-stepping before initialization is
// complete. The self-start procedure itself should never consider
Expand All @@ -307,7 +307,7 @@ bool AdamsBashforthN::can_change_step_size_impl(
}

template <typename T>
void AdamsBashforthN::add_boundary_delta_impl(
void AdamsBashforth::add_boundary_delta_impl(
const gsl::not_null<T*> result,
const TimeSteppers::BoundaryHistoryEvaluator<T>& coupling,
const TimeSteppers::BoundaryHistoryCleaner& cleaner,
Expand Down Expand Up @@ -347,17 +347,17 @@ void AdamsBashforthN::add_boundary_delta_impl(
}

template <typename T>
void AdamsBashforthN::boundary_dense_output_impl(
void AdamsBashforth::boundary_dense_output_impl(
const gsl::not_null<T*> result,
const TimeSteppers::BoundaryHistoryEvaluator<T>& coupling,
const double time) const {
return boundary_impl(result, coupling, ApproximateTime{time});
}

template <typename T, typename TimeType>
void AdamsBashforthN::boundary_impl(const gsl::not_null<T*> result,
const BoundaryHistoryEvaluator<T>& coupling,
const TimeType& end_time) const {
void AdamsBashforth::boundary_impl(const gsl::not_null<T*> result,
const BoundaryHistoryEvaluator<T>& coupling,
const TimeType& end_time) const {
// Might be different from order_ during self-start.
const auto current_order = coupling.integration_order();

Expand Down Expand Up @@ -592,17 +592,16 @@ void AdamsBashforthN::boundary_impl(const gsl::not_null<T*> result,
} // for local_evaluation_step
}

bool operator==(const AdamsBashforthN& lhs, const AdamsBashforthN& rhs) {
bool operator==(const AdamsBashforth& lhs, const AdamsBashforth& rhs) {
return lhs.order_ == rhs.order_;
}

bool operator!=(const AdamsBashforthN& lhs, const AdamsBashforthN& rhs) {
bool operator!=(const AdamsBashforth& lhs, const AdamsBashforth& rhs) {
return not(lhs == rhs);
}

TIME_STEPPER_DEFINE_OVERLOADS(AdamsBashforthN)
LTS_TIME_STEPPER_DEFINE_OVERLOADS(AdamsBashforthN)
TIME_STEPPER_DEFINE_OVERLOADS(AdamsBashforth)
LTS_TIME_STEPPER_DEFINE_OVERLOADS(AdamsBashforth)
} // namespace TimeSteppers

PUP::able::PUP_ID TimeSteppers::AdamsBashforthN::my_PUP_ID = // NOLINT
0;
PUP::able::PUP_ID TimeSteppers::AdamsBashforth::my_PUP_ID = 0; // NOLINT
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

/// \file
/// Defines class AdamsBashforthN

#pragma once

#include <vector>
Expand Down Expand Up @@ -189,7 +186,7 @@ namespace TimeSteppers {
* is the \f$j\f$th coefficient for an Adams-Bashforth step over the
* union times from step \f$n\f$ to step \f$n+1\f$.
*/
class AdamsBashforthN : public LtsTimeStepper {
class AdamsBashforth : public LtsTimeStepper {
public:
static constexpr const size_t maximum_order = 8;

Expand All @@ -203,13 +200,13 @@ class AdamsBashforthN : public LtsTimeStepper {
static constexpr Options::String help = {
"An Adams-Bashforth Nth order time-stepper."};

AdamsBashforthN() = default;
explicit AdamsBashforthN(size_t order);
AdamsBashforthN(const AdamsBashforthN&) = default;
AdamsBashforthN& operator=(const AdamsBashforthN&) = default;
AdamsBashforthN(AdamsBashforthN&&) = default;
AdamsBashforthN& operator=(AdamsBashforthN&&) = default;
~AdamsBashforthN() override = default;
AdamsBashforth() = default;
explicit AdamsBashforth(size_t order);
AdamsBashforth(const AdamsBashforth&) = default;
AdamsBashforth& operator=(const AdamsBashforth&) = default;
AdamsBashforth(AdamsBashforth&&) = default;
AdamsBashforth& operator=(AdamsBashforth&&) = default;
~AdamsBashforth() override = default;

size_t order() const override;

Expand All @@ -222,16 +219,15 @@ class AdamsBashforthN : public LtsTimeStepper {
TimeStepId next_time_id(const TimeStepId& current_id,
const TimeDelta& time_step) const override;

WRAPPED_PUPable_decl_template(AdamsBashforthN); // NOLINT
WRAPPED_PUPable_decl_template(AdamsBashforth); // NOLINT

explicit AdamsBashforthN(CkMigrateMessage* /*unused*/) {}
explicit AdamsBashforth(CkMigrateMessage* /*unused*/) {}

// clang-tidy: do not pass by non-const reference
void pup(PUP::er& p) override; // NOLINT

private:
friend bool operator==(const AdamsBashforthN& lhs,
const AdamsBashforthN& rhs);
friend bool operator==(const AdamsBashforth& lhs, const AdamsBashforth& rhs);

// Some of the private methods take a parameter of type "Delta" or
// "TimeType". Delta is expected to be a TimeDelta or an
Expand Down Expand Up @@ -285,5 +281,5 @@ class AdamsBashforthN : public LtsTimeStepper {
size_t order_ = 3;
};

bool operator!=(const AdamsBashforthN& lhs, const AdamsBashforthN& rhs);
bool operator!=(const AdamsBashforth& lhs, const AdamsBashforth& rhs);
} // namespace TimeSteppers
28 changes: 14 additions & 14 deletions src/Time/TimeSteppers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@
spectre_target_sources(
${LIBRARY}
PRIVATE
AdamsBashforthN.cpp
Cerk2.cpp
Cerk3.cpp
Cerk4.cpp
Cerk5.cpp
AdamsBashforth.cpp
ClassicalRungeKutta4.cpp
DormandPrince5.cpp
Heun2.cpp
Rk3HesthavenSsp.cpp
Rk3Owren.cpp
Rk4Owren.cpp
Rk5Owren.cpp
RungeKutta.cpp
RungeKutta3.cpp
RungeKutta4.cpp
)

spectre_target_headers(
${LIBRARY}
INCLUDE_DIRECTORY ${CMAKE_SOURCE_DIR}/src
HEADERS
AdamsBashforthN.hpp
Cerk2.hpp
Cerk3.hpp
Cerk4.hpp
Cerk5.hpp
AdamsBashforth.hpp
ClassicalRungeKutta4.hpp
DormandPrince5.hpp
Factory.hpp
Heun2.hpp
LtsTimeStepper.hpp
Rk3HesthavenSsp.hpp
Rk3Owren.hpp
Rk4Owren.hpp
Rk5Owren.hpp
RungeKutta.hpp
RungeKutta3.hpp
RungeKutta4.hpp
TimeStepper.hpp
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

#include "Time/TimeSteppers/RungeKutta4.hpp"
#include "Time/TimeSteppers/ClassicalRungeKutta4.hpp"

#include <utility>

namespace TimeSteppers {

size_t RungeKutta4::order() const { return 4; }
size_t ClassicalRungeKutta4::order() const { return 4; }

size_t RungeKutta4::error_estimate_order() const { return 3; }
size_t ClassicalRungeKutta4::error_estimate_order() const { return 3; }

// The growth function for RK4 is (e.g. page 60 of
// http://www.staff.science.uu.nl/~frank011/Classes/numwisk/ch10.pdf
Expand All @@ -21,9 +21,10 @@ size_t RungeKutta4::error_estimate_order() const { return 3; }
// RK1 (i.e. forward Euler) would be 1, RK4 has a stable step
// determined by inserting mu->-2 dt into the above equation. Finding the
// solutions with a numerical root find yields a stable step of about 1.39265.
double RungeKutta4::stable_step() const { return 1.3926467817026411; }
double ClassicalRungeKutta4::stable_step() const { return 1.3926467817026411; }

const RungeKutta::ButcherTableau& RungeKutta4::butcher_tableau() const {
const RungeKutta::ButcherTableau& ClassicalRungeKutta4::butcher_tableau()
const {
// See (17.1.3) of Numerical Recipes 3rd Edition
static const ButcherTableau tableau{
// Substep times
Expand All @@ -47,7 +48,7 @@ const RungeKutta::ButcherTableau& RungeKutta4::butcher_tableau() const {
return tableau;
}

const RungeKutta::ButcherTableau& RungeKutta4::error_tableau() const {
const RungeKutta::ButcherTableau& ClassicalRungeKutta4::error_tableau() const {
// The embedded Zonneveld 4(3) scheme adds an extra substep at 3/4
// that is used only by the third-order error estimation scheme
static const ButcherTableau tableau = [this]() {
Expand All @@ -70,4 +71,4 @@ const RungeKutta::ButcherTableau& RungeKutta4::error_tableau() const {
}
} // namespace TimeSteppers

PUP::able::PUP_ID TimeSteppers::RungeKutta4::my_PUP_ID = 0; // NOLINT
PUP::able::PUP_ID TimeSteppers::ClassicalRungeKutta4::my_PUP_ID = 0; // NOLINT
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

/// \file
/// Defines class RungeKutta4.

#pragma once

#include <cstddef>
Expand Down Expand Up @@ -49,42 +46,42 @@ namespace TimeSteppers {
*
* The CFL factor/stable step size is 1.3926467817026411.
*/
class RungeKutta4 : public RungeKutta {
class ClassicalRungeKutta4 : public RungeKutta {
public:
using options = tmpl::list<>;
static constexpr Options::String help = {
"The standard fourth-order Runge-Kutta time-stepper."};

RungeKutta4() = default;
RungeKutta4(const RungeKutta4&) = default;
RungeKutta4& operator=(const RungeKutta4&) = default;
RungeKutta4(RungeKutta4&&) = default;
RungeKutta4& operator=(RungeKutta4&&) = default;
~RungeKutta4() override = default;
ClassicalRungeKutta4() = default;
ClassicalRungeKutta4(const ClassicalRungeKutta4&) = default;
ClassicalRungeKutta4& operator=(const ClassicalRungeKutta4&) = default;
ClassicalRungeKutta4(ClassicalRungeKutta4&&) = default;
ClassicalRungeKutta4& operator=(ClassicalRungeKutta4&&) = default;
~ClassicalRungeKutta4() override = default;

size_t order() const override;

size_t error_estimate_order() const override;

double stable_step() const override;

WRAPPED_PUPable_decl_template(RungeKutta4); // NOLINT
WRAPPED_PUPable_decl_template(ClassicalRungeKutta4); // NOLINT

explicit RungeKutta4(CkMigrateMessage* /*unused*/) {}
explicit ClassicalRungeKutta4(CkMigrateMessage* /*unused*/) {}

private:
const ButcherTableau& butcher_tableau() const override;

const ButcherTableau& error_tableau() const override;
};

inline bool constexpr operator==(const RungeKutta4& /*lhs*/,
const RungeKutta4& /*rhs*/) {
inline bool constexpr operator==(const ClassicalRungeKutta4& /*lhs*/,
const ClassicalRungeKutta4& /*rhs*/) {
return true;
}

inline bool constexpr operator!=(const RungeKutta4& /*lhs*/,
const RungeKutta4& /*rhs*/) {
inline bool constexpr operator!=(const ClassicalRungeKutta4& /*lhs*/,
const ClassicalRungeKutta4& /*rhs*/) {
return false;
}
} // namespace TimeSteppers
Loading