Exemple #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
Exemple #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))
Exemple #3
0
        return 'my'

    def all_elements(self):
        return []

    def reset(self):
        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...")
Exemple #4
0
The :mod:`gridsim.electrical` module implements the electrical part of the
gridsim simulator. It basically manages Consuming-Producing-Storing (CPS)
Elements, which consume (positive sign) and/or produce (negative sign) a
certain amount of energy (``delta_energy``) at each simulation step.

CPS elements may be attach to buses of an electrical power network, which is
also made of branches as connections between buses.

*Example*:

.. literalinclude:: ../../demo/loadflow.py
    :linenos:

shows a pure electrical example made of a reference 5-bus network
(see e.g. Xi-Fan Wang, Yonghua Song, Malcolm Irving, Modern power systems
analysis), to the non-slack buses of which are attached 4 CPS elements :
1 with constant power, production, 3 with random gaussian distributed power
consumption.

Here is the class diagram of the electrical package:

.. figure:: ./figures/model-electrical.png
    :align: center
    :scale: 100 %

"""
from gridsim.simulation import Simulator
from .simulation import ElectricalSimulator

Simulator.register_simulation_module(ElectricalSimulator)
Exemple #5
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')
Exemple #6
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)

Exemple #7
0
from gridsim.simulation import Simulator
from gridsim.unit import units
from gridsim.electrical.network import ElectricalPVBus, ElectricalPQBus,\
    ElectricalTransmissionLine, ElectricalGenTransformer
from gridsim.electrical.element import GaussianRandomElectricalCPSElement, \
    ConstantElectricalCPSElement
from gridsim.recorder import PlotRecorder
from gridsim.electrical.loadflow import DirectLoadFlowCalculator

from gridsim.iodata.output import FigureSaver

# Create the simulation.
sim = Simulator()
esim = sim.electrical
esim.load_flow_calculator = DirectLoadFlowCalculator()

# add buses to simulator
# slack bus has been automatically added
esim.add(ElectricalPQBus('Bus 1'))
esim.add(ElectricalPQBus('Bus 2'))
esim.add(ElectricalPQBus('Bus 3'))
esim.add(ElectricalPVBus('Bus 4'))

# add branches to simulator
# this operation directly connects them to buses, buses have to be already added
# variant 1
esim.connect(
    'Branch 5-3', esim.bus('Slack Bus'), esim.bus('Bus 3'),
    ElectricalGenTransformer('Tap 1', complex(1.05), 0.03 * units.ohm))
tl1 = esim.connect(
    'Branch 3-1', esim.bus('Bus 3'), esim.bus('Bus 1'),
Exemple #8
0
.. literalinclude:: ../../demo/thermal.py
    :linenos:

* On line 11 we create a new simulation.
* On lines 22 to 35 we create a very simple thermal process with one room and
  the outside temperature from a data file.
* On line 38 we create a plot recorder and on line 39 we record all temperatures
  using the plot recorder.
* On line 44 & 45 we initialize the simulation and start the simulation for the
  month avril with a resolution of 1 hour.
* On linea 51 to 53 we save the data in several formats.

The figure looks like this one:

.. figure:: ../../demo/output/thermal-example.png
            :align: center

Here is the class diagram of the thermal package:

.. figure:: ./figures/model-thermal.png
    :align: center
    :scale: 100 %

"""

from gridsim.simulation import Simulator
from .simulation import ThermalSimulator

Simulator.register_simulation_module(ThermalSimulator)
Exemple #9
0
from gridsim.unit import units

from gridsim.simulation import Simulator
from gridsim.recorder import PlotRecorder
from gridsim.thermal.core import ThermalProcess, ThermalCoupling
from gridsim.iodata.output import CSVSaver

# Create a simulation.
sim = Simulator()

# Setup topology (For simplicity we just take a trivial thermal simulation):
#           __________                             ___________
#          |          |       ___________         |           |
#          | hot_room |]-----| coupling  |-------[| cold_room |
#          |          |      |    1m2    |        |           |
#          |   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,
Exemple #10
0
from gridsim.unit import units

from gridsim.simulation import Simulator
from gridsim.recorder import PlotRecorder
from gridsim.thermal.core import ThermalProcess, ThermalCoupling
from gridsim.iodata.output import CSVSaver

# Create a simulation.
sim = Simulator()

# Setup topology (For simplicity we just take a trivial thermal simulation):
#           __________                             ___________
#          |          |       ___________         |           |
#          | hot_room |]-----| coupling  |-------[| cold_room |
#          |          |      |    1m2    |        |           |
#          |   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)))
Exemple #11
0
from gridsim.unit import units
from gridsim.simulation import Simulator
from gridsim.recorder import PlotRecorder
from gridsim.thermal.core import ThermalProcess, ThermalCoupling
from gridsim.thermal.element import TimeSeriesThermalProcess
from gridsim.timeseries import SortedConstantStepTimeSeriesObject
from gridsim.iodata.input import CSVReader
from gridsim.iodata.output import FigureSaver, CSVSaver

# Gridsim simulator.
sim = Simulator()

# Create a simple thermal process: A room thermal coupling between the room and
# the outside temperature.
#    ___________
#   |           |
#   |   room    |
#   |    20 C   |            outside <= example time series (CSV) file
#   |           |]- 3 W/K
#   |___________|
#
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)))
Exemple #12
0
from gridsim.simulation import Simulator
from gridsim.unit import units
from gridsim.electrical.network import ElectricalPVBus, ElectricalPQBus,\
    ElectricalTransmissionLine, ElectricalGenTransformer
from gridsim.electrical.element import GaussianRandomElectricalCPSElement, \
    ConstantElectricalCPSElement
from gridsim.recorder import PlotRecorder
from gridsim.electrical.loadflow import DirectLoadFlowCalculator

from gridsim.iodata.output import FigureSaver

# Create the simulation.
sim = Simulator()
esim = sim.electrical
esim.load_flow_calculator = DirectLoadFlowCalculator()

# add buses to simulator
# slack bus has been automatically added
esim.add(ElectricalPQBus('Bus 1'))
esim.add(ElectricalPQBus('Bus 2'))
esim.add(ElectricalPQBus('Bus 3'))
esim.add(ElectricalPVBus('Bus 4'))

# add branches to simulator
# this operation directly connects them to buses, buses have to be already added
# variant 1
esim.connect('Branch 5-3', esim.bus('Slack Bus'), esim.bus('Bus 3'),
             ElectricalGenTransformer('Tap 1', complex(1.05), 0.03*units.ohm))
tl1 = esim.connect('Branch 3-1', esim.bus('Bus 3'), esim.bus('Bus 1'),
                   ElectricalTransmissionLine('Line 1',
                                              1.0*units.metre,
Exemple #13
0
    def reset(self):
        super(ElectroThermalHeaterCooler, self).reset()
        self.on = False

    def calculate(self, time, delta_time):
        self._internal_delta_energy = self.power * delta_time
        if not self.on:
            self._internal_delta_energy = 0

    def update(self, time, delta_time):
        super(ElectroThermalHeaterCooler, self).update(time, delta_time)
        self._thermal_process.add_energy(
            self._delta_energy * self._efficiency_factor)

# Gridsim simulator.
sim = Simulator()
sim.electrical.load_flow_calculator = DirectLoadFlowCalculator()

# Create a simple thermal process: A room and a thermal coupling between the
# room and the outside temperature.
#    ___________
#   |           |
#   |   room    |
#   |    20 C   |            outside <= example time series (CSV) file
#   |           |]- 3 W/K
#   |___________|
#
# The room has a surface of 50m2 and a height of 2.5m.
celsius = units(20, units.degC)
room = sim.thermal.add(ThermalProcess.room('room',
                                           50*units.meter*units.meter,
Exemple #14
0
from gridsim.unit import units
from gridsim.simulation import Simulator
from gridsim.thermal.core import ThermalCoupling, ThermalProcess
from gridsim.thermal.element import ConstantTemperatureProcess
from gridsim.recorder import PlotRecorder
from gridsim.iodata.output import FigureSaver, CSVSaver

# Gridsim simulator.
sim = Simulator()

# Create a simple thermal process: Two rooms and the thermal coupling between
# them and to the outside temperature.
#             __________                        ___________
#           |          |   ________________   |           |
#           |   room1  |]-| room1 to room2 |-[| cold_room |
#           |    18 C  |  |_____50_W/K_____|  |    25 C   |      outside 5 C
#  10 W/K -[|          |                      |           |]- 10 W/K
#           |__________|                      |___________|
#
celsius = units(18, units.degC)
room1 = sim.thermal.add(ThermalProcess.room('room1',
                                            50*units.meter*units.meter,
                                            2.5*units.metre,
                                            units.convert(celsius, units.kelvin)))
celsius = units(25, units.degC)
room2 = sim.thermal.add(ThermalProcess.room('room2',
                                            50*units.meter*units.meter,
                                            2.5*units.metre,
                                            units.convert(celsius, units.kelvin)))

celsius = units(5, units.degC)
Exemple #15
0
    def on_simulation_reset(self, subjects):
        print 'RESET, observing: ' + str(subjects)

    def on_simulation_step(self, time):
        # time is given in SI unit (i.e. second)
        print 'time = ' + str(units.convert(time * units.second,
                                            self._x_unit)) + ':'

    def on_observed_value(self, subject, time, value):
        # time and value are given in SI unit (i.e. second and kelvin)
        print '    ' + subject + '.' + self.attribute_name +\
              ' = ' + str(units.convert(value*units.kelvin, self._y_unit))


# Create simulator.
sim = Simulator()

# 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)))
Exemple #16
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')
Exemple #17
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))
Exemple #18
0
    def all_elements(self):
        return []

    def reset(self):
        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...")
Exemple #19
0
        super(ElectroThermalHeaterCooler, self).reset()
        self.on = False

    def calculate(self, time, delta_time):
        self._internal_delta_energy = self.power * delta_time
        if not self.on:
            self._internal_delta_energy = 0

    def update(self, time, delta_time):
        super(ElectroThermalHeaterCooler, self).update(time, delta_time)
        self._thermal_process.add_energy(self._delta_energy *
                                         self._efficiency_factor)


# Gridsim simulator.
sim = Simulator()
sim.electrical.load_flow_calculator = DirectLoadFlowCalculator()

# Create a simple thermal process: A room and a thermal coupling between the
# room and the outside temperature.
#    ___________
#   |           |
#   |   room    |
#   |    20 C   |            outside <= example time series (CSV) file
#   |           |]- 3 W/K
#   |___________|
#
# The room has a surface of 50m2 and a height of 2.5m.
celsius = units(20, units.degC)
room = sim.thermal.add(
    ThermalProcess.room('room',
Exemple #20
0
    def attribute_name(self):
        return 'time_test'

    def reset(self):
        for element in self.elements:
            element.reset()

    def calculate(self, time, delta_time):
        for element in self.elements:
            element.calculate(time, delta_time)

    def update(self, time, delta_time):
        for element in self.elements:
            element.update(time, delta_time)

Simulator.register_simulation_module(TimeTestModule)


class TestTime(unittest.TestCase):

    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))
Exemple #21
0
from gridsim.unit import units
from gridsim.simulation import Simulator
from gridsim.thermal.core import ThermalCoupling, ThermalProcess
from gridsim.thermal.element import ConstantTemperatureProcess
from gridsim.recorder import PlotRecorder
from gridsim.iodata.output import FigureSaver, CSVSaver

# Gridsim simulator.
sim = Simulator()

# Create a simple thermal process: Two rooms and the thermal coupling between
# them and to the outside temperature.
#             __________                        ___________
#           |          |   ________________   |           |
#           |   room1  |]-| room1 to room2 |-[| cold_room |
#           |    18 C  |  |_____50_W/K_____|  |    25 C   |      outside 5 C
#  10 W/K -[|          |                      |           |]- 10 W/K
#           |__________|                      |___________|
#
celsius = units(18, units.degC)
room1 = sim.thermal.add(
    ThermalProcess.room('room1',
                        50 * units.meter * units.meter, 2.5 * units.metre,
                        units.convert(celsius, units.kelvin)))
celsius = units(25, units.degC)
room2 = sim.thermal.add(
    ThermalProcess.room('room2',
                        50 * units.meter * units.meter, 2.5 * units.metre,
                        units.convert(celsius, units.kelvin)))

celsius = units(5, units.degC)
Exemple #22
0
        super(ConsoleRecorder, self).__init__(attribute_name, x_unit, y_unit)

    def on_simulation_reset(self, subjects):
        print 'RESET, observing: ' + str(subjects)

    def on_simulation_step(self, time):
        # time is given in SI unit (i.e. second)
        print 'time = ' + str(units.convert(time*units.second, self._x_unit)) + ':'

    def on_observed_value(self, subject, time, value):
        # time and value are given in SI unit (i.e. second and kelvin)
        print '    ' + subject + '.' + self.attribute_name +\
              ' = ' + str(units.convert(value*units.kelvin, self._y_unit))

# Create simulator.
sim = Simulator()

# 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)))
Exemple #23
0
from gridsim.unit import units
from gridsim.simulation import Simulator
from gridsim.recorder import PlotRecorder
from gridsim.thermal.core import ThermalProcess, ThermalCoupling
from gridsim.thermal.element import TimeSeriesThermalProcess
from gridsim.timeseries import SortedConstantStepTimeSeriesObject
from gridsim.iodata.input import CSVReader
from gridsim.iodata.output import FigureSaver, CSVSaver

# Gridsim simulator.
sim = Simulator()

# Create a simple thermal process: A room thermal coupling between the room and
# the outside temperature.
#    ___________
#   |           |
#   |   room    |
#   |    20 C   |            outside <= example time series (CSV) file
#   |           |]- 3 W/K
#   |___________|
#
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,
Exemple #24
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).
Exemple #25
0
from gridsim.simulation import Simulator
from .simulation import ControllerSimulator

Simulator.register_simulation_module(ControllerSimulator)
Exemple #26
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)