| helics 3.6.1

InputInfo.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 "basic_CoreTypes.hpp"
10
11 #include <memory>
12 #include <string>
13 #include <string_view>
14 #include <tuple>
15 #include <utility>
16 #include <vector>
17
18 namespace helics {
20 class InputInfo {
21 public:
23 struct dataRecord {
24 Time time{Time::minVal()};
25 unsigned int iteration{0};
26 std::shared_ptr<const SmallBuffer> data;
28 dataRecord() = default;
29 dataRecord(Time recordTime, std::shared_ptr<const SmallBuffer> recordData):
30 time(recordTime), data(std::move(recordData))
31 {
32 }
33 dataRecord(Time recordTime,
34 unsigned int recordIteration,
35 std::shared_ptr<const SmallBuffer> recordData):
36 time(recordTime), iteration(recordIteration), data(std::move(recordData))
37 {
38 }
39 };
40
41 struct sourceInformation {
42 std::string key;
43 std::string type;
44 std::string units;
45 sourceInformation() = default;
46 sourceInformation(std::string_view key_, std::string_view type_, std::string_view units_):
47 key(key_), type(type_), units(units_)
48 {
49 }
50 };
52 InputInfo(GlobalHandle handle,
53 std::string_view key_,
54 std::string_view type_,
55 std::string_view units_): id(handle), key(key_), type(type_), units(units_)
56 {
57 }
58
59 const GlobalHandle id;
60 const std::string key;
61 const std::string type;
62 const std::string units;
64 bool required{false};
65 bool optional{false};
66 bool has_target{false};
68 bool only_update_on_change{false};
70 bool not_interruptible{false};
72 bool strict_type_matching{false};
73 bool ignore_unit_mismatch{false};
74 int32_t required_connnections{0};
76 Time minTimeGap{timeZero};
78 std::vector<std::pair<helics::Time, unsigned int>> current_data_time;
80 std::vector<std::shared_ptr<const SmallBuffer>> current_data;
81 std::vector<GlobalHandle> input_sources;
82 std::vector<Time> deactivated;
83 std::vector<sourceInformation> source_info;
84 std::vector<int32_t> priority_sources;
85 private:
86 std::vector<std::vector<dataRecord>> data_queues;
87
88 public:
90 const std::vector<std::shared_ptr<const SmallBuffer>>& getAllData() const;
92 const std::shared_ptr<const SmallBuffer>& getData(int index) const;
94 const std::shared_ptr<const SmallBuffer>& getData(uint32_t* inputIndex) const;
97 [[nodiscard]] bool addData(GlobalHandle source_id,
98 Time valueTime,
99 unsigned int iteration,
100 std::shared_ptr<const SmallBuffer> data);
101
106 bool updateTimeUpTo(Time newTime);
111 bool updateTimeInclusive(Time newTime);
112
117 bool updateTimeNextIteration(Time newTime);
119 Time nextValueTime() const;
123 bool addSource(GlobalHandle newSource,
124 std::string_view sourceName,
125 std::string_view stype,
126 std::string_view sunits);
128 void removeSource(GlobalHandle sourceToRemove, Time minTime);
130 void removeSource(std::string_view sourceName, Time minTime);
132 void disconnectFederate(GlobalFederateId fedToDisconnect, Time minTime);
134 void clearFutureData();
135
136 const std::string& getInjectionType() const;
137 const std::string& getInjectionUnits() const;
139 const std::string& getSourceName(GlobalHandle source) const;
140 const std::string& getTargets() const;
141
142 void setProperty(int32_t option, int32_t value);
143 int32_t getProperty(int32_t option) const;
144
145 private:
146 bool updateData(dataRecord&& update, int index);
147 mutable std::string inputUnits;
148 mutable std::string inputType;
149 mutable std::string sourceTargets;
150 };
151
152 bool checkTypeMatch(std::string_view type1, std::string_view type2, bool strict_match);
153
154 bool checkUnitMatch(const std::string& unit1, const std::string& unit2, bool strict_match);
155 } // namespace helics
helics::GlobalFederateId
Definition: GlobalFederateId.hpp:75
helics::GlobalHandle
Definition: GlobalFederateId.hpp:147
helics::InputInfo
Definition: InputInfo.hpp:20
helics::InputInfo::priority_sources
std::vector< int32_t > priority_sources
the list of priority inputs;
Definition: InputInfo.hpp:84
helics::InputInfo::addData
bool addData(GlobalHandle source_id, Time valueTime, unsigned int iteration, std::shared_ptr< const SmallBuffer > data)
Definition: InputInfo.cpp:85
helics::InputInfo::updateTimeNextIteration
bool updateTimeNextIteration(Time newTime)
Definition: InputInfo.cpp:363
helics::InputInfo::disconnectFederate
void disconnectFederate(GlobalFederateId fedToDisconnect, Time minTime)
Definition: InputInfo.cpp:190
helics::InputInfo::current_data
std::vector< std::shared_ptr< const SmallBuffer > > current_data
the most recent published data
Definition: InputInfo.hpp:80
helics::InputInfo::input_sources
std::vector< GlobalHandle > input_sources
the sources of the input signals
Definition: InputInfo.hpp:81
helics::InputInfo::units
const std::string units
the nominal type of data for the input
Definition: InputInfo.hpp:62
helics::InputInfo::id
const GlobalHandle id
identifier for the handle
Definition: InputInfo.hpp:59
helics::InputInfo::removeSource
void removeSource(GlobalHandle sourceToRemove, Time minTime)
Definition: InputInfo.cpp:205
helics::InputInfo::has_target
bool has_target
Definition: InputInfo.hpp:66
helics::InputInfo::not_interruptible
bool not_interruptible
indicator that this handle should not be used for interrupting
Definition: InputInfo.hpp:70
helics::InputInfo::ignore_unit_mismatch
bool ignore_unit_mismatch
ignore unit mismatches
Definition: InputInfo.hpp:73
helics::InputInfo::deactivated
std::vector< Time > deactivated
indicator that the source has been deactivated
Definition: InputInfo.hpp:82
helics::InputInfo::required
bool required
flag indicating that the subscription requires a matching publication
Definition: InputInfo.hpp:64
helics::InputInfo::key
const std::string key
the identifier for the input
Definition: InputInfo.hpp:60
helics::InputInfo::updateTimeInclusive
bool updateTimeInclusive(Time newTime)
Definition: InputInfo.cpp:405
helics::InputInfo::addSource
bool addSource(GlobalHandle newSource, std::string_view sourceName, std::string_view stype, std::string_view sunits)
Definition: InputInfo.cpp:158
helics::InputInfo::clearFutureData
void clearFutureData()
Definition: InputInfo.cpp:240
helics::InputInfo::current_data_time
std::vector< std::pair< helics::Time, unsigned int > > current_data_time
the most recent published data times
Definition: InputInfo.hpp:78
helics::InputInfo::InputInfo
InputInfo(GlobalHandle handle, std::string_view key_, std::string_view type_, std::string_view units_)
Definition: InputInfo.hpp:52
helics::InputInfo::required_connnections
int32_t required_connnections
Definition: InputInfo.hpp:74
helics::InputInfo::strict_type_matching
bool strict_type_matching
indicator that the handle need to have strict type matching
Definition: InputInfo.hpp:72
helics::InputInfo::getAllData
const std::vector< std::shared_ptr< const SmallBuffer > > & getAllData() const
Definition: InputInfo.cpp:21
helics::InputInfo::getData
const std::shared_ptr< const SmallBuffer > & getData(int index) const
Definition: InputInfo.cpp:28
helics::InputInfo::nextValueTime
Time nextValueTime() const
Definition: InputInfo.cpp:457
helics::InputInfo::updateTimeUpTo
bool updateTimeUpTo(Time newTime)
Definition: InputInfo.cpp:330
helics::InputInfo::source_info
std::vector< sourceInformation > source_info
the name,type,units of the sources
Definition: InputInfo.hpp:83
helics::InputInfo::getSourceName
const std::string & getSourceName(GlobalHandle source) const
Definition: InputInfo.cpp:273
helics::InputInfo::only_update_on_change
bool only_update_on_change
flag indicating that the data should only be updated on change
Definition: InputInfo.hpp:68
helics::InputInfo::optional
bool optional
flag indicating that any targets are optional
Definition: InputInfo.hpp:65
helics::InputInfo::minTimeGap
Time minTimeGap
the minimum time between updates
Definition: InputInfo.hpp:76
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
helics::InputInfo::dataRecord
Definition: InputInfo.hpp:23
helics::InputInfo::dataRecord::time
Time time
the time of the data value
Definition: InputInfo.hpp:24
helics::InputInfo::dataRecord::iteration
unsigned int iteration
the iteration number of the data value
Definition: InputInfo.hpp:25
helics::InputInfo::dataRecord::data
std::shared_ptr< const SmallBuffer > data
the data value
Definition: InputInfo.hpp:26
helics::InputInfo::dataRecord::dataRecord
dataRecord()=default
helics::InputInfo::sourceInformation
Definition: InputInfo.hpp:41