Skip to content
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
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Checks: '*,
-fuchsia-*,
# defaulting virtual functions in CoordinateMap,
-google-default-arguments,
# Documented as redundant with -Wold-style-cast. Has more false positives.,
-google-readability-casting,
# specifying int32_t and int64_t instead of just int,
-google-runtime-int,
# redundant with other checks,
Expand Down
85 changes: 50 additions & 35 deletions src/DataStructures/TaggedVariant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,28 @@ class TaggedVariant {
TaggedVariant<OtherTags...>, TaggedVariant>>::value ==
0> = nullptr>
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr TaggedVariant(TaggedVariant<OtherTags...>&& other);
constexpr TaggedVariant(TaggedVariant<OtherTags...>&& other)
: TaggedVariant(visit(
[]<typename Tag>(
std::pair<tmpl::type_<Tag>, typename Tag::type&&> entry) {
return TaggedVariant(std::in_place_type<Tag>,
std::move(entry.second));
},
std::move(other))) {}

template <typename... OtherTags,
Requires<tmpl::size<tmpl::list_difference<
TaggedVariant<OtherTags...>, TaggedVariant>>::value ==
0> = nullptr>
constexpr TaggedVariant& operator=(TaggedVariant<OtherTags...>&& other);
constexpr TaggedVariant& operator=(TaggedVariant<OtherTags...>&& other) {
visit(
[&]<typename Tag>(
std::pair<tmpl::type_<Tag>, typename Tag::type&&> entry) {
emplace<Tag>(std::move(entry.second));
},
std::move(other));
return *this;
}
/// @}

/// The index into the `Tags...` of the active object.
Expand Down Expand Up @@ -407,6 +422,39 @@ constexpr bool operator>=(const TaggedVariant<Tags...>& a,
return not(a < b);
}

/// Comparison operators against single-tag variants. Primarily useful
/// in tests.
/// @{
template <typename... Tags, typename Tag,
Requires<(sizeof...(Tags) > 1 and
(... or std::is_same_v<Tags, Tag>))> = nullptr>
constexpr bool operator==(const TaggedVariant<Tags...>& a,
const TaggedVariant<Tag>& b) {
return holds_alternative<Tag>(a) and get<Tag>(a) == get<Tag>(b);
}
template <typename... Tags, typename Tag,
Requires<(sizeof...(Tags) > 1 and
(... or std::is_same_v<Tags, Tag>))> = nullptr>
constexpr bool operator==(const TaggedVariant<Tag>& a,
const TaggedVariant<Tags...>& b) {
return b == a;
}
template <typename... Tags, typename Tag,
Requires<(sizeof...(Tags) > 1 and
(... or std::is_same_v<Tags, Tag>))> = nullptr>
constexpr bool operator!=(const TaggedVariant<Tags...>& a,
const TaggedVariant<Tag>& b) {
return not(a == b);
}
template <typename... Tags, typename Tag,
Requires<(sizeof...(Tags) > 1 and
(... or std::is_same_v<Tags, Tag>))> = nullptr>
constexpr bool operator!=(const TaggedVariant<Tag>& a,
const TaggedVariant<Tags...>& b) {
return not(a == b);
}
/// @}

template <
typename... Tags,
Requires<(... and (std::is_move_constructible_v<typename Tags::type> and
Expand All @@ -415,39 +463,6 @@ constexpr void swap(TaggedVariant<Tags...>& a,
TaggedVariant<Tags...>& b) noexcept(noexcept(a.swap(b))) {
a.swap(b);
}

template <typename... Tags>
template <
typename... OtherTags,
Requires<tmpl::size<tmpl::list_difference<TaggedVariant<OtherTags...>,
TaggedVariant<Tags...>>>::value ==
0>>
constexpr TaggedVariant<Tags...>::TaggedVariant(
TaggedVariant<OtherTags...>&& other)
: TaggedVariant(visit(
[]<typename Tag>(
std::pair<tmpl::type_<Tag>, typename Tag::type&&> entry) {
return TaggedVariant(std::in_place_type<Tag>,
std::move(entry.second));
},
std::move(other))) {}

template <typename... Tags>
template <
typename... OtherTags,
Requires<tmpl::size<tmpl::list_difference<TaggedVariant<OtherTags...>,
TaggedVariant<Tags...>>>::value ==
0>>
constexpr TaggedVariant<Tags...>& TaggedVariant<Tags...>::operator=(
TaggedVariant<OtherTags...>&& other) {
visit(
[&]<typename Tag>(
std::pair<tmpl::type_<Tag>, typename Tag::type&&> entry) {
emplace<Tag>(std::move(entry.second));
},
std::move(other));
return *this;
}
} // namespace variants

namespace std {
Expand Down
13 changes: 12 additions & 1 deletion src/Evolution/Initialization/Evolution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,18 @@ struct TimeStepperHistory {
// one additional point per order, so this is the order that
// requires no initial past steps.
const size_t starting_order =
time_stepper.order() - time_stepper.number_of_past_steps();
visit(
[]<typename Tag>(
const std::pair<tmpl::type_<Tag>, typename Tag::type&&> order) {
if constexpr (std::is_same_v<Tag,
TimeSteppers::Tags::FixedOrder>) {
return order.second;
} else {
return order.second.minimum;
}
},
time_stepper.order()) -
time_stepper.number_of_past_steps();
history->integration_order(starting_order);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,18 @@ struct InitializeCharacteristicEvolutionTime {
const auto& time_stepper = db::get<::Tags::TimeStepper<TimeStepper>>(box);

const size_t starting_order =
time_stepper.number_of_past_steps() == 0 ? time_stepper.order() : 1;
visit(
[]<typename Tag>(
const std::pair<tmpl::type_<Tag>, typename Tag::type&&> order) {
if constexpr (std::is_same_v<Tag,
TimeSteppers::Tags::FixedOrder>) {
return order.second;
} else {
return order.second.minimum;
}
},
time_stepper.order()) -
time_stepper.number_of_past_steps();

typename ::Tags::HistoryEvolvedVariables<EvolvedCoordinatesVariablesTag>::
type coordinate_history(starting_order);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,18 @@ struct InitializeEvolvedVariables {
*worldtube_radius = excision_sphere.radius();

const size_t starting_order =
time_stepper.number_of_past_steps() == 0 ? time_stepper.order() : 1;
visit(
[]<typename Tag>(
const std::pair<tmpl::type_<Tag>, typename Tag::type&&> order) {
if constexpr (std::is_same_v<Tag,
TimeSteppers::Tags::FixedOrder>) {
return order.second;
} else {
return order.second.minimum;
}
},
time_stepper.order()) -
time_stepper.number_of_past_steps();
*time_stepper_history =
typename ::Tags::HistoryEvolvedVariables<variables_tag>::type{
starting_order};
Expand Down
2 changes: 1 addition & 1 deletion src/Executables/TimeStepperSummary/TimeStepperSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ using Row = std::tuple<std::string, size_t, size_t, size_t, double, double,
template <typename Stepper>
Row generate_row(const Stepper& stepper, std::string name) {
return {std::move(name),
stepper.order(),
get<TimeSteppers::Tags::FixedOrder>(stepper.order()),
stepper.number_of_substeps(),
stepper.number_of_substeps_for_error(),
stepper.stable_step(),
Expand Down
16 changes: 3 additions & 13 deletions src/Time/Actions/SelfStartActions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ struct Initialize {
const auto values_needed =
db::get<::Tags::Next<::Tags::TimeStepId>>(box).slab_number() == 0
? 0
: db::get<::Tags::TimeStepper<TimeStepper>>(box).order() - 1;
: get<TimeSteppers::Tags::FixedOrder>(
db::get<::Tags::TimeStepper<TimeStepper>>(box).order()) -
1;

// Decrease the step so that the generated history will be
// entirely before the first step. This ensures we will not
Expand Down Expand Up @@ -426,18 +428,6 @@ struct Cleanup {
},
make_not_null(&box));
});
using history_tags = ::Tags::get_all_history_tags<DbTags>;
tmpl::for_each<history_tags>([&box](auto tag_v) {
using tag = typename decltype(tag_v)::type;
ASSERT(db::get<tag>(box).integration_order() ==
db::get<::Tags::TimeStepper<TimeStepper>>(box).order(),
"Volume history order is: "
<< db::get<tag>(box).integration_order()
<< " but time stepper requires order: "
<< db::get<::Tags::TimeStepper<TimeStepper>>(box).order()
<< ". This may indicate that the step size has varied during "
"self-start, which should not be permitted.");
});
return {Parallel::AlgorithmExecution::Continue, std::nullopt};
}
};
Expand Down
6 changes: 5 additions & 1 deletion src/Time/TimeSteppers/AdamsBashforth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <optional>
#include <pup.h>

#include "DataStructures/TaggedVariant.hpp"
#include "Time/ApproximateTime.hpp"
#include "Time/BoundaryHistory.hpp"
#include "Time/EvolutionOrdering.hpp"
Expand Down Expand Up @@ -41,7 +42,10 @@ AdamsBashforth::AdamsBashforth(const size_t order) : order_(order) {
}
}

size_t AdamsBashforth::order() const { return order_; }
variants::TaggedVariant<Tags::FixedOrder, Tags::VariableOrder>
AdamsBashforth::order() const {
return variants::TaggedVariant<Tags::FixedOrder>(order_);
}

uint64_t AdamsBashforth::number_of_substeps() const { return 1; }

Expand Down
4 changes: 3 additions & 1 deletion src/Time/TimeSteppers/AdamsBashforth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cstdint>
#include <optional>

#include "DataStructures/TaggedVariant.hpp"
#include "Options/String.hpp"
#include "Time/StepperErrorEstimate.hpp"
#include "Time/TimeStepId.hpp"
Expand Down Expand Up @@ -217,7 +218,8 @@ class AdamsBashforth : public LtsTimeStepper {
AdamsBashforth& operator=(AdamsBashforth&&) = default;
~AdamsBashforth() override = default;

size_t order() const override;
variants::TaggedVariant<Tags::FixedOrder, Tags::VariableOrder> order()
const override;

uint64_t number_of_substeps() const override;

Expand Down
6 changes: 4 additions & 2 deletions src/Time/TimeSteppers/AdamsMoultonPc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <optional>
#include <pup.h>

#include "DataStructures/TaggedVariant.hpp"
#include "Time/ApproximateTime.hpp"
#include "Time/EvolutionOrdering.hpp"
#include "Time/History.hpp"
Expand Down Expand Up @@ -38,8 +39,9 @@ AdamsMoultonPc<Monotonic>::AdamsMoultonPc(const size_t order) : order_(order) {
}

template <bool Monotonic>
size_t AdamsMoultonPc<Monotonic>::order() const {
return order_;
variants::TaggedVariant<Tags::FixedOrder, Tags::VariableOrder>
AdamsMoultonPc<Monotonic>::order() const {
return variants::TaggedVariant<Tags::FixedOrder>(order_);
}

template <bool Monotonic>
Expand Down
4 changes: 3 additions & 1 deletion src/Time/TimeSteppers/AdamsMoultonPc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <pup.h>
#include <string>

#include "DataStructures/TaggedVariant.hpp"
#include "Options/String.hpp"
#include "Time/StepperErrorEstimate.hpp"
#include "Time/TimeSteppers/LtsTimeStepper.hpp"
Expand Down Expand Up @@ -122,7 +123,8 @@ class AdamsMoultonPc : public LtsTimeStepper {
AdamsMoultonPc& operator=(AdamsMoultonPc&&) = default;
~AdamsMoultonPc() override = default;

size_t order() const override;
variants::TaggedVariant<Tags::FixedOrder, Tags::VariableOrder> order()
const override;

uint64_t number_of_substeps() const override;

Expand Down
1 change: 1 addition & 0 deletions src/Time/TimeSteppers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ spectre_target_sources(
Rk5Owren.cpp
Rk5Tsitouras.cpp
RungeKutta.cpp
TimeStepper.cpp
)

spectre_target_headers(
Expand Down
7 changes: 6 additions & 1 deletion src/Time/TimeSteppers/ClassicalRungeKutta4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@

#include <utility>

#include "DataStructures/TaggedVariant.hpp"

namespace TimeSteppers {

size_t ClassicalRungeKutta4::order() const { return 4; }
variants::TaggedVariant<Tags::FixedOrder, Tags::VariableOrder>
ClassicalRungeKutta4::order() const {
return variants::TaggedVariant<Tags::FixedOrder>(4);
}

// The growth function for RK4 is (e.g. page 60 of
// http://www.staff.science.uu.nl/~frank011/Classes/numwisk/ch10.pdf
Expand Down
4 changes: 3 additions & 1 deletion src/Time/TimeSteppers/ClassicalRungeKutta4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <cstddef>

#include "DataStructures/TaggedVariant.hpp"
#include "Options/String.hpp"
#include "Time/TimeSteppers/RungeKutta.hpp"
#include "Utilities/Serialization/CharmPupable.hpp"
Expand Down Expand Up @@ -59,7 +60,8 @@ class ClassicalRungeKutta4 : public RungeKutta {
ClassicalRungeKutta4& operator=(ClassicalRungeKutta4&&) = default;
~ClassicalRungeKutta4() override = default;

size_t order() const override;
variants::TaggedVariant<Tags::FixedOrder, Tags::VariableOrder> order()
const override;

double stable_step() const override;

Expand Down
7 changes: 6 additions & 1 deletion src/Time/TimeSteppers/DormandPrince5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

#include "Time/TimeSteppers/DormandPrince5.hpp"

#include "DataStructures/TaggedVariant.hpp"

namespace TimeSteppers {

size_t DormandPrince5::order() const { return 5; }
variants::TaggedVariant<Tags::FixedOrder, Tags::VariableOrder>
DormandPrince5::order() const {
return variants::TaggedVariant<Tags::FixedOrder>(5);
}

// The growth function for DP5 is
//
Expand Down
4 changes: 3 additions & 1 deletion src/Time/TimeSteppers/DormandPrince5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <cstddef>

#include "DataStructures/TaggedVariant.hpp"
#include "Options/String.hpp"
#include "Time/TimeSteppers/RungeKutta.hpp"
#include "Utilities/Serialization/CharmPupable.hpp"
Expand Down Expand Up @@ -53,7 +54,8 @@ class DormandPrince5 : public RungeKutta {
DormandPrince5& operator=(DormandPrince5&&) = default;
~DormandPrince5() override = default;

size_t order() const override;
variants::TaggedVariant<Tags::FixedOrder, Tags::VariableOrder> order()
const override;

double stable_step() const override;

Expand Down
7 changes: 6 additions & 1 deletion src/Time/TimeSteppers/Heun2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

#include "Time/TimeSteppers/Heun2.hpp"

#include "DataStructures/TaggedVariant.hpp"

namespace TimeSteppers {

size_t Heun2::order() const { return 2; }
variants::TaggedVariant<Tags::FixedOrder, Tags::VariableOrder> Heun2::order()
const {
return variants::TaggedVariant<Tags::FixedOrder>(2);
}

// The stability polynomial is
//
Expand Down
Loading
Loading