Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional type assignment possible for a parameter?

Tags:

modelica

I'm trying to let a parameter be of a specific type depending on a condition to be met. But I'm not quite sure how to do this or if this is actually possible/legal in Modelica. In principle what I would like to have is something like this (non-working code example):

package test
type TypeA=enumeration(A,C,E);
type TypeB=enumeration(B,D,F);

model foo
    parameter Boolean Condition;
    parameter if Condition then TypeA else TypeB MyParameter; 
end foo;
end test;
like image 522
Dietmar Winkler Avatar asked Nov 04 '22 23:11

Dietmar Winkler


1 Answers

I was hoping to acheive this with a replaceable model or replaceable type, but I'm not getting there.

However, the code below allows you to change the type of MyParameter in an instantance of foo. Maybe this helps, or it gives inspiration to someone to finish the job.

package test
type TypeA = enumeration(A,C, E);
type TypeB = enumeration(B, D, F);

model foo
  parameter Boolean Condition;
  replaceable type MyType = TypeA;
  parameter MyType MyParameter;
end foo;

model UseFoo
  foo myfoo(Condition=true, redeclare TypeB MyType,
  MyParameter = TypeB.B);
end UseFoo;

end test;
like image 141
saroele Avatar answered Nov 08 '22 04:11

saroele