OpenModelica


Forgot password? | Forgot username? | Register

how to do a sweep parameter and save results in different csv files ?

how to do a sweep parameter and save results in different csv files ?

Hello everyone,

I want to know how we can do a sweep parameter and save results in different csv files.
For example, I have a RC model and I want to change the value of R and save results of the simulation in a csv file.

I tried with a mos script but it didn't work.

Thank you

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

Hi Nasrou,

I usually do parametric sweeps like this:
https://github.com/adamLange/openModeliaSweep

Adam

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

Hi Adam,

Thank you for your response. I want to do a parameter sweep with a .mos script because I'm more comfortable with mos scripts than python.

And i want also to save results of my simulation in a csv file.

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

Thank you Adeel for your response.

I want to know how can i save my results for each paramaeter in a csv file ?

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

In the example change .mat to .csv

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

Thank you Adeel.

It allowed me to advance considerably in my project.

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

I do the same thing (like the documentation about the sweep parameter) for my model but i get a warning : The initial conditions are not fully specified, and I don't understand why i get this warning.

Someone have an idea ?

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

You need to fix your model. To see where exactly you need to fix use "-d=initialization".
So basically call your mos script like this,

Code:

omc.exe -d=initialization script.mos

And you will get more information about which initial condition are missing.

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

I fixed this problem but I don't found my csv file.

it is normal ?

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

Usually the result files are generated in the working directory. In your case it is the one where your mos script is located.
Can you share the output of your mos script?

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

Do you mean the output files ?

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

No I mean the output of the mos script.

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

This is my model ( I made it with OMEdit ) :

Code:

model RCmodel

  Modelica.Electrical.Spice3.Basic.R_Resistor R(R = 1)  annotation(
    Placement(visible = true, transformation(origin = {-50, 42}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Spice3.Basic.C_Capacitor C(C = 2)  annotation(
    Placement(visible = true, transformation(origin = {-16, 8}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Spice3.Basic.Ground Gr annotation(
    Placement(visible = true, transformation(origin = {-62, -32}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Spice3.Sources.V_constant V(V = 2)  annotation(
    Placement(visible = true, transformation(origin = {-154, 12}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
equation
  connect(V.n, Gr.p) annotation(
    Line(points = {{-154, 2}, {-154, 2}, {-154, -22}, {-62, -22}, {-62, -22}}, color = {0, 0, 255}));
  connect(V.p, R.p) annotation(
    Line(points = {{-154, 22}, {-156, 22}, {-156, 42}, {-60, 42}, {-60, 42}}, color = {0, 0, 255}));
  connect(C.n, Gr.p) annotation(
    Line(points = {{-16, -2}, {-16, -2}, {-16, -22}, {-62, -22}, {-62, -22}}, color = {0, 0, 255}));
  connect(R.n, C.p) annotation(
    Line(points = {{-40, 42}, {-16, 42}, {-16, 18}, {-16, 18}}, color = {0, 0, 255}));
  annotation(
    uses(Modelica(version = "3.2.2")));
end RCmodel;

My mos script :

Code:

cd();

loadModel(Modelica);
getErrorString();
loadFile("RCmodel.mo");
getErrorString();
buildModel(RCmodel);
getErrorString();

for i in 1:3 loop

    c := 0.1 + i;
   
    system("./RCserie -override=C.C=" +String(c)+" -r=RCserie" +String(i) + "_res.mat");
   
    getErrorString();

   

end for;

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

I am interested in seeing the output of the mos script.

Your model is named RCmodel so you should get and executable with name RCmodel. I wonder then why you are calling RCserie with system command.

Also it has to be "_res.csv" instead of "_res.mat" if you want csv file.

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

I can't open the RCmodel executable because i don't have in my computer this dll : libsundials_idas.dll

I changed RCserie by RCmodel in my system command but it still not working ( i still not have my csv file even if i change _res.mat by _res.csv )

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

You need to set the path in your terminal so it can find the libsundials_idas.dll.
Run the following command,

Code:

set PATH=%OPENMODELICAHOME%\bin;%PATH%

and then run your script.

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

which PATH you are talking about ? is it the mos file Path ?

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

Its the environment PATH variable. You need to run the command exactly as I posted.

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?


I runned exactly your command. But I still have the same problem with the dll current/hmm

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

I need to see the output of the following commands otherwise I can't help much.

Code:

echo %OPENMODELICAHOME%

set PATH=%OPENMODELICAHOME%\bin;%PATH%
echo %PATH%
omc.exe script.mos

Run the above commands one by one. Replace the script.mos with your script.

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?




This is a screen shot of what i got after running these commands.

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

1. Use %OPENMODELICAHOME% instead of typing the OpenModelica path.
2. Move the system command out of for loop. Because the commands in the for loop are executed but not printed to the console. You can also just comment out the for and end for lines.

Post the output again.

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

There is also a problem in the script. I have fixed it.
Use the following one,

Code:

cd(); 

loadModel(Modelica);
getErrorString();
loadFile("RCmodel.mo");
getErrorString();
buildModel(RCmodel);
getErrorString();

for i in 1:3 loop
    c := 0.1 + i;
    system("RCmodel -override=C.C=" +String(c)+" -r=RCmodel" +String(i) + "_res.csv");
    getErrorString();
end for;

Basically there is no need to call the executable with "./".

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

If I move my system command out of the for loop then i will not simulate my model for each value of my parameter !!

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

I know. This is just for testing purpose.
However, if you use the new updated script then everything should work fine.

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

When I use your script, i get my csv files but inside these files I don't have values (numbers) i have things like ù$%...

I don't know why i get this .

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

Use the following,

Code:

cd();

loadModel(Modelica);
getErrorString();
loadFile("RCmodel.mo");
getErrorString();
buildModel(RCmodel, outputFormat="csv");
getErrorString();

for i in 1:3 loop
  c := 0.1 + i;
  system("RCmodel -override=C.C=" +String(c)+" -r=RCmodel" +String(i) + "_res.csv");
  getErrorString();
end for;

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

It works current/big_smile Thank you very much for your help, It's been more than 10 days since i'm looking for a solution.

Nasrou

Administrator has disabled public posting. Please login or register in order to proceed.

Re: how to do a sweep parameter and save results in different csv files ?

Thank you Adeel for your response.


^Goldenslot^

Administrator has disabled public posting. Please login or register in order to proceed.
There are 0 guests and 0 other users also viewing this topic
You are here: