{ "cells": [ { "cell_type": "markdown", "id": "5556432f", "metadata": {}, "source": [ "# Tutorial 2: Accessing and modifying model data" ] }, { "cell_type": "markdown", "id": "8899e69a", "metadata": {}, "source": [ "This tutorial demonstrates how to get and set values of objects based on their topological key (tk)." ] }, { "cell_type": "markdown", "id": "3ac05a55-e21e-4901-b553-84c7ddd8105e", "metadata": {}, "source": [ "## SIR 3S Installation" ] }, { "cell_type": "code", "execution_count": 1, "id": "48425a98-e197-4b30-94de-1f2839f9d619", "metadata": {}, "outputs": [], "source": [ "SIR3S_SIRGRAF_DIR = r\"C:\\3S\\SIR 3S\\SirGraf-90-15-00-20x64_Quebec-Upd1\" #change to local path" ] }, { "cell_type": "markdown", "id": "2ec45128", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "markdown", "id": "5ae3d26b", "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": "3ea16e3d", "metadata": {}, "outputs": [], "source": [ "import sir3stoolkit" ] }, { "cell_type": "markdown", "id": "5fb318de", "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": "e1cad8f6", "metadata": {}, "outputs": [], "source": [ "from sir3stoolkit.core import wrapper" ] }, { "cell_type": "code", "execution_count": 4, "id": "ee9b4080", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sir3stoolkit" ] }, { "cell_type": "markdown", "id": "e3acc1e7", "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": "3d4e829d", "metadata": {}, "outputs": [], "source": [ "wrapper.Initialize_Toolkit(SIR3S_SIRGRAF_DIR)" ] }, { "cell_type": "markdown", "id": "37f67f8f", "metadata": {}, "source": [ "## Initialization" ] }, { "cell_type": "markdown", "id": "49b21e98", "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": "a6ffe9da", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Initialization complete\n" ] } ], "source": [ "s3s = wrapper.SIR3S_Model()" ] }, { "cell_type": "code", "execution_count": 7, "id": "4d9d92b5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Initialization complete\n" ] } ], "source": [ "s3s_view = wrapper.SIR3S_View()" ] }, { "cell_type": "markdown", "id": "34309a14", "metadata": {}, "source": [ "## Open Model" ] }, { "cell_type": "code", "execution_count": 8, "id": "0918738e", "metadata": {}, "outputs": [], "source": [ "dbFilePath=r\"Tutorial2_Model.db3\"" ] }, { "cell_type": "code", "execution_count": 9, "id": "e984b61e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Model is open for further operation\n" ] } ], "source": [ "s3s.OpenModel(dbName=dbFilePath, \n", " providerType=s3s.ProviderTypes.SQLite, \n", " Mid=\"M-1-0-1\", \n", " saveCurrentlyOpenModel=False, \n", " namedInstance=\"\", \n", " userID=\"\", \n", " password=\"\")" ] }, { "cell_type": "markdown", "id": "59002c02", "metadata": {}, "source": [ "This model has been prepared and contains two nodes connected by a pipe." ] }, { "cell_type": "markdown", "id": "8862300c", "metadata": {}, "source": [ "## Get Values" ] }, { "cell_type": "markdown", "id": "720e5b9f", "metadata": {}, "source": [ "Our goal is to find out what the type of the nodes is (PKON, QKON, etc.), and which length and roughness the pipe has." ] }, { "cell_type": "markdown", "id": "7d784e11", "metadata": {}, "source": [ "The [GetValue()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.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." ] }, { "cell_type": "markdown", "id": "83cf88cd", "metadata": {}, "source": [ "### SIR 3S object types" ] }, { "cell_type": "markdown", "id": "2835cf9c", "metadata": {}, "source": [ "First, we need to obtain the internal SIR 3S object types to later pass to our function for obtaining the attribute names." ] }, { "cell_type": "markdown", "id": "d4f44083", "metadata": {}, "source": [ "You can use dir() to get an overview over the different object types existing in SIR 3S." ] }, { "cell_type": "code", "execution_count": 10, "id": "6de0d626-ef76-4a33-b081-86e2d957efec", "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": "9553616e", "metadata": {}, "source": [ "In our simple example we are only interested in the object types of nodes and pipes." ] }, { "cell_type": "code", "execution_count": 11, "id": "21506747", "metadata": {}, "outputs": [], "source": [ "node_type=s3s.ObjectTypes.Node" ] }, { "cell_type": "code", "execution_count": 12, "id": "a5081ead", "metadata": {}, "outputs": [], "source": [ "pipe_type=s3s.ObjectTypes.Pipe" ] }, { "cell_type": "markdown", "id": "438d38a1", "metadata": {}, "source": [ "### GetTksofElementType()" ] }, { "cell_type": "markdown", "id": "c8826bee", "metadata": {}, "source": [ "Now, we obtain the tks of the nodes and pipes in this model." ] }, { "cell_type": "markdown", "id": "fc0778a1", "metadata": {}, "source": [ "We use [GetTksofElementType()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.GetTksofElementType) to create a list of all node tks in the model." ] }, { "cell_type": "code", "execution_count": 13, "id": "f7379f50", "metadata": {}, "outputs": [], "source": [ "nodes=s3s.GetTksofElementType(ElementType=node_type)" ] }, { "cell_type": "code", "execution_count": 14, "id": "5f4efeca", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['4921762654790163024', '5483574590487309449']\n" ] } ], "source": [ "print(nodes)" ] }, { "cell_type": "markdown", "id": "e3cbfef1", "metadata": {}, "source": [ "If you don't want to predefine your element type you can also just pass it like done below" ] }, { "cell_type": "code", "execution_count": 15, "id": "19372c81", "metadata": {}, "outputs": [], "source": [ "pipes=s3s.GetTksofElementType(ElementType=s3s.ObjectTypes.Pipe)" ] }, { "cell_type": "code", "execution_count": 16, "id": "173ad436", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['4614473539164226343']\n" ] } ], "source": [ "print(pipes)" ] }, { "cell_type": "markdown", "id": "299bc123", "metadata": {}, "source": [ "### GetTkFromIDReference()" ] }, { "cell_type": "markdown", "id": "5cde8c1d", "metadata": {}, "source": [ "We can use the [GetTkFromIDReference()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.GetGeometryInformation) function, in case we have an ID reference value of a certain element given and want to get its tk." ] }, { "cell_type": "markdown", "id": "ea88275b", "metadata": {}, "source": [ "The nodes in our model have ID reference \"A\" and \"B\"." ] }, { "cell_type": "code", "execution_count": 17, "id": "1050bb1a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'4921762654790163024'" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.GetTkFromIDReference(IdRef=\"A\", object_type=s3s.ObjectTypes.Node)" ] }, { "cell_type": "code", "execution_count": 18, "id": "141e422a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'4921762654790163024'" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.GetTkFromIDReference(IdRef=\"A\", object_type=s3s.ObjectTypes.Node)" ] }, { "cell_type": "markdown", "id": "33d06bfd", "metadata": {}, "source": [ "We can see that they are the same tks we got from GetTksofElementType()." ] }, { "cell_type": "markdown", "id": "53f9248b", "metadata": {}, "source": [ "### GetObjectTypeof_Key()" ] }, { "cell_type": "markdown", "id": "dd55f59a", "metadata": {}, "source": [ "If we already have a tk/pk of an element we can use the [GetObjectTypeof_Key()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.GetObjectTypeof_Key) function to obtain its datatype." ] }, { "cell_type": "code", "execution_count": 19, "id": "ecf108b2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ObjectTypes.Node\n" ] } ], "source": [ "print(s3s.GetObjectTypeof_Key(Key=nodes[0]))" ] }, { "cell_type": "markdown", "id": "db3d47b6", "metadata": {}, "source": [ "### GetPropertiesofElementType()" ] }, { "cell_type": "markdown", "id": "cf25c5cb", "metadata": {}, "source": [ "Now, we obtain the internal SIR 3S attribute names. These will be necessary for our value query." ] }, { "cell_type": "markdown", "id": "2f40f6f6", "metadata": {}, "source": [ "We use [GetPropertiesofElementType()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.GetPropertiesofElementType) to create a list of all properties of nodes and pipes." ] }, { "cell_type": "code", "execution_count": 20, "id": "ab4ddfe1", "metadata": {}, "outputs": [], "source": [ "node_properties=s3s.GetPropertiesofElementType(ElementType=node_type)" ] }, { "cell_type": "code", "execution_count": 21, "id": "6caf0598", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['Name', 'Ktyp', 'Zkor', 'QmEin', 'Lfakt', 'Fkpzon', 'Fkfstf', 'Fkutmp', 'Fkfqps', 'Fkcont', 'Fk2lknot', 'Beschreibung', 'Idreferenz', 'Iplanung', 'Kvr', 'Qakt', 'Xkor', 'Ykor', 'NodeNamePosition', 'ShowNodeName', 'KvrKlartext', 'NumberOfVERB', 'HasBlockConnection', 'Tk', 'Pk', 'InVariant', 'GeometriesDiffer', 'SymbolFactor', 'bz.Drakonz', 'bz.Fk', 'bz.Fkpvar', 'bz.Fkqvar', 'bz.Fklfkt', 'bz.PhEin', 'bz.Tm', 'bz.Te', 'bz.PhMin']\n" ] } ], "source": [ "print(node_properties)" ] }, { "cell_type": "code", "execution_count": 22, "id": "6bc41c88", "metadata": {}, "outputs": [], "source": [ "pipe_properties=s3s.GetPropertiesofElementType(ElementType=pipe_type)" ] }, { "cell_type": "code", "execution_count": 23, "id": "228a2dc3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['Name', 'FkdtroRowd', 'Fkltgr', 'Fkstrasse', 'L', 'Lzu', 'Rau', 'Jlambs', 'Lambda0', 'Zein', 'Zaus', 'Zuml', 'Asoll', 'Indschall', 'Baujahr', 'Hal', 'Fkcont', 'Fk2lrohr', 'Beschreibung', 'Idreferenz', 'Iplanung', 'Kvr', 'LineWidthMM', 'DottedLine', 'DN', 'Di', 'KvrKlartext', 'HasClosedNSCHs', 'Tk', 'Pk', 'InVariant', 'Xkor', 'Ykor', 'GeometriesDiffer', 'bz.Fk', 'bz.Qsvb', 'bz.Irtrenn', 'bz.Leckstatus', 'bz.Leckstart', 'bz.Leckend', 'bz.Leckort', 'bz.Leckmenge', 'bz.Imptnz', 'bz.Zvlimptnz', 'bz.Kantenzv', 'bz.ITrennWithNSCH']\n" ] } ], "source": [ "print(pipe_properties)" ] }, { "cell_type": "markdown", "id": "a1f5cec2", "metadata": {}, "source": [ "### GetValue()" ] }, { "cell_type": "markdown", "id": "1ea252ea", "metadata": {}, "source": [ "Now, we can access values of indiviudal nodes with a corresponding tk." ] }, { "cell_type": "markdown", "id": "e48ac31f", "metadata": {}, "source": [ "We use [GetValue](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.GetValue) for such individual value query." ] }, { "cell_type": "markdown", "id": "c38f5cc8", "metadata": {}, "source": [ "#### Node 1" ] }, { "cell_type": "markdown", "id": "bb722962", "metadata": {}, "source": [ "As tk we just use the first tk from our nodes list." ] }, { "cell_type": "code", "execution_count": 24, "id": "5aa6e4ae", "metadata": {}, "outputs": [], "source": [ "node1_ktyp=s3s.GetValue(Tk=nodes[0], propertyName='Ktyp')" ] }, { "cell_type": "code", "execution_count": 25, "id": "2bd59d64", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "('PKON', 'string')\n" ] } ], "source": [ "print(node1_ktyp)" ] }, { "cell_type": "markdown", "id": "1e73764c", "metadata": {}, "source": [ "As you can see it returns a tuple value consisting of the actual value (here: 'PKON') of the attribute and the attribute data type." ] }, { "cell_type": "markdown", "id": "380c7be0", "metadata": {}, "source": [ "You can access the indiviudal components as follows." ] }, { "cell_type": "code", "execution_count": 26, "id": "333b92e8", "metadata": {}, "outputs": [], "source": [ "actual_value=node1_ktyp[0]" ] }, { "cell_type": "code", "execution_count": 27, "id": "47960f8f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "PKON\n" ] } ], "source": [ "print(actual_value)" ] }, { "cell_type": "code", "execution_count": 28, "id": "107d8d85", "metadata": {}, "outputs": [], "source": [ "data_type=node1_ktyp[1]" ] }, { "cell_type": "code", "execution_count": 29, "id": "728d80fe", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "string\n" ] } ], "source": [ "print(data_type)" ] }, { "cell_type": "markdown", "id": "a2005118", "metadata": {}, "source": [ "#### Node 2" ] }, { "cell_type": "markdown", "id": "25df42c6", "metadata": {}, "source": [ "Now we use the second tk from our nodes list." ] }, { "cell_type": "code", "execution_count": 30, "id": "e9b7e4fa", "metadata": {}, "outputs": [], "source": [ "node2_ktyp_actual_value=s3s.GetValue(Tk=nodes[1], propertyName='Ktyp')[0]" ] }, { "cell_type": "code", "execution_count": 31, "id": "f86a4429", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "QKON\n" ] } ], "source": [ "print(node2_ktyp_actual_value)" ] }, { "cell_type": "markdown", "id": "3024fa9b", "metadata": {}, "source": [ "#### Pipe" ] }, { "cell_type": "markdown", "id": "b2d63c3a", "metadata": {}, "source": [ "For the pipe we will just ignore the datatypes of the attributes and just access the value." ] }, { "cell_type": "code", "execution_count": 32, "id": "05a547c9", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['Name', 'FkdtroRowd', 'Fkltgr', 'Fkstrasse', 'L', 'Lzu', 'Rau', 'Jlambs', 'Lambda0', 'Zein', 'Zaus', 'Zuml', 'Asoll', 'Indschall', 'Baujahr', 'Hal', 'Fkcont', 'Fk2lrohr', 'Beschreibung', 'Idreferenz', 'Iplanung', 'Kvr', 'LineWidthMM', 'DottedLine', 'DN', 'Di', 'KvrKlartext', 'HasClosedNSCHs', 'Tk', 'Pk', 'InVariant', 'Xkor', 'Ykor', 'GeometriesDiffer', 'bz.Fk', 'bz.Qsvb', 'bz.Irtrenn', 'bz.Leckstatus', 'bz.Leckstart', 'bz.Leckend', 'bz.Leckort', 'bz.Leckmenge', 'bz.Imptnz', 'bz.Zvlimptnz', 'bz.Kantenzv', 'bz.ITrennWithNSCH']\n" ] } ], "source": [ "print(pipe_properties)" ] }, { "cell_type": "code", "execution_count": 33, "id": "a2ec773f", "metadata": {}, "outputs": [], "source": [ "pipe_length=s3s.GetValue(Tk=pipes[0], propertyName='L')[0]" ] }, { "cell_type": "code", "execution_count": 34, "id": "f0c92dcc", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "141,4214\n" ] } ], "source": [ "print(pipe_length)" ] }, { "cell_type": "code", "execution_count": 35, "id": "25a08515", "metadata": {}, "outputs": [], "source": [ "pipe_roughness=s3s.GetValue(Tk=pipes[0], propertyName='RAU')[0]" ] }, { "cell_type": "code", "execution_count": 36, "id": "30d64c63", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0,25\n" ] } ], "source": [ "print(pipe_roughness)" ] }, { "cell_type": "markdown", "id": "1773c47f", "metadata": {}, "source": [ "### GetGeometryInformation()" ] }, { "cell_type": "markdown", "id": "47052e26", "metadata": {}, "source": [ "We can use the [GetGeometryInformation()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.GetGeometryInformation) function to obtain the geometries of the objects based on their tk." ] }, { "cell_type": "code", "execution_count": 37, "id": "6e19ed40", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "POINT (0 0)\n", "POINT (100 100)\n" ] } ], "source": [ "for node in nodes:\n", " print(s3s.GetGeometryInformation(Tk=node))" ] }, { "cell_type": "code", "execution_count": 38, "id": "1a015942", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'LINESTRING (0 0, 100 100)'" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.GetGeometryInformation(Tk=pipes[0])" ] }, { "cell_type": "markdown", "id": "ed5aa0cd", "metadata": {}, "source": [ "## Set Values" ] }, { "cell_type": "markdown", "id": "61817332", "metadata": {}, "source": [ "### SetValues()" ] }, { "cell_type": "markdown", "id": "87589dae", "metadata": {}, "source": [ "You can use the [SetValue()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.SetValue) function to change non-result non-geometry values of objects based on their tk." ] }, { "cell_type": "markdown", "id": "87dd604f", "metadata": {}, "source": [ "#### Node" ] }, { "cell_type": "code", "execution_count": 39, "id": "3da262f7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "('PKON', 'string')\n" ] } ], "source": [ "print(s3s.GetValue(Tk=nodes[0], propertyName='Ktyp'))" ] }, { "cell_type": "markdown", "id": "764a7ce3", "metadata": {}, "source": [ "Here we change a node from PKON to QKON" ] }, { "cell_type": "code", "execution_count": 40, "id": "8d59b31c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Value is set\n" ] } ], "source": [ "s3s.SetValue(nodes[0], propertyName='Ktyp', Value='QKON')" ] }, { "cell_type": "code", "execution_count": 41, "id": "5409f1bc", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "('QKON', 'string')\n" ] } ], "source": [ "print(s3s.GetValue(Tk=nodes[0], propertyName='Ktyp'))" ] }, { "cell_type": "markdown", "id": "a02bea25", "metadata": {}, "source": [ "#### Pipe" ] }, { "cell_type": "code", "execution_count": 42, "id": "ae2740da", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0,25\n" ] } ], "source": [ "print(s3s.GetValue(Tk=pipes[0], propertyName='RAU')[0])" ] }, { "cell_type": "markdown", "id": "d105da6f", "metadata": {}, "source": [ "Here we change the roughness of a pipe from value 3 to 6." ] }, { "cell_type": "code", "execution_count": 43, "id": "06007a1d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Value is set\n" ] } ], "source": [ "s3s.SetValue(Tk=pipes[0], propertyName='RAU', Value='6')" ] }, { "cell_type": "code", "execution_count": 44, "id": "afca0af3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "6\n" ] } ], "source": [ "print(s3s.GetValue(Tk=pipes[0], propertyName='RAU')[0])" ] }, { "cell_type": "markdown", "id": "89d078ac", "metadata": {}, "source": [ "### SetGeometryInformation()" ] }, { "cell_type": "markdown", "id": "286bcb4a", "metadata": {}, "source": [ "You can use the [SetGeometryInformation()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.SetGeometryInformation) function to change non-result geometry values of objects based on their tk. The geometry has to be given in Wkt format." ] }, { "cell_type": "markdown", "id": "917efd3a", "metadata": {}, "source": [ "Let's move the simple network 100 into positive x-direction." ] }, { "cell_type": "markdown", "id": "a3ba0297", "metadata": {}, "source": [ "#### Node" ] }, { "cell_type": "code", "execution_count": 45, "id": "6951dfa0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Geometry Information is set correctly\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.SetGeometryInformation(Tk=nodes[0], Wkt=\"POINT (100 0)\")" ] }, { "cell_type": "code", "execution_count": 46, "id": "c9c319d9", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Geometry Information is set correctly\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.SetGeometryInformation(Tk=nodes[1], Wkt=\"POINT (200 100)\")" ] }, { "cell_type": "markdown", "id": "1ff07253", "metadata": {}, "source": [ "#### Pipe" ] }, { "cell_type": "code", "execution_count": 47, "id": "127dd37f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Geometry Information is set correctly\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s3s.SetGeometryInformation(Tk=pipes[0], Wkt=\"LINESTRING (100 0, 200 100)\")" ] }, { "cell_type": "markdown", "id": "c99862ea", "metadata": {}, "source": [ "## Save Changes" ] }, { "cell_type": "markdown", "id": "a5c45f0d", "metadata": {}, "source": [ "If you want your changes made to the model to be saved use the [SaveChanges()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model.SaveChanges) function." ] }, { "cell_type": "code", "execution_count": 48, "id": "77b4e3f5", "metadata": {}, "outputs": [], "source": [ "#s3s.SaveChanges()" ] }, { "cell_type": "markdown", "id": "3e418317-303f-40d1-80aa-af17a6323763", "metadata": {}, "source": [ "Alternatively, the user can save the changes when closing the model using the [CloseModel()](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_View.CloseModel) function." ] }, { "cell_type": "code", "execution_count": 49, "id": "38021e5b-5725-4be7-bfd5-6bde6e6255cc", "metadata": {}, "outputs": [], "source": [ "#s3s.CloseModel(saveChangesBeforeClosing=True)" ] }, { "cell_type": "markdown", "id": "e12649c6", "metadata": {}, "source": [ "Now you are able to access values from SIR 3S objects based on their tk, but using the above methods only works for non-result values. " ] }, { "cell_type": "markdown", "id": "c721f6ab", "metadata": {}, "source": [ "__Next:__ Tutorial 3: Accessing simulation results" ] } ], "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 }