Did you know INOSIM can be remote-controlled by any program that can send signals via the COM-Interface? Let us sketch a scenario of how this feature can be used to ease your simulation efforts.
INOSIM is the perfect tool for the evaluation of complex what-if-scenarios. To meet your production goals, there are options like installing further reactors, but different production order lists must be considered as well. Simulating the combination of all options can easily result in a large number of experiments you need to simulate. This means you would need to manually select experiments and click on “Start Simulation” each time. In case a simulation run of a complex model takes one hour, 15 experiments could be easily simulated overnight, while your computer would be unused anyway. Of course, getting up once an hour to start another simulation run is not an option.
Wouldn’t it be nice if you could execute one INOSIM simulation run after the other automatically?
Any COM-Interface capable programming language can control INOSIM. The INOSIM RemoteControl object can be parametrized with the database file path, project and experiment name, visibility, and license to be used. Optionally, a user data value can be transmitted. You can even create a new database and import a project via the COM-Interface. More properties and options are described in the INOSIM user documentation (INOSIM > Appendix > COM Interface).
A simulation run is started by calling the RunSimulation property. Within your project’s VBA code, you can access the RemoteControl object. If you hand over a user data value, it is stored in the object’s UserData property. At the end of the simulation, a value can be stored in the object’s Result property.
Control INOSIM with Excel
In this Tip & Trick, let us introduce you to an Excel workbook with macros that can be used to run several experiments of one INOSIM project automatically. On the sheet “Remote Control Settings” you will need to specify
- path and file name of the INOSIM database file (e.g., “C:\Databases\Example-DB.imdf”)
- project name
- whether the user interface of INOSIM should be visible, minimized in the taskbar or invisible during simulation. (Hiding the interface can speed up loading time.)
- experiment names you want to run
- optionally, a UserData value
How it works
As soon as you click on “Start”, the Excel macro will open the INOSIM database, load the specified project and select the correct experiment, reset, and then start the simulation run. To give it a try, you can download the project file and the Excel workbook with included macro at the end of this page.
The following code is used in the Excel macro:
Sub Start_Batch_Processing() Application.DisplayAlerts = False Set sim = CreateObject("INOSIM.RemoteControl.12.0") Dim s As Worksheet Set s = ActiveSheet sim.Database = s.Cells(1, 2) '"C:\Databases\Example12.imdf" sim.Project = s.Cells(2, 2) '"T&T Remote Control" sim.Visibility = CStr(s.Cells(3, 2)) '0 visible, 1 taskbar, 2 invisible sim.License = "ExpertEdition" sim.LogFile = "C:\Temp\Protocol.txt" Dim r As Long For r = 6 To s.Cells(4, 2) + 6 If s.Cells(r, 2) > 0 Then sim.Experiment = CStr(s.Cells(r, 3)) sim.UserData = s.Cells(r, 4) s.Cells(r, 5) = sim.RunSimulation End If Next End Sub
The INOSIM project simulated in this example uses the following code to access the UserData property in the Simulation_Init procedure. The RemoteControl-object is nothing in case you started the simulation manually (INOSIM start button). Therefore, the value 2 is assigned to the variable Orderlist_nr. If the simulation was started via the COM-Interface, RemoteControl-object is not nothing and therefore the value of UserData is used.
Dim Orderlist_nr As Integer 'data from remote control: which order list should be used If RemoteControl Is Nothing Then Orderlist_nr = 2 Else Orderlist_nr = RemoteControl.UserData End If
In the EndSim procedure, the following code is executed to hand over the total simulation duration in hours to the RemoteControl object’s Results property. This value is then printed to column E in the Excel spreadsheet.
If RemoteControl Is Nothing Then Console.Print total_duration Else RemoteControl.Result = total_duration End If
More than just ONE number as Result or UserData?
In this example, only numbers are used as UserData and Result. In fact, these properties have the data type Variant. This means that Strings, Booleans, even arrays (e.g., data matrices) can be processed as well. Let’s assume you need to transmit more than just the orderlist_nr variable to each simulation run, but additionally also the boolean value “Level Control” and the string value for “Product Name”. Use your Excel-VBA skills to write this data into an array, and assign it to the UserData property. Within the INOSIM model, use the array directly or transform it into a table object.
Vice versa, in INOSIM, an array can be created to store simulation results and assigned to the RemoteControl.Result property. Within Excel VBA, write this array into your desired format.
What follows is the adjusted Excel Macro “Start_Batch_Processing_Array” to use the values in columns E, F, G as an array for simulation input.
Sub Start_Batch_Processing_Array() Application.DisplayAlerts = False Set sim = CreateObject("INOSIM.RemoteControl.12.0") Dim s As Worksheet Set s = ActiveSheet Dim Data As Variant ReDim Data(1 To 2, 1 To 3) '2 rows, 3 columns Dim c As Long 'write table header to array For c = 1 To 3 Data(1, c) = s.Cells(5, c + 3) Next sim.Database = s.Cells(1, 2) '"C:\Databases\Example12.imdf" sim.Project = s.Cells(2, 2) '"T&T Remote Control" sim.Visibility = CStr(s.Cells(3, 2)) '0 visible, 1 taskbar, 2 invisible sim.License = "ExpertEdition" sim.LogFile = "C:\Temp\Protocol.txt" Dim r As Long For r = 6 To s.Cells(4, 2) + 6 If s.Cells(r, 2) > 0 Then sim.Experiment = CStr(s.Cells(r, 3)) 'sim.UserData = s.Cells(r, 4) 'write experiment input data For c = 1 To 3 Data(2, c) = s.Cells(r, c + 3) Next sim.UserData = Data s.Cells(r, 7) = sim.RunSimulation End If Next End Sub
Please note that, once the Excel macro has been started, it cannot be stopped and will try to perform all simulation runs in the list. In this case, use the Windows Task Manager to stop the Excel process.
You think the project name should be defined separately in each row? You would like to create a new database for each new run? Feel free to change the sheet and macro to meet your needs.
In this Tip & Trick we have demonstrated the use of INOSIM’s Remote Control feature with Excel, because it is commonly available. However, INOSIM can also be remote controlled from other COM-compatible software like MatLab.