参数的条件类型分配可能吗? [英] Conditional type assignment possible for a parameter?

查看:36
本文介绍了参数的条件类型分配可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图根据要满足的条件让参数具有特定类型.但我不太确定如何做到这一点,或者这在 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;

推荐答案

我希望用可替换的模型或可替换的类型来实现这一点,但我没有实现.

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

但是,下面的代码允许您在 foo 的实例中更改 MyParameter 的类型.也许这会有所帮助,或者它会激励某人完成工作.

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;

这篇关于参数的条件类型分配可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆