Exemple #1
0
def test_center_tap_load_writing():
    """
    Tests the writing of center tap loads.
    """
    from ditto.models.load import Load
    from ditto.models.phase_load import PhaseLoad

    m = Store()
    l = Load(m)
    l.name = "load1"
    l.is_center_tap = 1
    l.center_tap_perct_1_N = .5
    l.center_tap_perct_N_2 = .5
    l.center_tap_perct_1_2 = 0

    pl = PhaseLoad(m)
    pl.p = 10
    pl.q = 8
    pl.phase = "C"
    l.phase_loads.append(pl)

    w = Writer(output_path=current_directory)
    w.write(m)

    with open(os.path.join(current_directory, "loads.txt"), "r") as fp:
        lines = fp.readlines()

    assert lines[
        -1] == ",SPOT,0,C,,,0,PQ,50.0,50.0,0.005,0.004,0.005,0.004,0\n"

    # Cleaning
    os.remove(os.path.join(current_directory, "loads.txt"))
    os.remove(os.path.join(current_directory, "equipment.txt"))
    os.remove(os.path.join(current_directory, "network.txt"))
def test_opendss_to_cyme():
    '''
        Test the OpenDSS to Cyme conversion.
    '''
    from ditto.readers.opendss.read import Reader
    from ditto.store import Store
    from ditto.writers.cyme.write import Writer

    opendss_models = [
        f for f in os.listdir(
            os.path.join(current_directory, 'data/small_cases/opendss/'))
        if not f.startswith('.')
    ]
    for model in opendss_models:
        m = Store()
        r = Reader(master_file=os.path.join(
            current_directory,
            'data/small_cases/opendss/{model}/master.dss'.format(model=model)),
                   buscoordinates_file=os.path.join(
                       current_directory,
                       'data/small_cases/opendss/{model}/buscoord.dss'.format(
                           model=model)))
        r.parse(m)
        m.set_names()
        #TODO: Log properly
        print('>OpenDSS model {model} read...'.format(model=model))
        output_path = tempfile.TemporaryDirectory()
        w = Writer(output_path=output_path.name, log_path=output_path)
        w.write(m)
        #TODO: Log properly
        print('>...and written to CYME.\n')
    def apply(cls, stack, output_path, base_dir=None):
        if base_dir and (not os.path.exists(output_path)):
            output_path = os.path.join(base_dir, output_path)

        logger.info('Writing {!r} out to {!r}.'.format(stack.model,
                                                       output_path))
        writer = CymeWriter(output_path=output_path, log_path=output_path)
        writer.write(stack.model)
        return True
def main():
    '''
    Conversion example of a relatively large test system: the EPRI J1 feeder.
    OpenDSS ---> CYME example.
    This example uses the dss files located in tests/data/big_cases/opendss/epri_j1
    '''

    #Path settings (assuming it is run from examples folder)
    #Change this if you wish to use another system
    path = '../tests/data/big_cases/opendss/epri_j1'

    ###############################
    #  STEP 1: READ FROM OPENDSS  #
    ###############################
    #
    #Create a Store object
    print('>>> Creating empty model...')
    model = Store()

    #Instanciate a Reader object
    r = Reader(master_file=os.path.join(path, 'master.dss'),
               buscoordinates_file=os.path.join(path, 'buscoords.dss'))

    #Parse (can take some time for large systems...)
    print('>>> Reading from OpenDSS...')
    start = time.time()  #basic timer
    r.parse(model)
    end = time.time()
    print('...Done (in {} seconds'.format(end - start))

    ###########################
    #  STEP 2: WRITE TO CYME  #
    ###########################
    #
    #Instanciate a Writer object
    w = Writer(output_path='./')

    #Write to CYME (can also take some time for large systems...)
    print('>>> Writing to CYME...')
    start = time.time()  #basic timer
    w.write(model)
    end = time.time()
    print('...Done (in {} seconds'.format(end - start))
Exemple #5
0
def test_ephasor_writer():
    from ditto.writers.ephasor.write import Writer
    from ditto.models.node import Node
    from ditto.models.line import Line
    from ditto.models.load import Load
    from ditto.models.regulator import Regulator
    from ditto.models.wire import Wire
    from ditto.models.capacitor import Capacitor
    from ditto.models.powertransformer import PowerTransformer
    from ditto.models.winding import Winding
    from ditto.models.phase_winding import PhaseWinding
    from ditto.store import Store
    from ditto.models.base import Unicode
    from ditto.models.power_source import PowerSource
    from ditto.models.feeder_metadata import Feeder_metadata

    m = Store()
    src = PowerSource(
        m,
        name="f1_src",
        phases=[Unicode("A"), Unicode("B"),
                Unicode("C")],
        nominal_voltage=12470,
        connecting_element="n1",
        is_sourcebus=True,
    )
    meta = Feeder_metadata(m,
                           name="f1",
                           nominal_voltage=12470,
                           headnode="f1_src",
                           substation="f1_src")
    node1 = Node(m, name="n1", feeder_name="f1")
    node2 = Node(m, name="n2", feeder_name="f1")
    node3 = Node(m, name="n3", feeder_name="f1")
    wirea = Wire(m, gmr=1.3, X=2, Y=20)
    wiren = Wire(m, gmr=1.2, X=2, Y=20)
    line1 = Line(
        m,
        name="l1",
        wires=[wirea, wiren],
        from_element="n1",
        to_element="n2",
        feeder_name="f1",
    )
    load1 = Load(m, name="load1", feeder_name="f1")

    phase_winding = PhaseWinding(m, phase=u"A")

    winding1 = Winding(
        m,
        phase_windings=[phase_winding],
        connection_type="Y",
        nominal_voltage=12.47,
        rated_power=25,
        resistance=10,
    )
    winding2 = Winding(
        m,
        phase_windings=[phase_winding],
        connection_type="Y",
        nominal_voltage=6.16,
        rated_power=25,
        resistance=10,
    )
    transformer1 = PowerTransformer(
        m,
        name="t1",
        from_element="n2",
        to_element="n3",
        windings=[winding1, winding2],
        feeder_name="f1",
    )
    transformer1.reactances.append(6)
    # reg1 = Regulator(m, name='t1_reg', connected_transformer='t1', connected_winding=2, pt_ratio=60, delay=2)
    # cap1 = Capacitor(m, name='cap1', connecting_element='n2', num_phases=3, nominal_voltage=7.2, var=300, connection_type='Y')
    m.set_names()
    t = tempfile.TemporaryDirectory()
    writer = Writer(output_path=t.name, log_path="./")
    writer.write(m)
Exemple #6
0
def test_opendss_writer():
    from ditto.writers.opendss.write import Writer
    from ditto.models.node import Node
    from ditto.models.line import Line
    from ditto.models.load import Load
    from ditto.models.regulator import Regulator
    from ditto.models.wire import Wire
    from ditto.models.capacitor import Capacitor
    from ditto.models.powertransformer import PowerTransformer
    from ditto.models.winding import Winding

    # from ditto.model import Model
    from ditto.store import Store
    from ditto.models.storage import Storage
    from ditto.models.phase_storage import PhaseStorage
    from ditto.models.base import Unicode
    from ditto.models.base import Float
    from ditto.models.power_source import PowerSource
    from ditto.models.phase_load import PhaseLoad

    m = Store()
    node1 = Node(m, name="n1")
    node2 = Node(m, name="n2")
    node3 = Node(m, name="n3")
    wirea = Wire(m, gmr=1.3, X=2, Y=20)
    wiren = Wire(m, gmr=1.2, X=2, Y=20)
    line1 = Line(m, name="l1", wires=[wirea, wiren])
    phase_load1 = PhaseLoad(m, p=5400, q=2615.3394)
    load1 = Load(m, name="load1", phase_loads=[phase_load1])

    winding1 = Winding(
        m,
        connection_type="W",
        nominal_voltage=12.47,
        rated_power=25,
    )
    winding2 = Winding(
        m,
        connection_type="W",
        nominal_voltage=6.16,
        rated_power=25,
    )
    transformer1 = PowerTransformer(
        m,
        name="t1",
        from_element="n2",
        to_element="n3",
        windings=[winding1, winding2],
        feeder_name="f1",
    )
    transformer1.reactances.append(6)
    reg1 = Regulator(
        m,
        name="t1_reg",
        connected_transformer="t1",
        pt_ratio=60,
        delay=2,
    )
    cap1 = Capacitor(
        m,
        name="cap1",
        nominal_voltage=7.2,
        connection_type="Y",
    )
    print(line1.impedance_matrix)

    # Storage testing
    phase_storage_A = PhaseStorage(m, phase="A", p=15.0, q=5.0)
    phase_storage_B = PhaseStorage(m, phase="B", p=16.0, q=6.0)
    storage = Storage(
        m,
        name="store1",
        connecting_element="n3",
        nominal_voltage=12470.0,
        rated_power=10000.0,
        rated_kWh=100.0,
        stored_kWh=75.5,
        reserve=20.0,
        discharge_rate=25.0,
        charge_rate=18.7,
        charging_efficiency=15.3,
        discharging_efficiency=22.0,
        resistance=20,
        reactance=10,
        model_=1,
        phase_storages=[phase_storage_A, phase_storage_B],
    )

    # PV systems testing
    PV_system = PowerSource(
        m,
        name="PV1",
        is_sourcebus=False,
        nominal_voltage=12470,
        phases=[Unicode("A"), Unicode("C")],
        rated_power=20000.0,
        connection_type="D",
        cutout_percent=30.0,
        cutin_percent=15.3,
        resistance=14.0,
        reactance=5.2,
        v_max_pu=100,
        v_min_pu=60,
        power_factor=0.9,
    )

    t = tempfile.TemporaryDirectory()
    writer = Writer(output_path=t.name)
    # writer.write_wiredata(m)
    # writer.write_linegeometry(m)
    # writer.write_linecodes(m)
    writer.write_storages(m)
    writer.write_PVs(m)
    writer.write_lines(m)
    writer.write_loads(m)
    writer.write_transformers(m)
    writer.write_regulators(m)
    writer.write_capacitors(m)