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

Add trigger StepsWithinSlab #6361

Merged
merged 2 commits into from
Nov 6, 2024
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
11 changes: 10 additions & 1 deletion src/Evolution/Initialization/Evolution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "Time/Tags/AdaptiveSteppingDiagnostics.hpp"
#include "Time/Tags/HistoryEvolvedVariables.hpp"
#include "Time/Tags/StepChoosers.hpp"
#include "Time/Tags/StepNumberWithinSlab.hpp"
#include "Time/Tags/Time.hpp"
#include "Time/Tags/TimeStep.hpp"
#include "Time/Tags/TimeStepId.hpp"
Expand Down Expand Up @@ -110,7 +111,8 @@ struct TimeStepping {
using default_initialized_simple_tags =
tmpl::push_back<StepChoosers::step_chooser_simple_tags<
Metavariables, TimeStepperBase::local_time_stepping>,
::Tags::TimeStepId, ::Tags::AdaptiveSteppingDiagnostics>;
::Tags::TimeStepId, ::Tags::StepNumberWithinSlab,
::Tags::AdaptiveSteppingDiagnostics>;

/// Tags for items in the DataBox that are mutated by the apply function
using return_tags =
Expand Down Expand Up @@ -176,6 +178,7 @@ struct ProjectTimeStepping : tt::ConformsTo<amr::protocols::Projector> {
using return_tags =
tmpl::list<::Tags::TimeStepId, ::Tags::Next<::Tags::TimeStepId>,
::Tags::TimeStep, ::Tags::Next<::Tags::TimeStep>, ::Tags::Time,
::Tags::StepNumberWithinSlab,
::Tags::AdaptiveSteppingDiagnostics,
::Tags::ChangeSlabSize::SlabSizeGoal>;
using argument_tags = tmpl::list<Parallel::Tags::ArrayIndex>;
Expand All @@ -186,6 +189,7 @@ struct ProjectTimeStepping : tt::ConformsTo<amr::protocols::Projector> {
const gsl::not_null<TimeDelta*> /*time_step*/,
const gsl::not_null<TimeDelta*> /*next_time_step*/,
const gsl::not_null<double*> /*time*/,
const gsl::not_null<uint64_t*> /*step_number_within_slab*/,
const gsl::not_null<AdaptiveSteppingDiagnostics*>
/*adaptive_stepping_diagnostics*/,
const gsl::not_null<double*> /*slab_size_goal*/,
Expand All @@ -200,6 +204,7 @@ struct ProjectTimeStepping : tt::ConformsTo<amr::protocols::Projector> {
const gsl::not_null<TimeDelta*> time_step,
const gsl::not_null<TimeDelta*> next_time_step,
const gsl::not_null<double*> time,
const gsl::not_null<uint64_t*> step_number_within_slab,
const gsl::not_null<AdaptiveSteppingDiagnostics*>
adaptive_stepping_diagnostics,
const gsl::not_null<double*> slab_size_goal,
Expand All @@ -211,6 +216,7 @@ struct ProjectTimeStepping : tt::ConformsTo<amr::protocols::Projector> {
*next_time_step = get<::Tags::Next<::Tags::TimeStep>>(parent_items);
*time = get<::Tags::Time>(parent_items);
*slab_size_goal = get<::Tags::ChangeSlabSize::SlabSizeGoal>(parent_items);
*step_number_within_slab = get<::Tags::StepNumberWithinSlab>(parent_items);

// Since AdaptiveSteppingDiagnostics are reduced over all elements, we
// set the slab quantities to the same value over all children, and the
Expand Down Expand Up @@ -239,6 +245,7 @@ struct ProjectTimeStepping : tt::ConformsTo<amr::protocols::Projector> {
const gsl::not_null<TimeDelta*> time_step,
const gsl::not_null<TimeDelta*> next_time_step,
const gsl::not_null<double*> time,
const gsl::not_null<uint64_t*> step_number_within_slab,
const gsl::not_null<AdaptiveSteppingDiagnostics*>
adaptive_stepping_diagnostics,
const gsl::not_null<double*> slab_size_goal,
Expand All @@ -263,6 +270,8 @@ struct ProjectTimeStepping : tt::ConformsTo<amr::protocols::Projector> {
*time = get<::Tags::Time>(slowest_child_items);
*slab_size_goal =
get<::Tags::ChangeSlabSize::SlabSizeGoal>(slowest_child_items);
*step_number_within_slab =
get<::Tags::StepNumberWithinSlab>(slowest_child_items);
const auto& slowest_child_diagnostics =
get<::Tags::AdaptiveSteppingDiagnostics>(slowest_child_items);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Time/Tags/AdaptiveSteppingDiagnostics.hpp"
#include "Time/Tags/HistoryEvolvedVariables.hpp"
#include "Time/Tags/StepChoosers.hpp"
#include "Time/Tags/StepNumberWithinSlab.hpp"
#include "Time/Tags/Time.hpp"
#include "Time/Tags/TimeStep.hpp"
#include "Time/Tags/TimeStepId.hpp"
Expand Down Expand Up @@ -81,7 +82,7 @@ struct InitializeCharacteristicEvolutionTime {
using simple_tags = tmpl::list<
::Tags::TimeStepId, ::Tags::Next<::Tags::TimeStepId>, ::Tags::TimeStep,
::Tags::Next<::Tags::TimeStep>, ::Tags::Time,
::Tags::AdaptiveSteppingDiagnostics,
::Tags::StepNumberWithinSlab, ::Tags::AdaptiveSteppingDiagnostics,
::Tags::HistoryEvolvedVariables<EvolvedCoordinatesVariablesTag>,
::Tags::HistoryEvolvedVariables<evolved_swsh_variables_tag>>;
using compute_tags = time_stepper_ref_tags<LtsTimeStepper>;
Expand Down
8 changes: 7 additions & 1 deletion src/Time/Actions/AdvanceTime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

#pragma once

#include <cstdint>
#include <optional>
#include <tuple>

#include "DataStructures/DataBox/DataBox.hpp"
#include "Parallel/AlgorithmExecution.hpp"
#include "Time/AdaptiveSteppingDiagnostics.hpp"
#include "Time/Tags/AdaptiveSteppingDiagnostics.hpp"
#include "Time/Tags/StepNumberWithinSlab.hpp"
#include "Time/Time.hpp"
#include "Time/TimeStepId.hpp"
#include "Time/TimeSteppers/TimeStepper.hpp"
Expand Down Expand Up @@ -54,6 +56,7 @@ namespace Actions {
/// DataBox changes:
/// - Tags::Next<Tags::TimeStepId>
/// - Tags::Next<Tags::TimeStep>
/// - Tags::StepNumberWithinSlab
/// - Tags::Time
/// - Tags::TimeStepId
/// - Tags::TimeStep
Expand All @@ -76,22 +79,25 @@ struct AdvanceTime {

db::mutate<Tags::TimeStepId, Tags::Next<Tags::TimeStepId>, Tags::TimeStep,
Tags::Time, Tags::Next<Tags::TimeStep>,
Tags::AdaptiveSteppingDiagnostics>(
Tags::StepNumberWithinSlab, Tags::AdaptiveSteppingDiagnostics>(
[](const gsl::not_null<TimeStepId*> time_id,
const gsl::not_null<TimeStepId*> next_time_id,
const gsl::not_null<TimeDelta*> time_step,
const gsl::not_null<double*> time,
const gsl::not_null<TimeDelta*> next_time_step,
const gsl::not_null<uint64_t*> step_number_within_slab,
const gsl::not_null<AdaptiveSteppingDiagnostics*> diags,
const TimeStepper& time_stepper, const bool using_error_control) {
const bool new_step = next_time_id->substep() == 0;
if (time_id->slab_number() != next_time_id->slab_number()) {
*step_number_within_slab = 0;
++diags->number_of_slabs;
// Put this here instead of unconditionally doing the next
// check because on the first call time_id doesn't have a
// valid slab so comparing the times will FPE.
++diags->number_of_steps;
} else if (new_step) {
++(*step_number_within_slab);
++diags->number_of_steps;
}

Expand Down
1 change: 1 addition & 0 deletions src/Time/Tags/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ spectre_target_headers(
IsUsingTimeSteppingErrorControl.hpp
MinimumTimeStep.hpp
StepChoosers.hpp
StepNumberWithinSlab.hpp
StepperErrorTolerances.hpp
StepperErrors.hpp
Time.hpp
Expand Down
17 changes: 17 additions & 0 deletions src/Time/Tags/StepNumberWithinSlab.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

#pragma once

#include <cstdint>

#include "DataStructures/DataBox/Tag.hpp"

namespace Tags {
/// \ingroup DataBoxTagsGroup
/// \ingroup TimeGroup
/// \brief Number of time step taken within a Slab
struct StepNumberWithinSlab : db::SimpleTag {
using type = uint64_t;
};
} // namespace Tags
2 changes: 2 additions & 0 deletions src/Time/Triggers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ spectre_target_sources(
OnSubsteps.cpp
SlabCompares.cpp
Slabs.cpp
StepsWithinSlab.cpp
TimeCompares.cpp
Times.cpp
)
Expand All @@ -20,6 +21,7 @@ spectre_target_headers(
OnSubsteps.hpp
SlabCompares.hpp
Slabs.hpp
StepsWithinSlab.hpp
TimeCompares.hpp
TimeTriggers.hpp
Times.hpp
Expand Down
8 changes: 8 additions & 0 deletions src/Time/Triggers/StepsWithinSlab.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

#include "Time/Triggers/StepsWithinSlab.hpp"

namespace Triggers {
PUP::able::PUP_ID StepsWithinSlab::my_PUP_ID = 0; // NOLINT
} // namespace Triggers
68 changes: 68 additions & 0 deletions src/Time/Triggers/StepsWithinSlab.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

#pragma once

#include <cstdint>
#include <memory>
#include <pup.h>
#include <pup_stl.h>
#include <utility>

#include "Options/ParseOptions.hpp"
#include "Options/String.hpp"
#include "ParallelAlgorithms/EventsAndTriggers/Trigger.hpp"
#include "Time/TimeSequence.hpp"
#include "Utilities/Serialization/CharmPupable.hpp"
#include "Utilities/TMPL.hpp"

/// \cond
namespace Tags {
struct StepNumberWithinSlab;
} // namespace Tags
/// \endcond

namespace Triggers {
/// \ingroup EventsAndTriggersGroup
/// \ingroup TimeGroup
/// Trigger at specified numbers of slabs after the simulation start.
class StepsWithinSlab : public Trigger {
public:
/// \cond
StepsWithinSlab() = default;
explicit StepsWithinSlab(CkMigrateMessage* /*unused*/) {}
using PUP::able::register_constructor;
WRAPPED_PUPable_decl_template(StepsWithinSlab); // NOLINT
/// \endcond

static constexpr Options::String help{
"Trigger at specified numbers of steps within each slab."};

explicit StepsWithinSlab(
std::unique_ptr<TimeSequence<uint64_t>> steps_within_slab)
: steps_within_slab_(std::move(steps_within_slab)) {}

using argument_tags = tmpl::list<Tags::StepNumberWithinSlab>;

bool operator()(const uint64_t step_within_slab) const {
return steps_within_slab_->times_near(step_within_slab)[1] ==
step_within_slab;
}

// NOLINTNEXTLINE(google-runtime-references)
void pup(PUP::er& p) override { p | steps_within_slab_; }

private:
std::unique_ptr<TimeSequence<uint64_t>> steps_within_slab_{};
};
} // namespace Triggers

template <>
struct Options::create_from_yaml<Triggers::StepsWithinSlab> {
template <typename Metavariables>
static Triggers::StepsWithinSlab create(const Option& options) {
return Triggers::StepsWithinSlab(
options.parse_as<std::unique_ptr<TimeSequence<uint64_t>>,
Metavariables>());
}
};
Loading
Loading