Пример #1
0
def test_value_federate_runFederateTestDouble(vFed):
    defaultValue = 1.0
    testValue = 2.0
    pubid = h.helicsFederateRegisterGlobalTypePublication(
        vFed, "pub1", h.HELICS_DATA_TYPE_DOUBLE, "")
    subid = h.helicsFederateRegisterSubscription(vFed, "pub1", "double", "")
    h.helicsSubscriptionSetDefaultDouble(subid, defaultValue)

    h.helicsFederateEnterExecutionMode(vFed)

    # publish string1 at time=0.0;
    h.helicsPublicationPublishDouble(pubid, testValue)

    status, value = h.helicsSubscriptionGetDouble(subid)
    assert value == defaultValue

    status, grantedtime = h.helicsFederateRequestTime(vFed, 1.0)
    assert grantedtime == 0.01

    status, value = h.helicsSubscriptionGetDouble(subid)
    assert value == testValue

    # publish string1 at time=0.0;
    h.helicsPublicationPublishDouble(pubid, testValue + 1)

    status, grantedtime = h.helicsFederateRequestTime(vFed, 2.0)
    assert grantedtime == 0.02

    status, value = h.helicsSubscriptionGetDouble(subid)
    assert value == testValue + 1
Пример #2
0
epid = h.helicsFederateRegisterGlobalEndpoint(fed, "endpoint2", "")

status = h.helicsFederateEnterExecutionMode(fed)
print("PI RECEIVER: Entering execution mode")

value = 0.0
prevtime = 0

currenttime = h.helicsFederateRequestTime(fed, 100)[-1]
print("PI RECEIVER: Current time is {} ".format(currenttime))

isupdated = h.helicsSubscriptionIsUpdated(sub)

if isupdated == 1:
    result, value = h.helicsSubscriptionGetDouble(sub)
    print("PI RECEIVER: Received value = {} at time {} from PI SENDER".format(
        value, currenttime))

while currenttime <= 100:

    currenttime = h.helicsFederateRequestTime(fed, 100)[-1]

    isupdated = h.helicsSubscriptionIsUpdated(sub)

    if isupdated == 1:
        result, value = h.helicsSubscriptionGetDouble(sub)
        print("PI RECEIVER: Received value = {} at time {} from PI SENDER".
              format(value, currenttime))
    while h.helicsEndpointHasMessage(epid):
        value = h.helicsEndpointGetMessage(epid)
Пример #3
0
def main():

    fed = create_federate()

    pubid1 = h.helicsFederateRegisterGlobalTypePublication(
        fed, "GenOutput/Alta", h.HELICS_DATA_TYPE_COMPLEX, "")
    pubid2 = h.helicsFederateRegisterGlobalTypePublication(
        fed, "GenOutput/Brighton", h.HELICS_DATA_TYPE_COMPLEX, "")
    pubid3 = h.helicsFederateRegisterGlobalTypePublication(
        fed, "GenOutput/ParkCity", h.HELICS_DATA_TYPE_COMPLEX, "")
    pubid4 = h.helicsFederateRegisterGlobalTypePublication(
        fed, "GenOutput/Solitude", h.HELICS_DATA_TYPE_COMPLEX, "")
    pubid5 = h.helicsFederateRegisterGlobalTypePublication(
        fed, "GenOutput/Sundance", h.HELICS_DATA_TYPE_COMPLEX, "")

    subid1 = h.helicsFederateRegisterSubscription(
        fed, "DistributionSim_B4_G_1/totalLoad", "complex", "")
    subid2 = h.helicsFederateRegisterSubscription(
        fed, "DistributionSim_B4_R_1_2/totalLoad", "complex", "")
    subid3 = h.helicsFederateRegisterSubscription(
        fed, "DistributionSim_B4_R_1_1/totalLoad", "complex", "")
    subid4 = h.helicsFederateRegisterSubscription(
        fed, "DistributionSim_B3_R_3_4/totalLoad", "complex", "")
    subid5 = h.helicsFederateRegisterSubscription(
        fed, "DistributionSim_B3_R_3_3/totalLoad", "complex", "")
    subid6 = h.helicsFederateRegisterSubscription(
        fed, "DistributionSim_B3_R_3_2/totalLoad", "complex", "")
    subid7 = h.helicsFederateRegisterSubscription(
        fed, "DistributionSim_B3_R_3_1/totalLoad", "complex", "")
    subid8 = h.helicsFederateRegisterSubscription(
        fed, "DistributionSim_B2_G_1/totalLoad", "complex", "")
    subid9 = h.helicsFederateRegisterSubscription(
        fed, "DistributionSim_B2_R_2_3/totalLoad", "complex", "")
    subid10 = h.helicsFederateRegisterSubscription(
        fed, "DistributionSim_B2_R_2_2/totalLoad", "complex", "")
    subid11 = h.helicsFederateRegisterSubscription(
        fed, "DistributionSim_B2_R_2_1/totalLoad", "complex", "")

    subid12 = h.helicsFederateRegisterSubscription(
        fed, "MarketSim/AGCGenDispatch/Alta", "double", "")
    subid13 = h.helicsFederateRegisterSubscription(
        fed, "MarketSim/AGCGenDispatch/Brighton", "double", "")
    subid14 = h.helicsFederateRegisterSubscription(
        fed, "MarketSim/AGCGenDispatch/ParkCity", "double", "")
    subid15 = h.helicsFederateRegisterSubscription(
        fed, "MarketSim/AGCGenDispatch/Solitude", "double", "")
    subid16 = h.helicsFederateRegisterSubscription(
        fed, "MarketSim/AGCGenDispatch/Sundance", "double", "")

    h.helicsFederateEnterExecutionMode(fed)

    hours = 1
    seconds = int(60 * 60 * hours)
    grantedtime = -1
    random.seed(0)
    for t in range(0, seconds, 60 * 5):
        status, value = h.helicsSubscriptionGetDouble(subid12)
        c = complex(value, 0)
        status = h.helicsPublicationPublishComplex(pubid1, c.real, c.imag)
        status, value = h.helicsSubscriptionGetDouble(subid13)
        c = complex(value, 0)
        status = h.helicsPublicationPublishComplex(pubid2, c.real, c.imag)
        status, value = h.helicsSubscriptionGetDouble(subid14)
        c = complex(value, 0)
        status = h.helicsPublicationPublishComplex(pubid3, c.real, c.imag)
        status, value = h.helicsSubscriptionGetDouble(subid15)
        c = complex(value, 0)
        status = h.helicsPublicationPublishComplex(pubid4, c.real, c.imag)
        status, value = h.helicsSubscriptionGetDouble(subid16)
        c = complex(value, 0)
        status = h.helicsPublicationPublishComplex(pubid5, c.real, c.imag)
        # status = h.helicsEndpointSendEventRaw(epid, "fixed_price", 10, t)
        while grantedtime < t:
            status, grantedtime = h.helicsFederateRequestTime(fed, t)
        time.sleep(1)
        logger.info("Python Federate grantedtime = {}".format(grantedtime))

    t = 60 * 60 * 24
    while grantedtime < t:
        status, grantedtime = h.helicsFederateRequestTime(fed, t)
    logger.info("Destroying federate")
    destroy_federate(fed)