helics 3.7.0
Loading...
Searching...
No Matches
InputInfo.hpp
1/*
2Copyright (c) 2017-2026,
3Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Energy
4Innovation LLC. See the top-level NOTICE for additional details. All rights reserved.
5SPDX-License-Identifier: BSD-3-Clause
6*/
7#pragma once
8
9#include "basic_CoreTypes.hpp"
10
11#include <cstdint>
12#include <memory>
13#include <string>
14#include <string_view>
15#include <tuple>
16#include <utility>
17#include <vector>
18
19namespace helics {
21class InputInfo {
22 public:
24 struct dataRecord {
25 Time time{Time::minVal()};
26 unsigned int iteration{0};
27 std::shared_ptr<const SmallBuffer> data;
29 dataRecord() = default;
30 dataRecord(Time recordTime, std::shared_ptr<const SmallBuffer> recordData):
31 time(recordTime), data(std::move(recordData))
32 {
33 }
34 dataRecord(Time recordTime,
35 unsigned int recordIteration,
36 std::shared_ptr<const SmallBuffer> recordData):
37 time(recordTime), iteration(recordIteration), data(std::move(recordData))
38 {
39 }
40 };
41
43 std::string key;
44 std::string type;
45 std::string units;
46 sourceInformation() = default;
47 sourceInformation(std::string_view key_, std::string_view type_, std::string_view units_):
48 key(key_), type(type_), units(units_)
49 {
50 }
51 };
54 std::string_view key_,
55 std::string_view type_,
56 std::string_view units_): id(handle), key(key_), type(type_), units(units_)
57 {
58 }
59
61 const std::string key;
62 const std::string type;
63 const std::string units;
65 bool required{false};
66 bool optional{false};
67 bool has_target{false};
71 bool not_interruptible{false};
79 std::vector<std::pair<helics::Time, unsigned int>> current_data_time;
81 std::vector<std::shared_ptr<const SmallBuffer>> current_data;
82 std::vector<GlobalHandle> input_sources;
83 std::vector<Time> deactivated;
84 std::vector<sourceInformation> source_info;
85 std::vector<int32_t> priority_sources;
86 private:
87 std::vector<std::vector<dataRecord>> data_queues;
88 std::uint64_t queuedDataSizeBytes{0};
89
90 public:
92 const std::vector<std::shared_ptr<const SmallBuffer>>& getAllData() const;
94 const std::shared_ptr<const SmallBuffer>& getData(int index) const;
96 const std::shared_ptr<const SmallBuffer>& getData(uint32_t* inputIndex) const;
99 [[nodiscard]] bool addData(GlobalHandle source_id,
100 Time valueTime,
101 unsigned int iteration,
102 std::shared_ptr<const SmallBuffer> data);
103
108 bool updateTimeUpTo(Time newTime);
113 bool updateTimeInclusive(Time newTime);
114
119 bool updateTimeNextIteration(Time newTime);
121 Time nextValueTime() const;
125 bool addSource(GlobalHandle newSource,
126 std::string_view sourceName,
127 std::string_view stype,
128 std::string_view sunits);
130 void removeSource(GlobalHandle sourceToRemove, Time minTime);
132 void removeSource(std::string_view sourceName, Time minTime);
134 void disconnectFederate(GlobalFederateId fedToDisconnect, Time minTime);
136 void clearFutureData();
138 std::uint64_t queuedDataSize() const { return queuedDataSizeBytes; }
139
140 const std::string& getInjectionType() const;
141 const std::string& getInjectionUnits() const;
143 const std::string& getSourceName(GlobalHandle source) const;
144 const std::string& getTargets() const;
145
146 void setProperty(int32_t option, int32_t value);
147 int32_t getProperty(int32_t option) const;
148
149 private:
150 bool updateData(dataRecord&& update, int index);
151 mutable std::string inputUnits;
152 mutable std::string inputType;
153 mutable std::string sourceTargets;
154};
155
156bool checkTypeMatch(std::string_view type1, std::string_view type2, bool strict_match);
157
158bool checkUnitMatch(const std::string& unit1, const std::string& unit2, bool strict_match);
159} // namespace helics
Definition GlobalFederateId.hpp:75
Definition GlobalFederateId.hpp:147
Definition InputInfo.hpp:21
std::vector< int32_t > priority_sources
the list of priority inputs;
Definition InputInfo.hpp:85
bool addData(GlobalHandle source_id, Time valueTime, unsigned int iteration, std::shared_ptr< const SmallBuffer > data)
Definition InputInfo.cpp:108
bool updateTimeNextIteration(Time newTime)
Definition InputInfo.cpp:392
void disconnectFederate(GlobalFederateId fedToDisconnect, Time minTime)
Definition InputInfo.cpp:215
std::vector< std::shared_ptr< const SmallBuffer > > current_data
the most recent published data
Definition InputInfo.hpp:81
std::vector< GlobalHandle > input_sources
the sources of the input signals
Definition InputInfo.hpp:82
const std::string units
the nominal type of data for the input
Definition InputInfo.hpp:63
const GlobalHandle id
identifier for the handle
Definition InputInfo.hpp:60
std::uint64_t queuedDataSize() const
Definition InputInfo.hpp:138
void removeSource(GlobalHandle sourceToRemove, Time minTime)
Definition InputInfo.cpp:230
bool has_target
Definition InputInfo.hpp:67
bool not_interruptible
indicator that this handle should not be used for interrupting
Definition InputInfo.hpp:71
bool ignore_unit_mismatch
ignore unit mismatches
Definition InputInfo.hpp:74
std::vector< Time > deactivated
indicator that the source has been deactivated
Definition InputInfo.hpp:83
bool required
flag indicating that the subscription requires a matching publication
Definition InputInfo.hpp:65
const std::string key
the identifier for the input
Definition InputInfo.hpp:61
bool updateTimeInclusive(Time newTime)
Definition InputInfo.cpp:436
bool addSource(GlobalHandle newSource, std::string_view sourceName, std::string_view stype, std::string_view sunits)
Definition InputInfo.cpp:183
void clearFutureData()
Definition InputInfo.cpp:267
std::vector< std::pair< helics::Time, unsigned int > > current_data_time
the most recent published data times
Definition InputInfo.hpp:79
InputInfo(GlobalHandle handle, std::string_view key_, std::string_view type_, std::string_view units_)
Definition InputInfo.hpp:53
int32_t required_connnections
Definition InputInfo.hpp:75
bool strict_type_matching
indicator that the handle need to have strict type matching
Definition InputInfo.hpp:73
const std::vector< std::shared_ptr< const SmallBuffer > > & getAllData() const
Definition InputInfo.cpp:24
const std::shared_ptr< const SmallBuffer > & getData(int index) const
Definition InputInfo.cpp:31
Time nextValueTime() const
Definition InputInfo.cpp:490
bool updateTimeUpTo(Time newTime)
Definition InputInfo.cpp:357
std::vector< sourceInformation > source_info
the name,type,units of the sources
Definition InputInfo.hpp:84
const std::string & getSourceName(GlobalHandle source) const
Definition InputInfo.cpp:301
bool only_update_on_change
flag indicating that the data should only be updated on change
Definition InputInfo.hpp:69
bool optional
flag indicating that any targets are optional
Definition InputInfo.hpp:66
Time minTimeGap
the minimum time between updates
Definition InputInfo.hpp:77
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition AsyncFedCallInfo.hpp:14
constexpr Time timeZero
Definition helicsTime.hpp:31
TimeRepresentation< count_time< 9 > > Time
Definition helicsTime.hpp:27
STL namespace.
Definition InputInfo.hpp:24
Time time
the time of the data value
Definition InputInfo.hpp:25
unsigned int iteration
the iteration number of the data value
Definition InputInfo.hpp:26
std::shared_ptr< const SmallBuffer > data
the data value
Definition InputInfo.hpp:27
Definition InputInfo.hpp:42