while h.helicsBrokerIsConnected(broker): time.sleep(1) h.helicsFederateFree(fed) h.helicsCloseLibrary() if __name__ == "__main__": broker = create_broker() # fed = create_federate() ################################# Registering federate from json ######################################## fed = h.helicsCreateValueFederateFromConfig("Transmission_json.json") h.helicsFederateRegisterInterfaces(fed, "Transmission_json.json") federate_name = h.helicsFederateGetName(fed)[-1] print(" Federate {} has been registered".format(federate_name)) pubkeys_count = h.helicsFederateGetPublicationCount(fed) subkeys_count = h.helicsFederateGetInputCount(fed) print(subkeys_count) ###################### Reference to Publications and Subscription form index ############################# pubid = {} subid = {} for i in range(0, pubkeys_count): pubid["m{}".format(i)] = h.helicsFederateGetPublicationByIndex(fed, i) pubtype = h.helicsPublicationGetType(pubid["m{}".format(i)]) print(pubtype) for i in range(0, subkeys_count): subid["m{}".format(i)] = h.helicsFederateGetInputByIndex(fed, i) h.helicsInputSetDefaultComplex(subid["m{}".format(i)], 0, 0)
while (h.helicsBrokerIsConnected(broker)): time.sleep(1) h.helicsFederateFree(fed) h.helicsCloseLibrary() if __name__ == "__main__": broker = create_broker() #fed = create_federate() ################################# Registering federate from json ######################################## fed = h.helicsCreateValueFederateFromConfig('Transmission_json.json') status = h.helicsFederateRegisterInterfaces(fed, 'Transmission_json.json') federate_name = h.helicsFederateGetName(fed)[-1] print(" Federate {} has been registered".format(federate_name)) pubkeys_count = h.helicsFederateGetPublicationCount(fed) subkeys_count = h.helicsFederateGetInputCount(fed) print(subkeys_count) ###################### Reference to Publications and Subscription form index ############################# pubid = {} subid = {} for i in range(0, pubkeys_count): pubid["m{}".format(i)] = h.helicsFederateGetPublicationByIndex(fed, i) pubtype = h.helicsPublicationGetType(pubid["m{}".format(i)]) print(pubtype) for i in range(0, subkeys_count): subid["m{}".format(i)] = h.helicsFederateGetInputByIndex(fed, i) status = h.helicsInputSetDefaultComplex(subid["m{}".format(i)], 0, 0)
def test_bad_input_type_publication_2_tests(): broker = createBroker(1) vFed1, fedinfo = createValueFederate(1, "test") pubid = h.helicsFederateRegisterGlobalTypePublication( vFed1, "pub1", "string", "") with pt.raises(h.HelicsException): # @test_throws h.HELICSErrorRegistrationFailure pubid2 = h.helicsFederateRegisterGlobalTypePublication( vFed1, "pub1", "string", "") with pt.raises(h.HelicsException): # @test_throws h.HELICSErrorInvalidArgument h.helicsFederateRegisterFromPublicationJSON(vFed1, "unknownfile.json") with pt.raises(h.HelicsException): # @test_throws h.HELICSErrorExternalArgument h.helicsFederateRegisterInterfaces(vFed1, "unknownfile.json") subid = h.helicsFederateRegisterTypeInput(vFed1, "inp1", "string", "") # @test_throws h.HELICSErrorRegistrationFailure with pt.raises(h.HelicsException): subid2 = h.helicsFederateRegisterTypeInput(vFed1, "inp1", "string", "") h.helicsInputAddTarget(subid, "pub1") h.helicsFederateSetTimeProperty(vFed1, h.HELICS_PROPERTY_TIME_PERIOD, 1.0) h.helicsFederateEnterExecutingModeIterativeAsync( vFed1, h.HELICS_ITERATION_REQUEST_NO_ITERATION) res = h.helicsFederateEnterExecutingModeIterativeComplete(vFed1) assert res == h.HELICS_ITERATION_RESULT_NEXT_STEP h.helicsPublicationPublishTime(pubid, 27.0) # @test_throws h.HELICSErrorInvalidArgument with pt.raises(h.HelicsException): h.helicsFederatePublishJSON(vFed1, "unknownfile.json") h.helicsFederateRequestNextStep(vFed1) string = h.helicsInputGetString(subid) assert string[0] == "2" assert string[1] == "7" h.helicsFederateClearUpdates(vFed1) h.helicsFederateFinalize(vFed1) # @test_throws h.HELICSErrorInvalidFunctionCall with pt.raises(h.HelicsException): h.helicsPublicationPublishRaw(pubid, string.encode()) # @test_throws h.HELICSErrorInvalidFunctionCall with pt.raises(h.HelicsException): h.helicsPublicationPublishString(pubid, string) # @test_throws h.HELICSErrorInvalidFunctionCall with pt.raises(h.HelicsException): h.helicsPublicationPublishInteger(pubid, 5) # @test_throws h.HELICSErrorInvalidFunctionCall with pt.raises(h.HelicsException): h.helicsPublicationPublishBoolean(pubid, True) # @test_throws h.HELICSErrorInvalidFunctionCall with pt.raises(h.HelicsException): h.helicsPublicationPublishDouble(pubid, 39.2) # @test_throws h.HELICSErrorInvalidFunctionCall with pt.raises(h.HelicsException): h.helicsPublicationPublishTime(pubid, 19.2) # @test_throws h.HELICSErrorInvalidFunctionCall with pt.raises(h.HelicsException): h.helicsPublicationPublishChar(pubid, "a") # @test_throws h.HELICSErrorInvalidFunctionCall with pt.raises(h.HelicsException): h.helicsPublicationPublishComplex(pubid, 2.5 + -9.8j) # @test_throws h.HELICSErrorInvalidFunctionCall with pt.raises(h.HelicsException): h.helicsPublicationPublishVector(pubid, [1.3, 2.9]) # @test_throws h.HELICSErrorInvalidFunctionCall with pt.raises(h.HelicsException): h.helicsPublicationPublishNamedPoint(pubid, "hello world", 2.0) destroyFederate(vFed1, fedinfo) destroyBroker(broker)