예제 #1
0
    def test_simulation_time(self):

        total_time = 1*units.hour
        delta_time = 1*units.second

        sim = Simulator()
        el = sim.time_test.add(TimeTestElement('test'))
        sim.reset()
        sim.run(total_time, delta_time)

        self.assertEqual(el.val, units.value(total_time, units.second))
        self.assertEqual(el.iter, 3601)  # from 0 to 3601 included
예제 #2
0
    '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)

print("Saving data...")

# Save the figures as images.
saver = FigureSaver(bus_pwr, "PQ Bus power")
saver.save('./output/bus_pwr.pdf')
saver = FigureSaver(line_pwr, "Line power")
saver.save('./output/line_pwr.pdf')
예제 #3
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')
예제 #4
0
    def physical_write_params(self, write_params):
        pass


if __name__ == '__main__':
    readparam = [(ParamType.READPARAM1), (ParamType.READPARAM2), (ParamType.READPARAM3)]
    writeparam = [(ParamType.WRITEPARAM1), (ParamType.WRITEPARAM2)]

    pqcontroller = PQController(readparam, writeparam)

    opcode = {'w1': (ParamType.WRITEPARAM1), 'w2': (ParamType.WRITEPARAM2)}

    pqcontroller.init_console(opcode)

    console = ConsoleCyberPhysicalSystem("consolecyberphysicalsystem")

    console.initialize(readparam, writeparam)
    console.add(pqcontroller)

    Simulator.register_simulation_module(CyberPhysicalModule)

    sim = Simulator(RealTimeExecutionManager(10 * units.seconds))

    sim.cyberphysical.add_actor_listener(console)
    sim.cyberphysical.add_module_listener(pqcontroller)

    sim.reset()
    print('start simulation')
    sim.run(10 * units.seconds, 1 * units.seconds)
    print('end simulation')
예제 #5
0
        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')
예제 #6
0
#          |          |       ___________         |           |
#          | 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)
예제 #7
0
# 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)
예제 #8
0
                        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')
예제 #9
0
#          |   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")
예제 #10
0
#
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")
예제 #11
0
파일: thermal.py 프로젝트: gridsim/gridsim
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')
예제 #12
0
파일: loadflow.py 프로젝트: gridsim/gridsim
                        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)

print("Saving data...")

# Save the figures as images.
saver = FigureSaver(bus_pwr, "PQ Bus power")
saver.save('./output/bus_pwr.pdf')
saver = FigureSaver(line_pwr, "Line power")
saver.save('./output/line_pwr.pdf')
예제 #13
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')
예제 #14
0
                                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.
sim.run(2*units.hour, 1*units.second)

print("Saving data...")

# Save the figures as images.
FigureSaver(kelvin, "Temperature (K)").save('./output/fig1.png')
FigureSaver(celsius, "Temperature (C)").save('./output/fig2.png')
FigureSaver(flow, "Flow").save('./output/fig3.png')

CSVSaver(celsius).save('./output/fig2.csv')
예제 #15
0
                    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.
sim.run(2 * units.hour, 1 * units.second)

print("Saving data...")

# Save the figures as images.
FigureSaver(kelvin, "Temperature (K)").save('./output/fig1.png')
FigureSaver(celsius, "Temperature (C)").save('./output/fig2.png')
FigureSaver(flow, "Flow").save('./output/fig3.png')

CSVSaver(celsius).save('./output/fig2.csv')
예제 #16
0
        element.id = len(self.elements)
        self.elements.append(element)
        return element

    def attribute_name(self):
        return 'minimal'

    def reset(self):
        #print 'reset'
        for element in self.elements:
            element.reset()

    def calculate(self, time, delta_time):
        #print 'calculate, time=' + str(time) + ', delta_time=' + str(delta_time)
        for element in self.elements:
            element.calculate(time, delta_time)

    def update(self, time, delta_time):
        #print 'update, time=' + str(time) + ', delta_time=' + str(delta_time)
        for element in self.elements:
            element.update(time, delta_time)

Simulator.register_simulation_module(MinimalGridsimModuleAbstract)

sim = Simulator()
sim.minimal.say_hello()
el = sim.minimal.add(MinimalSimulationElement('test'))
sim.reset()
sim.run(1*units.seconds, 250*units.milliseconds)

예제 #17
0
    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')
예제 #18
0
        pass


if __name__ == '__main__':
    readparam = [(ParamType.READPARAM1), (ParamType.READPARAM2),
                 (ParamType.READPARAM3)]
    writeparam = [(ParamType.WRITEPARAM1), (ParamType.WRITEPARAM2)]

    pqcontroller = PQController(readparam, writeparam)

    opcode = {'w1': (ParamType.WRITEPARAM1), 'w2': (ParamType.WRITEPARAM2)}

    pqcontroller.init_console(opcode)

    console = ConsoleCyberPhysicalSystem("consolecyberphysicalsystem")

    console.initialize(readparam, writeparam)
    console.add(pqcontroller)

    Simulator.register_simulation_module(CyberPhysicalModule)

    sim = Simulator(RealTimeExecutionManager(10 * units.seconds))

    sim.cyberphysical.add_actor_listener(console)
    sim.cyberphysical.add_module_listener(pqcontroller)

    sim.reset()
    print('start simulation')
    sim.run(10 * units.seconds, 1 * units.seconds)
    print('end simulation')
예제 #19
0
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)