50 * units.meter * units.meter, 2.5 * units.metre, units.convert(celsius, units.kelvin))) outside = sim.thermal.add( TimeSeriesThermalProcess('outside', SortedConstantStepTimeSeriesObject( CSVReader('./data/example_time_series.csv')), lambda t: t * units.hours, temperature_calculator=lambda t: units.convert( units(t, units.degC), units.kelvin))) sim.thermal.add( ThermalCoupling('room to outside', 1 * units.thermal_conductivity, room, outside)) # Create a plot recorder that records the temperatures of all thermal processes. temp = PlotRecorder('temperature', units.second, units.degC) sim.record(temp, sim.thermal.find(has_attribute='temperature')) print("Running simulation...") # Run the simulation for an hour with a resolution of 1 second. sim.reset(31 * 4 * units.day) sim.run(31 * units.day, 1 * units.hours) print("Saving data...") # Create a PDF document, add the two figures of the plot recorder to the # document and close the document. FigureSaver(temp, "Temperature").save('./output/thermal-example.pdf') FigureSaver(temp, "Temperature").save('./output/thermal-example.png') CSVSaver(temp).save('./output/thermal-example.csv')
'Bus 1', GaussianRandomElectricalCPSElement('Load1', 1.6 * units.watt, 0.1 * units.watt)) esim.attach( 'Bus 2', GaussianRandomElectricalCPSElement('Load2', 2.0 * units.watt, 0.2 * units.watt)) esim.attach( 'Bus 3', GaussianRandomElectricalCPSElement('Load3', 3.7 * units.watt, 0.3 * units.watt)) esim.attach('Bus 4', ConstantElectricalCPSElement('Gen', -5.0 * units.watt)) # Create a plot recorder which records power on each bus. bus_pwr = PlotRecorder('P', units.second, units.watt) sim.record(bus_pwr, esim.find(element_class=ElectricalPQBus)) # Create a plot recorder which records power on transmission lines. line_pwr = PlotRecorder('Pij', units.second, units.watt) sim.record(line_pwr, [tl1, tl2, tl3]) # It is recommended to perform the simulator reset operation. sim.reset() print("Running simulation...") # Run the simulation for two hours with a resolution of 1 minute. total_time = 2 * units.hours delta_time = 1 * units.minutes sim.run(total_time, delta_time)
ConstantTemperatureProcess('outside', units.convert(celsius, units.kelvin))) sim.thermal.add( ThermalCoupling('room1 to outside', 10 * units.thermal_conductivity, room1, outside)) sim.thermal.add( ThermalCoupling('room2 to outside', 10 * units.thermal_conductivity, room2, outside)) sim.thermal.add( ThermalCoupling('room1 to room2', 50 * units.thermal_conductivity, room1, room2)) # Create a plot recorder that records the temperatures of all thermal processes. kelvin = PlotRecorder('temperature', units.second, units.kelvin) sim.record(kelvin, sim.thermal.find(has_attribute='temperature')) # Create a plot recorder that records the temperatures of all thermal # processes in Kelvin. celsius = PlotRecorder('temperature', units.minutes, units.degC) sim.record(celsius, sim.thermal.find(has_attribute='temperature')) # Create a second plot recorder which records all energy flows # (thermal couplings) between the different processes. flow = PlotRecorder('power', units.second, units.watt) sim.record(flow, sim.thermal.find(element_class=ThermalCoupling)) print("Running simulation...") # Run the simulation for an hour with a resolution of 1 second.
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))
# | |^^^^^^| | | # |__|heater|__| | # __|__ |__________________________| # --- # target = units(20, units.degC) # the hysteresis is a delta of temperature hysteresis = 1 * units.delta_degC thermostat = sim.controller.add( Thermostat('thermostat', units.convert(target, units.kelvin), hysteresis, room, heater, 'on')) # Create a plot recorder that records the temperatures of all thermal processes. temp = PlotRecorder('temperature', units.second, units.degC) sim.record(temp, sim.thermal.find(has_attribute='temperature')) # Create a plot recorder that records the control value of the thermostat given # to the heater. control = PlotRecorder('on', units.second, bool) sim.record(control, sim.electrical.find(has_attribute='on')) # Create a plot recorder that records the power used by the electrical heater. power = PlotRecorder('delta_energy', units.second, units.joule) sim.record(power, sim.find(friendly_name='heater')) print("Running simulation...") # Run the simulation for an hour with a resolution of 1 second. sim.reset() sim.run(5 * units.hour, units.second)
pass def calculate(self, time, delta_time): pass def update(self, time, delta_time): for el in self._elements: el.update(time, delta_time) Simulator.register_simulation_module(MyModule) # Create a simulator, add an element and record the temperature signal using # a recorder. sim = Simulator() print("Loading data...") obj = sim.my.add(MyObject("myObject", CSVReader('./data/example_time_series.csv'))) obj.convert("temperature", lambda t: units(t, units.degC)) rec = PlotRecorder('temperature', units.month, units.kelvin) sim.record(rec, obj) print("Running simulation...") sim.run(units.year, units.day) print("Saving data...") FigureSaver(rec, "Temperature").save('./output/timeseries2-example.png')
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 calculate(self, time, delta_time): pass def update(self, time, delta_time): for el in self._elements: el.update(time, delta_time) Simulator.register_simulation_module(MyModule) # Create a simulator, add an element and record the temperature signal using # a recorder. sim = Simulator() print("Loading data...") obj = sim.my.add( MyObject("myObject", CSVReader('./data/example_time_series.csv'))) obj.convert("temperature", lambda t: units(t, units.degC)) rec = PlotRecorder('temperature', units.month, units.kelvin) sim.record(rec, obj) print("Running simulation...") sim.run(units.year, units.day) print("Saving data...") FigureSaver(rec, "Temperature").save('./output/timeseries2-example.png')
# | | ___________ | | # | hot_room |]-----| coupling |-------[| cold_room | # | 60 C | | 1m2 | | | # | | |__100_W/K__| | 20 C | # |__________| <-----------> |___________| # 1m celsius = units(60, units.degC) hot_room = sim.thermal.add(ThermalProcess.room('hot_room', 50*units.meter*units.meter, 2.5*units.metre, celsius.to(units.kelvin))) celsius = units(20, units.degC) cold_room = sim.thermal.add(ThermalProcess.room('cold_room', 50*units.meter*units.meter, 2.5*units.metre, celsius.to(units.kelvin))) sim.thermal.add(ThermalCoupling('coupling', 100*units.thermal_conductivity, hot_room, cold_room)) # Add a custom console recorder to the attribute "temperature" of the hot # room thermal process. sim.record(ConsoleRecorder("temperature", units.second, units.degC), sim.thermal.find(element_class=ThermalProcess)) # Simulate sim.run(1*units.hour, 5*units.minute)
# celsius = units(60, units.degC) hot_room = sim.thermal.add(ThermalProcess.room('hot_room', 50*units.meter*units.meter, 2.5*units.metre, celsius.to(units.kelvin))) celsius = units(20, units.degC) cold_room = sim.thermal.add(ThermalProcess.room('cold_room', 50*units.meter*units.meter, 2.5*units.metre, celsius.to(units.kelvin))) sim.thermal.add(ThermalCoupling('coupling', 100*units.thermal_conductivity, hot_room, cold_room)) # Add the temperature recorder. temperature_recorder = PlotRecorder('temperature', units.second, units.degC) sim.record(temperature_recorder, sim.thermal.find(instance_of=ThermalProcess)) # Add the power recorder. power_recorder = PlotRecorder('power', units.second, units.watt) sim.record(power_recorder, sim.thermal.find(instance_of=ThermalCoupling)) # Simulate sim.run(1*units.hours, 10*units.minutes) CSVSaver(temperature_recorder).save("./output/temp.csv")
# | 60 C | |__100_W/K__| | 20 C | # |__________| <-----------> |___________| # 1m # celsius = units(60, units.degC) hot_room = sim.thermal.add( ThermalProcess.room('hot_room', 50 * units.meter * units.meter, 2.5 * units.metre, celsius.to(units.kelvin))) celsius = units(20, units.degC) cold_room = sim.thermal.add( ThermalProcess.room('cold_room', 50 * units.meter * units.meter, 2.5 * units.metre, celsius.to(units.kelvin))) sim.thermal.add( ThermalCoupling('coupling', 100 * units.thermal_conductivity, hot_room, cold_room)) # Add the temperature recorder. temperature_recorder = PlotRecorder('temperature', units.second, units.degC) sim.record(temperature_recorder, sim.thermal.find(instance_of=ThermalProcess)) # Add the power recorder. power_recorder = PlotRecorder('power', units.second, units.watt) sim.record(power_recorder, sim.thermal.find(instance_of=ThermalCoupling)) # Simulate sim.run(1 * units.hours, 10 * units.minutes) CSVSaver(temperature_recorder).save("./output/temp.csv")
celsius = units(20, units.degC) room = sim.thermal.add(ThermalProcess.room('room', 50*units.meter*units.meter, 2.5*units.metre, units.convert(celsius, units.kelvin))) outside = sim.thermal.add( TimeSeriesThermalProcess('outside', SortedConstantStepTimeSeriesObject(CSVReader('./data/example_time_series.csv')), lambda t: t*units.hours, temperature_calculator= lambda t: units.convert(units(t, units.degC), units.kelvin))) sim.thermal.add(ThermalCoupling('room to outside', 1*units.thermal_conductivity, room, outside)) # Create a plot recorder that records the temperatures of all thermal processes. temp = PlotRecorder('temperature', units.second, units.degC) sim.record(temp, sim.thermal.find(has_attribute='temperature')) print("Running simulation...") # Run the simulation for an hour with a resolution of 1 second. sim.reset(31*4*units.day) sim.run(31*units.day, 1*units.hours) print("Saving data...") # Create a PDF document, add the two figures of the plot recorder to the # document and close the document. FigureSaver(temp, "Temperature").save('./output/thermal-example.pdf') FigureSaver(temp, "Temperature").save('./output/thermal-example.png') CSVSaver(temp).save('./output/thermal-example.csv')
esim.connect('Branch 4-2', esim.bus('Bus 4'), esim.bus('Bus 2'), ElectricalGenTransformer('Tap 2', complex(1.05), 0.015*units.ohm)) # attach electrical elements to buses, electrical elements are automatically # added to simulator esim.attach('Bus 1', GaussianRandomElectricalCPSElement('Load1', 1.6*units.watt, 0.1*units.watt)) esim.attach('Bus 2', GaussianRandomElectricalCPSElement('Load2', 2.0*units.watt, 0.2*units.watt)) esim.attach('Bus 3', GaussianRandomElectricalCPSElement('Load3', 3.7*units.watt, 0.3*units.watt)) esim.attach('Bus 4', ConstantElectricalCPSElement('Gen', -5.0*units.watt)) # Create a plot recorder which records power on each bus. bus_pwr = PlotRecorder('P', units.second, units.watt) sim.record(bus_pwr, esim.find(element_class=ElectricalPQBus)) # Create a plot recorder which records power on transmission lines. line_pwr = PlotRecorder('Pij', units.second, units.watt) sim.record(line_pwr, [tl1, tl2, tl3]) # It is recommended to perform the simulator reset operation. sim.reset() print("Running simulation...") # Run the simulation for two hours with a resolution of 1 minute. total_time = 2*units.hours delta_time = 1*units.minutes sim.run(total_time, delta_time)
# |__|heater|__| | # __|__ |__________________________| # --- # target = units(20, units.degC) # the hysteresis is a delta of temperature hysteresis = 1*units.delta_degC thermostat = sim.controller.add(Thermostat('thermostat', units.convert(target, units.kelvin), hysteresis, room, heater, 'on')) # Create a plot recorder that records the temperatures of all thermal processes. temp = PlotRecorder('temperature', units.second, units.degC) sim.record(temp, sim.thermal.find(has_attribute='temperature')) # Create a plot recorder that records the control value of the thermostat given # to the heater. control = PlotRecorder('on', units.second, bool) sim.record(control, sim.electrical.find(has_attribute='on')) # Create a plot recorder that records the power used by the electrical heater. power = PlotRecorder('delta_energy', units.second, units.joule) sim.record(power, sim.find(friendly_name='heater')) print("Running simulation...") # Run the simulation for an hour with a resolution of 1 second. sim.reset() sim.run(5 * units.hour, units.second)
outside = sim.thermal.add( ConstantTemperatureProcess('outside', units.convert(celsius, units.kelvin))) sim.thermal.add(ThermalCoupling('room1 to outside', 10*units.thermal_conductivity, room1, outside)) sim.thermal.add(ThermalCoupling('room2 to outside', 10*units.thermal_conductivity, room2, outside)) sim.thermal.add(ThermalCoupling('room1 to room2', 50*units.thermal_conductivity, room1, room2)) # Create a plot recorder that records the temperatures of all thermal processes. kelvin = PlotRecorder('temperature', units.second, units.kelvin) sim.record(kelvin, sim.thermal.find(has_attribute='temperature')) # Create a plot recorder that records the temperatures of all thermal # processes in Kelvin. celsius = PlotRecorder('temperature', units.minutes, units.degC) sim.record(celsius, sim.thermal.find(has_attribute='temperature')) # Create a second plot recorder which records all energy flows # (thermal couplings) between the different processes. flow = PlotRecorder('power', units.second, units.watt) sim.record(flow, sim.thermal.find(element_class=ThermalCoupling)) print("Running simulation...") # Run the simulation for an hour with a resolution of 1 second.
# Setup topology (For simplicity we just take a trivial thermal simulation): # __________ ___________ # | | ___________ | | # | hot_room |]-----| coupling |-------[| cold_room | # | 60 C | | 1m2 | | | # | | |__100_W/K__| | 20 C | # |__________| <-----------> |___________| # 1m celsius = units(60, units.degC) hot_room = sim.thermal.add( ThermalProcess.room('hot_room', 50 * units.meter * units.meter, 2.5 * units.metre, celsius.to(units.kelvin))) celsius = units(20, units.degC) cold_room = sim.thermal.add( ThermalProcess.room('cold_room', 50 * units.meter * units.meter, 2.5 * units.metre, celsius.to(units.kelvin))) sim.thermal.add( ThermalCoupling('coupling', 100 * units.thermal_conductivity, hot_room, cold_room)) # Add a custom console recorder to the attribute "temperature" of the hot # room thermal process. sim.record(ConsoleRecorder("temperature", units.second, units.degC), sim.thermal.find(element_class=ThermalProcess)) # Simulate sim.run(1 * units.hour, 5 * units.minute)