helics  3.5.2
InputInfo.hpp
1 /*
2 Copyright (c) 2017-2024,
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 
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  };
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};
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
Definition: GlobalFederateId.hpp:75
Definition: GlobalFederateId.hpp:147
Definition: InputInfo.hpp:20
std::vector< int32_t > priority_sources
the list of priority inputs;
Definition: InputInfo.hpp:84
bool addData(GlobalHandle source_id, Time valueTime, unsigned int iteration, std::shared_ptr< const SmallBuffer > data)
Definition: InputInfo.cpp:84
bool updateTimeNextIteration(Time newTime)
Definition: InputInfo.cpp:362
void disconnectFederate(GlobalFederateId fedToDisconnect, Time minTime)
Definition: InputInfo.cpp:189
std::vector< std::shared_ptr< const SmallBuffer > > current_data
the most recent published data
Definition: InputInfo.hpp:80
std::vector< GlobalHandle > input_sources
the sources of the input signals
Definition: InputInfo.hpp:81
const std::string units
the nominal type of data for the input
Definition: InputInfo.hpp:62
const GlobalHandle id
identifier for the handle
Definition: InputInfo.hpp:59
void removeSource(GlobalHandle sourceToRemove, Time minTime)
Definition: InputInfo.cpp:204
bool has_target
Definition: InputInfo.hpp:66
bool not_interruptible
indicator that this handle should not be used for interrupting
Definition: InputInfo.hpp:70
bool ignore_unit_mismatch
ignore unit mismatches
Definition: InputInfo.hpp:73
std::vector< Time > deactivated
indicator that the source has been deactivated
Definition: InputInfo.hpp:82
bool required
flag indicating that the subscription requires a matching publication
Definition: InputInfo.hpp:64
const std::string key
the identifier for the input
Definition: InputInfo.hpp:60
bool updateTimeInclusive(Time newTime)
Definition: InputInfo.cpp:404
bool addSource(GlobalHandle newSource, std::string_view sourceName, std::string_view stype, std::string_view sunits)
Definition: InputInfo.cpp:157
void clearFutureData()
Definition: InputInfo.cpp:239
std::vector< std::pair< helics::Time, unsigned int > > current_data_time
the most recent published data times
Definition: InputInfo.hpp:78
InputInfo(GlobalHandle handle, std::string_view key_, std::string_view type_, std::string_view units_)
Definition: InputInfo.hpp:52
int32_t required_connnections
Definition: InputInfo.hpp:74
bool strict_type_matching
indicator that the handle need to have strict type matching
Definition: InputInfo.hpp:72
const std::vector< std::shared_ptr< const SmallBuffer > > & getAllData() const
Definition: InputInfo.cpp:20
const std::shared_ptr< const SmallBuffer > & getData(int index) const
Definition: InputInfo.cpp:27
Time nextValueTime() const
Definition: InputInfo.cpp:456
bool updateTimeUpTo(Time newTime)
Definition: InputInfo.cpp:329
std::vector< sourceInformation > source_info
the name,type,units of the sources
Definition: InputInfo.hpp:83
const std::string & getSourceName(GlobalHandle source) const
Definition: InputInfo.cpp:272
bool only_update_on_change
flag indicating that the data should only be updated on change
Definition: InputInfo.hpp:68
bool optional
flag indicating that any targets are optional
Definition: InputInfo.hpp:65
Time minTimeGap
the minimum time between updates
Definition: InputInfo.hpp:76
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
Definition: InputInfo.hpp:23
Time time
the time of the data value
Definition: InputInfo.hpp:24
unsigned int iteration
the iteration number of the data value
Definition: InputInfo.hpp:25
std::shared_ptr< const SmallBuffer > data
the data value
Definition: InputInfo.hpp:26
Definition: InputInfo.hpp:41