0 Votes

Getting started with Co-Simulation

Last modified by superadmin on 2025/01/14 17:42

Previous (setup_Python)     |     Back to Start     |     Next (run_sim)

Setting up MATLAB

You need four files in order to set up and running a co-simulation with MATLAB: 

  1. idalibN.h
  2. idalibN.dll
  3. libzmq-mt-4_3_4.dll
  4. libsodium.dll

Make sure that you have the 64-bit version of the above files. 

First the libraries from the two files mentioned at the beginning of this document should be loaded
loadlibrary('~\idalibN.dll','~\idalibN.h');

Creating a channel

This is done using the function CreateStorage which requires which requires 6 arguments: pointer to channel name, number of variables passed on the channel, number of clients linked to the same variable, extrapolation time, whether to interpolate the variables or not, and whether there is an opc server or not. I what follows an example is shown for the channel that will be reading the data from the “Export” in ICE

 
Channel_name = 'ICE_zone';
Channel_ptr = libpointer('cstring',Channel_name);
nVar = 1;
nSync = 1;
dTExtrap = 0;
VarInterp = 0;
VarInterp_ptr = libpointer('doublePtr',VarInterp);
opc = 0;

[hStore1]=calllib('idalibN','CreateStorage',Channel_ptr,nVar,nSync,dTExtrap,VarInterp_ptr,opc);
OPening the channel
calllib('idalibN','OpenStorage',Channel_ptr);

The second channel that will communicate with the “Import” in ICE can be created and opened in the same way, but takes the following parameters

 
Channel2_name = 'ICE_heatCtr';
Channel2_ptr = libpointer('cstring',Channel2_name);
nVar = 1;
nSync = 1;
dTExtrap = 125;
VarInterp = 0;
VarInterp_ptr = libpointer('doublePtr',VarInterp);  

Retrieve and send data

To retrieve and send data now, all that needs to be done is to use the functions StoreData and RetrieveStoredData

StoreData takes as arguments the name of the storage, the time of stored slice, a pointer to the data to store/send and whether to extrapolate or not
calllib('idalibN','StoreData',hStore2,i,dData_ptr,extrap);
RetrieveStoredData takes as arguments the name of the storage, the time of the retrieved slice and a pointer to the retrieved data
calllib('idalibN','RetrieveStoredData',hStore1,i,dData_sim_ptr) 
At the end of the MATLAB script the storages have to be closed using the function CloseStorage
calllib('idalibN','CloseStorage',hStore2);
calllib('idalibN','CloseStorage',hStore1);
unloadlibrary('idalibN');
Previous (setup_Python)     |     Back to Start     |     Next (run_sim)