 |
helics
2.8.1
|
Go to the documentation of this file.
10 #include "helics/external/variant.hpp"
11 #include "helics/helics-config.h"
13 #include "helics_cxx_export.h"
28 using defV = mpark::variant<double,
33 std::vector<std::complex<double>>,
43 complex_vector_loc = 5,
47 HELICS_CXX_EXPORT
bool changeDetected(
const defV& prevValue,
const std::string& val,
double deltaV);
48 HELICS_CXX_EXPORT
bool changeDetected(
const defV& prevValue,
const char* val,
double deltaV);
49 HELICS_CXX_EXPORT
bool
52 const std::vector<std::complex<double>>& val,
54 HELICS_CXX_EXPORT
bool
56 HELICS_CXX_EXPORT
bool
58 HELICS_CXX_EXPORT
bool changeDetected(
const defV& prevValue,
double val,
double deltaV);
59 HELICS_CXX_EXPORT
bool changeDetected(
const defV& prevValue, int64_t val,
double deltaV);
61 HELICS_CXX_EXPORT
bool changeDetected(
const defV& prevValue,
const NamedPoint& val,
double deltaV);
67 return (obj) ? 1LL : 0LL;
73 return static_cast<int64_t
>(val);
77 return static_cast<int64_t
>(val);
81 return static_cast<int64_t
>(val);
85 return static_cast<int64_t
>(val);
89 return static_cast<int64_t
>(val);
93 return static_cast<int64_t
>(val);
97 return static_cast<int64_t
>(val);
101 return val.getBaseTimeCode();
106 return static_cast<double>(val);
109 inline std::complex<double>
make_valid(
const std::complex<float>& val)
111 return {val.real(), val.imag()};
118 return std::forward<X>(obj);
124 HELICS_CXX_EXPORT
void valueExtract(
const defV& dv, std::complex<double>& val);
127 HELICS_CXX_EXPORT
void valueExtract(
const defV& dv, std::vector<double>& val);
130 HELICS_CXX_EXPORT
void valueExtract(
const defV& dv, std::vector<std::complex<double>>& val);
144 HELICS_CXX_EXPORT
defV readJsonValue(
const data_view& dv);
148 HELICS_CXX_EXPORT
void
151 HELICS_CXX_EXPORT
void
154 HELICS_CXX_EXPORT
void
165 HELICS_CXX_EXPORT
void valueExtract3(
const data_view& dv,
data_type baseType,
defV& val);
169 std::enable_if_t<std::is_arithmetic<X>::value && (!std::is_same<X, char>::value)>
172 switch (dv.index()) {
174 val =
static_cast<X
>(mpark::get<double>(dv));
177 val =
static_cast<X
>(mpark::get<int64_t>(dv));
184 val =
static_cast<X
>(std::abs(mpark::get<std::complex<double>>(dv)));
188 const auto& vec = mpark::get<std::vector<double>>(dv);
192 case complex_vector_loc:
194 const auto& vec = mpark::get<std::vector<std::complex<double>>>(dv);
198 case named_point_loc: {
199 const auto& np = mpark::get<NamedPoint>(dv);
200 if (std::isnan(np.value)) {
203 val =
static_cast<X
>(np.value);
212 std::enable_if_t<std::is_arithmetic<X>::value>
215 constexpr
size_t byte_order_check_size = 1;
217 case data_type::helics_any: {
218 if (dv.
size() ==
sizeof(
double) + byte_order_check_size) {
220 if (std::isnormal(V)) {
221 val =
static_cast<X
>(V);
224 val =
static_cast<X
>(Vint);
226 }
else if (dv.
size() == 2 *
sizeof(double) + byte_order_check_size) {
228 val =
static_cast<X
>(std::abs(V));
229 }
else if (dv.
size() ==
sizeof(int) + byte_order_check_size) {
231 if (std::isnormal(V)) {
232 val =
static_cast<X
>(V);
235 val =
static_cast<X
>(Vint);
237 }
else if (dv.
size() ==
sizeof(char)) {
238 val =
static_cast<X
>((dv[0] ==
'0') ? 0 : 1);
241 val =
static_cast<X
>(std::stod(dv.
string()));
243 catch (
const std::invalid_argument&) {
250 case data_type::helics_string:
254 case data_type::helics_bool:
255 val =
static_cast<X
>((dv.
string() !=
"0"));
257 case data_type::helics_named_point: {
259 if (std::isnan(npval.value)) {
263 catch (
const std::invalid_argument&) {
264 val =
static_cast<X
>(
266 std::conditional_t<std::is_integral<X>::value, int64_t,
double>>());
269 val =
static_cast<X
>(npval.value);
274 case data_type::helics_double: {
276 val =
static_cast<X
>(V);
279 case data_type::helics_int:
280 case data_type::helics_time: {
282 val =
static_cast<X
>(V);
286 case data_type::helics_vector: {
291 case data_type::helics_complex: {
293 val =
static_cast<X
>(std::abs(V));
296 case data_type::helics_complex_vector: {
301 case data_type::helics_json:
304 case data_type::helics_custom:
305 throw(std::invalid_argument(
"unrecognized helics type"));
309 HELICS_CXX_EXPORT
void valueConvert(
defV& val,
data_type newType);
constexpr Time timeZero
Definition: helics-time.hpp:31
void helicsBrokerSetTimeBarrier(helics_broker broker, helics_time barrierTime, helics_error *err)
Definition: helicsExport.cpp:529
size_t cleanUpBrokers()
Definition: BrokerFactory.cpp:266
helics_broker helicsCreateBrokerFromArgs(const char *type, const char *name, int argc, const char *const *argv, helics_error *err)
Definition: helicsExport.cpp:412
std::string name
the text value for the named point
Definition: helicsTypes.hpp:113
Definition: helicsTypes.hpp:111
core_type
Definition: core-types.hpp:37
static X interpret(const data_view &block)
Definition: ValueConverter_impl.hpp:317
Definition: core-exceptions.hpp:39
@ helics_error_invalid_object
Definition: helics_enums.h:206
Definition: core-exceptions.hpp:94
helics_core helicsCreateCoreFromArgs(const char *type, const char *name, int argc, const char *const *argv, helics_error *err)
Definition: helicsExport.cpp:301
void helicsCoreMakeConnections(helics_core core, const char *file, helics_error *err)
Definition: helicsExport.cpp:631
int64_t make_valid(bool obj)
Definition: HelicsPrimaryTypes.hpp:65
std::string helicsComplexVectorString(const std::vector< std::complex< double >> &val)
Definition: helicsTypes.cpp:282
X invalidValue()
Definition: helicsTypes.hpp:485
helics_bool helicsCoreConnect(helics_core core, helics_error *err)
Definition: helicsExport.cpp:728
Definition: ValueConverter.hpp:26
void helicsCoreSetLogFile(helics_core core, const char *logFileName, helics_error *err)
Definition: helicsExport.cpp:667
helics_bool helicsIsCoreTypeAvailable(const char *type)
Definition: helicsExport.cpp:107
void helicsCloseLibrary(void)
Definition: helicsExport.cpp:866
double value
the data value for the named point
Definition: helicsTypes.hpp:114
void helicsBrokerGlobalError(helics_broker broker, int errorCode, const char *errorString, helics_error *err)
Definition: helicsExport.cpp:547
std::vector< double > helicsGetVector(const std::string &val)
Definition: helicsTypes.cpp:334
TimeRepresentation< count_time< 9 > > Time
Definition: helics-time.hpp:27
double helics_time
Definition: api-data.h:81
void * helics_core
Definition: api-data.h:46
std::shared_ptr< Core > FindOrCreate(core_type type, const std::string &coreName, std::vector< std::string > args)
Definition: CoreFactory.cpp:180
Common functions for the HELICS C api.
helics_core helicsCreateCore(const char *type, const char *name, const char *initString, helics_error *err)
Definition: helicsExport.cpp:266
helics_federate helicsFederateClone(helics_federate fed, helics_error *err)
Definition: FederateExport.cpp:519
helics_bool helicsCoreWaitForDisconnect(helics_core core, int msToWait, helics_error *err)
Definition: helicsExport.cpp:773
void helicsBrokerMakeConnections(helics_broker broker, const char *file, helics_error *err)
Definition: helicsExport.cpp:591
const helics_bool helics_false
Definition: api-data.h:95
void helicsBrokerDisconnect(helics_broker broker, helics_error *err)
Definition: helicsExport.cpp:783
Definition: data_view.hpp:22
const helics_bool helics_true
Definition: api-data.h:94
static X interpret(const data_view &block)
Definition: ValueConverter.hpp:101
helics_bool helicsCoreIsValid(helics_core core)
Definition: helicsExport.cpp:351
constexpr auto versionString
Definition: helicsVersion.hpp:16
helics_bool helicsBrokerIsValid(helics_broker broker)
Definition: helicsExport.cpp:459
@ helics_error_system_failure
Definition: helics_enums.h:201
NamedPoint helicsGetNamedPoint(const std::string &val)
Definition: helicsTypes.cpp:348
Definition: core-exceptions.hpp:76
const char * helicsBrokerGetIdentifier(helics_broker broker)
Definition: helicsExport.cpp:676
void helicsCoreDisconnect(helics_core core, helics_error *err)
Definition: helicsExport.cpp:746
double vectorNorm(const std::vector< double > &vec)
Definition: helicsTypes.cpp:66
const char * helicsCoreGetAddress(helics_core core)
Definition: helicsExport.cpp:708
void helicsBrokerAddSourceFilterToEndpoint(helics_broker broker, const char *filter, const char *endpoint, helics_error *err)
Definition: helicsExport.cpp:565
@ helics_error_user_abort
Definition: helics_enums.h:192
void helicsBrokerSetGlobal(helics_broker broker, const char *valueName, const char *value, helics_error *err)
Definition: helicsExport.cpp:507
Definition: core-exceptions.hpp:67
@ helics_error_registration_failure
Definition: helics_enums.h:208
Definition: core-exceptions.hpp:48
@ DEFAULT
ZMQ if available or UDP.
Definition: core/Core.hpp:42
helics_error helicsErrorInitialize(void)
Definition: helicsExport.cpp:47
Definition: core-exceptions.hpp:85
bool changeDetected(const defV &prevValue, const std::string &val, double)
Definition: helicsPrimaryTypes.cpp:16
@ helics_error_invalid_argument
Definition: helics_enums.h:204
helics_bool helicsCoreIsConnected(helics_core core)
Definition: helicsExport.cpp:645
bool helicsBoolValue(const std::string &val)
Definition: helicsTypes.cpp:528
void helicsCoreSetGlobal(helics_core core, const char *valueName, const char *value, helics_error *err)
Definition: helicsExport.cpp:654
const char * helicsGetCompilerVersion(void)
Definition: helicsExport.cpp:38
void helicsBrokerFree(helics_broker broker)
Definition: helicsExport.cpp:827
std::string string() const
Definition: data_view.hpp:113
const char * helicsGetVersion(void)
Definition: helicsExport.cpp:28
void helicsCoreGlobalError(helics_core core, int errorCode, const char *errorString, helics_error *err)
Definition: helicsExport.cpp:556
const char * helicsCoreGetIdentifier(helics_core core)
Definition: helicsExport.cpp:686
void helicsFederateDestroy(helics_federate fed)
Definition: helicsExport.cpp:799
void helicsLoadSignalHandler()
Definition: helicsExport.cpp:74
void helicsBrokerAddDestinationFilterToEndpoint(helics_broker broker, const char *filter, const char *endpoint, helics_error *err)
Definition: helicsExport.cpp:578
std::string helicsVectorString(const std::vector< double > &val)
Definition: helicsTypes.cpp:244
Json::Value loadJsonStr(const std::string &jsonString)
Definition: JsonProcessingFunctions.cpp:50
Definition: api_objects.h:42
constexpr auto compiler
Definition: helicsVersion.hpp:33
@ fed
special logging command for message coming from a fed
Definition: loggingHelper.hpp:32
const char * helicsGetBuildFlags(void)
Definition: helicsExport.cpp:33
void helicsFederateFree(helics_federate fed)
Definition: helicsExport.cpp:837
void helicsCoreAddDestinationFilterToEndpoint(helics_core core, const char *filter, const char *endpoint, helics_error *err)
Definition: helicsExport.cpp:618
void helicsClearSignalHandler()
Definition: helicsExport.cpp:79
@ helics_error_other
Definition: helics_enums.h:190
mpark::variant< double, int64_t, std::string, std::complex< double >, std::vector< double >, std::vector< std::complex< double > >, NamedPoint > defV
Definition: HelicsPrimaryTypes.hpp:34
void helicsBrokerSetLogFile(helics_broker broker, const char *logFileName, helics_error *err)
Definition: helicsExport.cpp:520
helics_federate helicsGetFederateByName(const char *fedName, helics_error *err)
Definition: helicsExport.cpp:360
void helicsFederateFinalize(helics_federate fed, helics_error *err)
Definition: FederateExport.cpp:605
helics_bool helicsBrokerIsConnected(helics_broker broker)
Definition: helicsExport.cpp:468
Definition: api_objects.h:52
std::vector< std::complex< double > > helicsGetComplexVector(const std::string &val)
Definition: helicsTypes.cpp:341
void helicsAbort(int errorCode, const char *errorString)
Definition: helicsExport.cpp:877
std::string helicsComplexString(double real, double imag)
Definition: helicsTypes.cpp:79
Definition: api-data.h:166
naming a set of types that are interchangeable and recognizable inside the HELICS application API and...
void helicsCoreDataLink(helics_core core, const char *source, const char *target, helics_error *err)
Definition: helicsExport.cpp:492
type_location
Definition: HelicsPrimaryTypes.hpp:37
std::shared_ptr< Broker > create(core_type type, const std::string &configureString)
Definition: BrokerFactory.cpp:100
void helicsCoreDestroy(helics_core core)
Definition: helicsExport.cpp:811
FedObject * getFedObject(helics_federate fed, helics_error *err) noexcept
Definition: FederateExport.cpp:27
@ helics_error_connection_failure
Definition: helics_enums.h:207
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
CoreObject * getCoreObject(helics_core core, helics_error *err) noexcept
Definition: helicsExport.cpp:204
void helicsBrokerClearTimeBarrier(helics_broker broker)
Definition: helicsExport.cpp:538
data_type
Definition: helicsTypes.hpp:275
const char * helicsBrokerGetAddress(helics_broker broker)
Definition: helicsExport.cpp:697
constexpr local_federate_id local_core_id(-259)
size_t size() const noexcept
Definition: data_view.hpp:107
constexpr auto buildFlags
Definition: helicsVersion.hpp:30
double getDoubleFromString(const std::string &val)
Definition: helicsTypes.cpp:416
size_t cleanUpCores()
Definition: CoreFactory.cpp:313
void helicsErrorClear(helics_error *err)
Definition: helicsExport.cpp:56
void helicsLoadSignalHandlerCallback(helics_bool(*handler)(int))
Definition: helicsExport.cpp:97
int32_t error_code
Definition: api-data.h:167
void valueExtract(const defV &dv, std::string &val)
Definition: helicsPrimaryTypes.cpp:174
std::complex< double > getComplexFromString(const std::string &val)
Definition: helicsTypes.cpp:398
data_type getTypeFromString(const std::string &typeName)
Definition: helicsTypes.cpp:187
helics_broker helicsBrokerClone(helics_broker broker, helics_error *err)
Definition: helicsExport.cpp:445
helics_core helicsCoreClone(helics_core core, helics_error *err)
Definition: helicsExport.cpp:336
void helicsCoreFree(helics_core core)
Definition: helicsExport.cpp:817
void * helics_broker
Definition: api-data.h:51
void helicsBrokerDataLink(helics_broker broker, const char *source, const char *target, helics_error *err)
Definition: helicsExport.cpp:479
const char * message
Definition: api-data.h:168
void helicsBrokerDestroy(helics_broker broker)
Definition: helicsExport.cpp:805
Definition: core/Broker.hpp:18
@ helics_error_external_type
Definition: helics_enums.h:189
void helicsCoreAddSourceFilterToEndpoint(helics_core core, const char *filter, const char *endpoint, helics_error *err)
Definition: helicsExport.cpp:605
std::string helicsNamedPointString(const NamedPoint &point)
Definition: helicsTypes.cpp:300
BrokerObject * getBrokerObject(helics_broker broker, helics_error *err) noexcept
Definition: helicsExport.cpp:221
int helics_bool
Definition: api-data.h:92
helics_broker helicsCreateBroker(const char *type, const char *name, const char *initString, helics_error *err)
Definition: helicsExport.cpp:384
@ ip
using both types of ports (tcp/or udp) for communication
Definition: core-exceptions.hpp:18
std::complex< double > helicsGetComplex(const std::string &val)
Definition: helicsTypes.cpp:207
helics_bool helicsBrokerWaitForDisconnect(helics_broker broker, int msToWait, helics_error *err)
Definition: helicsExport.cpp:763
@ helics_error_invalid_function_call
Definition: helics_enums.h:196
void * helics_federate
Definition: api-data.h:56
void helicsCoreSetReadyToInit(helics_core core, helics_error *err)
Definition: helicsExport.cpp:719