modelSimpleRoom

Simple room model implemented in Python that outputs the temperature and the energy

Extends from Modelica.Icons.Example (Icon for runnable examples).

Information

This example demonstrates the implementation of a simple room model that is implemented in the Python module Resources/Python-Sources/SimpleRoom.py. The Python model computes a first-order response to the room model. It returns the current room air temperature and the energy consumed during the simulation. The Python module also passes an object from one call to the next. This object contains the past room temperature, energy and time when the function was called, stored as a Python dictionary. This illustrates how Python data structures can be passed between function calls, thereby enabling for example to call some (memory-intensive) machine learning program, implemented in Python, from a Modelica block that may then pass the output of this program to a controller.

Note that this example is for demonstration only. An implementation in Modelica would be much simpler and computationally more efficient.

Components

TypeNameDefaultDescription
Buildings.Utilities.Time.ModelTimemodTimModel time
Python_3_8.Real_RealpytPython interface
Modelica.Blocks.Sources.ConstantT0Initial temperature
Modelica.Blocks.Routing.Multiplex4mulMultiplex
Controls.OBC.CDL.Conversions.BooleanToRealonOffOn off control
Modelica.Blocks.Sources.SineTAmbAmbient temperature
Buildings.Controls.OBC.CDL.Reals.Subtractsub1Inputs different
Buildings.Controls.OBC.CDL.Reals.HysteresisonOffConOn/off control

Revisions

  • December 11, 2023, by Jianjun Hu:
    Reimplemented on-off control to avoid using the obsolete OnOffController. This is for #3595.
  • August 27, 2021, by Michael Wetter:
    Updated to Python 3.8.
  • April 10, 2020, by Jianjun Hu and Michael Wetter:
    Updated to Python 3.6.
  • January 31, 2018, by Michael Wetter and Thierry Nouidui:
    First implementation.