- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » how to do a sweep parameter and save...
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
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
- adamLange
- 29 Posts
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
Re: how to do a sweep parameter and save results in different csv files ?
- adeas
- 454 Posts
Re: how to do a sweep parameter and save results in different csv files ?
In the example change .mat to .csv
Adeel.
- adeas
- 454 Posts
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
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.
- adeas
- 454 Posts
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.
- adeas
- 454 Posts
Re: how to do a sweep parameter and save results in different csv files ?
No I mean the output of the mos script.
Adeel.
- adeas
- 454 Posts
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
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.
- adeas
- 454 Posts
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
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.
- adeas
- 454 Posts
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.
- adeas
- 454 Posts
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.
- adeas
- 454 Posts
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.
- adeas
- 454 Posts
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.
- adeas
- 454 Posts
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.
- adeas
- 454 Posts
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.
- adeas
- 454 Posts
Re: how to do a sweep parameter and save results in different csv files ?
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » how to do a sweep parameter and save...