SST 16.0.0
Structural Simulation Toolkit
timeConverter.h
1// Copyright 2009-2026 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2026, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_TIMECONVERTER_H
13#define SST_CORE_TIMECONVERTER_H
14
15#include "sst/core/serialization/serialize_impl_fwd.h"
16#include "sst/core/sst_types.h"
17#include "sst/core/unitAlgebra.h"
18
19#include <string>
20
21namespace SST {
22
23class TimeLord;
24class SyncManager;
25
26/**
27 A class to convert between a component's view of time and the
28 core's view of time.
29*/
31{
32
33 friend class TimeLord;
34 friend class SyncManager;
37
38public:
39
40 /**
41 Do not directly invoke this constructor from Components to get
42 a TimeConverter. Instead, use the BaseComponent API functions and the constructor
43 that uses a TimeConverter* to create a TimeConverter.
44 */
46
47 /**
48 Create a TimeConverter for the time specified as a UnitAlgebra. The time must be in seconds, or it also supports
49 a unit of Hz, which will give you the time for the period of that frequency. You may also use an SI prefix as
50 part of the unit.
51
52 @param time Time to base the TimeConverter on
53 */
54 TimeConverter(const std::string& time); // Implemented in timeLord.cc
55
56 /**
57 Create a TimeConverter for the time specified as a UnitAlgebra. The time must be in seconds, or it also supports
58 a unit of Hz, which will give you the time for the period of that frequency.
59
60 @param time Time to base the TimeConverter on
61 */
62 TimeConverter(const UnitAlgebra& time); // Implemented in timeLord.cc
63
64 /**
65 Create a TimeConverter for the time specified as a UnitAlgebra. The time must be in seconds, or it also supports
66 a unit of Hz, which will give you the time for the period of that frequency. You may also use an SI prefix as
67 part of the unit.
68
69 @param time Time to base the TimeConverter on
70 */
71 TimeConverter(const char* time) :
72 TimeConverter(std::string(time))
73 {}
74
75 /**
76 Converts from the component's view to the core's view of time.
77 @param time time to convert to core time
78 */
79 SimTime_t convertToCoreTime(SimTime_t time) const { return time * factor; }
80
81 /**
82 Converts from the core's view to the components's view of time.
83 The result is truncated, not rounded.
84 @param time time to convert from core time
85 */
86 SimTime_t convertFromCoreTime(SimTime_t time) const { return time / factor; }
87
88 /**
89 * @return The factor used for conversions with Core Time
90 */
91 SimTime_t getFactor() const { return factor; }
92
93 /**
94 Resets a TimeConverter to uninitialized state (factor = 0)
95 */
96 void reset() { factor = 0; }
97
98 /**
99 @return The period represented by this TimeConverter as a UnitAlgebra
100 */
101 UnitAlgebra getPeriod() const; // Implemented in timeLord.cc
102
103 /**
104 * TimeConverter* returned by the core should *never* be deleted by
105 * Elements. This was moved to public due to needing to support ObjectMaps.
106 */
108
109 /**
110 Function to check to see if the TimeConverter is initialized
111 (non-zero factor)
112
113 @return true if TimeConverter is initialized (factor is
114 non-zero), false otherwise
115 */
116 bool isInitialized() const { return factor != 0; }
117
118 /**
119 Conversion to bool. This will allow !tc to work to check if it
120 has been initialized (has a non-zero factor).
121
122 @return true if TimeConverter is initialized (factor is
123 non-zero)
124 */
125 explicit operator bool() const { return factor != 0; }
126
127private:
128 /**
129 Factor for converting between core and component time
130 */
131 SimTime_t factor = 0;
132
133 explicit TimeConverter(SimTime_t fact) { factor = fact; }
134};
135
136template <>
138{
139 // Function implemented in timeLord.cc
140 void operator()(TimeConverter& s, serializer& ser, ser_opt_t options);
141
142 SST_FRIEND_SERIALIZE();
143};
144
145template <>
147{
148 // Function implemented in timeLord.cc
149 void operator()(TimeConverter*& s, serializer& ser, ser_opt_t options);
150
151 SST_FRIEND_SERIALIZE();
152};
153
154} // namespace SST
155
156#endif // SST_CORE_TIMECONVERTER_H
Base serialize class.
Definition serialize.h:132
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
Definition syncManager.h:192
A class to convert between a component's view of time and the core's view of time.
Definition timeConverter.h:31
bool isInitialized() const
Function to check to see if the TimeConverter is initialized (non-zero factor).
Definition timeConverter.h:116
~TimeConverter()
TimeConverter* returned by the core should never be deleted by Elements.
Definition timeConverter.h:107
TimeConverter()
Do not directly invoke this constructor from Components to get a TimeConverter.
Definition timeConverter.h:45
void reset()
Resets a TimeConverter to uninitialized state (factor = 0).
Definition timeConverter.h:96
UnitAlgebra getPeriod() const
Definition timeLord.cc:119
SimTime_t getFactor() const
Definition timeConverter.h:91
SimTime_t convertFromCoreTime(SimTime_t time) const
Converts from the core's view to the components's view of time.
Definition timeConverter.h:86
SimTime_t convertToCoreTime(SimTime_t time) const
Converts from the component's view to the core's view of time.
Definition timeConverter.h:79
TimeConverter(const char *time)
Create a TimeConverter for the time specified as a UnitAlgebra.
Definition timeConverter.h:71
Class for creating and managing TimeConverter objects.
Definition timeLord.h:41
Performs Unit math in full precision.
Definition unitAlgebra.h:107