helics  3.3.0
InputInfo.hpp
1 /*
2 Copyright (c) 2017-2022,
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;
27 
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),
37  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_):
57  id(handle),
58  key(key_), type(type_), units(units_)
59  {
60  }
61 
62  const GlobalHandle id;
63  const std::string key;
64  const std::string type;
65  const std::string units;
66  bool required{false};
68  bool optional{false};
69  bool has_target{false};
70  bool only_update_on_change{false};
73  bool not_interruptible{false};
75  bool strict_type_matching{false};
76  bool ignore_unit_mismatch{false};
77  int32_t required_connnections{0};
81  std::vector<std::pair<helics::Time, unsigned int>> current_data_time;
83  std::vector<std::shared_ptr<const SmallBuffer>> current_data;
84  std::vector<GlobalHandle> input_sources;
85  std::vector<Time> deactivated;
86  std::vector<sourceInformation> source_info;
87  std::vector<int32_t> priority_sources;
88  private:
89  std::vector<std::vector<dataRecord>> data_queues;
90 
91  public:
93  const std::vector<std::shared_ptr<const SmallBuffer>>& getAllData() const;
95  const std::shared_ptr<const SmallBuffer>& getData(int index) const;
97  const std::shared_ptr<const SmallBuffer>& getData(uint32_t* inputIndex) const;
100  [[nodiscard]] bool addData(GlobalHandle source_id,
101  Time valueTime,
102  unsigned int iteration,
103  std::shared_ptr<const SmallBuffer> data);
104 
109  bool updateTimeUpTo(Time newTime);
114  bool updateTimeInclusive(Time newTime);
115 
120  bool updateTimeNextIteration(Time newTime);
122  Time nextValueTime() const;
126  bool addSource(GlobalHandle newSource,
127  std::string_view sourceName,
128  std::string_view stype,
129  std::string_view sunits);
131  void removeSource(GlobalHandle sourceToRemove, Time minTime);
133  void removeSource(std::string_view sourceName, Time minTime);
135  void clearFutureData();
136 
137  const std::string& getInjectionType() const;
138  const std::string& getInjectionUnits() const;
140  const std::string& getSourceName(GlobalHandle source) const;
141  const std::string& getTargets() const;
142 
143  void setProperty(int32_t option, int32_t value);
144  int32_t getProperty(int32_t option) const;
145 
146  private:
147  bool updateData(dataRecord&& update, int index);
148  mutable std::string inputUnits;
149  mutable std::string inputType;
150  mutable std::string sourceTargets;
151 };
152 
153 bool checkTypeMatch(std::string_view type1, std::string_view type2, bool strict_match);
154 
155 bool checkUnitMatch(const std::string& unit1, const std::string& unit2, bool strict_match);
156 } // namespace helics
helics::timeZero
constexpr Time timeZero
Definition: helicsTime.hpp:31
helics::InputInfo
Definition: InputInfo.hpp:20
helics::InputInfo::InputInfo
InputInfo(GlobalHandle handle, std::string_view key_, std::string_view type_, std::string_view units_)
Definition: InputInfo.hpp:53
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:81
helics::InputInfo::removeSource
void removeSource(GlobalHandle sourceToRemove, Time minTime)
Definition: InputInfo.cpp:177
helics::InputInfo::priority_sources
std::vector< int32_t > priority_sources
the list of priority inputs;
Definition: InputInfo.hpp:87
helics::InputInfo::strict_type_matching
bool strict_type_matching
indicator that the handle need to have strict type matching
Definition: InputInfo.hpp:75
helics::InputInfo::addSource
bool addSource(GlobalHandle newSource, std::string_view sourceName, std::string_view stype, std::string_view sunits)
Definition: InputInfo.cpp:154
helics::InputInfo::required
bool required
flag indicating that the subscription requires a matching publication
Definition: InputInfo.hpp:67
helics::InputInfo::dataRecord
Definition: InputInfo.hpp:23
helics::InputInfo::nextValueTime
Time nextValueTime() const
Definition: InputInfo.cpp:429
helics::InputInfo::id
const GlobalHandle id
identifier for the handle
Definition: InputInfo.hpp:62
helics_definitions.hpp
base helics enumerations for C++ API's, a namespace wrapper for the definitions defined in helics_enu...
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27
helics::InputInfo::dataRecord::data
std::shared_ptr< const SmallBuffer > data
the data value
Definition: InputInfo.hpp:26
helics::InputInfo::dataRecord::time
Time time
the time of the data value
Definition: InputInfo.hpp:24
helics::InputInfo::dataRecord::dataRecord
dataRecord()=default
helics::InputInfo::has_target
bool has_target
Definition: InputInfo.hpp:69
helics::InputInfo::ignore_unit_mismatch
bool ignore_unit_mismatch
ignore unit mismatches
Definition: InputInfo.hpp:76
helics::InputInfo::units
const std::string units
the nominal type of data for the input
Definition: InputInfo.hpp:65
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:71
helics::InputInfo::clearFutureData
void clearFutureData()
Definition: InputInfo.cpp:212
helics::InputInfo::updateTimeInclusive
bool updateTimeInclusive(Time newTime)
Definition: InputInfo.cpp:377
helics::InputInfo::required_connnections
int32_t required_connnections
Definition: InputInfo.hpp:77
helics::CONNECTIONS
@ CONNECTIONS
print summary+federate level connection information
Definition: logging.hpp:27
helics::InputInfo::minTimeGap
Time minTimeGap
the minimum time between updates
Definition: InputInfo.hpp:79
helics::InputInfo::input_sources
std::vector< GlobalHandle > input_sources
the sources of the input signals
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:84
helics::InputInfo::dataRecord::iteration
unsigned int iteration
the iteration number of the data value
Definition: InputInfo.hpp:25
helics::InputInfo::deactivated
std::vector< Time > deactivated
indicator that the source has been deactivated
Definition: InputInfo.hpp:85
helics::InputInfo::key
const std::string key
the identifier for the input
Definition: InputInfo.hpp:63
helics::InputInfo::getData
const std::shared_ptr< const SmallBuffer > & getData(int index) const
Definition: InputInfo.cpp:27
helics::InputInfo::updateTimeUpTo
bool updateTimeUpTo(Time newTime)
Definition: InputInfo.cpp:302
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::InputInfo::updateTimeNextIteration
bool updateTimeNextIteration(Time newTime)
Definition: InputInfo.cpp:335
helics::InputInfo::getSourceName
const std::string & getSourceName(GlobalHandle source) const
Definition: InputInfo.cpp:245
helics::GlobalHandle
Definition: GlobalFederateId.hpp:144
helics::InputInfo::sourceInformation
Definition: InputInfo.hpp:42
helics::InputInfo::optional
bool optional
flag indicating that any targets are optional
Definition: InputInfo.hpp:68
helics::InputInfo::not_interruptible
bool not_interruptible
indicator that this handle should not be used for interrupting
Definition: InputInfo.hpp:73
helics::InputInfo::current_data
std::vector< std::shared_ptr< const SmallBuffer > > current_data
the most recent published data
Definition: InputInfo.hpp:83
helics::InputInfo::getAllData
const std::vector< std::shared_ptr< const SmallBuffer > > & getAllData() const
Definition: InputInfo.cpp:20
helics::isValidIndex
bool isValidIndex(sizeType testSize, const SizedDataType &vec)
Definition: core-data.hpp:171
helics::InputInfo::source_info
std::vector< sourceInformation > source_info
the name,type,units of the sources
Definition: InputInfo.hpp:86