Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# setTimedelta routine is a multiplier for the default timedelta.
# Set one second message interval #
h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_delta, deltat)
h.helicsFederateInfoSetIntegerProperty(fedinfo, h.helics_property_int_log_level, 1)
mFed = h.helicsCreateMessageFederate("TestA Federate", fedinfo)
yield mFed
h.helicsFederateFinalize(mFed)
state = h.helicsFederateGetState(mFed)
assert state == 3
while (h.helicsBrokerIsConnected(broker)):
time.sleep(1)
h.helicsFederateInfoFree(fedinfo)
h.helicsFederateFree(mFed)
h.helicsCloseLibrary()
def mFed():
initstring = "-f 1 --name=mainbroker"
fedinitstring = "--broker=mainbroker --federates=1"
deltat = 0.01
h.helicsGetVersion()
# Create broker #
broker = h.helicsCreateBroker("zmq", "", initstring)
isconnected = h.helicsBrokerIsConnected(broker)
if isconnected == 1:
pass
# Create Federate Info object that describes the federate properties #
fedinfo = h.helicsCreateFederateInfo()
# Set Federate name #
h.helicsFederateInfoSetCoreName(fedinfo, "CoreA Federate")
# Set core type from string #
h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")
# Federate init string #
h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)
def vFed():
initstring = "-f 1 --name=mainbroker"
fedinitstring = "--broker=mainbroker --federates=1"
deltat = 0.01
#TODO: should add an assert here about helicsGetVersion
h.helicsGetVersion()
# Create broker #
broker = h.helicsCreateBroker("zmq", "", initstring)
isconnected = h.helicsBrokerIsConnected(broker)
if isconnected == 1:
pass
# Create Federate Info object that describes the federate properties #
fedinfo = h.helicsCreateFederateInfo()
# Set Federate name #
h.helicsFederateInfoSetCoreName(fedinfo, "TestA Core")
# Set core type from string #
h.helicsFederateInfoSetCoreTypeFromString(fedinfo, "zmq")
# Federate init string #
h.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring)
def destroy_federate(fed):
h.helicsFederateFinalize(fed)
# status, state = h.helicsFederateGetState(fed)
# assert state == 3
while (h.helicsBrokerIsConnected(broker)):
time.sleep(1)
h.helicsFederateFree(fed)
h.helicsCloseLibrary()
def destroy_value_federate(fed, broker):
status = h.helicsFederateFinalize(fed)
assert status == 0
status, state = h.helicsFederateGetState(fed)
assert status == 0
assert state == 3
while (h.helicsBrokerIsConnected(broker)):
time.sleep(1)
h.helicsFederateFree(fed)
h.helicsCloseLibrary()
def create_broker():
initstring = "2 --name=mainbroker"
broker = h.helicsCreateBroker("zmq", "", initstring)
isconnected = h.helicsBrokerIsConnected(broker)
if isconnected == 1:
pass
return broker
def destroy_federate(fed):
h.helicsFederateFinalize(fed)
# status, state = h.helicsFederateGetState(fed)
# assert state == 3
while (h.helicsBrokerIsConnected(broker)):
time.sleep(1)
h.helicsFederateFree(fed)
h.helicsCloseLibrary()
def create_broker():
initstring = "--federates=2 --name=mainbroker"
broker = h.helicsCreateBroker("zmq", "", initstring)
isconnected = h.helicsBrokerIsConnected(broker)
if isconnected == 1:
pass
return broker