Sim Unit DLL Programming Guide
Sim Unit DLL Programming Guide
1/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
HSC Sim flowsheet process model consist of unit operations connected with each other using
streams. Two types of unit operation models may be used: 1) Excel and 2) DLL type models.
Excel models may be created using build in Excel editor and unit wizards.
DLL type unit models must be created using some of MS Visual Studio languages. This manual
describes how to create your own models using [Link] and build them into a DLL file used in Sim
process models.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
2/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Contents
50.1. HSC Sim unit DLL programming quick start 4
50.1.1. Requirements 5
50.1.2. Creating a new project 6
50.1.3. Unit DLL Template 9
50.1.4. Namespaces 11
50.1.5. Input and output streams 14
50.1.6. Parameters 16
50.1.7. Model internal states 17
50.1.8. Runtime variables 18
50.1.9. Model parameter initialization 19
50.1.10. Calculation within the example unit model 20
50.1.11. Applying and testing the model 22
50.1.12. Example code 25
50.2. HSC unit DLL class technical documentation 27
50.2.1. Basic requirements 27
50.2.2. Unit DLL interfaces and their versions 31
50.2.3. Unit DLL initialization 31
50.2.4. Input and Output streams 31
[Link]. Several streams connected to a single Input/Output stream variable 32
50.2.5. Mode specific differences 33
[Link]. Reactions (Hydro) Unit DLLs 33
[Link]. Distributions (Pyro) Unit DLLs 35
[Link]. Particles (MinPro and Recycling) Unit DLLs 37
50.2.6. Unit DLL Properties (parameters) 38
[Link]. Parameter basics 38
[Link]. How Sim updates the property values between Sim and Unit DLL 38
[Link]. Allowed property types 39
[Link]. Model parameters 39
[Link].1. Groups 40
[Link]. Internal states 41
[Link]. Runtime variables 42
[Link]. Model fit parameters 43
[Link]. InitModelParameters subroutine in Unit DLL 43
[Link]. HiddenPropertyNames subroutine in Unit DLL 44
50.3. Unit DLL Calculation 46
50.3.1. CalcStatic 46
50.3.2. CalcDynamic 46
50.3.3. Writing messages to Sim calculation log 47
50.3.4. Using HSC8Streams and manipulating stream contents 47
50.4. Stream composition 48
50.4.1. Basic stream manipulation routines 48
50.4.2. Different component types 50
[Link]. IStreamComponent 50
[Link]. StreamSpecies (IStreamSpecies) 50
[Link]. Particle (IParticle) 51
50.4.3. Processing the stream contents 52
[Link]. All stream components, no matter what type they are 52
[Link]. All phases (and all components) 52
50.4.4. PhaseGroups 52
[Link]. StreamPhaseGroup 52
[Link]. MineralPhaseGroup 53
[Link]. ConvertedPhaseGroup 53
[Link]. GlobalPhaseGroup 53
50.4.5. Named variables available in the Unit DLL calculations 53
[Link]. HSC (given as a parameter to CalcStatic and CalcDynamic) 53
[Link]. timestepseconds (parameter to CalcDynamic) 53
[Link]. ReferenceStream (protected property in Unit DLL base class, available for all Unit DLLs) 53
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
3/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
4/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
The HSC Chemistry flowsheet simulator module Sim offers its users the possibility of
creating their own custom unit operation models. Unit operation models can be created
by using either a built-in Excel editor or by using one of the programming languages
supported by Microsoft Visual Studio. These self-made unit operation models enable
the user to create tailored process models for many different types of industrial
processes.
This document helps write the code for a custom unit by using Microsoft Visual Studio
IDE (Integrated Development Environment) and Visual [Link] programming
language. Although we use Visual Studio and Visual [Link] in the examples, this is
not the only suitable programming language. Other options include for instance C# and
F# (see [Link] for further information).
Readers with no previous knowledge of these languages might find it useful later to
refer to some online or printed learning resources, which are readily available.
In this quick start instructions, a simple functioning model for a thickener unit will be
created. In HSC Sim the unit files are referred as Unit DLLs as the models are
wrapped inside dynamic link library (DLL) files.
In addition, the unit DLL class template and some example program code projects can
be found in ‘C:\Program Files (x86)\HSC10\Sim\Unit DLL Examples’ folder.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
5/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
50.1.1. Requirements
As mentioned earlier, the tool of choice for development in this manual is Visual Studio.
A free version of Visual Studio (Visual Studio Express for Windows Desktop) is
available for download from Microsoft for free, but it is possible to use any other version
of it (Professional, Premium or Ultimate). Version 4.5 (or later) of the .NET framework
has to be installed in the system when developing DLL unit models. For example,
Visual Studio 2012 or newer includes installation files for .NET Framework 4.5.
Fig. 1. The examples in this document were written with Visual Studio 2012 Professional. The
other editions of Visual Studio look similar, but the menu arrangements vary depending on the
user settings.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
6/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Open the New Project dialog box by choosing File > New > Project. Open Installed |
Templates | Visual Basic | Windows group as shown in Fig. 2. Choose the Class
Library template. Next, enter the location (folder) and name for the project.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
7/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Next, choose Project > YourUnitName Properties… to open the project properties
dialog. Open the References tab, see Fig. 3.
Press the Add button and select the following assembly from the Assemblies |
Framework group by ticking its check box and clicking OK.
[Link]
[Link]
Continue adding references by clicking Browse at the bottom of the window and
locating the following HSC Chemistry assemblies:
After successful addition of the libraries, your References tab should look similar to Fig.
4.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
8/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Fig. 4. References tab after adding the references to the required class libraries.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
9/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
DLL unit [Link] template may be used to create new DLL units. The user must
specify Namespace, Input and output streams, model parameters, internal states,
runtime variables and static or dynamic calculation formulas.
When model is ready user must compile DLL and copy DLL file into a correct folder
where HSC Sim can find it.
The parameters which user specifies in the parameters section will arise automatically
into Parameters sheet in the same order as typed in the source code.
Imports [Link]
Imports [Link]
Imports [Link]
Imports [Link].UnitDLL9_1
'---Inputs:
<StreamIn("Input", 1)>
Public Property Input As IHSC8Stream
'---Outputs:
<StreamOut("Output", 1)>
Public Property Output As IHSC8Stream
#End Region
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
10/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
End Sub
End Sub
#End Region
End Class
Fig. 5. Image of DLL Unit Template.
Fig. 6. DLL Unit source code #Region "Model Parameters" will fill automatically Parameters
sheet in DLL unit editor workbook. Printscreen example is from Flotation cell unit model with
long list of different type of calculation parameters.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
11/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
50.1.4. Namespaces
The references have made the existing HSC namespaces available in our class library
project. To make it easier to refer to the classes in those namespaces, we will add a
few Imports statements to the beginning of the file. This makes referring to the classes
easier. As an example, a variable declaration such as
can be written as
after the appropriate namespace (in this case [Link]) has been imported.
From here on, screenshots are not used to show how the source code has been
modified; instead they are shown as text. Copying and pasting a code to your own
model’s source code is OK, but you might find it useful to know that the complete code
for the example unit is listed in Appendix B.
Instead of using a generic class name such as Class1 for our class, we will change the
class name to ExampleThickener. The class file name can be changed in the solution
explorer by right-clicking the file name and choosing Rename (e.g.
[Link]). Keeping the names consistent might turn out to be useful later,
especially if you have several files and classes in your class library project. It is
possible to create several unit model classes within one file, but a more common
practice is to have each class in its own file.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
12/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
The next step is to add general information about your unit. This is done by using an
attribute element (marked as <attribute info>) that resides just before the class
statement, see the example below. The information inserted here is shown in the
‘select unit models’ dialog in HSC Sim.
<Addin("Example Unit")>
<QualificationData("Static", "True")>
<QualificationData("Dynamic", "False")>
<QualificationData("TypeCode", "MU-100-10-DEV")>
<QualificationData("Technology", "Others")>
<QualificationData("Version", "1.0")>
<QualificationData("Description", "Description")>
<QualificationData("Author", "© Outotec (Finland), Authors: X")>
Public Class ExampleThickener
End Class
The information contained in the attribute includes the name of the model, description
of the model, the name of the author, and whether the model is intended for static or
dynamic modeling (at the moment only Static can be used).
An optional field in the attribute is the type code field. The type code can be any user-
selected code to identify the model in addition to its name. For example, the HSC Sim
models use the following notation: first, a two-lettered abbreviation that tells us the
category of the unit (MU – mineral unit, HU – hydro unit, PU – pyro unit, RU – recycling
unit), followed by a three-digit process area number and a two-digit unit model number.
The information within the required attribute fields is important for HSC Sim to be able
to handle the file properly, so it should be written in the same manner as in the
example.
Note: If the TypeCode ends with "DEV", then the Unit DLL file is not saved with the
flowsheet. Normally Unit DLL files are supposed to be saved with the flowsheet so they
can be copied to other users but when you are developing the Unit DLL, it is better to
save the test flowsheets without DLL files and then Sim will always load and use the
latest version of your Unit DLL.
The base class for each model class is the UnitDLL class. It has to be inherited and the
Visual Basic way to express this is to use the Inherits keyword right after your class
name.
#End Region
End Class
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
13/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
When the text Inherits UnitDLL is inserted, Visual Studio automatically adds two
methods (CalcStatic and CalcDynamic), that have to be overridden in the model class.
In this example, an internal Private Sub method called CalcOutput has been added. It
is called by both the static and dynamic calculation modes. If the model is static only,
both functions, CalcStatic and CalcDynamic, have to perform the same static
calculation just like in the example.
The code can include #Region directives, which make it is possible to collapse and
hide blocks of code in Visual Basic files. It is not compulsory to use the #Region
directive, but it might be useful to be able to hide blocks of code in larger files. This way
it is easier to focus on only portions of it at a time.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
14/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
In HSC Sim 9, material and energy are transferred from one unit to another via
streams. The examples below show how to declare the streams that connect to a unit
in HSC Sim.
A unit can have input and output streams in the following ways:
One or more input streams (the number of streams is known). Each of them is
declared as a Property preceded by a StreamIn attribute, as shown here:
<StreamIn("Feed", 1)>
Public Property Feed As IHSC8Stream
<StreamIn("Feeds", 1)>
Public Property Feeds As List(Of IHSC8Stream)
<StreamOut("Overflow", 1)>
Public Property Overflow As IHSC8Stream
<StreamOut("Outputs", 1)>
Public Property AllOutputs As List(Of IHSC8Stream)
<StreamIn("Cake_Wash_Water", 2, Required:=False)>
Public Property CakeWashWater As IHSC8Stream
<StreamOut("Water_Outlet_A", 3, Required:=False)>
Public Property WaterOutA As IHSC8Stream
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
15/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Our example unit has one input stream and two output streams. The input stream is
called Feed and is assigned a stream number of 1 and set as the default input. If an
input stream is defined as default, HSC Sim automatically assigns the first user-drawn
input stream to this input stream. If no default streams are set, HSC Sim opens a dialog
box in which the latest user-drawn stream can be assigned to one of the pre-defined
streams in the model (such as Overflow or Underflow, as below).
'Inputs:
<StreamIn("Feed", 1, IsDefaultInput:=True)>
Public Property Feed As IHSC8Stream
'Outputs:
<StreamOut("Overflow", 1)>
Public Property Overflow As IHSC8Stream
<StreamOut("Underflow", 2)>
Public Property Underflow As IHSC8Stream
#End Region
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
16/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
50.1.6. Parameters
Model parameters have initial values and the information concerning them are defined
inside the Parameter attribute. The heading, name, measure unit, and description have
to be specified for a parameter, but its limits are optional. Users can later change the
parameter values in HSC Sim 9, where a user interface is automatically provided for
doing this. An example of model parameter declaration is shown here:
In the example below, the heading is declared as a constant character string. Using
constants is useful as the heading field is used to categorize and group the parameters
of the model. Using constant strings also makes group naming less error-prone.
Maximum and minimum limits are also set for the parameter (minimum as MinLim:=1,
maximum as MaxLim:=100). A parameter value has to be set by the user between its
maximum and minimum values if such values are defined.
#End Region
As for the colon, e.g. MinLim:=1, this means that the value for MinLim is passed by
name. In other words, it is okay to code these limits in any sequence and it is not
compulsory to indicate if a particular limit is omitted (i.e. they are optional).
Parameter values can also be provided by using a specific table type class, see
UnitTableDouble, UnitTableString and UnitTableObject.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
17/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Model internal states are public properties, which are stored by HSC Sim in the model
.xls file, but are not shown to the user in the user interface. These properties can be
used to store the model state between calculations, e.g. previous round output streams
can be stored.
Since the example does not need to store any of its states, this part can be neglected
or a region stub can be inserted into the example model’s source code for future
reference.
#Region "Model Internal States"
'Not in use in this unit
#End Region
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
18/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Runtime variables are for presenting the model internal states during the calculation,
i.e. information that cannot be provided from/to the model with the output/input stream.
They are also used for controlling certain model operating conditions (=model internal
states) during the runtime, especially in dynamic simulations. An example of such a
case is a tank level measurement (runtime output variable) that is controlled by using a
HSC control that changes the tank outlet valve position (runtime input variable).
The variables can be inputs (write only), outputs (read only), or inputs and outputs
(read/write).
The example does not utilize runtime variables either, so only a region stub is inserted
into to the code, although it is not necessary. In the future it will be easy to make
amendments to the code by filling the empty regions with relevant program code.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
19/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
InitModelParameters sub is called by HSC Sim when the model is applied. This sub
is not necessary for all units. Typically this is needed if some tables are to be initialized
based on the input stream structure of the model.
Protected Overrides Sub InitModelParameters(HSC As IHSC8, RefFeed As
IHSC8Stream)
'[Link](HSC, RefFeed)
End Sub
The example code does not need to initialize any parameters beforehand. The
example code is left without any reference to model parameter initialization.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
20/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
The simple thickener unit that is modeled here first counts the amount of solids and
water in the input stream. It then calculates how much water is needed in the underflow
to reach the desired solids percentage (set via a parameter) in the underflow stream.
Solids percentage x in the underflow is calculated as follows:
𝑚𝑠𝑜𝑙𝑖𝑑𝑠 (1)
=𝑥
𝑚𝑠𝑜𝑙𝑖𝑑𝑠 + 𝑚𝑤𝑎𝑡𝑒𝑟
Since x is the parameter value that the user sets and the amount of solids is known
due to prior calculations, equation (1) can be rearranged to
(1 − 𝑥) (2)
𝑚𝑤𝑎𝑡𝑒𝑟 = 𝑚𝑠𝑜𝑙𝑖𝑑𝑠
𝑥
Equation (2) is included in the model code. Finally, the example unit directs all the
solids and the required amount of water to the underflow and the excess water to the
overflow.
It is worth mentioning that it is possible to send messages from the model to the HSC
Sim user interface. The sent messages are shown in the log viewer. Some examples
are included in the example code and the way the messages are displayed is
demonstrated in the next chapter.
The Unit model can send three types of messages to the user during the calculation:
Info messages
InfoMessage("Cyclone is roping according to SPOC criterion.")
Warning messages
WarningMessage("Solids percentage target(s) could not be reached.")
Error messages
RaiseFatalErrorException("Recovery calculation for selected particle
floatability type is not supported by this model version.")
About debugging a class library project (such as a unit model project), please refer to a
web page like [Link] (Debugging
DLL Projects) and follow the given instructions (when you need to select Start external
program please choose C:\Program Files (x86)\HSC10\Programs\[Link]).
It is possible to utilize the info and warning message, too. Add info messages to your
model and have it send appropriate information to the log viewer so that you can track
your model operation. If unexpected or inconsistent results come up, make changes to
the code and re-build your project. Then test the new version of your model within HSC
Sim.
Below is the code for the CalcOutput method. It is called by the CalcStatic and
CalcDynamic methods and it is the method in our example that does the calculations. It
includes both an InfoMessage and a WarningMessage to show how they can be
implemented. No further code is needed in this example.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
21/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
End Sub
#End Region
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
22/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Once the model is ready, choose Build > Build Solution. This command builds the
solution and creates the [Link] file with the required support files
(UnitDLL9_2.dll) in the bin/Debug folder, which in the case of our example is located at
C:\UnitModels\ExampleUnit\ExampleUnit\bin\Debug
Start HSC Sim 9. Draw a generic unit and right-click on the new unit. Choose “Unit
Model Editor”. Make sure that Unit 1 is selected and then locate Example Unit (since
the type code for this unit started with an H, it is listed in the Reactions tab, which
shows the Hydro units). Double-click the name of the unit and click OK. Now our model
is applied to the newly drawn unit.
Draw an input stream in the unit. Add an output stream. A dialog box opens that asks
you to assign an output port to the stream; choose Overflow. Add another stream. Now
the flowsheet should look something like the one in Fig. 7.
Double-click the unit to open its properties view. Choose Variable List Editor and add
H2O to the Water Phase. Add SiO2 to Pure Phase (in the figure: Solid Phase), see Fig.
8.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
23/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Fig. 8. Variable List Editor after compounds have been added and a phase name has been
modified.
Accept changes by clicking the Activate button in the top left corner. Choose the Input
sheet and specify the amount of incoming compounds, e.g. 5 t/h of H2O and 2 t/h of
SiO2. Close the properties window. Press the Simulate button (light blue right-pointing
arrow) in the toolbar. After the calculations are ready, turn on the Toggle Stream
Visualization Mode by clicking the eyeball-like icon in the toolbar.
For illustrative purposes “Species: H2O (t/h)” option has been selected from the
dropdown menu in the toolbar, see Fig. 9. The Log viewer can be made viewable by
choosing View > Toolbars > Log viewer. Use the Log viewer to locate the information
messages sent from the model.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
24/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Fig. 9. Streams visualized and the log viewer showing InfoMessages. Warnings can be viewed
similarly through the Log viewer.
To change a parameter value, double-click the unit in the flowsheet and select the
Configuration sheet. This sheet contains all user-specified parameters along with their
measure units, possible limits, and descriptions of the parameters.
Fig. 10. Users can change parameter values via the Configuration sheet.
If a value below the minimum limit is typed into the value cell, the value in the cell is
automatically changed to the minimum value. A similar automatic change takes place
when a value that is too great is typed into the value cell.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
25/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Imports [Link]
Imports [Link]
Imports [Link]
Imports [Link].UnitDLL9_2
<AddIn("Example Unit")>
<QualificationData("Static", "True")>
<QualificationData("Dynamic", "False")>
<QualificationData("TypeCode", "MU-100-10-DEV")>
<QualificationData("Technology", "Others")>
<QualificationData("Version", "1.0")>
<QualificationData("Description", "Unit modelling example")>
<QualificationData("Author", "Company Name - Your Name")>
Public Class ExampleThickener
Inherits UnitDLL
'Inputs:
<StreamIn("Feed", 1, IsDefaultInput:=True)>
Public Property Feed As IHSC8Stream
'Outputs:
<StreamOut("Overflow", 1, Required:=False)>
Public Property Overflow As IHSC8Stream
<StreamOut("Underflow", 2)>
Public Property Underflow As IHSC8Stream
#End Region
#End Region
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
26/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
#End Region
End Sub
#End Region
End Class
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
27/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
The compiled DLL (Dynamic Link Library) must reside in subfolder under
<user>\AppData\Roaming\Outotec\HSC10\DevelopmentUnitDLL
(so your DLL could be in
C:\users\username\AppData\Roamng\Outotec\HSC10\DevelopmentUnitDLL\MyAddinFolder\[Link])
The assembly must have references to
[Link]
[Link]
UnitDLL9_2.dll (found in C:\Program Files (x86)\HSC10\Programs or ..\..\Lib if you
are using the Sim source code)
SimAddinView9_2.dll (found in C:\Program Files
(x86)\HSC10\Sim\UnitDLLPipelines\9\AddInViews). Note that "Copy Local" must
be False.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
28/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Publisher "Joe Programmer" (Optional) Author of the DLL. This is displayed in the
Author part in Unit model type selector
This can be also given in a <QualificationData>
attribute (see below)
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
29/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Some class information (such as "supports dynamic calculations", "Typecode", "Technology") can
be defined with <QualificationData> attribute. Supported values are:
Static "True" / "False" If "True", then the Unit DLL supports calculations in Static
(default) mode
Dynamic "True" / "False" If "True", then the Unit DLL supports calculations in Dynamic
(default) mode
If the type code ends with "DEV", the Unit DLL is handled a bit
differently than normally. Typically Unit DLL is saved with the
flowsheet which means that the flowsheet will always use the
version of the Unit DLL which was in use when the flowsheet
was created. "DEV" prefix in the name means that you can
create a test flowsheet with the initial version of your Unit DLL
and then use the same flowsheet for testing your Unit DLL
while you keep updating your code. Just remember to remove
the DEV extension before you publish the Unit DLL.
About version numbers: If the major version stays the same, then Sim
assumes that the configuration options of the Unit DLL stay the same.
Therefore it is possible to update the Unit DLL version and still keep the
old parameters. However, if the user chooses to update version 1.1 to
2.0, then the unit file is fully cleared and all configuration options are
reset to their default values.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
30/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Imports [Link]
Imports [Link]
Imports [Link]
End Sub
End Sub
End Class
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
31/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
New versions of the Unit DLL interface are published every now and then. In the new
versions, some new features are added, some old may be removed
New version of HSC installation will always support the DLL with old interface versions For
example some release version of HSC Sim can support totally following all interface
versions:
9 ([Link] and [Link])
9_1 (UnitDLL9_1.dll and SimAddinView9_1.dll)
9_2 (UnitDLL9_2.dll and SimAddinView9_2.dll)
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
32/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
When drawing the flowsheet, the user can choose which stream is connected to which
Input/Output property
Multiple streams can be connected to the same property
Input:
If the property type is IHSC8Stream, then the input streams are added
together and the sum is put to the IHSC8Stream variable
Currently supported only for HSC Sim particles based unit models
If the property type is List(Of IHSC8Stream), then the list contains all the
streams as separate streams
It is usually done like this in HSC Sim reaction based unit models.
Output:
If the property type is IHSC8Stream, then only one output stream can be
connected to this variable
If the property type is List(Of IHSC8Stream), then multiple output streams
can be connected
The list contains empty IHSC8streams for each connected output
stream
Each stream has a parameter which contains the stream GUID
(identifier that can be used in the user interface to distinguish
different output streams in some table etc.)
It is not possible to use the stream name in Unit DLL because
the stream name may change at any time and that would
destroy the configuration in the Unit DLL
instead the Unit DLL uses the GUID in UnitTable row/column
names and Sim converts that to human-readable stream
name in the graphical user interface
The GUID can be obtained with the following method:
<StreamOut("Outputs", 1)>
Dim s = [Link] ' Get the GUID of the output stream and use it
somewhere
Next
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
33/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
the Unit DLL code is pretty similar in different HSC Sim calculation modes but there are
some differences that the programmer should be aware of
The input and output streams ALWAYS contain only IStreamSpecies (particles are not
possible in Hydro)
You can't create output species that don't exist in the input (input contains all species that
have been defined in the Hydro variable list editor and no other species can be used)
If you create species that don't exist in the variable list, the calculations are
immediately stopped when Sim tries to write the species to the Hydro Output sheet
Hydro input streams contain also information from the variable list
This information is stored in Input stream parameters -> the information is not
automatically copied to output/tank streams when you add
StreamComponentAmounts to the other streams
Since some of these parameters are important during calculations (volume
calculation parameters being the most important), Sim can't combine different input
streams and still retain that data
Therefore Unit DLL coder must "manually" copy the Hydro specific volume
data to the tank/output
And Sim can't combine input streams to one IHSC8Stream
If an unlimited amount of inputs can be connected to the Unit DLL, then you must define the
input as List(Of IHSC8Stream)
Just IHSC8Stream doesn't work because Sim can't combine multiple input streams
and still automatically merge the hydro specific parameters of the streams
Hydro input streams contain information about phase volume calculations
This information is given in the Hydro variable list editor
It affects how water phase volume is calculated
If this information is lost, then the water phase is calculated using the default volume
calculation routine which doesn't take ions into account -> gives different results
than the Excel side
The information is stored in Input streams as parameters which means that
if you just add the species to a tank using the normal AddStream routine, the
volume calculation information is not copied to the tank -> tank volume is
calculated incorrectly
Therefore you must copy the hydro volume calculation information from the
Input stream to the Tank using
[Link](tankStream) command.
By default, Hydro Output sheet temperature and pressure fields are defined by the user =
values in the output HSC8Stream are NOT used.
The Unit DLL must set a certain parameter for a PhaseGroup if it wants the Output
sheet to get temperature values from that phase:
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
34/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
' The Output sheet temperature is taken from the first phasegroup in the stream
(note that the phasegroup order is almost random so this works correctly only if all
phasegroups have the same temperature)
[Link]([Link]
eGroup)
' The Output sheet pressure is taken from the first phasegroup in the stream (note
that the phasegroup order is almost random so this works correctly only if all
phasegroups have the same
pressure)[Link]([Link]
[Link])
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
35/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Pyro Unit DLL has three options to generate output:
1. Use only variables that already exist on Output sheet
If the output stream contains variables that don't exist on Output
sheet, the calculation is stopped because of an error
2. Add new variables to Output sheet if necessary
Unit DLL can output species that don't yet exist on Output sheet. If
such species are found in the Unit DLL output, the new species are
automatically added to Output sheet variable list, even during
calculations
3. Update the Output sheet variable list according to Unit DLL output
New species are added to Output sheet variable list automatically
If Output sheet contains variables that don't exist in the Unit DLL
output stream, they are removed from the variable list
This keeps the Output sheet "clean" but may cause lots of changes
during calculations if the output streams change a lot
Unit DLL can/must specify the mode for each stream separately by setting
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
36/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
[Link] property:
' Allow adding new variables, but unused variables are not removed from Output sheet
[Link] =
[Link]
' Update the variable list according to the stream output (add new variables and
delete unused variables from Output sheet)
[Link] =
[Link]
Note that updating the variable list during calculations may slow down
calculations so try to avoid unnecessary variable list updating
However, if the output variable list doesn't change during calculations
(usually it is not necessary after the first round), then you can safely
use even OverwriteVariables mode
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
37/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
In MinPro, both Input and Output may contain both IStreamSpecies (at least in Liquid and
Gas phases) and IParticles (in particle phase)
You can create new components "on the fly" so you can create different kind of particles
(and even convert species to different species). For example a grindin mill outoput can
consist of small particles that were not existing in the input stream at all
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
38/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
All public variables in the Unit DLL should be defined as one of the attributes listed here
later on
Variables must be Public Properties
Properties that have one of these attributes are saved properly with the flowsheet and
loaded back when the flowsheet is loaded or calculations are started
If Unit DLL uses public variables that are not defined with one of these attributes, then the
contents of those variables are lost when
Calculations are started/stopped
Flowsheet is saved/loaded
So do not use class member variables without one of these attributes unless you
use some other wrapper property to save the value
[Link]. How Sim updates the property values between Sim and Unit DLL
Unit DLL has defined the properties and their types (Model parameter, Runtime variable,
Internal state)
Sim extracts the list of these parameters from the Unit DLL and creates an user interface so
the user can change and see the values
When the user changes a parameter or parameters are written from Sim to Unit DLL for
some other reason (calculations start, during calculations, flowsheet is loaded, etc.), Sim
does the following things in this order:
1. Write the parameter value(s) to the Unit DLL
Sim writes the new value or values directly to the Unit DLL properties
Unit DLL property setter can do some processing immediately at this point
(for example ensure that the sum of some variables is exactly the desired
value etc.)
2. Updates the reference stream (MinPro only) to the Unit DLL by setting the
ReferenceStream variable (reference stream is needed e.g. for retrieving fowsheet
‘master’ particle size fraction list)
3. Call Unit DLL InitModelParameters sub
Here the Unit DLL can ensure that all tables and values are initialized
correctly
4. Read all property values from the Unit DLL
All values are read at this point because setting one property and calling
InitModelParameters may have changed several other property values in the
Unit DLL so everything must be updated in the user interface
5. Call Unit DLL HiddenProperties sub
Unit DLL may hide some properties from the user, for example if the Unit
DLL has several configuration levels (simple, advanced)
6. Update the user interface
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
39/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
String
Double
Single
Integer
Boolean
UnitTableDouble
UnitTableString
IHSC8Stream
List(Of IHSC8Stream)
Enum
Class types
Arrays of any of the previous
except UnitTableDouble, UnitTableString, IHSC8Stream and List(Of IHSC8Stream)
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
40/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
[Link].1. Groups
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
41/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
<InternalState("Tank")>
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
42/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Runtimeparameters are parameters that are updated between Sim and Unit DLL every
calculation round
Examples are writing some valve setting to the Unit DLL, reading tank level from Unit DLL,
etc.
In Sim, the Runtime parameters are usually used with Sim controls
Defined with RuntimeVariable attribute:
' Write only property defined in the property definition (WriteOnly specifier)
<RuntimeVariable("Bypass ON", "", "Set line bypass ON")>
Public WriteOnly Property BypassON As Boolean
Set(value as Boolean)
Me._byPassOn = value
End Set
End Property
' Read only property defined in the property definition (ReadOnly specifier)
<RuntimeVariable("Bypass Status", "", "Line bypass ON/OFF")>
Public ReadOnly Property BypassStatus As Boolean
Get
Return Me._bypassStat
End Get
End Property
' Writeonly property defined using the RuntimeVariable attribute (ModelInput and
ModelOutput)
<RuntimeVariable("Valve Opening", "%", "Set the valve opening (0 - 100)",
ModelInput := True, ModelOutput := False)>
Public Property ValveOpening As Double
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
43/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
[Link](HSC, ReferenceFeed)
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
44/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Return lst
End Function
Note that the function should return property names defined in Unit DLL code, not the
display names that are shown to the user in Sim.
Unit DLL base class contains a helper routine AddHiddenPropertyGroup which can be used
to hide all properties that belong to a given group (that are seen as navigation links in the user
interface in the left side panel) For example "Sizing" group can be hidden with this single
command:
Return lst
End Function
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
45/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
A more advanced way to hide multiple properties (or class properties which may have lots of
subproperties) with one command is AddHiddenPropertyPrefix
Give Property name (or beginning of it) as the argument.
If it is "Tank1", then property "Tank1", subproperties "[Link]", "[Link]" are
hidden
If "Tank", then everything beginning with "Tank" is hidden, including "Tank1", "Tank2"
and "[Link]"
' Hide all properties that begin with "DoubleArray" (for example "DoubleArray_1",
"DoubleArray_2", etc.)
AddHiddenPropertyPrefix(lst, "DoubleArray")
Return lst
End Function
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
46/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Unit DLL has two mandatory routines, CalcStatic (for static calculations) and CalcDynamic (for
dynamic calculations):
50.3.1. CalcStatic
Process the input streams (input amounts are in t/h) and create output streams (output
amounts are in t/h)
Usually the static calculations don't require much internal states because there are no tanks
or other internal stuff in the unit
50.3.2. CalcDynamic
Sometimes dynamic calculations may be the same as the static calculations (in really
simple cases where there are no tanks or anything else)
If the model is not meant to be dynamic, a good practice is to call same static calculation
routines when CalcDynamic is called by Sim
However, usually dynamic calculations use internal tanks etc.
Calculation principle is:
Input streams are in measured in t/h
Also output streams are measured in t/h
However, Unit DLL should only process an amount that it gets and outputs during
one Sim calculation time step (for example 1 second)
Time step is given in timestepseconds parameter
Therefore you get InputAmount (t/h) * timeStepSeconds / 3600 tons of
material to the Unit DLL internal tank (for example), calculate how much stuff
the Unit DLL would output in the timestep and then multiply it by 3600 /
timeStepSeconds to get the output in t/h
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
47/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Method Effect
WriteToLog Writes a "normal" log message to the calculation log
InfoMessage Writes an "information" message to the calculation log. Information
message is not an error or a warning but it is slightly more
"important" than a normal log message.
WarningMessage Writes a warning to a log. A warning does not stop calculations but it
is an indication that probably something is going wrong. Warnings
are displayed to the user after calculations,
RaiseFatalErrorException Fatal error. An error is written to the log and the calculations are
stopped immediately. This means that the calculations are going so
wrong that there is no point trying to calculate any further.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
48/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
HSC8Stream (or the interface IHSC8Stream) is meant to contain all contents of one stream
It can also be used to store the contents of some container, for example a tank
All amounts in HSC8Stream are measured in tons (per hour)
For each component stored in the stream there are three things:
The component (for example, "H2O" or some particle)
Amount (tons or tons / hour)
Phase
Adding a similar component to the same phase increments the first component amount
So adding 10 x 1 t of "H2O" = adding 10 t of "H2O"
HSC8Stream takes care of this automatically
It is also possible to store some extra data ("parameters") for the whole stream or for a
phase
However, since parameters are not stored within the components, they are not
automatically copied to other streams when the components are added to them
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
49/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Dim Input As IHSC8Stream ' Let's assume that this has been initialized and
contains some data
Dim Output As IHSC8Stream ' Let's assume that this has been initialized as empty
Dim Tank As IHSC8Stream ' Let's assume that this has been initialized and contains
some data
Dim Output As IHSC8Stream ' Let's assume that this has been initialized as empty
Dim Input As IHSC8Stream ' Let's assume that this has been initialized and
contains some data
Dim Output As IHSC8Stream ' Let's assume that this has been initialized as empty
There are lots of readymade extension methods (for example .AddStream copies all
contents of one stream so there is no need to write a loop for it)
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
50/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
[Link]. IStreamComponent
All components implement this interface so it is always safe to access the components
using this interface
If you are writing a Hydro Unit DLL, you know that all components are IStreamSpecies ->
[Link] contains always the species name and you don't even need to
check/cast the component to IStreamSpecies.
The most relevant members of IStreamComponent are:
Name (species name if the item is a species, may be anything if the item is a
IParticle)
ComponentSG (density of the component)
Dim newSpecies = New StreamSpecies("H2O", 0.992) ' "H2O" species, density 0.992
Dim newSpecies2 = New StreamSpecies("Fe", HSC) ' "Fe" species, get the density from
database using the given IHSC8 interface
Dim newSpecies2 = NewStreamSpecies("Fe") ' "Fe" species, get the density from
database
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
51/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
52/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
50.4.4. PhaseGroups
[Link]. StreamPhaseGroup
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
53/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
[Link]. MineralPhaseGroup
[Link]. ConvertedPhaseGroup
The only source for this phasegroup is MinPro -> Hydro converter Unit DLL
You don't see this anywhere else
The converter puts all generated species to this single phasegroup and the target of the
stream (for example a Hydro unit) will notice the ConvertedPhaseGroup and do some
special processing and divides it to correct phases in its Input sheet
[Link]. GlobalPhaseGroup
This is used only for storing HSC8Stream global parameters. They need to belong to some
phasegroup that is different than the other phasegroups
Never use this phasegroup directly
[Link]. ReferenceStream (protected property in Unit DLL base class, available for all
Unit DLLs)
The global referencestream variable is rarely used because InitModelParameters gets the same
information as a method parameter. However, this could be used to calculate some element
recoveries, for example.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
54/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
'Apply Format To UI
WriteFormatsToUI()
End Sub
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
55/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
(for example
C:\users\username\AppData\Roamng\Outotec\HSC10\DevelopmentUnitDLL\MyAddinFolder\[Link])
Alternatively you can use the import function in the Sim by using the Unit Model Selector.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
56/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
50.7. How-to...
50.7.1. How to create new Particle / Stream / other instances
Sim creates automatically a dropdowns for enum properties in the user interfaces:
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
57/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
...
You can use classes as property types if the following rules are followed:
The class must have a default constructor (new without parameters) because Sim
needs to be able to create class instances automatically
The class variables and properties must follow the same rules as the main Unit DLL
properties if they are to be saved with the flowsheet
Both the class properties and the Unit DLL property must have RuntimeVariable,
ModelParameter or InternalState attribute applied to them. The visibility of the
single class property is defined as follows:
So the visibility of the parameter is always the least of the two parameters
(ModelParameter being the most visible and InternalState being the most
hidden)
Sim user interface updates automatlcally when the array size changes and the user
interface looks like this:
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
58/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Unit tables enable the coder to create two-dimensional tables in the user interface
There are three table types:
UnitTableDouble (all elements are numbers)
UnitTableString (all elements are strings)
UnitTableObject (all elements are either Double, String or Nothing (an empty cell)).
Unit DLL can set the column and row names of the Unit table and Sim takes care of the rest
(displaying the unit table, handling all user interface issues and saving/loading the data)
Usually the Unit tables are initialized in the InitModelParameters routine of the Unit DLL
because that is the best place to handle any changes in the unit (for example if streams are
connected/disconnected, etc.)
You can set the rows and columns of the table using the following methods:
Easiest:
SetColumns(columnNames as List(Of String), defaultvalue)
SetRows(newRowNames as List(Of String), defaultvalue)
These create new rows/columns if necessary and delete unused rows
These set the row/column order to the same order as given in the list
After calling these functions you know that the row/column list is what you
want
These routines do not destroy existing data so if the list already contains
rows "B" and "C" and now you set the list to "A", "B", "C", then only a new
row is added and the existing values remain.
Of course, if you set the list to "A", "B", then the whole row "C" is
destroyed
If a new row/column needs to be created, then it is filled with the value from
defaultValue parameter
More detailed:
Inserting new rows/columns
InsertRow(newRowName, defaultValue)
AddColumnData(newColumnName, defaultValue)
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
59/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
There are two (overloaded) routines for reading and writing data:
SetParam(row, column, newValue)
GetParam(row, column)
The value type (Double, String or Object) depends on the Unit table type
(UnitTableDouble, UnitTableString or UnitTableObject)
You can use either the row/column name or numeric index as the row/column
parameters:
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
60/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
The formats are named according to the cell color, boarder style, alignment and number
format
A cell may contain multiple formats, and are separated by underscore (_)
For Example, the entries in "...Normal_RightThin_CenterAlign" for exampel
means that:
Normal (white) color is used
The right side of the cell contains a thin black boarder
The text is centered
The Cell Color/Style is always defined in the first entry. The available styles are:
Error after the cell style indicates a red font, for example:
The cell boarder is typically defined after the cell style and font. The boarder is a
combination of placement (Right, Left, Top, Bottom) and thickness (Thin, Medium,
Thick).
Styles with alignment contain the placement (right, center or left) combined with the
word "Align", for example "RightAlign".
Styles with number format contain words like percent (0.25 -> 25.00%), Celsius (25
-> 25 °C) etc.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
61/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
62/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
ComboBox
Note! Use indexes to get and set combobox values. Also note that indexing starts from 1!
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
63/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Checkbox
'Uncheck
[Link](row, col, False)
Comments
'Set Comment
[Link](row, col, "Boo!")
'Get Comment
[Link](row, col)
ClearCell
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
64/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
50.8. IHSC
The IHSC object provides most of the calculation routines that are available in HSC Sim
Some of them for examples are: MW (molar weight of some species), BP (boiling point of
species), etc.
HSC methods are typically applied when processing species (in Hydro and Pyro modes)
but they are rarely needed in MinPro models because MinPro calculations are usually done
with other routines of the stream object.
All IHSC8 methods use Kelvins, kWh and bar as their units (unless specified otherwise)
The user can set the fill levels of tanks of all units using the Sim dynamic calculation user interface).
Usually the tanks can be emptied but also their fill level can be set using a value between 0..100.
Since HSC Sim can't know what Unit DLL properties and internal variables handle the tank content, the
Unit DLL programmer must handle the tank level setting with his own code.
Implementing the tank level manipulation is optional: Some Unit DLLs don't have an internal tank and in
some cases modifying the tank level from "outside" just is not supported.
SetTankLevel is called with a Double parameter (usually between 0..100). 0 means that the
tank should be emptied, 100 means that the tank is filled completely. However, although
strongly discouraged, the Unit DLL programmer can interpret the number as he/she wants.
When SetTankLevel is called, all stream content properties (both input and output) have
their actual values, so the programmer can get a suitable tank content from any stream.
But be prepared: in some cases the stream contents may be empty, for example if
the flowsheet has never been run.
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy
Sim Unit DLL Programming
65/65
Jussi-Pekka Kentala, Marko Leino,
Antti Remes, Matti Hietala
September 7, 2023
Sim requires that all Unit DLL list properties are arrays but it is much more convenient to
use List(Of something) in programming instead of [Link] arrays
Solution: use a wrapper property:
' Wrapper which communicates the contents of the list to Sim and back
<InternalState("Double List")>
Public Property DoubleArray As Double()
Get
Return [Link]
End Get
Set(value As Double())
MyList = New List(Of Double)(value)
End Set
End Property
...
' In the actual code you can just use the MyList property and don't need to worry
about the array property at all
[Link](123.45)
Metso reserves the right to modify these specifications at any time without prior notice. Copyright © 2023, Metso Finland Oy