0
votes

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;
2
Do you really need that A is partial? Your last example compiles if you remove the partial keyword before model A end A;. Declaring A as partial and then instancing it with A a[...] is a contradiction.Tobias
You're right, it is a contradiction. However, I would like A to be partial as it should act as a kind of abstract type which is not supposed to be instantiated. Do you have an idea how to do that in Modelica?Mathabc

2 Answers

2
votes

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.

1
votes

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