コード例 #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
ファイル: pqcontroller.py プロジェクト: DeanZeng/gridsim
        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')
コード例 #3
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')
コード例 #4
0
ファイル: minimalmodule.py プロジェクト: gridsim/gridsim
        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 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))
コード例 #6
0
ファイル: test_esimDLF.py プロジェクト: gridsim/gridsim
    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))
コード例 #7
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')