예제 #1
0
def dpsim():
    # Parameters
    V_nom = 20e3
    p_load_nom = 100e3
    q_load_nom = 50e3
    line_resistance = 0.05
    line_inductance = 0.1
    line_capacitance = 0.1e-6
    name = 'test_shmem_import_export'

    # Nodes and Components
    n1 = dpsimpy.sp.SimNode('n1', dpsimpy.PhaseType.Single)
    n2 = dpsimpy.sp.SimNode('n2', dpsimpy.PhaseType.Single)

    extnet = dpsimpy.sp.ph1.NetworkInjection('Slack')
    extnet.set_parameters(voltage_set_point=V_nom)
    extnet.set_base_voltage(V_nom)
    extnet.modify_power_flow_bus_type(dpsimpy.PowerflowBusType.VD)

    line = dpsimpy.sp.ph1.PiLine('PiLine')
    line.set_parameters(R=line_resistance,
                        L=line_inductance,
                        C=line_capacitance)
    line.set_base_voltage(V_nom)

    load = dpsimpy.sp.ph1.Load('Load')
    load.set_parameters(active_power=p_load_nom,
                        reactive_power=q_load_nom,
                        nominal_voltage=V_nom)
    load.modify_power_flow_bus_type(dpsimpy.PowerflowBusType.PQ)

    extnet.connect([n1])
    line.connect([n1, n2])
    load.connect([n2])
    system = dpsimpy.SystemTopology(50, [n1, n2], [extnet, line, load])

    sim = dpsimpy.RealTimeSimulation(name, dpsimpy.LogLevel.debug)
    sim.set_system(system)
    sim.set_domain(dpsimpy.Domain.SP)
    sim.set_solver(dpsimpy.Solver.NRP)
    sim.set_time_step(1)
    sim.set_final_time(10)
    sim.do_init_from_nodes_and_terminals(False)

    logger = dpsimpy.Logger(name)
    sim.add_logger(logger)
    sim.log_attr('n1', 'v')
    sim.log_attr('n2', 'v')

    intf = dpsimpyvillas.InterfaceShmem()
    sim.add_interface(intf)
    sim.import_attr('Load', 'P', 0)
    sim.export_attr('n2', 'v', 0, dpsimpy.AttrModifier.mag)

    return sim, intf
예제 #2
0
def dpsim0():
    sim_name = "ShmemDistributed0"
    time_step = 0.001
    final_time = 10

    n1 = dpsimpy.dp.SimNode('n1', dpsimpy.PhaseType.Single, [10])
    n2 = dpsimpy.dp.SimNode('n2', dpsimpy.PhaseType.Single, [5])

    evs = dpsimpy.dp.ph1.VoltageSource('v_intf', dpsimpy.LogLevel.debug)
    evs.set_parameters(complex(5, 0))

    vs1 = dpsimpy.dp.ph1.VoltageSource('vs_1', dpsimpy.LogLevel.debug)
    vs1.set_parameters(complex(10, 0))

    r12 = dpsimpy.dp.ph1.Resistor('r_12', dpsimpy.LogLevel.debug)
    r12.set_parameters(1)

    evs.connect([dpsimpy.dp.SimNode.gnd, n2])
    vs1.connect([dpsimpy.dp.SimNode.gnd, n1])
    r12.connect([n1, n2])

    sys = dpsimpy.SystemTopology(50, [n1, n2], [evs, vs1, r12])

    dpsimpy.Logger.set_log_dir('logs/' + sim_name)

    logger = dpsimpy.Logger(sim_name)
    logger.log_attribute('v1', 'v', n1)
    logger.log_attribute('v2', 'v', n2)
    logger.log_attribute('r12', 'i_intf', r12)
    logger.log_attribute('ievs', 'i_intf', evs)
    logger.log_attribute('vevs', 'v_intf', evs)

    sim = dpsimpy.RealTimeSimulation(sim_name)
    sim.set_system(sys)
    sim.set_time_step(time_step)
    sim.set_final_time(final_time)

    intf = dpsimpyvillas.InterfaceShmem('/dpsim0-out', '/dpsim0-in')

    sim.import_attr('v_intf', 'V_ref', 0)
    sim.export_attr('v_intf', 'i_intf', 0, 0, 0)

    sim.add_interface(intf, True)
    sim.add_logger(logger)

    evs.set_intf_current([[complex(5, 0)]])

    sim.run(1)
예제 #3
0
def dpsim1():
    sim_name = "ShmemDistributed1"
    time_step = 0.001
    final_time = 10

    n2 = dpsimpy.dp.SimNode('n2', dpsimpy.PhaseType.Single, [5])

    ecs = dpsimpy.dp.ph1.CurrentSource('i_intf', dpsimpy.LogLevel.debug)
    ecs.set_parameters(complex(5, 0))
    r02 = dpsimpy.dp.ph1.Resistor('r_02', dpsimpy.LogLevel.debug)
    r02.set_parameters(1)

    ecs.connect([dpsimpy.dp.SimNode.gnd, n2])
    r02.connect([dpsimpy.dp.SimNode.gnd, n2])

    sys = dpsimpy.SystemTopology(50, [n2], [ecs, r02])

    dpsimpy.Logger.set_log_dir('logs/' + sim_name)

    logger = dpsimpy.Logger(sim_name)
    logger.log_attribute('v2', 'v', n2)
    logger.log_attribute('r02', 'i_intf', r02)
    logger.log_attribute('vecs', 'v_intf', ecs)
    logger.log_attribute('iecs', 'i_intf', ecs)

    sim = dpsimpy.RealTimeSimulation(sim_name)
    sim.set_system(sys)
    sim.set_time_step(time_step)
    sim.set_final_time(final_time)
    intf = dpsimpyvillas.InterfaceShmem('/dpsim1-out', '/dpsim1-in')

    sim.import_attr('i_intf', 'I_ref', 0)
    sim.export_attr('i_intf', 'v_intf', 0, 0, 0, scale=complex(-1, 0))

    sim.add_interface(intf)
    sim.add_logger(logger)

    sim.run(1)
예제 #4
0
n2 = dpsimpy.dp.SimNode('n2', dpsimpy.PhaseType.Single, [5])

evs = dpsimpy.dp.ph1.VoltageSource('v_intf', dpsimpy.LogLevel.debug)
evs.set_parameters(complex(5, 0))

vs1 = dpsimpy.dp.ph1.VoltageSource('vs_1', dpsimpy.LogLevel.debug)
vs1.set_parameters(complex(10, 0))

r12 = dpsimpy.dp.ph1.Resistor('r_12', dpsimpy.LogLevel.debug)
r12.set_parameters(1)

evs.connect([dpsimpy.dp.SimNode.gnd, n2])
vs1.connect([dpsimpy.dp.SimNode.gnd, n1])
r12.connect([n1, n2])

sys = dpsimpy.SystemTopology(50, [n1, n2], [evs, vs1, r12])

dpsimpy.Logger.set_log_dir('logs/' + sim_name)

logger = dpsimpy.Logger(sim_name)
logger.log_attribute('v1', 'v', n1)
logger.log_attribute('v2', 'v', n2)
logger.log_attribute('r12', 'i_intf', r12)
logger.log_attribute('ievs', 'i_intf', evs)
logger.log_attribute('vevs', 'v_intf', evs)

sim = dpsimpy.RealTimeSimulation(sim_name)
sim.set_system(sys)
sim.set_time_step(time_step)
sim.set_final_time(final_time)
    n1 = dpsimpy.dp.SimNode('n1')
    n2 = dpsimpy.dp.SimNode('n2')

    vs1 = dpsimpy.dp.ph1.VoltageSource('vs_1', dpsimpy.LogLevel.debug)
    vs1.set_parameters(complex(10, 0))
    r12 = dpsimpy.dp.ph1.Resistor('r_1', dpsimpy.LogLevel.debug)
    r12.set_parameters(1)
    r02 = dpsimpy.dp.ph1.Resistor('r_02', dpsimpy.LogLevel.debug)
    r02.set_parameters(1)

    vs1.connect([dpsimpy.dp.SimNode.gnd, n1])
    r12.connect([n1, n2])
    r02.connect([dpsimpy.dp.SimNode.gnd, n2])

    sys = dpsimpy.SystemTopology(50, [n1, n2], [vs1, r12, r02])

    dpsimpy.Logger.set_log_dir('logs/' + sim_name)

    logger = dpsimpy.Logger(sim_name)
    logger.log_attribute('v1', 'v', n1)
    logger.log_attribute('v2', 'v', n2)
    logger.log_attribute('r12', 'i_intf', r12)
    logger.log_attribute('r02', 'i_intf', r02)

    sim = dpsimpy.RealTimeSimulation(sim_name)
    sim.set_system(sys)
    sim.set_time_step(time_step)
    sim.set_final_time(10)

    sim.add_logger(logger)
예제 #6
0
def dpsim():
    # Parameters
    V_nom = 20e3
    p_load_nom = 100e3
    q_load_nom = 50e3
    line_resistance = 0.05
    line_inductance = 0.1
    line_capacitance = 0.1e-6
    name = 'dpsim_mqtt_import_export'

    # Nodes and Components
    n1 = dpsimpy.sp.SimNode('n1', dpsimpy.PhaseType.Single)
    n2 = dpsimpy.sp.SimNode('n2', dpsimpy.PhaseType.Single)

    extnet = dpsimpy.sp.ph1.NetworkInjection('Slack')
    extnet.set_parameters(voltage_set_point=V_nom)
    extnet.set_base_voltage(V_nom)
    extnet.modify_power_flow_bus_type(dpsimpy.PowerflowBusType.VD)

    line = dpsimpy.sp.ph1.PiLine('PiLine')
    line.set_parameters(R=line_resistance,
                        L=line_inductance,
                        C=line_capacitance)
    line.set_base_voltage(V_nom)

    load = dpsimpy.sp.ph1.Load('Load')
    load.set_parameters(active_power=p_load_nom,
                        reactive_power=q_load_nom,
                        nominal_voltage=V_nom)
    load.modify_power_flow_bus_type(dpsimpy.PowerflowBusType.PQ)

    extnet.connect([n1])
    line.connect([n1, n2])
    load.connect([n2])
    system = dpsimpy.SystemTopology(50, [n1, n2], [extnet, line, load])

    sim = dpsimpy.RealTimeSimulation(name, dpsimpy.LogLevel.debug)
    sim.set_system(system)
    sim.set_domain(dpsimpy.Domain.SP)
    sim.set_solver(dpsimpy.Solver.NRP)
    sim.set_time_step(0.1)
    sim.set_final_time(10)
    sim.do_init_from_nodes_and_terminals(False)

    logger = dpsimpy.Logger(name)
    sim.add_logger(logger)
    sim.log_attr('n1', 'v')
    sim.log_attr('n2', 'v')

    intf_config = {
        "type": "mqtt",
        "format": "json",
        "host": "mqtt",
        "in": {
            "subscribe": "/mqtt-dpsim"
        },
        "out": {
            "publish": "/dpsim-mqtt"
        }
    }

    intf_config_2 = {
        "type": "shmem",
        "in": {
            "name": "/shmem-dpsim"
        },
        "out": {
            "name": "/dpsim-shmem"
        }
    }

    intf = dpsimpyvillas.InterfaceVillas(name="dpsim-mqtt", config=intf_config)
    sim.add_interface(intf)

    intf2 = dpsimpyvillas.InterfaceVillas(name="dpsim-shmem",
                                          config=intf_config_2)
    sim.add_interface(intf2)
    sim.import_attr('Load', 'P', 0, intf=intf)
    sim.export_attr('n1', 'v', 0, intf=intf)
    sim.export_attr('n2', 'v', 1, dpsimpy.AttrModifier.mag, intf=intf)
    sim.import_attr('Load', 'Q', 0, intf=intf2)
    sim.export_attr('n1', 'v', 0, intf=intf2)
    sim.export_attr('n2', 'v', 1, dpsimpy.AttrModifier.mag, intf=intf2)

    return sim, intf, intf2