25enum MultiInputHandlingMethod : uint16_t {
42 int referenceIndex{-1};
43 void* dataReference{
nullptr};
45 DataType targetType{DataType::HELICS_UNKNOWN};
47 DataType::HELICS_UNKNOWN};
48 bool changeDetectionEnabled{
false};
49 bool hasUpdate{
false};
50 bool disableAssign{
false};
51 bool useThreshold{
false};
52 bool multiUnits{
false};
53 MultiInputHandlingMethod inputVectorOp{
54 MultiInputHandlingMethod::NO_OP};
55 int32_t prevInputCount{0};
56 size_t customTypeHash{0U};
58 std::shared_ptr<units::precise_unit> outputUnits;
59 std::shared_ptr<units::precise_unit> inputUnits;
60 std::vector<std::pair<DataType, std::shared_ptr<units::precise_unit>>>
62 std::string givenTarget;
64 double threshold{0.0};
66 std::variant<std::function<void(
const double&, Time)>,
67 std::function<void(
const int64_t&, Time)>,
68 std::function<void(
const std::string&, Time)>,
69 std::function<void(
const std::complex<double>&, Time)>,
70 std::function<void(
const std::vector<double>&, Time)>,
71 std::function<void(
const std::vector<std::complex<double>>&, Time)>,
72 std::function<void(
const NamedPoint&, Time)>,
73 std::function<void(
const bool&, Time)>,
74 std::function<void(
const Time&, Time)>>
82 std::string_view actName,
83 std::string_view unitsOut = {});
87 std::string_view defaultType =
"def",
88 std::string_view units = {});
90 template<
class FedPtr>
91 Input(FedPtr& valueFed,
93 std::string_view defaultType =
"def",
94 std::string_view units = {}): Input(
std::addressof(*valueFed), key, defaultType, units)
97 std::is_base_of<ValueFederate, std::remove_reference_t<
decltype(*valueFed)>>::value,
98 "first argument must be a pointer to a ValueFederate");
101 Input(InterfaceVisibility locality,
102 ValueFederate* valueFed,
103 std::string_view key,
104 std::string_view defaultType =
"def",
105 std::string_view units = {});
107 template<
class FedPtr>
108 Input(InterfaceVisibility locality,
110 std::string_view key,
111 std::string_view defaultType =
"def",
112 std::string_view units = {}):
113 Input(locality,
std::addressof(*valueFed), key, defaultType, units)
116 std::is_base_of<ValueFederate, std::remove_reference_t<
decltype(*valueFed)>>::value,
117 "first argument must be a pointer to a ValueFederate");
120 Input(ValueFederate* valueFed,
121 std::string_view key,
123 std::string_view units = {}): Input(valueFed, key,
typeNameStringRef(defType), units)
127 template<
class FedPtr>
128 Input(FedPtr& valueFed, std::string_view key, DataType defType, std::string_view units = {}):
133 Input(InterfaceVisibility locality,
134 ValueFederate* valueFed,
135 std::string_view key,
136 std::string_view units = {}): Input(locality, valueFed, key,
"def", units)
140 template<
class FedPtr>
141 Input(InterfaceVisibility locality,
143 std::string_view key,
144 std::string_view units = {}): Input(locality, valueFed, key,
"def", units)
148 Input(InterfaceVisibility locality,
149 ValueFederate* valueFed,
150 std::string_view key,
152 std::string_view units = {}):
157 template<
class FedPtr>
158 Input(InterfaceVisibility locality,
160 std::string_view key,
162 std::string_view units = {}):
170 Time getLastUpdate()
const;
177 void registerNotificationCallback(std::function<
void(Time)> callback);
182 return ((injectionType == DataType::HELICS_UNKNOWN) ||
183 (injectionType == DataType::HELICS_CUSTOM)) ?
188 const std::string&
getType()
const {
return getExtractionType(); }
190 const std::string&
getUnits()
const {
return getExtractionUnits(); }
192 void addPublication(std::string_view target);
194 void addTarget(std::string_view target) { addPublication(target); }
200 bool checkUpdate(
bool assumeUpdate =
false);
214 bool isUpdated()
const;
216 virtual void setOption(int32_t option, int32_t value = 1)
override;
217 virtual int32_t getOption(int32_t option)
const override;
227 helicsType<X>() != DataType::HELICS_CUSTOM,
228 "callback type must be a primary helics type one of \"double, int64_t, named_point, bool, Time "
229 "std::vector<double>, std::vector<std::complex<double>>, std::complex<double>\"");
230 value_callback = std::move(callback);
236 void setDefault_impl(std::integral_constant<int, 0> , X&& val)
243 void setDefault_impl(std::integral_constant<int, 1> , X&& val)
245 lastValue = make_valid(std::forward<X>(val));
249 void setDefault_impl(std::integral_constant<int, 2> , X&& val)
251 auto res = ValueConverter<remove_cv_ref<X>>::convert(std::forward<X>(val));
252 lastValue = std::string(res.to_string());
253 setDefaultBytes(res);
257 void registerCallback();
276 changeDetectionEnabled =
true;
281 changeDetectionEnabled =
false;
291 void handleCallback(
Time time);
293 void getValue_impl(std::integral_constant<int, primaryType> , X& out);
296 void getValue_impl(std::integral_constant<int, primaryType> ,
char& out)
298 out = getValueChar();
302 void getValue_impl(std::integral_constant<int, convertibleType> ,
char& out)
304 out = getValueChar();
308 void getValue_impl(std::integral_constant<int, convertibleType> , X& out)
310 std::conditional_t<std::is_integral<X>::value,
311 std::conditional_t<std::is_same<X, char>::value, char, int64_t>,
314 getValue_impl(std::integral_constant<int, primaryType>(), gval);
315 out =
static_cast<X
>(gval);
319 void getValue_impl(std::integral_constant<int, nonConvertibleType> , X& out)
321 ValueConverter<X>::interpret(getBytes(), out);
325 X getValue_impl(std::integral_constant<int, primaryType> )
328 getValue_impl(std::integral_constant<int, primaryType>(), val);
333 X getValue_impl(std::integral_constant<int, convertibleType> )
335 std::conditional_t<std::is_integral<X>::value,
336 std::conditional_t<std::is_same<X, char>::value, char, int64_t>,
339 getValue_impl(std::integral_constant<int, primaryType>(), gval);
340 return static_cast<X
>(gval);
344 X getValue_impl(std::integral_constant<int, nonConvertibleType> )
346 return ValueConverter<X>::interpret(getBytes());
351 int getValue(
double* data,
int maxsize);
353 int getComplexValue(
double* data,
int maxsize);
355 int getValue(
char* str,
int maxsize);
373 const X& getValueRef();
375 double getDouble() {
return getValue_impl<double>(std::integral_constant<int, primaryType>()); }
377 const std::string&
getString() {
return getValueRef<std::string>(); }
382 size_t getByteCount();
384 size_t getStringSize();
386 size_t getVectorSize();
394 MultiInputHandlingMethod getMultiInputMode()
const {
return inputVectorOp; }
396 bool vectorDataProcess(
const std::vector<std::shared_ptr<const SmallBuffer>>& dataV);
398 const std::string& getTarget()
const
400 return (!givenTarget.empty()) ? givenTarget : getSourceTargets();
405 return (mName.empty()) ? getTarget() : getName();
410 void loadSourceInformation();
414 bool allowDirectFederateUpdate()
const
416 return hasUpdate && !changeDetectionEnabled &&
417 inputVectorOp == MultiInputHandlingMethod::NO_OP;
419 data_view checkAndGetFedUpdate();
420 void forceCoreDataUpdate();
421 friend class ValueFederateManager;
425HELICS_CXX_EXPORT
double
427 const std::shared_ptr<units::precise_unit>& inputUnits,
428 const std::shared_ptr<units::precise_unit>& outputUnits);
430HELICS_CXX_EXPORT
void
431 integerExtractAndConvert(
defV& store,
433 const std::shared_ptr<units::precise_unit>& inputUnits,
434 const std::shared_ptr<units::precise_unit>& outputUnits);
437void Input::getValue_impl(std::integral_constant<int, primaryType> , X& out)
439 auto dv = checkAndGetFedUpdate();
441 if (injectionType == DataType::HELICS_UNKNOWN) {
442 loadSourceInformation();
445 if (injectionType == helics::DataType::HELICS_DOUBLE) {
448 }
else if (injectionType == helics::DataType::HELICS_INT) {
450 integerExtractAndConvert(val, dv, inputUnits, outputUnits);
455 if (changeDetectionEnabled) {
471inline const X& getValueRefImpl(
defV& val)
473 valueConvert(val, helicsType<X>());
474 return std::get<X>(val);
478inline const std::string& getValueRefImpl(
defV& val)
481 if ((val.index() == named_point_loc)) {
482 return std::get<NamedPoint>(val).name;
484 valueConvert(val, DataType::HELICS_STRING);
485 return std::get<std::string>(val);
488HELICS_CXX_EXPORT
bool checkForNeededCoreRetrieval(std::size_t currentIndex,
493const X& Input::getValueRef()
495 static_assert(std::is_same<typeCategory<X>, std::integral_constant<int, primaryType>>::value,
496 "calling getValue By ref must be with a primary type");
497 auto dv = checkAndGetFedUpdate();
499 if (injectionType == DataType::HELICS_UNKNOWN) {
500 loadSourceInformation();
503 if (changeDetectionEnabled) {
505 if (injectionType == helics::DataType::HELICS_DOUBLE) {
508 }
else if (injectionType == helics::DataType::HELICS_INT) {
510 integerExtractAndConvert(val, dv, inputUnits, outputUnits);
522 if (checkForNeededCoreRetrieval(lastValue.index(),
525 forceCoreDataUpdate();
530 return getValueRefImpl<remove_cv_ref<X>>(lastValue);
naming a set of types that are interchangeable and recognizable inside the HELICS application API and...
Definition LocalFederateId.hpp:65
Definition application_api/Federate.hpp:880
Definition application_api/ValueFederate.hpp:28
Definition data_view.hpp:22
@ HELICS_MULTI_INPUT_OR_OPERATION
Definition helics_enums.h:333
@ HELICS_MULTI_INPUT_DIFF_OPERATION
Definition helics_enums.h:338
@ HELICS_MULTI_INPUT_NO_OP
Definition helics_enums.h:326
@ HELICS_MULTI_INPUT_MAX_OPERATION
Definition helics_enums.h:340
@ HELICS_MULTI_INPUT_AND_OPERATION
Definition helics_enums.h:330
@ HELICS_MULTI_INPUT_SUM_OPERATION
Definition helics_enums.h:335
@ HELICS_MULTI_INPUT_VECTORIZE_OPERATION
Definition helics_enums.h:328
@ HELICS_MULTI_INPUT_MIN_OPERATION
Definition helics_enums.h:342
@ HELICS_MULTI_INPUT_AVERAGE_OPERATION
Definition helics_enums.h:344
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition AsyncFedCallInfo.hpp:14
constexpr DataType helicsType()
Definition helicsTypes.hpp:378
DataType
Definition helicsTypes.hpp:273
constexpr double invalidDouble
defined constant for an invalid value as a double
Definition helicsTypes.hpp:499
const std::string & typeNameStringRef(DataType type)
Definition helicsTypes.cpp:64
void valueExtract(const defV &data, std::string &val)
Definition helicsPrimaryTypes.cpp:174
double doubleExtractAndConvert(const data_view &dv, const std::shared_ptr< units::precise_unit > &inputUnits, const std::shared_ptr< units::precise_unit > &outputUnits)
Definition Inputs.cpp:777
int64_t make_valid(bool obj)
Definition HelicsPrimaryTypes.hpp:68
bool changeDetected(const defV &prevValue, const std::string &val, double)
Definition helicsPrimaryTypes.cpp:20
std::conditional_t< helicsType< remove_cv_ref< X > >() !=DataType::HELICS_CUSTOM, std::integral_constant< int, primaryType >, std::conditional_t< isConvertableType< remove_cv_ref< X > >(), std::integral_constant< int, convertibleType >, std::integral_constant< int, nonConvertibleType > > > typeCategory
Definition helicsTypes.hpp:553
TimeRepresentation< count_time< 9 > > Time
Definition helicsTime.hpp:27
std::variant< double, int64_t, std::string, std::complex< double >, std::vector< double >, std::vector< std::complex< double > >, NamedPoint > defV
Definition HelicsPrimaryTypes.hpp:37