| helics 3.6.1

Clone.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
8 #pragma once
9 #include "../application_api/Endpoints.hpp"
10 #include "../application_api/Publications.hpp"
11 #include "../application_api/Subscriptions.hpp"
12 #include "helicsApp.hpp"
13
14 #include <deque>
15 #include <map>
16 #include <memory>
17 #include <set>
18 #include <string>
19 #include <tuple>
20 #include <utility>
21 #include <vector>
22
23 namespace helics {
24 class CloningFilter;
25
26 namespace apps {
28 class HELICS_CXX_EXPORT Clone: public App {
29 public:
35 Clone(std::string_view appName, FederateInfo& fedInfo);
39 explicit Clone(std::vector<std::string> args);
41 Clone(int argc, char* argv[]);
42
49 Clone(std::string_view appName,
50 const std::shared_ptr<Core>& core,
51 const FederateInfo& fedInfo);
52
58 Clone(std::string_view appName, CoreApp& core, const FederateInfo& fedInfo);
59
64 Clone(std::string_view appName, const std::string& configString);
66 Clone(Clone&& other_recorder) = default;
68 Clone& operator=(Clone&& record) = default;
70 ~Clone();
72 virtual void runTo(Time runToTime) override;
74 void saveFile(const std::string& filename = std::string{});
76 auto pointCount() const { return points.size(); }
78 auto messageCount() const { return messages.size(); }
83 std::tuple<Time, std::string, std::string> getValue(int index) const;
88 std::unique_ptr<Message> getMessage(int index) const;
89
93 void setFederateToClone(std::string_view federateName);
96 void setOutputFile(std::string_view fileName) { outFileName = fileName; }
97
98 private:
100 void addSubscription(std::string_view key);
101
103 void addSourceEndpointClone(std::string_view sourceEndpoint);
104
105 virtual void initialize() override;
106 void generateInterfaces();
107 void captureForCurrentTime(Time currentTime, int iteration = 0);
109 std::shared_ptr<helicsCLI11App> buildArgParserApp();
110
112 void initialSetup();
114 void processArgs();
115
116 protected:
118 class ValueCapture {
119 public:
120 helics::Time time;
121 int index{-1};
122 int16_t iteration{0};
123 bool first{false};
124 std::string value;
125 ValueCapture() = default;
126 ValueCapture(helics::Time t1, int id1, std::string_view val):
127 time(t1), index(id1), value(val)
128 {
129 }
130 };
131
132 bool allow_iteration{false};
133 bool verbose{false};
134 bool fileSaved{false};
135 Time nextPrintTimeStep{
136 helics::timeZero};
137 std::unique_ptr<CloningFilter> cFilt;
138 std::vector<ValueCapture> points;
139 std::deque<Input> subscriptions;
140 std::vector<std::string>
141 cloneSubscriptionNames;
142 std::unique_ptr<Endpoint> cloneEndpoint;
143 std::vector<std::unique_ptr<Message>> messages;
144 std::map<helics::InterfaceHandle, int> subids;
145 std::map<std::string_view, int> subkeys;
146 std::map<helics::InterfaceHandle, int> eptids; // translate subscription id to index
147 std::map<std::string_view, int> eptNames;
148 std::string captureFederate;
149 std::string fedConfig;
150 std::vector<int> pubPointCount;
151 };
152
153 } // namespace apps
154 } // namespace helics
helics::FederateInfo
Definition: FederateInfo.hpp:28
helics::apps::App
Definition: helicsApp.hpp:32
helics::apps::Clone::ValueCapture
Definition: Clone.hpp:118
helics::apps::Clone
Definition: Clone.hpp:28
helics::apps::Clone::eptNames
std::map< std::string_view, int > eptNames
translate endpoint name to index
Definition: Clone.hpp:147
helics::apps::Clone::Clone
Clone(Clone &&other_recorder)=default
helics::apps::Clone::cloneEndpoint
std::unique_ptr< Endpoint > cloneEndpoint
the endpoint for cloned message delivery
Definition: Clone.hpp:142
helics::apps::Clone::pubPointCount
std::vector< int > pubPointCount
a vector containing the counts of each publication
Definition: Clone.hpp:150
helics::apps::Clone::points
std::vector< ValueCapture > points
lists of points that were captured
Definition: Clone.hpp:138
helics::apps::Clone::subscriptions
std::deque< Input > subscriptions
the actual subscription objects
Definition: Clone.hpp:139
helics::apps::Clone::messageCount
auto messageCount() const
Definition: Clone.hpp:78
helics::apps::Clone::captureFederate
std::string captureFederate
storage for the name of the federate to clone
Definition: Clone.hpp:148
helics::apps::Clone::cFilt
std::unique_ptr< CloningFilter > cFilt
a pointer to a clone filter
Definition: Clone.hpp:137
helics::apps::Clone::operator=
Clone & operator=(Clone &&record)=default
helics::apps::Clone::setOutputFile
void setOutputFile(std::string_view fileName)
Definition: Clone.hpp:96
helics::apps::Clone::fedConfig
std::string fedConfig
storage for the federateConfiguration
Definition: Clone.hpp:149
helics::apps::Clone::cloneSubscriptionNames
std::vector< std::string > cloneSubscriptionNames
string of the subscriptions of the cloned federate
Definition: Clone.hpp:141
helics::apps::Clone::messages
std::vector< std::unique_ptr< Message > > messages
list of messages
Definition: Clone.hpp:143
helics::apps::Clone::pointCount
auto pointCount() const
Definition: Clone.hpp:76
helics::apps::Clone::subids
std::map< helics::InterfaceHandle, int > subids
map of the subscription ids
Definition: Clone.hpp:144
helics::apps::Clone::subkeys
std::map< std::string_view, int > subkeys
translate subscription names to an index
Definition: Clone.hpp:145
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::timeZero
constexpr Time timeZero
Definition: helicsTime.hpp:31
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27