Modelica array of partial model

风格不统一 提交于 2019-12-12 06:10:01

问题


Let A be a partial model and C, D be models which extend A. Given a model

partial model X
  A a[3];
end X;

how can I instantiate X, e.g. something along the lines of

A X.a = {C,D,C};

Update: I tried 2 variants. One is

package P
  partial model A end A;
  model B extends A; end B;
  model C extends A; end C;
  partial model X
    A a[3];
  end X;
  model Y extends X(a={c,b,c});
    B b;
    C c;
  end Y;
end P;

which fails with the warning "May only set inputs, parameters, and variables with default, but modified a.". The other one is

package P
  partial model A end A;
  model B extends A; end B;
  model C extends A; end C;
  partial model X
    replaceable A a[3];
  end X;
  model Y extends X;
    redeclare A a={c,b,c};
    B b;
    C c;
  end Y;
end P;

which fails with the error "Component a = {c,b,c}, but previously a = << Empty >>. The components are not identical."

Note that it is possible to do the following.

package P
  partial model A end A;
  model B extends A; end B;
  model C extends A; end C;
  partial model X
    A a[3] = {a1,a2,a3};
    replaceable A a1,a2,a3;
  end X;
  model Y extends X;
    redeclare B a1;
    redeclare C a2;
    redeclare B a3;
  end Y;
end P;

But I want P.X to use a parametric array. Then again, the following idea to achieve this, does not work.

package P
  partial model A end A;
  model B extends A; end B;
  model C extends A; end C;
  partial model X
    parameter Integer N;
    replaceable A a[N] = fill(ai,N);
    A ai;
  end X;
  model Y extends X(N=3);
    redeclare A a[3] = {b,c,b};
    B b;
    C c;
  end Y;
end P;

回答1:


Yes. Is illegal to instantiate a partial model without extending it from a non-partial model. Something like this might work:

model Y
  extend X(a = {C, D, C});
end Y;

Then Y.a is what you want.




回答2:


AFAIK a partial keyword means your model cannot be instantiated, so you'll probably have to extend X, too.



来源:https://stackoverflow.com/questions/29424371/modelica-array-of-partial-model

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