Add input txt in FMU for co-simulation - modelica

I have an FMU for co-simulation and I want to add as input to this model a txt file with CombiTable and then export it again as an FMU. My question is how can I achieve that since OpenModelica cannot import FMU for co-simulation.

There are several Modelica Tools that allow for the re-export of FMUs, e.g. Dymola and SimulationX.
If you want to do it with open source software, you could export the combitable as a second FMU, and create a containerized FMU with fmpy out of these two FMUs, see https://github.com/CATIA-Systems/FMPy/blob/master/tests/test_fmu_container.py for an example.

I'm not sure if there are any tools that support such a way to pack FMUs.
You could however make a co-simulation SSP via OMEdit.
First make another FMU that contains the combitable.
Then make a new SSP, add both these FMUs.

Related

Error of ModelStructure/Outputs by using FMU container

I am trying to combine three FMUs into one FMU that contains all of the three. Specifically, I have one FMU of a pandapower electricity network and 2 FMUs that are CSV files converted to FMUs by using PythonFMU tool. All of the FMUs have been tested by the FMU Check and they have been simulated together to check that everything works fine.
Then I am using FMPy tool to combine all of them together and export successfully the final FMU.
However, when I am trying to validate this I get the following error:
ModelStructure/Outputs must have exactly one entry for each variable with causality="output".
Any idea of what is wrong here?
Your problem seems to be fixed in https://github.com/CATIA-Systems/FMPy/issues/281#issuecomment-879092943
You should try to re-generate the containerized FMU with the developmenet branch of fmpy.

Exchanging Modelica FMU Models

I tried to exchange my Modelica model with one of my colleagues but ran into difficulties regarding paths to CSV-Files.
When I create the FMU the paths to some of the CSV files are set and point to folders on my computer. For example C:/Users/Me/file.csv. This obviously doesn't work for my colleague.
How can I export my Modelica model (Dymola) in such a way that the paths are set relative to the user?
The most common way is to use the loadResource() function provided with the Modelica Standard Library (MSL) at Modelica.Utilities.Files.loadResource to specify the path to the file. This is usually done using a Modelica URI, which could look like this:
filename=Modelica.Utilities.Files.loadResource("modelica://myLib/Resources/Data/file.csv")
This specifies a path relative to the libraries root path. Usually data files are stored in the Resources folder within the library.
This comes with the advantage, that when creating the FMU in Dymola, you can check the flag "Copy resources to FMU", which will embed the file in the FMU directly if checked. If unchecked, the file will be looked for in the specified directory.

Save array to base workspace from simulink model

I'm using a MATLAB function block within a Simulink model. I build this model and run it on a dspace system with 1 kHz. To evaluate my experiment I need the data (20x20 double array) that is calculated in my MATLAB function block. Is it possible to export the data to the base workspace?
To read a variable from your system, the easiest way to do so is using ControlDesk. Create a project and download/start your experiment using ControlDesk, then it is automatically aware of the running application and can read the variable. You now have to configure a Measurement (or Capture in old versions) and export the results to MAT. You can find detailed instructions in the documentation from dSPACE, called HelpDesk.
Alternatively you can use the XIL-API or HIL-API to automate the above steps.

Deployment of Simulink Models

I have been trying to find out how to deploy a Simulink model. There are possibilities and problems as well.
If I use Simulink Coder how can I find the generated code on my computer? Where is it saved as a file or package of files?
Can we deploy Simulink as .NET Assembly? If we can, where can I find a detailed documentation about it.
Is there any other way to use my Simulink model standalone?
Thank you for any effort.
By default all the code gets placed into a folder, in the current directory, called ModelName_CodeTarget, where ModelName is the name of your model and CodeTarget is the particular type of code you are generating. (This folder is created during the build process if it doesn't already exist.)
There is no mechanism for automatically generating a .Net assembly. Simulink Coder generates C code; what you do with it is then up to you (just as it would be with hand written code). Note that the process is fully customizable, so you could create your own build process to autmatically wrap the C code into an assembly (but it would be a very advanced maneuvre to do this).
There are a couple of Simulink Coder "targets" that generate standalone executable files. For instance, the GRT (Generic Real-Time) target generates a simple .exe file; the RSIM target (the Rapid Simulation Target) generates an exe where you can specify different .mat files that can be used to specify different model parameters for different simulation runs, and have the results of the different runs stored to different output .mat files.
Most of these questions are answered by looking at the early chapters of the Simulink Coder documentation.
It would be worth you taking some time to look at it to get a feel for how the code generation process works.

Compiling Simulink Code into .ELF object form

I have a simple model from simulink and I would like to generate code using the code generator in the simulink and then compile it using gcc into a .ELF object file. How can I proceed?
Thanks
You need the product called Simulink Coder (around matlab 2011b) or Real-time Workshop (for older matlab versions). Typing ver at the matlab command window will show what products and licences you have installed.
If Simulink Coder or RTW are installed, you use the menu Simulation->Configuration Parameters to set up the model for code generation.
If you have Embedded Coder you can set System Target File to ert.tlc, and this will produce a very concise main() routine to call your model code. Otherwise, use grt.tlc which produces a lot more bloat then ert, but is the only useful one available for on Windows.
There are a lot of options to go through and check - it really needs someone with a bit of experience to be present!
As you are requesting an ELF file, is this for an embedded system? If so, there is a lot more work to be done. If the target is not one of the already supported targets, then you need a target package, which will take either a lot of time and experience, or money to buy one.
Custom target development - a world of it's own:
http://www.mathworks.co.uk/help/toolbox/rtw/ug/bse3b2z.html