Skip to content

Commit

Permalink
Merge pull request #5873 from wthrowe/dense_output_timing
Browse files Browse the repository at this point in the history
Adjust timing of dense output checks
  • Loading branch information
kidder authored Mar 27, 2024
2 parents a6876d9 + 8e39367 commit 6527eed
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 35 deletions.
35 changes: 18 additions & 17 deletions src/Evolution/Actions/RunEventsAndDenseTriggers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ struct RunEventsAndDenseTriggers {

const auto step_end =
time_step_id.step_time() + db::get<::Tags::TimeStep>(box);
const evolution_less<double> before{time_step_id.time_runs_forward()};
const evolution_less_equal<double> before_equal{
time_step_id.time_runs_forward()};

using postprocessor_return_tags =
tmpl::join<tmpl::transform<Postprocessors, get_return_tags<tmpl::_1>>>;
Expand All @@ -223,7 +224,7 @@ struct RunEventsAndDenseTriggers {

for (;;) {
const double next_trigger = events_and_dense_triggers.next_trigger(box);
if (before(step_end.value(), next_trigger)) {
if (before_equal(step_end.value(), next_trigger)) {
return {Parallel::AlgorithmExecution::Continue, std::nullopt};
}

Expand All @@ -244,21 +245,6 @@ struct RunEventsAndDenseTriggers {
case TriggeringState::NotReady:
return {Parallel::AlgorithmExecution::Retry, std::nullopt};
case TriggeringState::NeedsEvolvedVariables: {
bool ready = true;
tmpl::for_each<Postprocessors>([&](auto postprocessor_v) {
using postprocessor = tmpl::type_from<decltype(postprocessor_v)>;
if (ready) {
if (not postprocessor::is_ready(make_not_null(&box),
make_not_null(&inboxes), cache,
array_index, component)) {
ready = false;
}
}
});
if (not ready) {
return {Parallel::AlgorithmExecution::Retry, std::nullopt};
}

using history_tag = ::Tags::HistoryEvolvedVariables<variables_tag>;
bool dense_output_succeeded = false;
variables_restorer.save();
Expand All @@ -279,6 +265,21 @@ struct RunEventsAndDenseTriggers {
return {Parallel::AlgorithmExecution::Continue, std::nullopt};
}

bool ready = true;
tmpl::for_each<Postprocessors>([&](auto postprocessor_v) {
using postprocessor = tmpl::type_from<decltype(postprocessor_v)>;
if (ready) {
if (not postprocessor::is_ready(make_not_null(&box),
make_not_null(&inboxes), cache,
array_index, component)) {
ready = false;
}
}
});
if (not ready) {
return {Parallel::AlgorithmExecution::Retry, std::nullopt};
}

postprocessor_restorer.save();
tmpl::for_each<Postprocessors>([&box](auto postprocessor_v) {
using postprocessor = tmpl::type_from<decltype(postprocessor_v)>;
Expand Down
4 changes: 0 additions & 4 deletions src/Time/TimeSteppers/AdamsMoultonPc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ template <typename T>
bool AdamsMoultonPc::dense_update_u_impl(const gsl::not_null<T*> u,
const ConstUntypedHistory<T>& history,
const double time) const {
// Special case required to handle the initial time.
if (time == history.back().time_step_id.step_time().value()) {
return true;
}
if (history.at_step_start()) {
return false;
}
Expand Down
5 changes: 0 additions & 5 deletions src/Time/TimeSteppers/Rk3HesthavenSsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ bool Rk3HesthavenSsp::dense_update_u_impl(const gsl::not_null<T*> u,
}
const double step_start = history.front().time_step_id.step_time().value();
const double step_end = history.back().time_step_id.step_time().value();
if (history.size() == 1 and time == step_end) {
// Special case necessary for dense output at the initial time,
// before taking a step.
return true;
}
const evolution_less<double> before{step_end > step_start};
if (history.size() == 1 or before(step_end, time)) {
return false;
Expand Down
5 changes: 0 additions & 5 deletions src/Time/TimeSteppers/RungeKutta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@ bool RungeKutta::dense_update_u_impl(const gsl::not_null<T*> u,
}
const double step_start = history.front().time_step_id.step_time().value();
const double step_end = history.back().time_step_id.step_time().value();
if (history.size() == 1 and time == step_end) {
// Special case necessary for dense output at the initial time,
// before taking a step.
return true;
}
const evolution_less<double> before{step_end > step_start};
if (history.size() == 1 or before(step_end, time)) {
return false;
Expand Down
18 changes: 16 additions & 2 deletions tests/Unit/Evolution/Actions/Test_RunEventsAndDenseTriggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,20 @@ void test(const bool time_runs_forward) {
check_not_reached(true);
check_not_reached(false);

// Triggers at the end of the step (should not run)
const auto check_step_end = [&set_up_component, &start_time, &step_size](
const std::optional<bool>& is_triggered) {
MockRuntimeSystem runner{
{std::make_unique<TimeSteppers::AdamsBashforth>(1)}};
set_up_component(
&runner, {{start_time + step_size, is_triggered, std::nullopt, false}});
CHECK(run_if_ready(make_not_null(&runner)));
TestEvent::check_calls({});
};
check_step_end(std::nullopt);
check_step_end(true);
check_step_end(false);

// Trigger isn't ready
{
MockRuntimeSystem runner{
Expand Down Expand Up @@ -516,11 +530,11 @@ void test(const bool time_runs_forward) {
},
make_not_null(&box), db::get<Tags::TimeStepper<TimeStepper>>(box));
}
CHECK(run_if_ready(make_not_null(&runner)));
if (data_needed) {
TestCase::check_dense(&runner, true, {});
TestEvent::check_calls({});
} else {
// If we don't need the data, it shouldn't matter whether it is missing.
CHECK(run_if_ready(make_not_null(&runner)));
TestEvent::check_calls({{step_center, stored_vars}});
}
};
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Helpers/Time/TimeSteppers/TimeStepperTestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ void check_dense_output(
auto step = step_size;
for (;;) {
history.insert(time_id, y, y);
if (not before((time_id.step_time() + step).value(), time)) {
if (before(time, (time_id.step_time() + step).value())) {
// Make sure the initial value is preserved.
y = 2.0 * *history.complete_step_start().value;
if (stepper.dense_update_u(make_not_null(&y), history, time)) {
return y - *history.complete_step_start().value;
}
REQUIRE(before(time_id.step_time().value(), time));
REQUIRE(not before(time, time_id.step_time().value()));
}
y = std::numeric_limits<double>::signaling_NaN();
if (use_error_methods) {
Expand Down

0 comments on commit 6527eed

Please sign in to comment.