TimeStepId.hpp
Go to the documentation of this file.
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 /// \file
5 /// Defines class TimeStepId.
6 
7 #pragma once
8 
9 #include <cstddef>
10 #include <cstdint>
11 #include <functional>
12 #include <iosfwd>
13 
14 #include "ErrorHandling/Assert.hpp"
15 #include "Time/Time.hpp"
16 
17 namespace PUP {
18 class er;
19 } // namespace PUP
20 
21 /// \ingroup TimeGroup
22 ///
23 /// A unique identifier for the temporal state of an integrated
24 /// system.
25 class TimeStepId {
26  public:
27  TimeStepId() = default;
28  /// Create a TimeStepId at the start of a step. If that step is at the
29  /// (evolution-defined) end of the slab the TimeStepId will be advanced
30  /// to the next slab.
31  TimeStepId(const bool time_runs_forward, const int64_t slab_number,
32  const Time& time) noexcept
33  : time_runs_forward_(time_runs_forward),
34  slab_number_(slab_number),
35  step_time_(time),
36  substep_(0),
37  substep_time_(time) {
38  canonicalize();
39  }
40  /// Create a TimeStepId at a substep at time `substep_time` in a step
41  /// starting at time `step_time`.
42  TimeStepId(const bool time_runs_forward, const int64_t slab_number,
43  const Time& step_time, const uint64_t substep,
44  const Time& substep_time) noexcept
45  : time_runs_forward_(time_runs_forward),
46  slab_number_(slab_number),
47  step_time_(step_time),
48  substep_(substep),
49  substep_time_(substep_time) {
50  ASSERT(substep_ != 0 or step_time_ == substep_time_,
51  "Initial substep must align with the step.");
52  canonicalize();
53  }
54 
55  bool time_runs_forward() const noexcept { return time_runs_forward_; }
56  int64_t slab_number() const noexcept { return slab_number_; }
57  /// Time at the start of the current step
58  const Time& step_time() const noexcept { return step_time_; }
59  uint64_t substep() const noexcept { return substep_; }
60  /// Time of the current substep
61  const Time& substep_time() const noexcept { return substep_time_; }
62 
63  bool is_at_slab_boundary() const noexcept {
64  return substep_ == 0 and substep_time_.is_at_slab_boundary();
65  }
66 
67  // clang-tidy: google-runtime-references
68  void pup(PUP::er& p) noexcept; // NOLINT
69 
70  private:
71  void canonicalize() noexcept;
72 
73  bool time_runs_forward_{false};
74  int64_t slab_number_{0};
75  Time step_time_{};
76  uint64_t substep_{0};
77  Time substep_time_{};
78 };
79 
80 bool operator==(const TimeStepId& a, const TimeStepId& b) noexcept;
81 bool operator!=(const TimeStepId& a, const TimeStepId& b) noexcept;
82 bool operator<(const TimeStepId& a, const TimeStepId& b) noexcept;
83 bool operator<=(const TimeStepId& a, const TimeStepId& b) noexcept;
84 bool operator>(const TimeStepId& a, const TimeStepId& b) noexcept;
85 bool operator>=(const TimeStepId& a, const TimeStepId& b) noexcept;
86 
87 std::ostream& operator<<(std::ostream& s, const TimeStepId& id) noexcept;
88 
89 size_t hash_value(const TimeStepId& id) noexcept;
90 
91 namespace std {
92 template <>
93 struct hash<TimeStepId> {
94  size_t operator()(const TimeStepId& id) const noexcept;
95 };
96 } // namespace std
Definition: Strahlkorper.hpp:14
TimeStepId(const bool time_runs_forward, const int64_t slab_number, const Time &step_time, const uint64_t substep, const Time &substep_time) noexcept
Create a TimeStepId at a substep at time substep_time in a step starting at time step_time.
Definition: TimeStepId.hpp:42
bool operator>(const Slab &a, const Slab &b) noexcept
Slab comparison operators give the time ordering. Overlapping unequal slabs should not be compared (a...
Definition: Slab.hpp:122
The time in a simulation. Times can be safely compared for exact equality as long as they do not belo...
Definition: Time.hpp:31
#define ASSERT(a, m)
Assert that an expression should be true.
Definition: Assert.hpp:51
bool operator<=(const Slab &a, const Slab &b) noexcept
Slab comparison operators give the time ordering. Overlapping unequal slabs should not be compared (a...
Definition: Slab.hpp:125
Defines Time and TimeDelta.
A unique identifier for the temporal state of an integrated system.
Definition: TimeStepId.hpp:25
const Time & substep_time() const noexcept
Time of the current substep.
Definition: TimeStepId.hpp:61
const Time & step_time() const noexcept
Time at the start of the current step.
Definition: TimeStepId.hpp:58
Defines macro ASSERT.
bool operator>=(const Slab &a, const Slab &b) noexcept
Slab comparison operators give the time ordering. Overlapping unequal slabs should not be compared (a...
Definition: Slab.hpp:128
bool operator<(const Slab &a, const Slab &b) noexcept
Slab comparison operators give the time ordering. Overlapping unequal slabs should not be compared (a...
Definition: Slab.hpp:117
TimeStepId(const bool time_runs_forward, const int64_t slab_number, const Time &time) noexcept
Create a TimeStepId at the start of a step. If that step is at the (evolution-defined) end of the sla...
Definition: TimeStepId.hpp:31