TimeId.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 TimeId.
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 TimeId {
26  public:
27  TimeId() = default;
28  /// Create a TimeId at the start of a step. If that step is at the
29  /// (evolution-defined) end of the slab the TimeId will be advanced
30  /// to the next slab.
31  TimeId(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  time_(time) {
38  canonicalize();
39  }
40  /// Create a TimeId at a substep at time `time` in a step starting
41  /// at time `step_time`.
42  TimeId(const bool time_runs_forward, const int64_t slab_number,
43  const Time& step_time, const uint64_t substep,
44  const Time& time) noexcept
45  : time_runs_forward_(time_runs_forward),
46  slab_number_(slab_number),
47  step_time_(step_time),
48  substep_(substep),
49  time_(time) {
50  ASSERT(substep_ != 0 or step_time_ == 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& time() const noexcept { return time_; }
62 
63  bool is_at_slab_boundary() const noexcept {
64  return substep_ == 0 and 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 time_{};
78 };
79 
80 bool operator==(const TimeId& a, const TimeId& b) noexcept;
81 bool operator!=(const TimeId& a, const TimeId& b) noexcept;
82 bool operator<(const TimeId& a, const TimeId& b) noexcept;
83 bool operator<=(const TimeId& a, const TimeId& b) noexcept;
84 bool operator>(const TimeId& a, const TimeId& b) noexcept;
85 bool operator>=(const TimeId& a, const TimeId& b) noexcept;
86 
87 std::ostream& operator<<(std::ostream& s, const TimeId& id) noexcept;
88 
89 size_t hash_value(const TimeId& id) noexcept;
90 
91 namespace std {
92 template <>
93 struct hash<TimeId> {
94  size_t operator()(const TimeId& id) const noexcept;
95 };
96 } // namespace std
Definition: Strahlkorper.hpp:14
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
TimeId(const bool time_runs_forward, const int64_t slab_number, const Time &time) noexcept
Create a TimeId at the start of a step. If that step is at the (evolution-defined) end of the slab th...
Definition: TimeId.hpp:31
A unique identifier for the temporal state of an integrated system.
Definition: TimeId.hpp:25
const Time & time() const noexcept
Time of the current substep.
Definition: TimeId.hpp:61
#define ASSERT(a, m)
Assert that an expression should be true.
Definition: Assert.hpp:49
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.
TimeId(const bool time_runs_forward, const int64_t slab_number, const Time &step_time, const uint64_t substep, const Time &time) noexcept
Create a TimeId at a substep at time time in a step starting at time step_time.
Definition: TimeId.hpp:42
Defines macro ASSERT.
const Time & step_time() const noexcept
Time at the start of the current step.
Definition: TimeId.hpp:58
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