示例#1
0
def run():
    ## Operation process for UEMS
    logger = Logger('Universal_ems_main') # The logger system has been started
    db_str = db_configuration.universal_database["db_str"] # Database format
    engine = create_engine(db_str, echo=False) # Create engine for universal energy management system databases
    Session = sessionmaker(bind=engine) # Create engine for target database
    session_uems = Session() # Create session for universal energy management system
    # IP = "10.25.196.56"
    IP = "*"
    # Start the information connection
    context = zmq.Context()
    socket = context.socket(zmq.REP)
    socket.bind("tcp://" + IP + ":5555")

    socket_upload = context.socket(zmq.REP)  # Upload information channel for local EMS
    socket_upload.bind("tcp://" + IP + ":5556")

    socket_download = context.socket(zmq.REQ)  # Download information channel for local EMS
    socket_download.bind("tcp://" + IP + ":5557")

    initialize = Main(socket)
    universal_models = initialize.universal_models
    local_models = initialize.local_models
    # Start the input information
    info_ed = economic_dispatch_info.local_sources() # Dynamic information for economic dispatch
    info_uc = economic_dispatch_info.local_sources() # Dynamic information for unit commitment
    info_opf = opf_model.informaiton_exchange() # Optimal power flow modelling

    # Generate different processes
    logger.info("The short term process in UEMS starts!")
    sched_short_term = BlockingScheduler()  # The schedulor for the optimal power flow
    sched_short_term.add_job(short_term_operation.short_term_operation_uems, 'cron',
                             args=(universal_models, local_models, socket_upload, socket_download, info_opf,
                                   session_uems), minute='0-59',
                             second='1')  # The operation is triggered minutely, this process will start at **:01
    sched_short_term.start()

    logger.info("The middle term process in UEMS starts!")
    sched_middle_term = BlockingScheduler()  # The schedulor for the optimal power flow
    sched_middle_term.add_job(middle_term_operation.middle_term_operation_uems, 'cron',
                             args=(universal_models, local_models, socket_upload, socket_download, info_ed,
                                   session_uems), minute='*/5',
                             second='1')  # The operation is triggered every 5 minute
    sched_middle_term.start()

    short_term_operation.short_term_operation_uems(universal_models, local_models, socket_upload, socket_download, info_opf,
            session_uems)

    logger.info("The long term process in UEMS starts!")
    sched_long_term = BlockingScheduler()  # The schedulor for the optimal power flow
    sched_long_term.add_job(long_term_operation.long_term_operation_uems, 'cron',
                              args=(universal_models, local_models, socket_upload, socket_download, info_uc,
                                    session_uems), minute='*/30',
                              second='1')  # The operation is triggered every half an hour
    sched_long_term.start()
def run():
    # Define the local models
    (local_model_short, local_model_middle,
     local_model_long) = start_up_lems.start_up_lems.start_up()
    # Convert local information to sharable information
    static_info = static_information.static_information_generation(
        local_model_short)
    # Set the database information
    db_str = db_configuration.local_database["db_str"]
    engine = create_engine(db_str, echo=False)
    Session = sessionmaker(bind=engine)
    session_lems_short = Session()
    session_lems_middle = Session()
    session_lems_long = Session()

    # Start the information connection
    context = zmq.Context()
    socket = context.socket(zmq.REQ)
    socket.connect("tcp://localhost:5555")

    socket_upload = context.socket(zmq.REQ)
    socket_upload.connect("tcp://localhost:5556")

    socket_upload_ed = context.socket(zmq.REQ)
    socket_upload_ed.connect("tcp://localhost:5557")

    socket_upload_uc = context.socket(zmq.REQ)
    socket_upload_uc.connect("tcp://localhost:5558")

    socket_download = context.socket(zmq.REP)
    socket_download.connect("tcp://localhost:5559")

    while True:
        socket.send(b"ConnectionRequest")

        message = socket.recv()
        if message == b"Start!":
            logger.info(
                "The connection between the local EMS and universal EMS establishes!"
            )
            break
        else:
            logger.error(
                "Waiting for the connection between the local EMS and universal EMS!"
            )

    information_receive_send.information_send(socket, static_info, 2)

    info_ed = economic_dispatch_info.local_sources()
    info_uc = economic_dispatch_info.local_sources(
    )  # The information model in the
    info_opf = opf_model.informaiton_exchange(
    )  # The optimal power flow modelling
    # By short-term operation process
    logger.info("The short-term process in local ems starts!")
    sched_lems = BlockingScheduler(
    )  # The schedulor for the optimal power flow
    sched_lems.add_job(lambda: short_term_operation.short_term_operation_lems(
        local_model_short, socket_upload, socket_download, info_opf,
        session_lems_short),
                       'cron',
                       minute='0-59',
                       second='1')  # The operation is triggered minutely

    logger.info("The middle-term process in local EMS starts!")
    sched_lems.add_job(
        lambda: middle_term_operation.middle_term_operation_lems(
            local_model_middle, socket_upload_ed, socket_download, info_ed,
            session_lems_middle),
        'cron',
        minute='*/5',
        second='5')  # The operation is triggered every five minute

    logger.info("The long term process in local EMS starts!")
    sched_lems.add_job(
        lambda: long_term_operation.long_term_operation_lems(
            local_model_long, socket_upload_uc, socket_download, info_uc,
            session_lems_long),
        'cron',
        minute='*/30',
        second='30')  # The operation is triggered every half an hour
    sched_lems.start()
示例#3
0
    def info_formulation(*args):
        import modelling.information_exchange_pb2 as dynamic_model  # The information model

        model = args[0]
        Target_time = args[1]
        # 1) Initial dynamic model
        dynamic_info = dynamic_model.informaiton_exchange()
        #################################The information structure
        ug_info = dynamic_model.informaiton_exchange.DgType()
        dg_info = dynamic_model.informaiton_exchange.DgType()
        ess_info = dynamic_model.informaiton_exchange.EssType()
        pv_info = dynamic_model.informaiton_exchange.PvType()
        wp_info = dynamic_model.informaiton_exchange.WpType()
        load_ac_info = dynamic_model.informaiton_exchange.Load_AC_Type()
        load_dc_info = dynamic_model.informaiton_exchange.Load_DC_Type()
        load_uac_info = dynamic_model.informaiton_exchange.Load_AC_Type()
        load_udc_info = dynamic_model.informaiton_exchange.Load_DC_Type()
        bic_info = dynamic_model.informaiton_exchange.Convertor_Type()

        # Obtain information from the external systems
        dynamic_info.AREA = model["UG"]["AREA"]
        dynamic_info.TIME_STAMP = Target_time
        # Update utility grid information
        ug_info.DG_ID = 0
        try:
            ug_info.GEN_STATUS = model["UG"]["GEN_STATUS"]
        except:
            ug_info.GEN_STATUS = model["UG"]["GEN_STATUS"][0]
        ug_info.PG = model["UG"]["COMMAND_PG"]
        try:
            ug_info.QG = model["UG"]["COMMANDD_QG"]
        except:
            ug_info.QG = 0
        ug_info.RG = model["UG"]["COMMAND_RG"]
        # Update dg part information
        dg_info.DG_ID = 1
        try:
            dg_info.GEN_STATUS = model["DG"]["GEN_STATUS"]
        except:
            dg_info.GEN_STATUS = model["DG"]["GEN_STATUS"][0]

        dg_info.PG = model["DG"]["COMMAND_PG"]
        dg_info.QG = model["DG"]["COMMAND_QG"]
        dg_info.RG = model["DG"]["COMMAND_RG"]

        dynamic_info.dg.extend([ug_info, dg_info])
        # Update ess part information
        ess_info.ESS_ID = 1
        ess_info.ESS_STATUS = 1
        ess_info.SOC = model["ESS"]["SOC"]
        ess_info.PG = model["ESS"]["COMMAND_PG"]
        ess_info.RG = model["ESS"]["COMMAND_RG"]
        dynamic_info.ess.extend([ess_info])

        # Update pv part information
        pv_info.NPV = model["PV"]["PMAX"]
        try:
            pv_info.PG = model["PV"]["PG"]
        except:
            pv_info.PG = model["PV"]["PG"][0]

        pv_info.COMMAND_CURT = model["PV"]["COMMAND_CURT"]
        dynamic_info.pv.extend([pv_info])

        # Update wp part information
        wp_info.NWP = model["WP"]["PMAX"]
        try:
            wp_info.PG = model["WP"]["PG"]
        except:
            wp_info.PG = model["WP"]["PG"][0]

        wp_info.COMMAND_CURT = model["WP"]["COMMAND_CURT"]
        dynamic_info.wp.extend([wp_info])
        # Update load_ac part information
        try:
            load_ac_info.PD = model["Load_ac"]["PD"]
        except:
            load_ac_info.PD = model["Load_ac"]["PD"][0]

        try:
            load_ac_info.QD = model["Load_ac"]["QD"]
        except:
            load_ac_info.QD = model["Load_ac"]["QD"][0]

        load_ac_info.COMMAND_SHED = model["Load_ac"]["COMMAND_SHED"]

        try:
            load_uac_info.PD = model["Load_uac"]["PD"]
        except:
            load_uac_info.PD = model["Load_uac"]["PD"][0]

        try:
            load_uac_info.QD = model["Load_uac"]["QD"]
        except:
            load_uac_info.QD = model["Load_uac"]["QD"][0]

        load_uac_info.COMMAND_SHED = model["Load_uac"]["COMMAND_SHED"]

        dynamic_info.load_ac.extend([load_ac_info, load_uac_info])
        # Update load_dc part information
        try:
            load_dc_info.PD = model["Load_dc"]["PD"]
        except:
            load_dc_info.PD = model["Load_dc"]["PD"][0]

        load_dc_info.COMMAND_SHED = model["Load_dc"]["COMMAND_SHED"]
        try:
            load_udc_info.PD = model["Load_udc"]["PD"]
        except:
            load_udc_info.PD = model["Load_udc"]["PD"][0]

        load_udc_info.COMMAND_SHED = model["Load_udc"]["COMMAND_SHED"]

        dynamic_info.load_dc.extend([load_dc_info, load_udc_info])
        # Update convertor part information
        bic_info.STATUS = 1
        bic_info.PAC2DC = model["BIC"]["COMMAND_AC2DC"]
        bic_info.PDC2AC = model["BIC"]["COMMAND_DC2AC"]

        dynamic_info.bic.extend([bic_info])

        dynamic_info.PMG = model["PMG"]
        dynamic_info.TIME_STAMP_COMMAND = Target_time

        return dynamic_info
示例#4
0
def run():
    # Define the local models
    local_models = {
        "DG": generators.Generator_AC.copy(),
        "UG": generators.Generator_AC.copy(),
        "Load_ac": loads.Load_AC.copy(),
        "Load_uac": loads.Load_AC.copy(),
        "BIC": convertors.BIC.copy(),
        "ESS": energy_storage_systems.BESS.copy(),
        "PV": generators.Generator_RES.copy(),
        "WP": generators.Generator_RES.copy(),
        "Load_dc": loads.Load_DC.copy(),
        "Load_udc": loads.Load_DC.copy(),
        "PMG": 0,
        "VDC": 0
    }

    # Update the local parameters
    local_models["UG"]["GEN_STATUS"] = 0
    local_models["WP"]["GEN_STATUS"] = 0
    local_models["Load_ac"]["FLEX"] = 0
    local_models["Load_uac"]["FLEX"] = 1
    local_models["Load_dc"]["FLEX"] = 0
    local_models["Load_udc"]["FLEX"] = 1
    # Convert local information to sharable information
    static_info = static_information.static_information_generation(
        local_models)
    # Set the database information
    db_str = db_configuration.local_database["db_str"]
    engine = create_engine(db_str, echo=False)
    Session = sessionmaker(bind=engine)
    session_lems = Session()

    # Start the information connection
    context = zmq.Context()
    socket = context.socket(zmq.REQ)
    socket.connect("tcp://localhost:5555")

    socket_upload = context.socket(zmq.REQ)
    socket_upload.connect("tcp://localhost:5556")

    socket_download = context.socket(zmq.REP)
    socket_download.connect("tcp://localhost:5557")

    while True:
        socket.send(b"ConnectionRequest")

        message = socket.recv()
        if message == b"Start!":
            logger.info(
                "The connection between the local EMS and universal EMS establishes!"
            )
            break
        else:
            logger.error(
                "Waiting for the connection between the local EMS and universal EMS!"
            )

    information_receive_send.information_send(socket, static_info, 2)

    info_ed = economic_dispatch_info.local_sources()
    info_uc = economic_dispatch_info.local_sources(
    )  # The information model in the
    info_opf = opf_model.informaiton_exchange(
    )  # The optimal power flow modelling
    # By short-term operation process
    logger.info("The short-term process in local ems starts!")
    sched_short_term = BlockingScheduler(
    )  # The schedulor for the optimal power flow
    sched_short_term.add_job(
        lambda: short_term_operation.short_term_operation_lems(
            local_models, socket_upload, socket_download, info_opf,
            session_lems),
        'cron',
        minute='0-59',
        second='1')  # The operation is triggered minutely
    sched_short_term.start()

    short_term_operation.short_term_operation_lems(local_models, socket_upload,
                                                   socket_download, info_opf,
                                                   session_lems)
    logger.info("The middle-term process in local EMS starts!")
    sched_middle_term = BlockingScheduler(
    )  # The schedulor for the optimal power flow
    sched_middle_term.add_job(
        lambda: middle_term_operation.middle_term_operation_lems(
            local_models, socket_upload, socket_download, info_ed, session_lems
        ),
        'cron',
        minute='*/5',
        second='1')  # The operation is triggered every five minute
    sched_middle_term.start()

    logger.info("The long term process in local EMS starts!")
    sched_long_term = BlockingScheduler(
    )  # The schedulor for the optimal power flow
    sched_long_term.add_job(
        lambda: long_term_operation.long_term_operation_lems(
            local_models, socket_upload, socket_download, info_uc, session_lems
        ),
        'cron',
        minute='*/30',
        second='1')  # The operation is triggered every half an hour
    sched_long_term.start()