helics  2.8.1
InputInfo.hpp
1 /*
2 Copyright (c) 2017-2021,
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_core_types.hpp"
10 
11 #include <memory>
12 #include <string>
13 #include <tuple>
14 #include <utility>
15 #include <vector>
16 
17 namespace helics {
19 class InputInfo {
20  public:
22  struct dataRecord {
23  Time time{Time::minVal()};
24  unsigned int iteration{0};
25  std::shared_ptr<const data_block> data;
26 
27  dataRecord() = default;
28  dataRecord(Time recordTime, std::shared_ptr<const data_block> recordData):
29  time(recordTime), data(std::move(recordData))
30  {
31  }
32  dataRecord(Time recordTime,
33  unsigned int recordIteration,
34  std::shared_ptr<const data_block> recordData):
35  time(recordTime),
36  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(const std::string& key_,
47  const std::string& type_,
48  const std::string& units_):
49  key(key_),
50  type(type_), units(units_)
51  {
52  }
53  };
56  const std::string& key_,
57  const std::string& type_,
58  const std::string& units_):
59  id(handle),
60  key(key_), type(type_), units(units_)
61  {
62  }
63 
64  const global_handle id;
65  const std::string key;
66  const std::string type;
67  const std::string units;
68  bool required{
69  false};
70  bool optional{false};
71  bool has_target{false};
73  false};
75  false};
77  false};
78  bool ignore_unit_mismatch{false};
79  int32_t required_connnections{0};
80  std::vector<std::pair<helics::Time, unsigned int>>
82  std::vector<std::shared_ptr<const data_block>>
84  std::vector<global_handle> 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 data_block>>& getAllData() const;
95  const std::shared_ptr<const data_block>& getData(int index) const;
97  const std::shared_ptr<const data_block>& getData(uint32_t* inputIndex) const;
99  void addData(global_handle source_id,
100  Time valueTime,
101  unsigned int iteration,
102  std::shared_ptr<const data_block> 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(global_handle newSource,
126  const std::string& sourceName,
127  const std::string& stype,
128  const std::string& sunits);
130  void removeSource(global_handle sourceToRemove, Time minTime);
132  void removeSource(const std::string& sourceName, Time minTime);
134  void clearFutureData();
135 
136  const std::string& getInjectionType() const;
137  const std::string& getInjectionUnits() const;
139  const std::string& getSourceName(global_handle source) const;
140 
141  private:
142  bool updateData(dataRecord&& update, int index);
143  mutable std::string inputUnits;
144  mutable std::string inputType;
145 };
146 
147 bool checkTypeMatch(const std::string& type1, const std::string& type2, bool strict_match);
148 
149 bool checkUnitMatch(const std::string& unit1, const std::string& unit2, bool strict_match);
150 } // namespace helics
helics::InputInfo
Definition: InputInfo.hpp:19
data
@ data
print timing+data transmissions
Definition: loggingHelper.hpp:30
helics::InputInfo::current_data
std::vector< std::shared_ptr< const data_block > > current_data
the most recent published data
Definition: InputInfo.hpp:83
helics::InputInfo::getSourceName
const std::string & getSourceName(global_handle source) const
Definition: InputInfo.cpp:207
helics::InputInfo::InputInfo
InputInfo(global_handle handle, const std::string &key_, const std::string &type_, const std::string &units_)
Definition: InputInfo.hpp:55
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::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:76
helics::InputInfo::required
bool required
flag indicating that the subscription requires a matching publication
Definition: InputInfo.hpp:68
helics::InputInfo::dataRecord::data
std::shared_ptr< const data_block > data
the data value
Definition: InputInfo.hpp:25
helics::InputInfo::dataRecord
Definition: InputInfo.hpp:22
helics::InputInfo::nextValueTime
Time nextValueTime() const
Definition: InputInfo.cpp:374
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helics-time.hpp:27
helics::InputInfo::dataRecord::time
Time time
the time of the data value
Definition: InputInfo.hpp:23
helics::InputInfo::dataRecord::dataRecord
dataRecord()=default
helics::InputInfo::has_target
bool has_target
flag indicating that the input has a source
Definition: InputInfo.hpp:71
helics::InputInfo::ignore_unit_mismatch
bool ignore_unit_mismatch
ignore unit mismatches
Definition: InputInfo.hpp:78
helics::InputInfo::id
const global_handle id
identifier for the handle
Definition: InputInfo.hpp:64
helics::InputInfo::addData
void addData(global_handle source_id, Time valueTime, unsigned int iteration, std::shared_ptr< const data_block > data)
Definition: InputInfo.cpp:82
helics::InputInfo::units
const std::string units
the nominal type of data for the input
Definition: InputInfo.hpp:67
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:72
helics::InputInfo::clearFutureData
void clearFutureData()
Definition: InputInfo.cpp:172
helics::global_handle
Definition: global_federate_id.hpp:128
helics::InputInfo::removeSource
void removeSource(global_handle sourceToRemove, Time minTime)
Definition: InputInfo.cpp:137
helics::InputInfo::updateTimeInclusive
bool updateTimeInclusive(Time newTime)
Definition: InputInfo.cpp:322
helics::InputInfo::required_connnections
int32_t required_connnections
an exact number of connections required
Definition: InputInfo.hpp:79
helics::InputInfo::input_sources
std::vector< global_handle > input_sources
the sources of the input signals
Definition: InputInfo.hpp:84
helics::InputInfo::getData
const std::shared_ptr< const data_block > & getData(int index) const
Definition: InputInfo.cpp:25
helics::InputInfo::addSource
bool addSource(global_handle newSource, const std::string &sourceName, const std::string &stype, const std::string &sunits)
Definition: InputInfo.cpp:113
helics::InputInfo::dataRecord::iteration
unsigned int iteration
the iteration number of the data value
Definition: InputInfo.hpp:24
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:65
helics::InputInfo::updateTimeUpTo
bool updateTimeUpTo(Time newTime)
Definition: InputInfo.cpp:247
helics::InputInfo::getAllData
const std::vector< std::shared_ptr< const data_block > > & getAllData() const
Definition: InputInfo.cpp:18
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:280
helics::InputInfo::sourceInformation
Definition: InputInfo.hpp:41
helics::InputInfo::optional
bool optional
flag indicating that any targets are optional
Definition: InputInfo.hpp:70
helics::InputInfo::not_interruptible
bool not_interruptible
indicator that this handle should not be used for interrupting
Definition: InputInfo.hpp:74
helics::isValidIndex
bool isValidIndex(sizeType testSize, const SizedDataType &vec)
Definition: core-data.hpp:249
helics::InputInfo::source_info
std::vector< sourceInformation > source_info
the name,type,units of the sources
Definition: InputInfo.hpp:86