Line data Source code
1 1 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : /// \file
5 : /// Defines class Slab
6 :
7 : #pragma once
8 :
9 : #include <cstddef>
10 : #include <functional>
11 : #include <iosfwd>
12 : #include <limits>
13 :
14 : class Time;
15 : class TimeDelta;
16 :
17 : namespace PUP {
18 : class er;
19 : } // namespace PUP
20 :
21 : /// \ingroup TimeGroup
22 : ///
23 : /// A chunk of time. Every element must reach slab boundaries
24 : /// exactly, no matter how it actually takes time steps to get there.
25 : /// The simulation can only be assumed to have global data available
26 : /// at slab boundaries.
27 1 : class Slab {
28 : public:
29 : /// Default constructor gives an invalid Slab.
30 1 : Slab() = default;
31 :
32 : /// Construct a slab running between two times (exactly).
33 1 : Slab(double start, double end);
34 :
35 : /// Construct a slab with a given start time and duration. The
36 : /// actual duration may differ by roundoff from the supplied value.
37 1 : static Slab with_duration_from_start(double start, double duration);
38 :
39 : /// Construct a slab with a given end time and duration. The
40 : /// actual duration may differ by roundoff from the supplied value.
41 1 : static Slab with_duration_to_end(double end, double duration);
42 :
43 0 : Time start() const;
44 0 : Time end() const;
45 0 : TimeDelta duration() const;
46 :
47 : /// Create a new slab immediately following this one with the same
48 : /// (up to roundoff) duration.
49 1 : Slab advance() const;
50 :
51 : /// Create a new slab immediately preceeding this one with the same
52 : /// (up to roundoff) duration.
53 1 : Slab retreat() const;
54 :
55 : /// Create a slab adjacent to this one in the direction indicated by
56 : /// the argument, as with advance() or retreat().
57 1 : Slab advance_towards(const TimeDelta& dt) const;
58 :
59 : /// Create a new slab with the same start time as this one with the
60 : /// given duration (up to roundoff).
61 1 : Slab with_duration_from_start(double duration) const;
62 :
63 : /// Create a new slab with the same end time as this one with the
64 : /// given duration (up to roundoff).
65 1 : Slab with_duration_to_end(double duration) const;
66 :
67 : /// Check if this slab is immediately followed by the other slab.
68 1 : bool is_followed_by(const Slab& other) const;
69 :
70 : /// Check if this slab is immediately preceeded by the other slab.
71 1 : bool is_preceeded_by(const Slab& other) const;
72 :
73 : /// Check if slabs overlap. Abutting slabs do not overlap.
74 1 : bool overlaps(const Slab& other) const;
75 :
76 : // NOLINTNEXTLINE(google-runtime-references)
77 0 : void pup(PUP::er& p);
78 :
79 : private:
80 0 : double start_ = std::numeric_limits<double>::signaling_NaN();
81 0 : double end_ = std::numeric_limits<double>::signaling_NaN();
82 :
83 0 : friend class Time;
84 0 : friend class TimeDelta;
85 :
86 0 : friend bool operator==(const Slab& a, const Slab& b);
87 1 : friend bool operator<(const Slab& a, const Slab& b);
88 0 : friend bool operator==(const Time& a, const Time& b);
89 : };
90 :
91 0 : bool operator!=(const Slab& a, const Slab& b);
92 :
93 : /// Slab comparison operators give the time ordering. Overlapping
94 : /// unequal slabs should not be compared (and will trigger an
95 : /// assertion).
96 : /// @{
97 : // NOLINTNEXTLINE(readability-redundant-declaration) redeclared for docs
98 1 : bool operator<(const Slab& a, const Slab& b);
99 1 : bool operator>(const Slab& a, const Slab& b);
100 1 : bool operator<=(const Slab& a, const Slab& b);
101 1 : bool operator>=(const Slab& a, const Slab& b);
102 : /// @}
103 :
104 0 : std::ostream& operator<<(std::ostream& os, const Slab& s);
105 :
106 0 : size_t hash_value(const Slab& s);
107 :
108 : namespace std {
109 : template <>
110 : struct hash<Slab> {
111 : size_t operator()(const Slab& s) const;
112 : };
113 : } // namespace std
114 :
115 : // Needs to be included so various return types are complete, but
116 : // cannot be included at the top because Time.hpp includes this file.
117 : #include "Time/Time.hpp" // NOLINT(misc-header-include-cycle)
|