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

How to specify "parameter/input/output" constraint by mos script?

How to specify "parameter/input/output" constraint by mos script?


Hi, I have a class defined as:

class Gamma
  Real c;
  parameter Alpha alpha;
  parameter Beta beta;
equation
  c = alpha.a + beta.b;
end Gamma;

it works with following command:

str_cmd := "Gamma.exe -override alpha.a=10,beta.b=20,outputFormat=csv";

However, if I want to get the value of beta by using c and alpha as parameters, I have to define another class?

For example, following is the command I wanted but it is not working (because c is not defined as parameter.)
str_cmd := "Gamma.exe -override c=30,alpha=10,outputFormat=csv";   // I wanted beta.b be computed as 20 (30 - 10).

-----------------------------
My question:

is it possible to define a class without specifying fixed "parameter" and "output" constraint keywords, but run some mos script by specifying the parameter or variable on the fly (before build the model)?




Re: How to specify "parameter/input/output" constraint by mos script?

Do you want this only at the beginning (initialization) or you want something like this?

Code:


class Gamma
  parameter Real c = alpha.a + beta.b;
  parameter Alpha alpha;
  parameter Beta beta;
end Gamma;

Re: How to specify "parameter/input/output" constraint by mos script?

Thanks Adrpo,

I never knew Modelica could set all to be parameter, good to know.

That way, if I understand correctly, is putting the equation as the default value. I could still get 30 with this, great.

However, If I use following command:
str_cmd := "Gamma.exe -override alpha.a=10,c=30,outputFormat=csv";

I will not be able to get beta.b=20 (by searching the .csv file, there is no "20").

----------------------------------

Actually, I wanted to define Gamma like this: (without any hint about input or output directions for variables)

class Gamma
  Real c;
  Alpha alpha;
  Beta beta;
equation
  c = alpha.a + beta.b;
end Gamma;

Then set it at script if possible at all:

loadFiles({"Alpha.mo", "Beta.mo", "Gamma.mo"});   
buildModel(Gamma, "alpha=parameter, beta=parameter, c=output");
....

----------------------------------
What's your suggestion?

Miles

Edited by: milesma - Sep-28-15 04:22:34

Re: How to specify "parameter/input/output" constraint by mos script?

removed duplicated post

Edited by: milesma - Sep-28-15 04:21:26

Re: How to specify "parameter/input/output" constraint by mos script?

The problem is that we don't put parameters inside the csv as it would have the same value and waste space. We only put parameters inside inside the .mat file.

You can do what you want using scripting and the setComponentProperties API, see https://www.openmodelica.org/download/OMC_API-HowTo.pdf

Code:


loadFiles({"Alpha.mo", "Beta.mo", "Gamma.mo"}); getErrorString();
// make c a parameter
setComponentProperties(Gamma, c, {false,false,false,false,false},{"parameter"},{false,false},{""}); getErrorString();
// remove c as parameter
setComponentProperties(Gamma, c, {false,false,false,false,false},{""},{false,false},{""}); getErrorString();

Cheers,
Adrian Pop/

Re: How to specify "parameter/input/output" constraint by mos script?

That's exactly what I wanted!
Now I can define Gamma as:

class Gamma
  Real c;
  Alpha alpha;
  Beta beta;
equation
  c = alpha.a + beta.b;
end Gamma;

Then use this script, it just works!!
loadFiles({"Alpha.mo", "Beta.mo", "Gamma.mo"});   

setComponentProperties(Gamma, alpha, {false,false,false,false,false},{"parameter"},{false,false},{""}); getErrorString();
setComponentProperties(Gamma, c, {false,false,false,false,false},{"parameter"},{false,false},{""}); getErrorString();

buildModel(Gamma);
instantiateModel(Gamma);
str_cmd := "Gamma.exe -override alpha.a=10,c=30,outputFormat=csv";
system(str_cmd); getErrorString();

-------------------------------------------------------

Bear with me, I have another question: how can I get a single value from the csv/plt file?
For example: In the above example, I've got following result in the .csv file (I believe it is for beta.b)

0,20
0.002,20
0.004,20
...
0.998,20
1,20
1,20

I know it is quite useful to plot with these information. But we all know the result is special: it is 30-10 = 20, it is always 20.

What kind of parameter can I set in the script to give me a single "20" in the file ?

Re: How to specify "parameter/input/output" constraint by mos script?

Hello everyone,

I have a model with different electrical components. When I get the output file as csv and I do not filter any variable (variable filter = " .* "), I cannot see the voltage of every single pin of the components in the models. For instance, I see the voltage of the negative pin of my device but not positive pin. Can anybody help me with this?


Best,
Pouya

There are 0 guests and 0 other users also viewing this topic
You are here: