Edward Hage
Tue, 13 Oct 2009 04:22:38 -0700
Dear people, How to assign part of a function-result to a model?See code hereunder. Function funcresult generates 4 vectors of 3 elements (A,B,C,D) , now A and B should be assigned to models modelinstance1[n] anc C and D to models modelinstance2[n].
model mainmodel public parameter Integer n = 3; parameter Real A[n](fixed =false); parameter Real B[n](fixed =false); parameter Real C[n](fixed =false); parameter Real D[n](fixed =false); protectedmodel1 modelinstance1[n] ( par1=A, par2=B); <---- although in model1 I also put the parameters par1 and par2 on fixed=false par1 and par2 are not defined (same story for model2 of course)
model2 modelinstance2[n] (par3 = C, par4=D, par5 =3);
initial algorithm
(A,B,C,D) := funcresult(input=n);
equation
xx
connect(modelinstance1[1], modelinstance2[1]); // etcetera
x
x
end mainmodel;
Remark:
if I use constants like:
model1 modelinstance1[3] ( par1={1,2,2}, par2={5,5,2});
model2 modelinstance2[3] (par3 = {2.12,12,12},
par4={67.67,67.4,33.2}, par5 =3);
than it does work.I can think of one workaround, and that is to create extra functions that call funcresult and only return A, B, C and D (so I need 4 functions). But I do not know if the function is than called 4 times, or that funcresult is only called once.
Better ideas ?