Tutorial 2: Creating or Opening a SIR 3S Model

This Tutorial demonstrates how to create new SIR 3S Models or open already existing ones.

Toolkit Release

[1]:
#pip install sir3stoolkit

Imports

DLL References

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.

[10]:
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.

[13]:
s3s = wrapper.SIR3S_Model()
Initialization complete
[14]:
s3s_view = wrapper.SIR3S_View()
Initialization complete

Create New Model

We are using the NewModel() function of SIR3S_Model() to create a new db3 file.

[15]:
dbFilePath=r"Toolkit_Tutorial2_NewModel.db3"
[16]:
s3s.NewModel(dbName=dbFilePath,
                           providerType=Interfaces.SirDBProviderType.SQLite,
                           namedInstance="",
                           netType=Interfaces.NetworkType.Undefined,
                           modelDescription="Tutorial New Model",
                           userID="",
                           password="")
New model is created with the model identifier: M-1-0-1

Now the Model has been created and is opened. All Toolkit commands now apply to this model until another one is opened. If there already existed a model file with this path and name, a new model with the same name but incremented model identifier is created.

[17]:
print(s3s.GetNetworkType()) # to check that the model is responsive
Undefined

Open Model

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

Now the Model has been opened the previous one was close without saving it. All Toolkit commands now apply to this model until another one is opened.

[20]:
print(s3s.GetNetworkType()) # to check that the correct model is responsive, model we are trying to open was createdd with type District Heating
DistrictHeating

Now follows: Tutorial 3: Getting and Setting Values