Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register
  • Index
  • » Users
  • » Amro
  • » Profile

Posts

Posts

Can I use a "dll" (generated by Julia) in modelica? If so can you give me an example or link for that?

I'm trying to simulate a model that I made, but I got the below error:

[2] 17:23:29 Translation Error
[C:/OM118/OM64bit/OMCompiler/Compiler/NFFrontEnd/NFUnit.mo: 883:7-883:68]: Internal error function lexer failed

Anyway to solve it?

I have a model in openModelica and I have exported it as FMU. I tried to import it by a simulation tool (EMTP). However, this tool failed to load the FMU and give me this message:
FMU must contain 32-bit Windows binaries. Not "win32 binary" in the FMU.

Any idea how to make my exported FMU has these 32-bit Windows binaries?


Make `Component R_ic` and `YY` parameters and let the compiler handle it. You can still change the parameter `YY` from outside.

Code:


  parameter Real X1 = 200;
  parameter Real R_ic = YY * 1 / X1;
  parameter Real YY;
  Modelica.Blocks.Continuous.FirstOrder firstOrder(T = 5, k = 1, y_start = R_ic);

Thank you!
How can I still change the parameter `YY` from outside as it is no longer input? I am setting `YY` an input because my model here will be as a black box, in which `YY` will be connected to a previous block in the Diagram view. Eventually, I want to use this black block as FMU in another simulation tool.

I have `YY` as Realinput. How can I solve the below error? I only need YY at the initial?

parameter Real X1 = 200
final parameter Real R_ic = YY * 1 / X1;
Modelica.Blocks.Interfaces.RealInput YY
Modelica.Blocks.Continuous.FirstOrder firstOrder(T = 5, k = 1, y_start = R_ic)

Translation Error
Component R_ic of variability parameter has binding 'YY* 1 / X1' of higher variability continuous.


//Translation Error
//Component y_start of variability parameter has binding 'R_ic[<firstOrder, firstOrder>]' of higher variability continuous.


sjoelund.se wrote:


You can override top-level inputs as well. If you want to connect them, they need to not be parameters. If you want them to be parameters, don't make them connectors (just Real, and write an equation instead of the connection).

Thank you for you reply.

If I have only "add" block in the diagram view.

model SumDummy
  Modelica.Blocks.Math.Add add
  input Real add.u1=1;
  input Real add.u2=2;
  output Real add.y;
equation
end SumDummy;

Can I use

buildModel(SumDummy)
system(SumDummy -override add.u1=3.2,add.u2=2.3)
readSimulationResult("SumDummy_res.mat",add.y)

Thanks!
I have added keyword parameters in frond of var1 and var2 to allow using:
system(SumDummy -override var1=3.2,var2=2.3)
from omshell.
Am I right?

I have a complex diagram in which I need to change the values of some parameters and observe the results. I tried to simplify the question to as below:
I have a simple addition block with two inputs (var1 and var2) and one output (y) designed in the diagram view.

Code:


model sumDummy
  parameter Modelica.Blocks.Interfaces.RealInput var1 annotation(
    Placement(visible = true, transformation(origin = {-70, 14}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-64, 14}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
  parameter Modelica.Blocks.Interfaces.RealInput var2 annotation(
    Placement(visible = true, transformation(origin = {-70, -38}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-54, -42}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
  Modelica.Blocks.Interfaces.RealOutput y annotation(
    Placement(visible = true, transformation(origin = {82, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {86, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Math.Add add annotation(
    Placement(visible = true, transformation(origin = {6, -6}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(var1, add.u1) annotation(
    Line(points = {{-70, 14}, {-34, 14}, {-34, 0}, {-6, 0}}, color = {0, 0, 127}));
  connect(var2, add.u2) annotation(
    Line(points = {{-70, -38}, {-34, -38}, {-34, -12}, {-6, -12}}, color = {0, 0, 127}));
  connect(add.y, y) annotation(
    Line(points = {{18, -6}, {82, -6}, {82, 2}}, color = {0, 0, 127}));
end sumDummy;

I need to change (var1 and var2) and view the output (y) by omshell. However, when I try to build the model by buildModel(SumDummy) I have the below error:

Code:


"Error: Too few equations, under-determined system. The model has 2 equation(s) and 4 variable(s).\n[C:/Program Files/OpenModelica1.18.0-64bit/lib/omlibrary/Modelica 4.0.0/Blocks/Interfaces.mo:342:5-343:57:writable] Warning: Variable add.u1 does not have any remaining equation to be solved in.\n  The original equations were:\n  Equation 2: add.y = add.k1 * add.u1 + add.k2 * add.u2, which needs to solve for add.u2\n[C:/Program Files/OpenModelica1.18.0-64bit/lib/omlibrary/Modelica 4.0.0/Blocks/Interfaces.mo:346:5-347:56:writable] Warning: Variable add.y does not have any remaining equation to be solved in.\n  The original equations were:\n  Equation 2: add.y = add.k1 * add.u1 + add.k2 * add.u2, which needs to solve for add.u2\n  Equation 1: add.y = y, which needs to solve for y\n"

Is it because the type of var1, var2 and y are interfaces? Any way to solve it?

Dec-29-21 19:01:18
how to utilize the exe file that is compiled when i simulate a model?

adrpo Thank you very much! Based on your great explanations, I have these below concerns please:
1- Is it possible to write system(\"./Model -override var1=6 -output s\") to put the output s in the environment? Since I care about the execution speed then using simulate() is not proper in my case. Alternatively, using system() to generate the "result_filename.mat|csv" and then using val(s,0,"twovariableaddition_res.csv") is also a consuming time. Do you think there would be a better alternative, such as using FMI?


My code worked in the default directory i.e. "C:\Users\user_name\AppData\Local\Temp\OpenModelica" and the system() command returned “0”. However, when I change the path directory to be through the One-Drive(i.e. "C:/path1/One- Drive/path2/model"), the code works except the system() command and it returns “1”.

2- Do you know why? is it because of the space?


There are alternatives to speed it up quite a bit if you only need for example just a few variables from a simulation run, you could skip the generation of the mat file entirely with -noemit: https://openmodelica.org/doc/OpenModeli … lag-noemit and using -output var1,var2,var3: https://openmodelica.org/doc/OpenModeli … lag-output
Then you would just read these variable values and use them for the next simulation.

3- Yes, I only need some variables from the simulation. Can you give me an example here, because I dont know where to add the two extensions -noemit and -output var1,var2,var3. Is it with simulate() or with system()?


Alternatively you could use FMI, generate an FMU from your model and use any FMI tool to run the FMU until a certain time, then read the values, then restart the FMU with the new values. No mat file is generated. I would suggest to use OMSimulator python interface for this: https://www.openmodelica.org/doc/OMSimu … ython.html
OMSimulator can run composite FMUs but you don't need that, one FMU should be enough, just load that and run it using stepUntil. I will try to make a python script example for this.

4- Yes, could you pleas give an example here?

Dec-28-21 21:24:26
how to utilize the exe file that is compiled when i simulate a model?

adrpo wrote:


There are alternatives to speed it up quite a bit if you only need for example just a few variables from a simulation run, you could skip the generation of the mat file entirely with -noemit: https://openmodelica.org/doc/OpenModeli … lag-noemit and using -output var1,var2,var3: https://openmodelica.org/doc/OpenModeli … lag-output
Then you would just read these variable values and use them for the next simulation.

Yes, I only need some variables from the simulation. Can you give me an example here, because I dont know where to add the two extensions -noemit and -output var1,var2,var3

Dec-28-21 21:18:57
how to utilize the exe file that is compiled when i simulate a model?

adrpo wrote:


3. Are you running those commands in cmd.exe or some other shell like powershell?
If yes, then you need to run it like this:
& "$env:OPENMODELICAHOME\bin\omc.exe" script.mos

Yes, from powershell

my script is "run_twovariableaddition.mos":

Code:


cd("C:/Users/amroa/AppData/Local/Temp/OpenModelica");
mkdir("Output"); getErrorString();
cd("Output"); getErrorString();
loadModel(Modelica); getErrorString();
loadFile("C:/Users/amroa/AppData/Local/Temp/OpenModelica/twovariableaddition.mo")
readFile("C:/Users/amroa/AppData/Local/Temp/OpenModelica/twovariableaddition.mo")
buildModel(twovariableaddition);
system("C:/Users/amroa/AppData/Local/Temp/OpenModelica/Output/twovariableaddition -override extpar1="+String(6)+",extpar2="+String(6)+" -r=twovariableaddition" + "_res.csv")

and I am running it from powershell as below and gave me an error:

Code:


PS C:\Users\amroa\AppData\Local\Temp\OpenModelica> & "$env:OPENMODELICAHOME\bin\omc.exe" run_twovariableaddition.mos
Error processing file: run_twovariableaddition.mos
[C:/Users/amroa/AppData/Local/Temp/OpenModelica/run_twovariableaddition.mos:1:52-1:52:writable] Error: Missing token: ASSIGN

# Error encountered! Exiting...
# Please check the error message and the flags.

Execution failed!

Dec-28-21 21:10:49
how to utilize the exe file that is compiled when i simulate a model?

.

Dec-28-21 21:10:47
how to utilize the exe file that is compiled when i simulate a model?

o

Dec-27-21 22:52:55
how to utilize the exe file that is compiled when i simulate a model?

Thank you very much for your reply!
I have implemented my code based on your guide (line-by-line) in omshell, and I have the following concerns please:

1- The code worked in the default directory i.e. "C:\Users\user_name\AppData\Local\Temp\OpenModelica" and the system() command returned “0”. However, when I change the path directory to be through the One-Drive(i.e. "C:/path1/One-Drive/path2/model"), the code works except the system() command and it returns “1”. Do you know why?

2- I want to put the system() command within a time-loop (iterations), in which the results of system() command will effect the next iteration. So, generating a results file such as .mat and reading form it (at each iteration) will consume a lot of time. Is there any way to show the results of system() command directly into the workspace of omshell rather than reading them from the generated results file (.mat)? I used val(variable, time) but it didnt return anything.

3- I have created a script.mos as you described. Then I open command window (in the same location of the script) and typed the below command to run the script but it gave the below error, how to solve it? Alternateviely, what is the command to run the script from the omshell, is it %OPENMODELICAHOME%\bin\omc script.mos?

PS C:\Users\user_name\AppData\Local\Temp\OpenModelica> %OPENMODELICAHOME%\bin\omc script.mos
%OPENMODELICAHOME%\bin\omc : The module '%OPENMODELICAHOME%' could not be loaded. For more information, run
'Import-Module %OPENMODELICAHOME%'.
At line:1 char:1
+ %OPENMODELICAHOME%\bin\omc run_twovariableaddition.mos
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (%OPENMODELICAHOME%\bin\omc:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoLoadModule

Dec-24-21 21:27:34
how to utilize the exe file that is compiled when i simulate a model?

I need to build my model in a specific path, so I am trying to use setTempDirectoryPath().
However, when I write the command setTempDirectoryPath("path/to/file") in omshell, it closes the omshell window.

Any reason for that or how to solve it


How to change some parameters in my model in the .xml file before running the executable?

Dec-24-21 21:27:32
how to utilize the exe file that is compiled when i simulate a model?

I need to build my model in a specific path, so I am trying to use setTempDirectoryPath().
However, when I write the command setTempDirectoryPath("path/to/file") in omshell, it closes the omshell window.

Any reason for that or how to solve it


How to change some parameters in my model in the .xml file before running the executable?

  • Index
  • » Users
  • » Amro
  • » Profile
You are here: