{ "cells": [ { "cell_type": "markdown", "id": "5b7dbabf", "metadata": {}, "source": [ "# Tutorial 6: Insert and Connect Elements" ] }, { "cell_type": "markdown", "id": "8899e69a", "metadata": {}, "source": [ "This Tutorial demonstrates how new elements such as nodes, pipes, tanks, valves, etc. can be inserted into a SIR 3S model and connected." ] }, { "cell_type": "markdown", "id": "a271e499-a4e8-4cf5-a510-7008fc501fa9", "metadata": {}, "source": [ "## SIR 3S Installation" ] }, { "cell_type": "code", "execution_count": 1, "id": "9241d47b-641e-4c68-b8f8-adad4806d086", "metadata": {}, "outputs": [], "source": [ "SIR3S_SIRGRAF_DIR = r\"C:\\3S\\SIR 3S Entwicklung\\SirGraf-90-15-00-16_Quebec_x64\" #change to local path" ] }, { "cell_type": "markdown", "id": "7887be8d", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "markdown", "id": "bbfb80b5", "metadata": {}, "source": [ "Note: The SIR 3S Toolkit requires the Sir3S_Toolkit.dll included in SIR 3S installations (version Quebec and higher)." ] }, { "cell_type": "code", "execution_count": 2, "id": "48372080", "metadata": {}, "outputs": [], "source": [ "import sir3stoolkit" ] }, { "cell_type": "markdown", "id": "e12d61e9", "metadata": {}, "source": [ "The core of sir3stoolkit is a Python wrapper around basic functionality of SIR 3S, offering a low-level access to the creation, modification and simulation of SIR 3S models. In the future pure python subpackages may be added." ] }, { "cell_type": "code", "execution_count": 3, "id": "f1baf699", "metadata": {}, "outputs": [], "source": [ "from sir3stoolkit.core import wrapper" ] }, { "cell_type": "code", "execution_count": 4, "id": "89da1276", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sir3stoolkit" ] }, { "cell_type": "markdown", "id": "6d982834", "metadata": {}, "source": [ "The [wrapper package](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.Initialize_Toolkit) has to be initialized with reference to a SIR 3S (SirGraf) installation." ] }, { "cell_type": "code", "execution_count": 5, "id": "817b0ebf", "metadata": {}, "outputs": [], "source": [ "wrapper.Initialize_Toolkit(SIR3S_SIRGRAF_DIR)" ] }, { "cell_type": "markdown", "id": "0352dd43", "metadata": {}, "source": [ "## Initialization" ] }, { "cell_type": "markdown", "id": "e14ffe06", "metadata": {}, "source": [ "The SIR 3S Toolkit contains two classes: [SIR3S_Model](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model) (model and data) and [SIR3S_View](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_View) (depiction in SIR Graf). All SIR 3S Toolkit functionality is accessed via the methods of these classes." ] }, { "cell_type": "code", "execution_count": 6, "id": "7e40a5af", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Initialization complete\n" ] } ], "source": [ "s3s = wrapper.SIR3S_Model()" ] }, { "cell_type": "code", "execution_count": 7, "id": "3770c93f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Initialization complete\n" ] } ], "source": [ "s3s_view = wrapper.SIR3S_View()" ] }, { "cell_type": "markdown", "id": "34309a14", "metadata": {}, "source": [ "## Create Model" ] }, { "cell_type": "code", "execution_count": 8, "id": "0918738e", "metadata": {}, "outputs": [], "source": [ "dbFilePath=r\"Toolkit_Tutorial6_Model.db3\"" ] }, { "cell_type": "code", "execution_count": 9, "id": "e984b61e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "New model is created with the model identifier: M-6-0-1\n" ] } ], "source": [ "s3s.NewModel(dbName=dbFilePath,\n", " providerType=s3s.ProviderTypes.SQLite, \n", " namedInstance=\"\", \n", " netType=s3s.NetworkType.DistrictHeating,\n", " modelDescription=\"Tutorial 6 Model\",\n", " userID=\"\", \n", " password=\"\")" ] }, { "cell_type": "markdown", "id": "e2490549", "metadata": {}, "source": [ "Now the model has been opened and the previous one has been closed without saving it. All SIR 3S Toolkit commands now apply to this model until another one is opened." ] }, { "cell_type": "code", "execution_count": 10, "id": "8e3adb92", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NetworkType.DistrictHeating\n" ] } ], "source": [ "print(s3s.GetNetworkType()) # to check that the correct model is responsive, model we are trying to open was created with type Undefined" ] }, { "cell_type": "markdown", "id": "1f2c3cb8", "metadata": {}, "source": [ "## SIR 3S object types" ] }, { "cell_type": "code", "execution_count": 11, "id": "1b8f7dfb", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['AGSN_HydraulicProfile', 'AirVessel', 'Arrow', 'Atmosphere', 'BlockConnectionNode', 'CalcPari', 'CharacteristicLossTable', 'CharacteristicLossTable_Row', 'Circle', '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', 'FWBZ_DistrictHeatingReferenceValues', 'FlapValve', 'FlowControlUnit', 'FluidQualityParamSet', 'FluidQualityParamSet_OS', 'FluidThermalPropertyGroup', 'FreeDuct', 'FunctionGenerator', 'FunctionTable', 'FunctionTable_Row', 'GasComponent', 'GasMixture', 'GeneralSection', 'Gravitation', 'HeatExchanger', 'HeatFeederConsumerStation', 'HeaterCooler', 'Histeresis', 'House', 'Hydrant', 'Integrator', 'LAYR_Layer', 'LoadFactorTable', 'LoadFactorTable_Row', 'LogicalComparison', 'LogicalStorage', 'MeasuredVariableTable', 'MeasuredVariableTable_Row', 'MinMaxSelection', 'Multiplier', 'NetValve', 'Node', 'NonReturnValvesTable', 'NonReturnValvesTable_Row', 'NumericalDisplay', 'ObjectContainerSymbol', 'OpenContainer', 'Oval', 'PARZ_TransientCalculationParameters', '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', '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', 'TransitionSymbol', 'Transmitter', 'TransportVariable', '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']\n" ] } ], "source": [ "object_types = [item for item in dir(s3s.ObjectTypes) if not (item.startswith('__') and item.endswith('__'))]\n", "print(object_types)" ] }, { "cell_type": "markdown", "id": "fc620bae", "metadata": {}, "source": [ "## InsertElement() - Generic Element Creation" ] }, { "cell_type": "markdown", "id": "d379cb12", "metadata": {}, "source": [ "We use the [InsertElement()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.InsertElement) function with the SIR 3S datatype and IdRef value (we just use default \"-1\"). " ] }, { "cell_type": "markdown", "id": "f6f72344", "metadata": {}, "source": [ "Let's just create two nodes: one connected to a tank and the other for now just a free end connected via a pipe to the first node." ] }, { "cell_type": "markdown", "id": "2e97bf26", "metadata": {}, "source": [ "### Containers" ] }, { "cell_type": "markdown", "id": "1f56c945", "metadata": {}, "source": [ "In SIR 3S every element exists in a specific container. If the container is not specified when creating the element it will be inserted in to the main container." ] }, { "cell_type": "code", "execution_count": 12, "id": "41d07b88", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element inserted successfully into the model with Tk: 5008034218814138857\n" ] } ], "source": [ "container_A=s3s.InsertElement(s3s.ObjectTypes.ObjectContainerSymbol, IdRef=\"\")" ] }, { "cell_type": "markdown", "id": "aa6e7d02", "metadata": {}, "source": [ "Here we should define the container A using [SetValue()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.SetValue), but for simplicity let's leave that out." ] }, { "cell_type": "markdown", "id": "89bbcd79", "metadata": {}, "source": [ "### Nodes" ] }, { "cell_type": "code", "execution_count": 13, "id": "b50e88fd", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element inserted successfully into the model with Tk: 5370202525391386318\n" ] } ], "source": [ "nodeKI=s3s.InsertElement(ElementType=s3s.ObjectTypes.Node, IdRef =\"-1\")" ] }, { "cell_type": "code", "execution_count": 14, "id": "393d48c4", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element inserted successfully into the model with Tk: 5217089350860543576\n" ] } ], "source": [ "nodeKK=s3s.InsertElement(ElementType=s3s.ObjectTypes.Node, IdRef =\"-1\")" ] }, { "cell_type": "markdown", "id": "4c416e7f", "metadata": {}, "source": [ "### Pipe - Connecting Element" ] }, { "cell_type": "markdown", "id": "a4c828b2", "metadata": {}, "source": [ "We again use [InsertElement()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.InsertElement) function to create a new element in this case a pipe. Then we connect both nodes with the pipe using the [ConnectConnectingElementWithNodes()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.ConnectConnectingElementWithNodes) function." ] }, { "cell_type": "code", "execution_count": 15, "id": "254dfcc5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element inserted successfully into the model with Tk: 5356888914134614362\n" ] } ], "source": [ "pipe=s3s.InsertElement(ElementType=s3s.ObjectTypes.Pipe, IdRef =\"-1\")" ] }, { "cell_type": "code", "execution_count": 16, "id": "93b4d366", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Objects connected successfully\n" ] } ], "source": [ "s3s.ConnectConnectingElementWithNodes(Tk=pipe, keyOfNodeI=nodeKI, keyOfNodeK=nodeKK)" ] }, { "cell_type": "markdown", "id": "53bc242c", "metadata": {}, "source": [ "### Tank - Bypass Element" ] }, { "cell_type": "markdown", "id": "10a3e8c9", "metadata": {}, "source": [ "We again use [InsertElement()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.InsertElement) to create a new element in this case a tank. Then we connect the KI node with the tank using the [ConnectBypassElementWithNode()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.ConnectBypassElementWithNode) function." ] }, { "cell_type": "code", "execution_count": 17, "id": "bbcdef46", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element inserted successfully into the model with Tk: 5372199443253516317\n" ] } ], "source": [ "tank=s3s.InsertElement(ElementType=s3s.ObjectTypes.OpenContainer, IdRef =\"-1\")" ] }, { "cell_type": "code", "execution_count": 18, "id": "2240f200", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Object connected successfully\n" ] } ], "source": [ "s3s.ConnectBypassElementWithNode(Tk=tank, keyOfNodeI=nodeKI)" ] }, { "cell_type": "markdown", "id": "2a586fb1", "metadata": {}, "source": [ "### Assign Property Values" ] }, { "cell_type": "markdown", "id": "34e0b209", "metadata": {}, "source": [ "Now we have created this basic network, but it lacks defined geometry, material, supplier data. We can use the [SetValue()](ConnectBypassElementWithNode) function from Tutorial 3 to assin those values. " ] }, { "cell_type": "code", "execution_count": 19, "id": "b9a135e1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Value is set\n", "Value is set\n", "Value is set\n", "Value is set\n" ] } ], "source": [ "s3s.SetValue(Tk=nodeKI, propertyName=\"Xkor\", Value=\"100\")\n", "s3s.SetValue(Tk=nodeKI, propertyName=\"Ykor\", Value=\"100\")\n", "s3s.SetValue(Tk=nodeKI, propertyName=\"Ktyp\", Value=\"PKON\")\n", "s3s.SetValue(Tk=nodeKI, propertyName=\"Ktyp\", Value=\"PKON\")" ] }, { "cell_type": "markdown", "id": "1cd2f0eb", "metadata": {}, "source": [ "... and so on for both nodes" ] }, { "cell_type": "code", "execution_count": 20, "id": "8feee922", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Value is set\n", "Value is set\n" ] } ], "source": [ "s3s.SetValue(Tk=pipe, propertyName=\"Kvr\", Value=\"1\")\n", "s3s.SetValue(Tk=pipe, propertyName=\"L\", Value=\"10\")" ] }, { "cell_type": "markdown", "id": "4c550deb", "metadata": {}, "source": [ "... and so on for the pipe and also the tank" ] }, { "cell_type": "markdown", "id": "49be18fd", "metadata": {}, "source": [ "### Assign to container A" ] }, { "cell_type": "markdown", "id": "e7e96813", "metadata": {}, "source": [ "The [InsertElement()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.InsertElement) function inserts elements into the main container. Let's try to move all elements created so far into the container A we created." ] }, { "cell_type": "code", "execution_count": 21, "id": "ccfbb0bc", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Value is set\n" ] } ], "source": [ "s3s.SetValue(Tk=nodeKI, propertyName=\"fkCont\", Value=container_A)" ] }, { "cell_type": "code", "execution_count": 22, "id": "ba9b577b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Value is set\n" ] } ], "source": [ "s3s.SetValue(Tk=nodeKK, propertyName=\"fkCont\", Value=container_A)" ] }, { "cell_type": "code", "execution_count": 23, "id": "e6c26ee0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Value is set\n" ] } ], "source": [ "s3s.SetValue(Tk=pipe, propertyName=\"fkCont\", Value=container_A)" ] }, { "cell_type": "markdown", "id": "a99055ef", "metadata": {}, "source": [ "# GetMainContainer()" ] }, { "cell_type": "markdown", "id": "7ab9557b", "metadata": {}, "source": [ "We can use the [GetMainContainer()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.GetMainContainer) function to obtain the tk of the main container." ] }, { "cell_type": "code", "execution_count": 24, "id": "5ebde0ca", "metadata": {}, "outputs": [], "source": [ "main_container=s3s.GetMainContainer()[0]" ] }, { "cell_type": "code", "execution_count": 25, "id": "32a69118", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "5404784316484532375\n" ] } ], "source": [ "print(main_container)" ] }, { "cell_type": "markdown", "id": "d19dc622", "metadata": {}, "source": [ "# IsMainContainer()" ] }, { "cell_type": "markdown", "id": "5d55cab1", "metadata": {}, "source": [ "We can use the [IsMainContainer()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.IsMainContainer) function to check whether the provided FkCont equals the FkCont obtained by [GetMainContainer()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.GetMainContainer)." ] }, { "cell_type": "code", "execution_count": 26, "id": "f98062c3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.IsMainContainer(fkCont=container_A)" ] }, { "cell_type": "code", "execution_count": 27, "id": "3271ea53", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.IsMainContainer(fkCont=main_container)" ] }, { "cell_type": "code", "execution_count": 28, "id": "6117747a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.IsMainContainer(s3s.GetValue(Tk=nodeKI, propertyName=\"fkCont\")[0])" ] }, { "cell_type": "markdown", "id": "00238747", "metadata": {}, "source": [ "We can see that nodKI is not in the main container as we moved it to the container A." ] }, { "cell_type": "code", "execution_count": 29, "id": "074f12d2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Value is set\n" ] } ], "source": [ "s3s.SetValue(Tk=nodeKI, propertyName=\"fkCont\", Value=s3s.GetMainContainer()[0])" ] }, { "cell_type": "code", "execution_count": 30, "id": "4b209021", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.IsMainContainer(s3s.GetValue(Tk=nodeKI, propertyName=\"fkCont\")[0])" ] }, { "cell_type": "markdown", "id": "accbb2f6", "metadata": {}, "source": [ "But we can move it back." ] }, { "cell_type": "markdown", "id": "849de8fd", "metadata": {}, "source": [ "## GetNumberOfElements" ] }, { "cell_type": "markdown", "id": "2841167b", "metadata": {}, "source": [ "As a side note. We can use the [GetNumberOfElements()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.GetNumberOfElements) function to get the number of all elements existing in our model of a specified datatype" ] }, { "cell_type": "code", "execution_count": 31, "id": "99ef5631", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2\n" ] } ], "source": [ "print(s3s.GetNumberOfElements(ElementType=s3s.ObjectTypes.Node))" ] }, { "cell_type": "markdown", "id": "1b00334d", "metadata": {}, "source": [ "## DeleteElement()" ] }, { "cell_type": "markdown", "id": "565aa293", "metadata": {}, "source": [ "Let's delete all Elements we have created so far." ] }, { "cell_type": "code", "execution_count": 32, "id": "979c1e3d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element deleted successfully\n" ] } ], "source": [ "s3s.DeleteElement(Tk=nodeKI)" ] }, { "cell_type": "code", "execution_count": 33, "id": "08683f89", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element deleted successfully\n" ] } ], "source": [ "s3s.DeleteElement(Tk=nodeKK)" ] }, { "cell_type": "markdown", "id": "109b28f1", "metadata": {}, "source": [ "Now we can check how many nodes still exist." ] }, { "cell_type": "code", "execution_count": 34, "id": "10ecf85c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n" ] } ], "source": [ "print(s3s.GetNumberOfElements(ElementType=s3s.ObjectTypes.Node))" ] }, { "cell_type": "code", "execution_count": 35, "id": "bfbaad10", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element deleted successfully\n" ] } ], "source": [ "s3s.DeleteElement(Tk=pipe)" ] }, { "cell_type": "code", "execution_count": 36, "id": "28677ea2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element deleted successfully\n" ] } ], "source": [ "s3s.DeleteElement(Tk=tank)" ] }, { "cell_type": "markdown", "id": "0785e502", "metadata": {}, "source": [ "## Specific Element Creation" ] }, { "cell_type": "markdown", "id": "bc3c17fb", "metadata": {}, "source": [ "The approach used above is tedious. Therefore more specific functions exists for the insertion of elements of certain data types which contain specific paramters for that type." ] }, { "cell_type": "markdown", "id": "c8187754", "metadata": {}, "source": [ "Let's try to build a more complex model this time. It is equivalent to Network 1. We will use template for editing models from Tutorial 5." ] }, { "cell_type": "markdown", "id": "4fb82373", "metadata": {}, "source": [ "### AddNewNode()" ] }, { "cell_type": "markdown", "id": "4838aa74", "metadata": {}, "source": [ "We use the [AddNewNode()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.AddNewNode) function to insert several nodes. We can already specify many properties such as geometry, node type, kvr, etc.." ] }, { "cell_type": "code", "execution_count": 37, "id": "dc034ec9", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Now you can make changes to the model\n", "New node added\n", "New node added\n", "New node added\n", "New node added\n", "New node added\n", "New node added\n", "New node added\n", "New node added\n", "New node added\n", "New node added\n", "New node added\n", "Transaction has ended. Please open up a new transaction if you want to make further changes\n", "Changes saved successfully\n", "Refresh successful\n" ] } ], "source": [ "s3s.StartTransaction(\"Inserting Nodes\") \n", "\n", "node10 = s3s.AddNewNode(tkCont=\"-1\", name=\"Node10\", typ=\"QKON\", x=200, y=700, z=213, qm_PH=0, symbolFactor=1, description=\"DNODE 10\", idRef=\"RefNode 10\", kvr=0)\n", "node11 = s3s.AddNewNode(tkCont=\"-1\", name=\"Node11\", typ=\"QKON\", x=300, y=700, z=213, qm_PH=0, symbolFactor=1, description=\"DNODE 11\", idRef=\"RefNode 11\", kvr=0)\n", "node12 = s3s.AddNewNode(tkCont=\"-1\", name=\"Node12\", typ=\"QKON\", x=500, y=700, z=210, qm_PH=0, symbolFactor=1, description=\"DNODE 12\", idRef=\"RefNode 12\", kvr=0)\n", "node13 = s3s.AddNewNode(tkCont=\"-1\", name=\"Node13\", typ=\"QKON\", x=700, y=700, z=208.5, qm_PH=0, symbolFactor=1, description=\"DNODE 13\", idRef=\"RefNode 13\", kvr=0)\n", "node21 = s3s.AddNewNode(tkCont=\"-1\", name=\"Node21\", typ=\"QKON\", x=300, y=400, z=210, qm_PH=0, symbolFactor=1, description=\"DNODE 21\", idRef=\"RefNode 21\", kvr=0)\n", "node22 = s3s.AddNewNode(tkCont=\"-1\", name=\"Node22\", typ=\"QKON\", x=500, y=400, z=208.5, qm_PH=0, symbolFactor=1, description=\"DNODE 22\", idRef=\"RefNode 22\", kvr=0)\n", "node23 = s3s.AddNewNode(tkCont=\"-1\", name=\"Node23\", typ=\"QKON\", x=700, y=400, z=207, qm_PH=0, symbolFactor=1, description=\"DNODE 23\", idRef=\"RefNode 23\", kvr=0)\n", "node31 = s3s.AddNewNode(tkCont=\"-1\", name=\"Node31\", typ=\"QKON\", x=300, y=100, z=210, qm_PH=0, symbolFactor=1, description=\"DNODE 31\", idRef=\"RefNode 31\", kvr=0)\n", "node32 = s3s.AddNewNode(tkCont=\"-1\", name=\"Node32\", typ=\"QKON\", x=500, y=100, z=213, qm_PH=0, symbolFactor=1, description=\"DNODE 32\", idRef=\"RefNode 32\", kvr=0)\n", "node9 = s3s.AddNewNode(tkCont=\"-1\", name=\"Node9\", typ=\"PKON\", x=150, y=700, z=255, qm_PH=0, symbolFactor=1, description=\"PNODE 9\", idRef=\"RefNode 9\", kvr=0)\n", "node2 = s3s.AddNewNode(tkCont=\"-1\", name=\"Node2\", typ=\"QKON\", x=500, y=850, z=240, qm_PH=0, symbolFactor=1, description=\"Tank 2\", idRef=\"RefNode 2\", kvr=0)\n", "\n", "s3s.EndTransaction()\n", "s3s.SaveChanges()\n", "s3s.RefreshViews()" ] }, { "cell_type": "markdown", "id": "98d89ae1", "metadata": {}, "source": [ "### AddNewPipe()" ] }, { "cell_type": "markdown", "id": "15ba3636", "metadata": {}, "source": [ "We use the [AddNewPipe()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.AddNewPipe) function to insert new pipes. This time there is no need for a seperate function to connect it to nodes, and many properties such as geometry, material, kvr, etc. are already set in this function." ] }, { "cell_type": "code", "execution_count": 38, "id": "0fa3e863", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Now you can make changes to the model\n", "New pipe added\n", "New pipe added\n", "New pipe added\n", "New pipe added\n", "New pipe added\n", "New pipe added\n", "New pipe added\n", "New pipe added\n", "New pipe added\n", "New pipe added\n", "New pipe added\n", "New pipe added\n", "Transaction has ended. Please open up a new transaction if you want to make further changes\n", "Changes saved successfully\n", "Refresh successful\n" ] } ], "source": [ "s3s.StartTransaction(\"Inserting Pipes\") \n", "\n", "pipeA = s3s.AddNewPipe(tkCont=\"-1\", tkFrom=node10, tkTo=node11, L=3160, linestring=\"LINESTRING(200 700, 300, 700)\", material=\"STDROHR\", dn=\"450\", roughness=0.25, idRef=\"Ref Pipe 10\", description=\"Pipe from Pump to network\", kvr=0)\n", "pipeB = s3s.AddNewPipe(tkCont=\"-1\", tkFrom=node11, tkTo=node12, L=1584, linestring=\"LINESTRING(300 700, 500, 700)\", material=\"STDROHR\", dn=\"350\", roughness=0.25, idRef=\"Ref Pipe 11\", description=\"Pipe from 11 to 12\", kvr=0)\n", "pipeC = s3s.AddNewPipe(tkCont=\"-1\", tkFrom=node12, tkTo=node13, L=1584, linestring=\"LINESTRING(500 700, 700, 700)\", material=\"STDROHR\", dn=\"250\", roughness=0.25, idRef=\"Ref Pipe 12\", description=\"Pipe from 12 to 13\", kvr=0)\n", "pipeD = s3s.AddNewPipe(tkCont=\"-1\", tkFrom=node21, tkTo=node22, L=1584, linestring=\"LINESTRING(300 400, 500, 400)\", material=\"STDROHR\", dn=\"250\", roughness=0.25, idRef=\"Ref Pipe 21\", description=\"Pipe from 21 to 22\", kvr=0)\n", "pipeE = s3s.AddNewPipe(tkCont=\"-1\", tkFrom=node22, tkTo=node23, L=1584, linestring=\"LINESTRING(500 400, 700, 400)\", material=\"STDROHR\", dn=\"300\", roughness=0.25, idRef=\"Ref Pipe 22\", description=\"Pipe from 22 to 23\", kvr=0)\n", "pipeF = s3s.AddNewPipe(tkCont=\"-1\", tkFrom=node31, tkTo=node32, L=1584, linestring=\"LINESTRING(300 100, 500, 100)\", material=\"STDROHR\", dn=\"150\", roughness=0.25, idRef=\"Ref Pipe 31\", description=\"Pipe from 31 to 32\", kvr=0)\n", "pipeG = s3s.AddNewPipe(tkCont=\"-1\", tkFrom=node2, tkTo=node12, L=60, linestring=\"LINESTRING(500 850, 500, 700)\", material=\"STDROHR\", dn=\"450\", roughness=0.25, idRef=\"Ref Pipe 110\", description=\"Pipe from Tank to network\", kvr=0)\n", "pipeH = s3s.AddNewPipe(tkCont=\"-1\", tkFrom=node11, tkTo=node21, L=1584, linestring=\"LINESTRING(300 700, 300, 400)\", material=\"STDROHR\", dn=\"250\", roughness=0.25, idRef=\"Ref Pipee 111\", description=\"Pipe from 11 to 21\", kvr=0)\n", "pipeI = s3s.AddNewPipe(tkCont=\"-1\", tkFrom=node12, tkTo=node22, L=1584, linestring=\"LINESTRING(500 700, 500, 400)\", material=\"STDROHR\", dn=\"300\", roughness=0.25, idRef=\"Ref Pipee 112\", description=\"Pipe from 12 to 22\", kvr=0)\n", "pipeJ = s3s.AddNewPipe(tkCont=\"-1\", tkFrom=node13, tkTo=node23, L=1584, linestring=\"LINESTRING(700 700, 700, 400)\", material=\"STDROHR\", dn=\"200\", roughness=0.25, idRef=\"Ref Pipee 113\", description=\"Pipe from 13 to 32\", kvr=0)\n", "pipeK = s3s.AddNewPipe(tkCont=\"-1\", tkFrom=node21, tkTo=node31, L=1584, linestring=\"LINESTRING(300 400, 300, 100)\", material=\"STDROHR\", dn=\"200\", roughness=0.25, idRef=\"Ref Pipee 121\", description=\"Pipe from 21 to 31\", kvr=0)\n", "pipeL = s3s.AddNewPipe(tkCont=\"-1\", tkFrom=node22, tkTo=node32, L=1584, linestring=\"LINESTRING(500 400, 500, 100)\", material=\"STDROHR\", dn=\"150\", roughness=0.25, idRef=\"Ref Pipee 122\", description=\"Pipe from 22 to 32\", kvr=0)\n", "\n", "s3s.EndTransaction()\n", "s3s.SaveChanges()\n", "s3s.RefreshViews()" ] }, { "cell_type": "markdown", "id": "e1e28ee7", "metadata": {}, "source": [ "### AddNewConnectingElement()" ] }, { "cell_type": "markdown", "id": "65995bd4", "metadata": {}, "source": [ "We use the [AddNewConnectingElement()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.AddNewConnectingElement) function to insert a new pump. This time there is no need for a seperate function to connect it to nodes. As this function covers more than just one element type it is not as specific as the previous two." ] }, { "cell_type": "code", "execution_count": 39, "id": "f2a86a91", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Now you can make changes to the model\n", "New connecting element added\n", "Transaction has ended. Please open up a new transaction if you want to make further changes\n", "Changes saved successfully\n", "Refresh successful\n" ] } ], "source": [ "s3s.StartTransaction(\"Insert Pump\") \n", "\n", "pump=s3s.AddNewConnectingElement(tkCont=\"-1\", tkFrom=node9, tkTo=node10, x=175, y=700, z=0, elementType=s3s.ObjectTypes.Pump, dn=200, symbolFactor=1, angleDegree=0, idRef=\"Pumpe\", description=\"standard pump\")\n", "\n", "s3s.EndTransaction()\n", "s3s.SaveChanges()\n", "s3s.RefreshViews()" ] }, { "cell_type": "markdown", "id": "180ae351", "metadata": {}, "source": [ "### AddNewBypassElement()" ] }, { "cell_type": "markdown", "id": "dab82dbc", "metadata": {}, "source": [ "We use the [AddNewBypassElement()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.AddNewBypassElement) function to insert a new tank. This time there is no need for a seperate function to connect it to a node. As this function covers more than just one element type it is not that specific just like the previous one." ] }, { "cell_type": "code", "execution_count": 40, "id": "9620b4e7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Now you can make changes to the model\n", "New Bypass element added\n", "Transaction has ended. Please open up a new transaction if you want to make further changes\n", "Changes saved successfully\n", "Refresh successful\n" ] } ], "source": [ "s3s.StartTransaction(\"Insert Pump\") \n", "\n", "tank=s3s.AddNewBypassElement(tkCont=\"-1\", tkFrom=node2, x=500, y=850, z=255, symbolFactor=1, elementType=s3s.ObjectTypes.OpenContainer, idRef=\"Tank\", description=\"Storage tank\")\n", "\n", "s3s.EndTransaction()\n", "s3s.SaveChanges()\n", "s3s.RefreshViews()" ] }, { "cell_type": "markdown", "id": "86eade0a", "metadata": {}, "source": [ "## GetEndNodes()" ] }, { "cell_type": "markdown", "id": "2108f7ca", "metadata": {}, "source": [ "As a side note: we can use the [GetEndNodes()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.GetEndNodes) function to get the tks of nodes an element is connected to. That works for all kinds of elements with different number of nodes. The are returned in the form tuple[str, str, str, str] = fkKI, fkKK, fkKI2, fkKK2." ] }, { "cell_type": "markdown", "id": "3b704589", "metadata": {}, "source": [ "It works for bypass elements with just one node." ] }, { "cell_type": "code", "execution_count": 41, "id": "8b2d327f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('5665723676294844823', '-1', '-1', '-1')" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.GetEndNodes(Tk=tank)" ] }, { "cell_type": "markdown", "id": "26bdbb5e", "metadata": {}, "source": [ "It works for connecting elements with two nodes." ] }, { "cell_type": "code", "execution_count": 42, "id": "0ecd19a6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('5739878139344995606', '5680811754375850174', '-1', '-1')" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.GetEndNodes(Tk=pump)" ] }, { "cell_type": "markdown", "id": "28354b10", "metadata": {}, "source": [ "It works for connecting elements with four nodes like heat exchangers that we have not used in this tutorial for simplicity reasons." ] }, { "cell_type": "code", "execution_count": 43, "id": "02b1f3db", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'LINESTRING Z(200 700 213, 200 700 0, 300 700 213)'" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.GetGeometryInformation(Tk=pipeA)" ] }, { "cell_type": "markdown", "id": "492be139", "metadata": {}, "source": [ "## GetElementInfo()" ] }, { "cell_type": "markdown", "id": "f9511cdb", "metadata": {}, "source": [ "As a side note: we can use the [GetElementInfo()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.GetElementInfo) function to obtain a short text that tells us what kind of element we consider based on the tk given and to which elements it is connected." ] }, { "cell_type": "code", "execution_count": 44, "id": "8f619ecd", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Info: Pumpe Node9 Node10\n" ] } ], "source": [ "s3s.GetElementInfo(Tk=pump)" ] }, { "cell_type": "code", "execution_count": 45, "id": "580b7a06", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Info: Offener Behälter Node2\n" ] } ], "source": [ "s3s.GetElementInfo(Tk=tank)" ] }, { "cell_type": "code", "execution_count": 46, "id": "d9c5f2be", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Element inserted successfully into the model with Tk: 5355078431502712981\n" ] }, { "data": { "text/plain": [ "'5355078431502712981'" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.InsertElement(ElementType=s3s.ObjectTypes.Node, IdRef=\"A\")" ] }, { "cell_type": "code", "execution_count": 47, "id": "f0986e95", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('', '')" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.GetValue('5655239364696389210', \"fkCont\")" ] }, { "cell_type": "code", "execution_count": 48, "id": "5e86c104", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('5404784316484532375', )" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.GetMainContainer()" ] }, { "cell_type": "code", "execution_count": 49, "id": "e5149f7b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Name',\n", " 'Ktyp',\n", " 'Zkor',\n", " 'QmEin',\n", " 'Lfakt',\n", " 'Fkpzon',\n", " 'Fkfstf',\n", " 'Fkutmp',\n", " 'Fkfqps',\n", " 'Fkcont',\n", " 'Fk2lknot',\n", " 'Beschreibung',\n", " 'Idreferenz',\n", " 'Iplanung',\n", " 'Kvr',\n", " 'Qakt',\n", " 'Xkor',\n", " 'Ykor',\n", " 'NodeNamePosition',\n", " 'ShowNodeName',\n", " 'KvrKlartext',\n", " 'NumberOfVERB',\n", " 'HasBlockConnection',\n", " 'Tk',\n", " 'Pk',\n", " 'IsMarked',\n", " 'InVariant',\n", " 'GeometriesDiffer',\n", " 'SymbolFactor',\n", " 'bz.Drakonz',\n", " 'bz.Fk',\n", " 'bz.Fkpvar',\n", " 'bz.Fkqvar',\n", " 'bz.Fklfkt',\n", " 'bz.PhEin',\n", " 'bz.Tm',\n", " 'bz.Te',\n", " 'bz.PhMin']" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.GetPropertiesofElementType(ElementType=s3s.ObjectTypes.Node)" ] }, { "cell_type": "markdown", "id": "b6064c3a", "metadata": {}, "source": [ "__Next:__ Tutorial 7: Miscellaneous" ] }, { "cell_type": "markdown", "id": "6fb4de39-a405-4741-92ae-4613320b93f4", "metadata": {}, "source": [ "__...__" ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.8" } }, "nbformat": 4, "nbformat_minor": 5 }