Tutorial 3: Getting and Setting Values

This Tutorial demonstrates how to get and set values of object based on their tk.

Toolkit Release

[1]:
#pip install sir3stoolkit

Imports

The Toolkit requires the Sir3S_Toolkit.dll included in SIR 3S installations (from Quebec and Up). Furthermore the Sir3S_Repository.Interfaces.dll is required to input native SIR 3S datatypes into some Toolkit functions.

[2]:
import clr as clr
[3]:
SIR3S_SIRGRAF_DIR = r"C:\3S\SIR 3S Entwicklung\SirGraf-90-15-00-11_Quebec_x64"
[4]:
clr.AddReference(SIR3S_SIRGRAF_DIR+r"\Sir3S_Repository.Interfaces")
import Sir3S_Repository.Interfaces as Interfaces
[5]:
clr.AddReference(SIR3S_SIRGRAF_DIR+r"\Sir3S_Toolkit")
import Sir3S_Toolkit

PythonWrapperToolkit

[6]:
import sir3stoolkit

The core of sir3stoolkit is a Python Wrapper around C#, that can be used to read, write, etc. to a SIR 3S Model. In the future pure python subpackages may be added.

[7]:
from sir3stoolkit.core import wrapper
[8]:
sir3stoolkit
[8]:
<module 'sir3stoolkit' from 'c:\\Users\\jablonski\\AppData\\Local\\anaconda3\\Lib\\site-packages\\sir3stoolkit\\__init__.py'>

The wrapper package has to be initialized with reference to a SIR Graf installation.

[9]:
wrapper.Initialize_Toolkit(SIR3S_SIRGRAF_DIR)

Initialization

Toolkit contains two classes: SIR3S_Model(model and data) and SIR3S_View(depiction in SIR Graf). All Toolkit functionality is accessed via the methods of these classes.

[10]:
s3s = wrapper.SIR3S_Model()
Initialization complete
[11]:
s3s_view = wrapper.SIR3S_View()
Initialization complete

Open Model

[12]:
dbFilePath=r"Tutorial3_Model.db3"
[13]:
s3s.OpenModel(dbName=dbFilePath,
                            providerType=Interfaces.SirDBProviderType.SQLite,
                            Mid="M-1-0-1",
                            saveCurrentlyOpenModel=False,
                            namedInstance="",
                            userID="",
                            password="")
Model is open for further operation

This model has been prepared and contains two nodes connected by a pipe.

Getting Values

Our goal is to find out what the typ of the nodes is (PKON, QKON, etc.), and what length and roughness the pipe has.

The GetValue function requires a tk to the object and the internal SIR 3S attribute name of the value we want to obtain. This guide will walk you through how to obtain those.

Interfaces.Sir3SObjectTypes

First, we need to obtian the internal SIR 3S element types to later pass to our function for obtaining the attribute names.

We use the Interfaces from Sir3S_Repository.dll

You can use dir() to get an overview over the different element types existing in SIR 3S.

[14]:
print(dir(Interfaces.Sir3SObjectTypes))
['AGSN_HydraulicProfile', 'AirVessel', 'Arrow', 'Atmosphere', 'BlockConnectionNode', 'CalcPari', 'CharacteristicLossTable', 'CharacteristicLossTable_Row', 'Circle', 'CompareTo', 'Compressor', 'CompressorTable', 'CompressorTable_Row', 'ControlEngineeringNexus', 'ControlMode', 'ControlPointTable', 'ControlPointTable_Row', 'ControlValve', 'ControlVariableConverter', 'ControlVariableConverterRSTE', 'CrossSectionTable', 'CrossSectionTable_Row', 'DPGR_DPKT_DatapointDpgrConnection', 'DPGR_DataPointGroup', 'DPKT_Datapoint', 'DamageRatesTable', 'DamageRatesTable_Row', 'DeadTimeElement', 'Demand', 'DifferentialRegulator', 'DirectionalArrow', 'DistrictHeatingConsumer', 'DistrictHeatingFeeder', 'Divider', 'DriveEfficiencyTable', 'DriveEfficiencyTable_Row', 'DrivePowerTable', 'DrivePowerTable_Row', 'EBES_FeederGroups', 'EfficiencyConverterTable', 'EfficiencyConverterTable_Row', 'ElementQuery', 'EnergyRecoveryTable', 'EnergyRecoveryTable_Row', 'EnvironmentTemp', 'Equals', 'FWBZ_DistrictHeatingReferenceValues', 'Finalize', 'FlapValve', 'FlowControlUnit', 'FluidQualityParamSet', 'FluidQualityParamSet_OS', 'FluidThermalPropertyGroup', 'Format', 'FreeDuct', 'FunctionGenerator', 'FunctionTable', 'FunctionTable_Row', 'GasComponent', 'GasMixture', 'GeneralSection', 'GetHashCode', 'GetName', 'GetNames', 'GetType', 'GetTypeCode', 'GetUnderlyingType', 'GetValues', 'Gravitation', 'HasFlag', 'HeatExchanger', 'HeatFeederConsumerStation', 'HeaterCooler', 'Histeresis', 'House', 'Hydrant', 'Integrator', 'IsDefined', 'LAYR_Layer', 'LoadFactorTable', 'LoadFactorTable_Row', 'LogicalComparison', 'LogicalStorage', 'MeasuredVariableTable', 'MeasuredVariableTable_Row', 'MemberwiseClone', 'MinMaxSelection', 'Multiplier', 'NetValve', 'Node', 'NonReturnValvesTable', 'NonReturnValvesTable_Row', 'NumericalDisplay', 'ObjectContainerSymbol', 'OpenContainer', 'Oval', 'Overloads', 'PARZ_TransientCalculationParameters', 'Parse', 'PhaseSeparation', 'PidController', 'Pipe', 'PipeGroup', 'PipeTable', 'PipeTable_Row', 'PipeVertex', 'Polygon', 'Polyline', 'PressureRegulator', 'PressureZone', 'Pt1Controller', 'Pump', 'PumpCharTable', 'PumpCharTable_Row', 'PumpGroup', 'PumpOfPumpGroup', 'PumpSpeedTable', 'PumpSpeedTable_Row', 'RART_ControlMode', 'REGP_ControlParameters', 'RMES_DPTS_RmesInternalDataPoint', 'Rectangle', 'ReferenceEquals', 'RegulatorsTable', 'RegulatorsTable_Row', 'ReturnTemperaturTable', 'ReturnTemperaturTable_Row', 'RoundRectangle', 'SIRGRAF', 'SPLZ_TimeSeries', 'SafetyValve', 'SetpointDevice', 'SolarCollector', 'StandPipe', 'Street', 'SummingPoint', 'SwitchInBlock', 'TemperatureTable', 'TemperatureTable_Row', 'Text', 'ThermalOutputTable', 'ThermalOutputTable_Row', 'ThermophysPropTable', 'ThermophysPropTable_Row', 'ToObject', 'ToString', 'TransitionSymbol', 'Transmitter', 'TransportVariable', 'TryParse', 'USCH_UserDefinedProperties', 'Unknown', 'VARA_ColorScale', 'VARA_ROWS_WidthOrScale', 'VRCT_ViewRectangle', 'Valve', 'ValveLiftTable', 'ValveLiftTable_Row', 'VarFlowTable', 'VarFlowTable_Row', 'VarPressureTable', 'VarPressureTable_Row', 'VentOpenCloseTable', 'VentOpenCloseTable_Row', 'VentValve', 'VentilatedPressureAirVessel', 'WBLZ_ThermalBalance', 'WeatherDataTable', 'WeatherDataTable_Row', '__and__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__float__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__index__', '__init__', '__init_subclass__', '__int__', '__invert__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__or__', '__overloads__', '__rand__', '__reduce__', '__reduce_ex__', '__repr__', '__ror__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__xor__', 'value__']

In our simple example we are only interested in the types of nodes and pipes.

[15]:
node_type=Interfaces.Sir3SObjectTypes.Node
[16]:
pipe_type=Interfaces.Sir3SObjectTypes.Pipe

GetTksofElementType()

Now, we obtain the tks of the nodes and pipes in this model.

We use GetTksofElementType() to create a list of all node tks in the model.

[17]:
nodes=s3s.GetTksofElementType(node_type)
[18]:
print(nodes)
['4921762654790163024', '5483574590487309449']

If you dont want to predefine your element type you can also just pass it like done below

[19]:
pipes=s3s.GetTksofElementType(ElementType=Interfaces.Sir3SObjectTypes.Pipe)
[20]:
print(pipes)
['4722505344321420574']

GetPropertiesofElementType()

Now, we obtain the internal SIR 3S attribute names. The will be necessary for our value query.

We use GetPropertiesofElementType() to create a list of all properties of nodes and pipes.

[21]:
node_properties=s3s.GetPropertiesofElementType(node_type)
[22]:
print(node_properties)
['Name', 'Ktyp', 'Zkor', 'QmEin', 'Lfakt', 'Fkpzon', 'Fkfstf', 'Fkutmp', 'Fkfqps', 'Fkcont', 'Fk2lknot', 'Beschreibung', 'Geomfix', 'Idreferenz', 'Iplanung', 'Kvr', 'Qakt', 'Xkor', 'Ykor', 'NodeNamePosition', 'KvrKlartext', 'NumberOfVERB', 'HasBlockConnection', 'Tk', 'Pk', 'IsMarked', 'InVariant', 'SymbolFactor', 'bz.Drakonz', 'bz.Fk', 'bz.Fkpvar', 'bz.Fkqvar', 'bz.Fklfkt', 'bz.PhEin', 'bz.Tm', 'bz.Te', 'bz.PhMin']

GetValue()

Now, we can access and value of indiviudal nodes with a corresponding tk.

We use GetValue for such individual value query.

Node 1

As tk we just use the first tk from our nodes list.

[24]:
node1_ktyp=s3s.GetValue(nodes[0], 'Ktyp')
[25]:
print(node1_ktyp)
('PKON', 'string')

As you can see it returns a tuple value consisting of the actual value (here: ‘PKON’) of the attribute and the attribute data type.

You can access the indiviudal components as follows.

[26]:
actual_value=node1_ktyp[0]
[27]:
print(actual_value)
PKON
[28]:
data_type=node1_ktyp[1]
[29]:
print(data_type)
string

Node 2

Now we use the second tk from our nodes list.

[30]:
node2_ktyp_actual_value=s3s.GetValue(nodes[1], 'Ktyp')[0]
[31]:
print(node2_ktyp_actual_value)
QKON

Pipe

For the pipe we will just ignore the datatypes of the attributes and instantly just access the value.

[32]:
print(node_properties)
['Name', 'Ktyp', 'Zkor', 'QmEin', 'Lfakt', 'Fkpzon', 'Fkfstf', 'Fkutmp', 'Fkfqps', 'Fkcont', 'Fk2lknot', 'Beschreibung', 'Geomfix', 'Idreferenz', 'Iplanung', 'Kvr', 'Qakt', 'Xkor', 'Ykor', 'NodeNamePosition', 'KvrKlartext', 'NumberOfVERB', 'HasBlockConnection', 'Tk', 'Pk', 'IsMarked', 'InVariant', 'SymbolFactor', 'bz.Drakonz', 'bz.Fk', 'bz.Fkpvar', 'bz.Fkqvar', 'bz.Fklfkt', 'bz.PhEin', 'bz.Tm', 'bz.Te', 'bz.PhMin']
[33]:
pipe_length=s3s.GetValue(pipes[0], 'L')[0]
[34]:
print(pipe_length)
5
[35]:
pipe_roughness=s3s.GetValue(pipes[0], 'RAU')[0]
[36]:
print(pipe_roughness)
3

WORK IN PROGRESS BELOW

Getting Result Values

GetResultProperties_from_elementKey()

[37]:
s3s.GetResultProperties_from_elementType(pipe_type, False)
[37]:
['A',
 'ACALC',
 'CPI',
 'CPK',
 'DH',
 'DP',
 'DRAGRED',
 'DRAKONZ',
 'DSI',
 'DSK',
 'DTTR',
 'DWVERL',
 'DWVERLABS',
 'ETAAV',
 'FS',
 'HR',
 'HVEC',
 'IAKTIV',
 'IRTRENN',
 'JV',
 'JV2',
 'LAMBDA',
 'LECKEINAUS',
 'LECKMENGE',
 'LECKORT',
 'LINEPACK',
 'LINEPACKGEOM',
 'LINEPACKRATE',
 'MAINELEMENT',
 'MAV',
 'MI',
 'MK',
 'MKOND',
 'MMAX_INST',
 'MMIN_INST',
 'MVEC',
 'MVECMAX_INST',
 'MVECMIN_INST',
 'PAV',
 'PDAMPF',
 'PHR',
 'PHVEC',
 'PMAX',
 'PMIN',
 'PR',
 'PVEC',
 'PVECMAX_INST',
 'PVECMIN_INST',
 'QI2',
 'QK2',
 'QMAV',
 'QMI',
 'QMK',
 'QMMAX_INST',
 'QMMIN_INST',
 'QMVEC',
 'QSVB',
 'RHOAV',
 'RHOI',
 'RHOK',
 'RHOVEC',
 'SVEC',
 'TAV',
 'TI',
 'TK',
 'TTRVEC',
 'TVEC',
 'TVECMAX_INST',
 'TVECMIN_INST',
 'VAV',
 'VI',
 'VK',
 'VMAX_INST',
 'VMIN_INST',
 'VOLDA',
 'WALTERI',
 'WALTERK',
 'WVL',
 'ZAUS',
 'ZEIN',
 'ZHKNR',
 'ZVEC']

GetResultValue()

[38]:
s3s.GetResultValue(pipes[0], 'PMIN')
[38]:
('', '')
[39]:
1/0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
Cell In[39], line 1
----> 1 1/0

ZeroDivisionError: division by zero

Model Creation

[ ]:
dbFilePath=r"Tutorial3_Model.db3"
[ ]:
s3s.NewModel(dbName=dbFilePath,
                           providerType=Interfaces.SirDBProviderType.SQLite,
                           namedInstance="",
                           netType=Interfaces.NetworkType.DistrictHeating,
                           modelDescription="Tutorial 3 Model",
                           userID="",
                           password="")
New model is created with the model identifier: M-1-0-1
[ ]:
nodeA=s3s.AddNewNode("-1", "Node A", "PKON", 0.0, 0.0, 0.0, 10.0, 5.0, "Node A Description", "A", 1)
New node added
[ ]:
nodeB=s3s.AddNewNode("-1", "Node B", "QKON", 10.0, 10.0, 0.0, 5.0, 5.0, "Node B Description", "B", 1)
New node added
[ ]:
s3s.AddNewPipe("-1", nodeA, nodeB, 5.0, "LINESTRING (120 76, 500 300, 620 480)", "ST", "50", 3.0, "AB", "Pipe from A to B", 1)
New pipe added
'4722505344321420574'
[ ]:
s3s.SaveChanges()
Changes saved successfully