1

I want to run around 100 simulations with my model changing two parameters f and TLoadand track the changes on the phase currents currentSensor.i[1] etc.

Now I'm stuck with the documentation on the Wolfram website because there is no definite explanation on how to use scripting with the SystemModeler. I found for example this link on the Wolfram site with some code but no explanation in which commandline I should use it.

I downloaded the WolframScript program and tried to open my model with wolframscript -file SMPM_VoltageSource_Inverter.mo but it says ToExpression::sntx: Invalid syntax in or before ... eventhouh my model simulates totally fine and without any errors in the SimulationCenter.

Can someone explain to me:

  • Is it possible to write scripts ?

If Yes:

  • How can I simulate my model?
  • How can I do a parameter sweep of f and TLoad? Is it as described in the link?
  • Is it possible to export data of currentSensor.i[1] as a csv-file? And how to?

Thank you for any help!

Moebo
  • 143
  • 8

1 Answers1

0

I don't know about wolfram sorry, but for OpenModelica the following works:

// to load Model from file use
// loadFile("fileName.mo");

loadString("
model M
  parameter Real a = 1;
  Real x;
equation
  x = a * sin(time);
end M;
"); getErrorString();

buildModel(M); getErrorString();

for a in {1,2,3,4} loop
  str_a := String(a); getErrorString(); 

  system("./M -override a=" + str_a); getErrorString();
  // for windows use 
  //system("M.exe -override a=" + str_a); getErrorString();

  system("mv M_res.mat " + "M_" + str_a + ".mat");
end for;

Put this in a file named for example model.mos and call it from terminal or command line, depending on your os, with omc model.mos if you have OpenModelica installed. this should generate a csv.

EDIT: I realized the original just saves the last value of x, you might want the full output. Therefore i changed the .mos-file. Each different result will be saved in a different file, if you want to change it to csv you just have to change the generated xml.

kabdelhak
  • 687
  • 3
  • 8
  • Unrelated thought: Why is it that you have to postfix most statements in mos with `getErrorString()`? This seems awfully redundant. I am curious why those errors don't automatically get e.g. returned, or emitted to stderr or as an exception/similar mechanism? – Christoph Oct 02 '19 at 08:07
  • Sometimes you don't want the errors and warnings to be emitted because you know they are not relevant for your case and too verbose. But maybe it would have been a better design decision to have a ``suppressErrorString()`` command instead. – kabdelhak Oct 03 '19 at 09:10
  • I see, thanks. yeah, or configurable logging levels like e.g. in Python... – Christoph Oct 07 '19 at 10:58