trnsystor.TrnsysModel

class trnsystor.TrnsysModel(meta, name)[source]

TrnsysModel class.

Initialize object.

Alone, this __init__ method does not do much. See the from_xml() class method for the official constructor of this class.

Parameters
  • meta (MetaData) – A class containing the model’s metadata.

  • name (str) – A user-defined name for this model.

classmethod from_xml(xml, **kwargs)[source]

Class method to create a TrnsysModel from an xml string.

Examples

Simply pass the xml path to the constructor.

>>> from trnsystor import TrnsysModel
>>> fan1 = TrnsysModel.from_xml("Tests/input_files/Type146.xml")
Parameters
  • xml (str or Path) – The path of the xml file.

  • **kwargs

Returns

The TRNSYS model.

Return type

TrnsysType

copy(invalidate_connections=True)[source]

Copy object.

The new object has a new unit_number. The new object is translated by 50 pts to the right on the canvas.

Parameters

invalidate_connections (bool) – If True, connections to other models will be reset.

property derivatives

Return derivatives of self.

property special_cards

Return special cards of self.

property initial_input_values

Return initial input values of self.

property parameters

Return parameters of self.

property external_files

Return external files of self.

property anchor_points

Return the 8-AnchorPoints as a dict.

The anchor point location (‘top-left’, etc.) is the key.

property reverse_anchor_points

Reverse anchor points.

update_meta(new_meta)[source]

Update self with new MetaData.

plot()[source]

Plot the model.

property centroid

Returns the model’s center Point().

Type

Point

connect_to(other, mapping=None, link_style_kwargs=None)

Connect the outputs of self to the inputs of other.

Important

Keep in mind that since python traditionally uses 0-based indexing, the same logic is used in this package even though TRNSYS uses traditionally 1-based indexing. The package will internally handle the 1-based index in the output .dck file.

Examples

Connect two TrnsysModel objects together by creating a mapping of the outputs of pipe_1 to the intputs of pipe_2. In this example we connect output_0 of pipe_1 to input_0 of pipe_2 and output_1 of pipe_1 to input_1 of pipe_2:

>>> pipe_1.connect_to(pipe_2, mapping={0:0, 1:1})

The same can be acheived using input/output names.

>>> pipe_1.connect_to(pipe_2, mapping={'Outlet_Air_Temperature':
>>> 'Inlet_Air_Temperature', 'Outlet_Air_Humidity_Ratio':
>>> 'Inlet_Air_Humidity_Ratio'})
Parameters
  • other (Component) – The other object

  • mapping (dict) – Mapping of output to intput numbers (or names)

  • link_style_kwargs (dict, optional) – dict of LinkStyle parameters

Raises

TypeError – A TypeError is raised when trying to connect to anything other than a :class:`TrnsysModel.

property inputs

returns the model’s inputs.

Type

InputCollection

invalidate_connections()

Iterate over successors and predecessors and remove the edges.

Todo: restore paths in self.studio_canvas.grid

property is_connected

Whether or not this Component is connected to another TypeVariable.

Connected to or connected by.

Return LinkStyles of self.

property model

Return the path of this model’s proforma.

property outputs

returns the model’s outputs.

Type

OutputCollection

property predecessors

Other objects from which this TypeVariable is connected. Predecessors.

set_canvas_position(pt, trnsys_coords=False)

Set position of self in the canvas.

Use cartesian coordinates: origin 0,0 is at bottom-left.

Hint

The Studio Canvas origin corresponds to the top-left of the canvas. The x coordinates increase from left to right, while the y coordinates increase from top to bottom.

  • top-left = “* $POSITION 0 0”

  • bottom-left = “* $POSITION 0 2000”

  • top-right = “* $POSITION 2000” 0

  • bottom-right = “* $POSITION 2000 2000”

For convenience, users should deal with cartesian coordinates. trnsystor will deal with the transformation.

Parameters
  • pt (Point or 2-tuple) – The Point geometry or a tuple of (x, y) coordinates.

  • trnsys_coords (bool) – Set to True of pt is given in Trnsys Studio coordinates: origin 0,0 is at top-left.

set_component_layer(layers)

Change the layer of self. Pass a list to change multiple layers.

Set outgoing link styles between self and other.

Parameters
  • other (Component) – The destination model.

  • loc (str or tuple) – loc (str): The location of the anchor. The strings ‘top-left’, ‘top-right’, ‘bottom-left’, ‘bottom-right’ place the anchor point at the corresponding corner of the TrnsysModel. The strings ‘top-center’, ‘center-right’, ‘bottom-center’, ‘center-left’ place the anchor point at the edge of the corresponding TrnsysModel. The string ‘best’ places the anchor point at the location, among the eight locations defined so far, with the shortest distance with the destination TrnsysModel (other). The location can also be a 2-tuple giving the coordinates of the origin TrnsysModel and the destination TrnsysModel.

  • color (str or tuple) – The color of the line. Accepts any matplotlib color. You can specify colors in many ways, including full names (‘green’), hex strings (‘#008000’), RGB or RGBA tuples ((0,1,0,1)) or grayscale intensities as a string (‘0.8’).

  • linestyle (str) – Possible values: ‘-‘ or ‘solid’, ‘–’ or ‘dashed’, ‘-.’ or ‘dashdot’, ‘:’ or ‘dotted’, ‘-.’ or ‘dashdotdot’.

  • linewidth (float) – The width of the line in points.

  • path (LineString or MultiLineString, optional) – The path of the link.

property successors

Other objects to which this TypeVariable is connected. Successors.

property type_number

104 for Type104.

Type

Return the model’s type number, eg.

property unit_name

‘Type104’.

Type

Return the model’s unit name, eg.

property unit_number

Return the model’s unit number (unique).