Esempio n. 1
0
from gridsim.util import Position
from gridsim.simulation import Simulator
from gridsim.electrical.core import AbstractElectricalCPSElement
from gridsim.electrical.network import ElectricalSlackBus
from gridsim.thermal.element import ThermalProcess

# Create the simulation.
sim = Simulator()

# Here you could create the topology of the actual simulation...
# ...

# Get all elements of the electrical simulation module
#   (Both statements do exactly the same).
print sim.find(module='electrical')
print sim.electrical.find()

# Get the electrical slack bus.
print sim.electrical.find(element_class=ElectricalSlackBus)

# Get all electrical consumer/producer/storage elements.
print sim.electrical.find(instance_of=AbstractElectricalCPSElement)

# Get the element with friendly name 'bus23'.
print sim.find(friendly_name='bus23')

# Get all elements which have the 'temperature' attribute.
print sim.find(has_attribute='temperature')

# Get all elements of the simulation that are close (1km)
#   to a given point (Route du rawyl 47, Sion).
Esempio n. 2
0
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)

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/thermostat-fig1.pdf')
FigureSaver(control, "Control").save('./output/thermostat-fig2.png')
FigureSaver(power, "Power").save('./output/thermostat-fig3.png')
Esempio n. 3
0
                                           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)

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/thermostat-fig1.pdf')
FigureSaver(control, "Control").save('./output/thermostat-fig2.png')
FigureSaver(power, "Power").save('./output/thermostat-fig3.png')