示例#1
0
    def test_plot_recorder(self):

        recorder = PlotRecorder('power', units.minute, units.watt)

        recorder.on_simulation_reset(['foo', 'bar'])

        delta_time = units.value(1*units.minute, units.second)
        recorder.on_simulation_step(delta_time)
        recorder.on_observed_value('foo', delta_time, 14.2*units.watt)
        recorder.on_observed_value('bar', delta_time, 12*units.watt)

        delta_time = units.value(2*units.minute, units.second)
        recorder.on_simulation_step(delta_time)
        recorder.on_observed_value('foo', delta_time, 12*units.watt)
        recorder.on_observed_value('bar', delta_time, 12.1*units.watt)

        delta_time = units.value(3*units.minute, units.second)
        recorder.on_simulation_step(delta_time)
        recorder.on_observed_value('foo', delta_time, 16.1*units.watt)
        recorder.on_observed_value('bar', delta_time, 14.2*units.watt)

        delta_time = units.value(4*units.minute, units.second)
        recorder.on_simulation_step(delta_time)
        recorder.on_observed_value('foo', delta_time, 18.4*units.watt)
        recorder.on_observed_value('bar', delta_time, 9*units.watt)

        self.assertEqual(recorder.x_unit(), 'minute')
        self.assertEqual(recorder.x_values(), [1.0, 2.0, 3.0, 4.0])
        self.assertDictEqual(recorder.y_values(),
                             {'bar': [12, 12.1, 14.2, 9],
                              'foo': [14.2, 12, 16.1, 18.4]})
        self.assertEqual(recorder.y_unit(), 'watt')
示例#2
0
    def test_reference(self):

        # Initialize the Gridsim simulator and get a reference to
        # its electrical part
        sim = Simulator()
        esim = sim.electrical
        esim.load_flow_calculator = DirectLoadFlowCalculator()

        # network initialization
        #----------------------

        # add buses to simulator
        # slack bus has been automatically added
        bus1 = esim.bus('Slack Bus')
        bus2 = esim.add(ElectricalPVBus('Bus 2'))
        bus3 = esim.add(ElectricalPQBus('Bus 3'))

        # add branches to simulator
        # line length is arbitrarily set to 1.0
        bra1 = esim.connect(
            'Branch 1-2', esim.bus('Slack Bus'), esim.bus('Bus 2'),
            ElectricalTransmissionLine('Line 1', 1.0 * units.metre,
                                       0.0576 * units.ohm))
        # line length is arbitrarily set to 1.0
        bra2 = esim.connect(
            'Branch 2-3', esim.bus('Bus 2'), esim.bus('Bus 3'),
            ElectricalTransmissionLine('Line 2', 1.0 * units.metre,
                                       0.092 * units.ohm))
        # line length is arbitrarily set to 1.0
        bra3 = esim.connect(
            'Branch 1-3', esim.bus('Slack Bus'), esim.bus('Bus 3'),
            ElectricalTransmissionLine('Line 3', 1.0 * units.metre,
                                       0.17 * units.ohm))

        # input buses electrical values
        #------------------------------
        esim.attach('Bus 2',
                    ConstantElectricalCPSElement('GD2', -.53 * units.watt))
        esim.attach('Bus 3',
                    ConstantElectricalCPSElement('GD3', .9 * units.watt))

        # create recorders to collect output data
        #-----------------------------------------
        # Create a plot recorder which records active power on slack bus.
        bus_pwr = PlotRecorder('P', units.second, units.watt)
        sim.record(bus_pwr, esim.find(element_class=ElectricalSlackBus))
        # Create a plot recorder which records theta angle on each bus.
        bus_th = PlotRecorder('Th', units.second, units.radian)

        sim.record(bus_th, esim.find(has_attribute='Th'))

        # Create a plot recorder which records power flow on each branch.
        bra_pwr = PlotRecorder('Pij', units.second, units.watt)

        sim.record(bra_pwr, esim.find(element_class=ElectricalNetworkBranch))

        # make one simulation step
        #-------------------------
        sim.reset()

        sim.step(1 * units.second)

        # get values stored by recorders
        # and compare them with references
        #----------------------------------
        # slack active power

        y = bus_pwr.y_values()
        p_slack = y[bus1.friendly_name][0]

        refslack = 0.37

        self.assertEqual(
            p_slack, refslack, "The power of the slack bus is " +
            str(p_slack) + " instead of " + str(refslack))

        y = bus_th.y_values()
        # theta angles of all buses
        th = np.array([
            y[bus1.friendly_name][0], y[bus2.friendly_name][0],
            y[bus3.friendly_name][0]
        ])

        ref_th = np.array([0., -0.00254839, -0.05537872])

        for ith, iref_th in zip(th, ref_th):
            self.assertAlmostEqual(ith, iref_th)

        # power flows of all branches
        y = bra_pwr.y_values()
        pbr = np.array([
            y[bra1.friendly_name][0], y[bra2.friendly_name][0],
            y[bra3.friendly_name][0]
        ])
        ref_pbr = np.array([0.044243, 0.574243, 0.325757])

        self.assertTrue(
            np.allclose(pbr, ref_pbr), "The power of the slack bus is " +
            str(p_slack) + " instead of " + str(refslack))
示例#3
0
    def test_reference(self):

        # Initialize the Gridsim simulator and get a reference to
        # its electrical part
        sim = Simulator()
        esim = sim.electrical
        esim.load_flow_calculator = DirectLoadFlowCalculator()

        # network initialization
        #----------------------

        # add buses to simulator
        # slack bus has been automatically added
        bus1 = esim.bus('Slack Bus')
        bus2 = esim.add(ElectricalPVBus('Bus 2'))
        bus3 = esim.add(ElectricalPQBus('Bus 3'))

        # add branches to simulator
        # line length is arbitrarily set to 1.0
        bra1 = esim.connect('Branch 1-2', esim.bus('Slack Bus'),
                            esim.bus('Bus 2'),
                            ElectricalTransmissionLine('Line 1',
                            1.0*units.metre, 0.0576*units.ohm))
        # line length is arbitrarily set to 1.0
        bra2 = esim.connect('Branch 2-3', esim.bus('Bus 2'),
                            esim.bus('Bus 3'),
                            ElectricalTransmissionLine('Line 2',
                            1.0*units.metre, 0.092*units.ohm))
        # line length is arbitrarily set to 1.0
        bra3 = esim.connect('Branch 1-3', esim.bus('Slack Bus'),
                            esim.bus('Bus 3'),
                            ElectricalTransmissionLine('Line 3',
                            1.0*units.metre, 0.17*units.ohm))

        # input buses electrical values
        #------------------------------
        esim.attach('Bus 2', ConstantElectricalCPSElement('GD2', -.53*units.watt))
        esim.attach('Bus 3', ConstantElectricalCPSElement('GD3', .9*units.watt))

        # create recorders to collect output data
        #-----------------------------------------
        # Create a plot recorder which records active power on slack bus.
        bus_pwr = PlotRecorder('P', units.second, units.watt)
        sim.record(bus_pwr, esim.find(element_class=ElectricalSlackBus))
        # Create a plot recorder which records theta angle on each bus.
        bus_th = PlotRecorder('Th', units.second, units.radian)

        sim.record(bus_th, esim.find(has_attribute='Th'))

        # Create a plot recorder which records power flow on each branch.
        bra_pwr = PlotRecorder('Pij', units.second, units.watt)

        sim.record(bra_pwr, esim.find(element_class=ElectricalNetworkBranch))

        # make one simulation step
        #-------------------------
        sim.reset()

        sim.step(1*units.second)

        # get values stored by recorders
        # and compare them with references
        #----------------------------------
        # slack active power

        y = bus_pwr.y_values()
        p_slack = y[bus1.friendly_name][0]

        refslack = 0.37

        self.assertEqual(p_slack, refslack, "The power of the slack bus is "
                         + str(p_slack) + " instead of " + str(refslack))

        y = bus_th.y_values()
        # theta angles of all buses
        th = np.array([y[bus1.friendly_name][0],
                       y[bus2.friendly_name][0],
                       y[bus3.friendly_name][0]])

        ref_th = np.array([0., -0.00254839, -0.05537872])

        for ith, iref_th in zip(th, ref_th):
            self.assertAlmostEqual(ith, iref_th)

        # power flows of all branches
        y = bra_pwr.y_values()
        pbr = np.array([y[bra1.friendly_name][0],
                        y[bra2.friendly_name][0],
                        y[bra3.friendly_name][0]])
        ref_pbr = np.array([0.044243, 0.574243, 0.325757])

        self.assertTrue(np.allclose(pbr, ref_pbr),
                        "The power of the slack bus is " + str(p_slack) +
                        " instead of " + str(refslack))