Esempio n. 1
0
    def test_convert(self):

        m = 3000*units.metre
        km = 3*units.kilometre

        g = 10*units.gram
        kg = 0.01*units.kilogram

        self.assertEqual(km, m)
        self.assertEqual(kg, g)

        self.assertEqual(units.convert(m, units.kilometer), km)
        self.assertEqual(units.convert(m, "kilometer"), 3.*units.km)
        self.assertRaises(DimensionalityError, self._convert, m, g)
Esempio n. 2
0
    def __init__(self, friendly_name, time_series, time_converter=None,
                 power_calculator=lambda t: units.convert(t, units.watt)):
        """
        __init__(self, friendly_name, reader, stream)

        This class provides a Consuming-Producing-Storing element whose consumed
        or produced power is read from a stream by the given reader.

        The presence of a column named `column_name` is assumed in the
        :class:`.TimeSeries`.

        :param friendly_name: Friendly name for the element.
            Should be unique within the simulation module.
        :type friendly_name: str
        :param time_series: The time series
        :type time_series: :class:`.TimeSeries`
        """
        super(TimeSeriesElectricalCPSElement, self).__init__(friendly_name)

        self._time_series = time_series
        self._time_series.load(time_converter=time_converter)

        self._power_calculator = power_calculator

        self._time_series.convert('power', self._power_calculator)

        self.calculate(0, 0)
Esempio n. 3
0
    def __init__(self, friendly_name, time_series, time_converter=None,
                 temperature_calculator=lambda t: units.convert(t, units.kelvin),
                 position=Position()):
        """
        __init__(self, friendly_name, time_series, stream, time_converter=None, temperature_calculator=lambda t: units.convert(t, units.kelvin), position=Position())

        Thermal process that reads the temperature out of a time series object
        (CSV file). It has an infinite thermal capacity.

        .. warning::

            It is important that the given data contains the
            field 'temperature' or you map a field to the attribute
            'temperature' using the function :func:`gridsim.timeseries.TimeSeriesObject.map_attribute()`.

        :param friendly_name: Friendly name to give to the process.
        :type friendly_name: str, unicode
        :type time_series: :class:`gridsim.timeseries.TimeSeries`
        :param temperature_calculator:
        :param position: The position of the thermal process.
        :type position: :class:`.Position`
        """
        # super constructor needs units as it is a "public" function
        super(TimeSeriesThermalProcess, self).\
            __init__(friendly_name,
                     float('inf')*units.heat_capacity, 0*units.kelvin,
                     1*units.kilogram,
                     position)

        self._time_series = time_series
        self._time_series.load(time_converter=time_converter)

        self._temperature_calculator = temperature_calculator

        self._time_series.convert('temperature', self._temperature_calculator)
Esempio n. 4
0
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)))

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'))
Esempio n. 5
0
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)
outside = sim.thermal.add(
    ConstantTemperatureProcess('outside', units.convert(celsius,
                                                        units.kelvin)))

sim.thermal.add(
    ThermalCoupling('room1 to outside', 10 * units.thermal_conductivity, room1,
                    outside))
sim.thermal.add(
Esempio n. 6
0
# 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, 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.hour,
                             temperature_calculator=lambda t: units.convert(
                                 units(t, units.degC), units.kelvin)))
sim.thermal.add(
    ThermalCoupling('room to outside', 10.0 * units.thermal_conductivity, room,
                    outside))

# Create a minimal electrical simulation network with a thermal heater connected
# to Bus0.
#
Esempio n. 7
0
 def _convert(self, a, u):
     return units.convert(a, u)
Esempio n. 8
0
 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))
Esempio n. 9
0
 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)) + ':'
Esempio n. 10
0
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)))

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...")
Esempio n. 11
0
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)
outside = sim.thermal.add(
    ConstantTemperatureProcess('outside', units.convert(celsius, units.kelvin)))

sim.thermal.add(ThermalCoupling('room1 to outside',
                                10*units.thermal_conductivity,
                                room1, outside))
sim.thermal.add(ThermalCoupling('room2 to outside',
                                10*units.thermal_conductivity,
Esempio n. 12
0
 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))
Esempio n. 13
0
 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)) + ':'