Exemple #1
0
def test_case(both=False, clean=False):
    """one specified scenario, simulated"""

    clean_files()
    
    data = """
           [test_case] opf
           """
         
            # remove generator g4
            # remove generator g23
            # set all demand 0.7

    data_2 = """
             [test_case_2] pf
             """
           
    scenario = text_to_scenario(data)
    psat = read_psat("rtskillmod.m")
    report = simulate_scenario(psat, scenario, clean)
    print "result = '" + str(report_in_limits(report)) + "'"

    if both:
        # clean_files()
        
        scenario_2 = text_to_scenario(data_2)
        psat_2 = report_to_psat(report, psat)
        report_2 = simulate_scenario(psat_2, scenario_2, clean)
        print "result 2 = '" + str(report_in_limits(report_2)) + "'"
Exemple #2
0
def test_case(both=False, clean=False):
    """one specified scenario, simulated"""

    clean_files()

    data = """
           [test_case] opf
           """

    # remove generator g4
    # remove generator g23
    # set all demand 0.7

    data_2 = """
             [test_case_2] pf
             """

    scenario = text_to_scenario(data)
    psat = read_psat("rtskillmod.m")
    report = simulate_scenario(psat, scenario, clean)
    print "result = '" + str(report_in_limits(report)) + "'"

    if both:
        # clean_files()

        scenario_2 = text_to_scenario(data_2)
        psat_2 = report_to_psat(report, psat)
        report_2 = simulate_scenario(psat_2, scenario_2, clean)
        print "result 2 = '" + str(report_in_limits(report_2)) + "'"
Exemple #3
0
def test005():
    """simulate an islanded system

       by cutting all the lines across one line it is seperated. But still 
       passes he simulation. Reoving all the generators hit the multiplier 
       limit on fix_mismatch.

       A power flow is more likely to fail. Theoretically an OPF could 
       treat the two islended sections as seperate power systems and
       optimise each. Unfortunatly PF doesn't yet work!
    """

    clean_files()
    clean = False

    data = """
           [example_4] pf
             remove line a24
             remove line a19
             remove line a18
             remove line a15
           """

    scenario = text_to_scenario(data)
    psat = read_psat("rts.m")
    report = simulate_scenario(psat, scenario, clean)

    print "result = '" + str(report_in_limits(report)) + "'"
Exemple #4
0
def example3():
    """one random failure"""
    
    psat = read_psat("rts.m")
    prob = read_probabilities("rts.net")
    batch = make_failures(prob, 1)
    scenario = batch[0]
    report = simulate_scenario(psat, scenario)
    print "result =", report_in_limits(report), "."
Exemple #5
0
def example5():

    clean_files()
    clean = False

    data = """
           [base] opf
           [dead_slack] opf
             remove generator g12
           [two_dead_slack] opf
             remove generator g12
             remove generator g13
           [three_dead_slack] opf
             remove generator g12
             remove generator g15
           [four_dead_slack] opf
             remove generator g13
             remove generator g12
           [five_dead_slack] opf
             remove generator g15
             remove generator g12
           [all_dead_slack] opf
             remove generator g12
             remove generator g13
             remove generator g15
           [rem_bus_1] opf
             remove bus 1
           [rem_li_a1] opf
             remove line a1
           [rem_gen_g1] opf
             remove generator g1
           [set_double] opf
             set all demand 2.0
           [set_half] opf
             set all demand 0.5
           """

    #data = """
    #       [fail_001] pf
    #         remove generator g32
    #         remove generator g13
    #"""

    batch = SimulationBatch()
    batch.read(StringIO(data))
    psat = read_psat("rts.m")

    for scenario in batch:
        report = simulate_scenario(psat, scenario, clean)
        print "result = '" + str(report_in_limits(report)) + "'"
Exemple #6
0
def test004():
    """
    run two simulations on differnt files
    """

    clean_files()
    clean = False

    data = """
           [notused] pf
             #set all demand 0.5
           """

    scenario = text_to_scenario(data)

    psat = read_psat("rts.m")
    scenario.title = "mod1"
    report = simulate_scenario(psat, scenario, clean)
    print "first result = '" + str(report_in_limits(report)) + "'"

    psat = read_psat("rts2.m")
    scenario.title = "mod2"
    report = simulate_scenario(psat, scenario, clean)
    print "second result = '" + str(report_in_limits(report)) + "'"
Exemple #7
0
def simulate_cases(outage_batch, failure_batch, psat, summary_file,
                   mismatch_file):
    clean_files()

    print "[C] simulate %d unique states with %d unique contingencies" % (
        len(outage_batch), len(failure_batch))

    for n, scenario in enumerate(outage_batch):
        try:
            print "[C] simulating state", n + 1, "of", int(
                math.ceil(len(outage_batch)))
            report = simulate_scenario(psat, scenario, False)
            scenario_psat = report_to_psat(report, psat)
            clean_files()
            mismatch_file.write(
                as_csv("---- ---- ---- ---- ---- ----".split()) + "\n")
            mismatch_file.write(
                as_csv([scenario.title] + list(scenario_psat.get_stats())) +
                "\n")
            mismatch_file.write(
                as_csv("---- ---- ---- ---- ---- ----".split()) + "\n")
            print "[C] simulating state - prep done."

            for x in failure_batch:
                x.result = None

            batch_simulate(failure_batch, scenario_psat, 100, True,
                           mismatch_file)

            filename = scenario.title + ".txt"
            with open(filename, "w") as result_file:
                failure_batch.csv_write(result_file)

            print "-" * 80
            print "---- Outage Case %d Stats ----" % n
            failure_batch.write_stats(sys.stdout)
            summary_file.write("Outage Case %d Stats\n" % n)
            summary_file.write("%s\n" % ("-" * 80))
            failure_batch.write_stats(summary_file)

            print "[C] simulating state", n + 1, "done"
        except Exception as exce:
            print "[E] Error Caught at main.simulate_cases (%s)" % scenario.title
            print exce
            raise
Exemple #8
0
def example4():
    """one specified scenario, simulated"""

    clean_files()
    clean = False

    data = """
           [example_4] opf
remove generator g12
           """
           
    #remove generator g33
    #set all demand 0.7686144
    #remove bus 6
             
    scenario = text_to_scenario(data)
    psat = read_psat("rts.m")
    report = simulate_scenario(psat, scenario, clean)

    print "result = '" + str(report_in_limits(report)) + "'"
Exemple #9
0
def simulate_cases(outage_batch, failure_batch, psat, summary_file, mismatch_file):
    clean_files()

    print "[C] simulate %d unique states with %d unique contingencies" % (
                                                        len(outage_batch),
                                                        len(failure_batch))
    
    for n, scenario in enumerate(outage_batch):
        try:
            print "[C] simulating state", n + 1, "of", int(math.ceil(len(outage_batch)))
            report = simulate_scenario(psat, scenario, False)
            scenario_psat = report_to_psat(report, psat)
            clean_files()
            mismatch_file.write(as_csv("---- ---- ---- ---- ---- ----".split()) + "\n")
            mismatch_file.write(as_csv([scenario.title] + list(scenario_psat.get_stats())) + "\n")
            mismatch_file.write(as_csv("---- ---- ---- ---- ---- ----".split()) + "\n")
            print "[C] simulating state - prep done."

            for x in failure_batch:
                x.result = None

            batch_simulate(failure_batch, scenario_psat, 100, True, mismatch_file)
            
            filename = scenario.title + ".txt"
            with open(filename, "w") as result_file:
                failure_batch.csv_write(result_file)
            
            print "-" * 80
            print "---- Outage Case %d Stats ----" % n
            failure_batch.write_stats(sys.stdout)
            summary_file.write("Outage Case %d Stats\n" % n)
            summary_file.write("%s\n" % ("-"*80))
            failure_batch.write_stats(summary_file)
            
            print "[C] simulating state", n + 1, "done"
        except Exception as exce:
            print "[E] Error Caught at main.simulate_cases (%s)" % scenario.title
            print exce
            raise
Exemple #10
0
def test007():
    """batch and single should gave same results"""
    
    clean_files()

    psat = read_psat("rts2.m")
    # prob = read_probabilities("rts.net")
    # batch = make_outages(prob, 2)

    data = """
[batch0] opf
  remove generator g1
  remove generator g4
  remove generator g31
  set all demand 0.3987456
  result pass
[batch1] opf
  remove generator g22
  remove generator g24
  set all demand 0.6670332
  result fail
           """

    batch = SimulationBatch()
    batch.read(StringIO(data))

    batch_simulate(batch, psat, 10, False)

    with open("rts.bch", "w") as result_file:
        batch.write(result_file)

    for n, scenario in enumerate(batch):
        scenario.title = "single" + str(n)
        report = simulate_scenario(psat, scenario, False) 
        scenario.result = report_in_limits(report)
    
    with open("rts2.bch", "w") as result_file:
        batch.write(result_file)
Exemple #11
0
 def sim(psat, scenario_text):
     scenario = text_to_scenario(scenario_text)
     return simulate_scenario(psat, scenario, clean)