| helics 3.6.1

GlobalTimeCoordinator.hpp
1 /*
2 Copyright (c) 2017-2025,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 #pragma once
8
9 #include "ActionMessage.hpp"
10 #include "BaseTimeCoordinator.hpp"
11 #include "CoreFederateInfo.hpp"
12 #include "TimeDependencies.hpp"
13
14 #include <atomic>
15 #include <functional>
16 #include <nlohmann/json_fwd.hpp>
17 #include <string>
18 #include <utility>
19 #include <vector>
20
21 namespace helics {
22
25 class GlobalTimeCoordinator: public BaseTimeCoordinator {
26 private:
27 // the variables for time coordination
28 Time currentMinTime{Time::minVal()};
29 TimeState currentTimeState{TimeState::initialized};
30 Time nextEvent{Time::maxVal()};
31 static constexpr std::int32_t mSequenceIncrement{100};
32
33 protected:
34 bool iterating{false};
35 bool mNewRequest{
36 true};
37 public:
38 GlobalTimeCoordinator() = default;
39
43 virtual bool updateTimeFactors() override;
44
45 private:
46 void transmitTimingMessagesUpstream(ActionMessage& msg) const;
47 void transmitTimingMessagesDownstream(ActionMessage& msg,
48 GlobalFederateId skipFed = GlobalFederateId{}) const;
49
50 void sendTimeUpdateRequest(Time triggerTime);
51
52 public:
53 virtual TimeProcessingResult processTimeMessage(const ActionMessage& cmd) override;
54 virtual MessageProcessingResult
55 checkExecEntry(GlobalFederateId triggerFed = GlobalFederateId{}) override;
56
57 virtual std::string printTimeStatus() const override;
58 virtual void generateDebuggingTimeInfo(nlohmann::json& base) const override;
59
60 virtual Time getNextTime() const override { return currentMinTime; }
61 };
62 } // namespace helics
helics::ActionMessage
Definition: ActionMessage.hpp:30
helics::BaseTimeCoordinator
Definition: BaseTimeCoordinator.hpp:25
helics::GlobalFederateId
Definition: GlobalFederateId.hpp:75
helics::GlobalTimeCoordinator
Definition: GlobalTimeCoordinator.hpp:25
helics::GlobalTimeCoordinator::getNextTime
virtual Time getNextTime() const override
Definition: GlobalTimeCoordinator.hpp:60
helics::GlobalTimeCoordinator::processTimeMessage
virtual TimeProcessingResult processTimeMessage(const ActionMessage &cmd) override
Definition: GlobalTimeCoordinator.cpp:157
helics::GlobalTimeCoordinator::checkExecEntry
virtual MessageProcessingResult checkExecEntry(GlobalFederateId triggerFed=GlobalFederateId{}) override
Definition: GlobalTimeCoordinator.cpp:183
helics::GlobalTimeCoordinator::iterating
bool iterating
flag indicating that the min dependency is iterating
Definition: GlobalTimeCoordinator.hpp:34
helics::GlobalTimeCoordinator::printTimeStatus
virtual std::string printTimeStatus() const override
Definition: GlobalTimeCoordinator.cpp:176
helics::GlobalTimeCoordinator::generateDebuggingTimeInfo
virtual void generateDebuggingTimeInfo(nlohmann::json &base) const override
Definition: GlobalTimeCoordinator.cpp:166
helics::GlobalTimeCoordinator::updateTimeFactors
virtual bool updateTimeFactors() override
Definition: GlobalTimeCoordinator.cpp:76
helics::GlobalTimeCoordinator::mNewRequest
bool mNewRequest
flag indicating a new request has been received since the last sequence Update
Definition: GlobalTimeCoordinator.hpp:35
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::MessageProcessingResult
MessageProcessingResult
Definition: CoreTypes.hpp:75
helics::TimeProcessingResult
TimeProcessingResult
Definition: TimeDependencies.hpp:42
helics::TimeState
TimeState
Definition: TimeDependencies.hpp:20
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27