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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With