def DSS(): dss = py_dss_interface.DSSDLL() actual = dss.started expected = True message = ("OpenDSSDirectDLL has been loaded: {}".format(actual)) assert actual is expected, message return dss
def solve_snap_13bus(): dss = py_dss_interface.DSSDLL() actual = dss.started expected = True message = ("OpenDSSDirectDLL has been loaded: {}".format(actual)) assert actual is expected, message dss13_path = os.path.join(pathlib.Path(script_path), "13Bus", "IEEE13Nodeckt.dss") dss.text("compile " + dss13_path) # It already performs power flow return dss
import py_dss_interface import matplotlib.pyplot as plt import numpy as np dss_file = r"C:\py-dss-interface-MiniCurso\8500-Node\Master-unbal.dss" dss = py_dss_interface.DSSDLL() dss.text("compile [{}]".format(dss_file)) dss.text("New Energymeter.m1 Line.ln5815900-1 1") dss.text("New Monitor.m1 Line.ln5815900-1 terminal=1 mode=1 ppolar=False") dss.text("Set Maxiterations=20") dss.text("set maxcontrolit=100") # Q2 - 1 dss.text("Batchedit Load..* daily=default") dss.text("set mode=daily") dss.text("set number=24") dss.text("set stepsize=1h") dss.text("solve") # Q2 - 2 dss.loads_write_name("328365B0a") loadshape = dss.loads_read_daily() # Q2 - 3 dss.monitors_write_name("m1") pa = dss.monitors_channel(1) qa = dss.monitors_channel(2)
def __init__(self, dssFileName): self.dss = py_dss_interface.DSSDLL() self.dssFileName = dssFileName
def run(pv_kva, pv_kw): random.seed(114) dss_file = r"C:\py-dss-interface-MiniCurso\8500-Node\Master-unbal.dss" dss = py_dss_interface.DSSDLL() dss.text("compile [{}]".format(dss_file)) dss.text("New Energymeter.m1 Line.ln5815900-1 1") dss.text("New Monitor.m1 Line.ln5815900-1 terminal=1 mode=1 ppolar=False") dss.text("Set Maxiterations=20") dss.text("set maxcontrolit=100") dss.text("Batchedit Load..* daily=default") # Q3 PVs bus_list = dss.circuit_allbusnames() bus_3ph_list = list() bus_kvbase_dict = dict() for index, bus in enumerate(bus_list): dss.circuit_setactivebus(bus) num_phases = len(dss.bus_nodes()) kv_base = dss.bus_kVbase() if num_phases == 3 and kv_base > 1.0: bus_3ph_list.append(bus) bus_kvbase_dict[bus] = kv_base pv_buses_list = random.sample(bus_3ph_list, 5) for pv_bus in pv_buses_list: functions.define_3ph_pvsystem_with_transformer(dss, pv_bus, bus_kvbase_dict[pv_bus], pv_kva, pv_kw) functions.add_bus_marker(dss, pv_bus, "red") dss.text("set mode=daily") dss.text("set number=24") dss.text("set stepsize=1h") dss.text("solve") dss.text("Plot Circuit Power Max=2000 dots=n labels=n C1=Blue 1ph=3") # Q3 - 2 dss.monitors_write_name("m1") pa = dss.monitors_channel(1) qa = dss.monitors_channel(2) pb = dss.monitors_channel(3) qb = dss.monitors_channel(4) pc = dss.monitors_channel(5) qc = dss.monitors_channel(6) pt = np.array(pa) + np.array(pb) + np.array(pc) qt = np.array(qa) + np.array(qb) + np.array(qc) plt.plot(list(range(1, len(pt) + 1)), pt, "g", label='P') plt.plot(list(range(1, len(qt) + 1)), qt, "b", label='Q') plt.title("Daily Active and Reactive Power at Feeder Head with PVs") plt.legend() plt.ylabel("kW, kvar") plt.xlabel("Hour") plt.xlim(1, 24) plt.grid(True) # plt.show() plt.savefig( r"C:\py-dss-interface-MiniCurso\8500-Node\demand-{}.jpg".format(pv_kw)) # Q3 - 1 pt_max = pt.max() peak_hour = pt.argmax() + 1 dss.meters_first() feeder_kwh = dss.meters_registervalues()[0] loads_kwh = dss.meters_registervalues()[4] losses_kwh = dss.meters_registervalues()[12] pv_kwh = loads_kwh + losses_kwh - feeder_kwh va, vaa = get_monitor_values(dss, dss.monitors_allnames()[1]) print("here") return feeder_kwh, loads_kwh, losses_kwh, pv_kwh
import numpy as np import random import add_pvs def set_pvs(dss, pv_buses_list, bus_kvbase_dict, pv_kva, pv_kw): for pv_bus in pv_buses_list: add_pvs.define_3ph_pvsystem_with_transformer(dss, pv_bus, bus_kvbase_dict[pv_bus], pv_kva, pv_kw) add_pvs.add_bus_marker(dss, pv_bus, "red") def set_generation(dss, pv_buses_list, bus_kvbase_dict, pv_kva, pv_kw): for pv_bus in pv_buses_list: add_pvs.define_3ph_generator_with_transformer(dss, pv_bus, bus_kvbase_dict[pv_bus], pv_kva, pv_kw) add_pvs.add_bus_marker(dss, pv_bus, "red") model_dss = py_dss_interface.DSSDLL(r"C:\py-dss-interface-Live\Model_DSS", "OpenDSSDirect_model.dll") real_dss = py_dss_interface.DSSDLL(r"C:\py-dss-interface-Live\Real_DSS", "OpenDSSDirect_real.dll") model_dss_file = r"C:\py-dss-interface-Live\8500-Node_model\Master.dss" real_dss_file = r"C:\py-dss-interface-Live\8500-Node_real\Master.dss" real_dss.text("compile [{}]".format(real_dss_file)) real_dss.text("Set Maxiterations=100") real_dss.text("set maxcontrolit=100") real_dss.text("set casename=real") real_dss.text("Batchedit Load..* daily=default") real_dss.text("set mode=daily") real_dss.text("set stepsize=1h") real_dss.text("Set controlmode=Off") bus_list = real_dss.circuit_allbusnames()
def hc_process(kva_to_kw, pf, circuit_pu, load_mult, percent, location): random.seed(location) dss_file = r"C:\PauloRadatz\GitHub\NEPSE_Python_OpenDSS\ckt5\Master_ckt5.dss" dss = py_dss_interface.DSSDLL() dss.text(f"Compile [{dss_file}]") dss.text("Set Maxiterations=100") dss.text("set maxcontrolit=100") dss.text("edit Reactor.MDV_SUB_1_HSB x=0.0000001") dss.text("edit Transformer.MDV_SUB_1 %loadloss=0.0000001 xhl=0.00000001") dss.text(f"edit vsource.source pu={circuit_pu}") # Ex 1 # a) Voltage profile at peak load and at offpeak load dss.text(f"batchedit load..* mode=1") dss.text(f"set loadmult={load_mult}") dss.solution_solve() # dss.text("plot profile phases=all") # b) Maximum and Minimum feeder voltages and c) Active and reactive power at the feederhead total_p_feederhead, total_q_feederhead, voltage_min, voltage_max = functions.get_powerflow_results( dss) # Ex 2 # a) Find all MV three-phase buses buses = dss.circuit_allbusnames() mv_buses = list() mv_bus_voltage_dict = dict() for bus in buses: dss.circuit_setactivebus(bus) if bus == "sourcebus": pass elif dss.bus_kVbase() >= 1.0 and len(dss.bus_nodes()) == 3: mv_buses.append(bus) mv_bus_voltage_dict[bus] = dss.bus_kVbase() # b) Select 20% of the MV three-phase buses selected_buses = random.sample(mv_buses, int(percent * len(mv_buses))) # c) Add PV systems for bus in selected_buses: functions.define_3ph_pvsystem(dss, bus, mv_bus_voltage_dict[bus], p_step * kva_to_kw, p_step) functions.add_bus_marker(dss, bus, "red", 2) dss.text("Interpolate") dss.solution_solve() # dss.text("Plot circuit") ov_violation = False thermal_violation = False i = 0 while not ov_violation and not thermal_violation and i < 1000: i += 1 functions.increment_pv_size(dss, p_step, kva_to_kw, pf, i) total_p_feederhead, total_q_feederhead, voltage_min, voltage_max = functions.get_powerflow_results( dss) if voltage_max >= v_threshold: ov_violation = True dss.lines_first() for _ in range(dss.lines_count()): if dss.lines_read_phases() == 3: dss.circuit_setactiveelement(dss.lines_read_name()) current = dss.cktelement_currentsmagang() rating_current = dss.cktelement_read_normamps() if max(current[0:12:2]) / rating_current > 1: thermal_violation = True break dss.lines_next() print( f"Overvoltage violation {ov_violation}\nThermal violation {thermal_violation}" ) penetration_level = (i - 1) * len(selected_buses) * p_step functions.increment_pv_size(dss, p_step, kva_to_kw, pf, i - 1) dss.solution_solve() total_p_feederhead, total_q_feederhead, voltage_min, voltage_max = functions.get_powerflow_results( dss) total_pv_p, total_pv_q = functions.get_total_pv_powers(dss) return penetration_level, total_pv_p, total_pv_q, total_p_feederhead, total_q_feederhead, voltage_min, voltage_max, ov_violation, thermal_violation