예제 #1
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')
예제 #2
0
from gridsim.simulation import Simulator
from .simulation import ControllerSimulator

Simulator.register_simulation_module(ControllerSimulator)
예제 #3
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)
예제 #4
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)

예제 #5
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')
예제 #6
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...")
예제 #7
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))
예제 #8
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...")
예제 #9
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)