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))
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))
from gridsim.unit import units from gridsim.simulation import Simulator # Create the main simulator object. sim = Simulator() # Build topology using the different simulation modules... # Reset the simulation. sim.reset() # Do a single step of 100ms. sim.step(100 * units.milliseconds) # Run the simulation from the sim.run(1 * units.hours, 100 * units.milliseconds)