Conditional type assignment possible for a parameter?

妖精的绣舞 提交于 2019-12-10 15:14:23

问题


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;

回答1:


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;


来源:https://stackoverflow.com/questions/10835622/conditional-type-assignment-possible-for-a-parameter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!