Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#3992 closed defect (worksforme)

A model to dynamically change network topology that does not work with OM

Reported by: massimo ceraolo Owned by: somebody
Priority: normal Milestone: 1.12.0
Component: *unknown* Version: v1.11.0
Keywords: Cc:

Description (last modified by massimo ceraolo)

I use for this ticket the same code that I used for #2755, that I reproduce below.
This code tries to connect "dynamically" electrical components.
If intConst is 1, positive pins of resistor R and E1 are connected to each other and current flows through E1; if it is 2 current flows through E2.
It is useful for algebraic networks (i.e. not having storage elements such as capacitors and inductors) since it allows changing the network topology at runtime.
Although it is a bit tricky, I don't see any reason for which this should be invalid modelica.
In Dymola it works well (and I've been satisfactorily using rather large models containing many of such "Commutator" for years)
I've checked it with OM v1.11.0-dev-16 and got currents in E1 and E2 being either 0 or fluctuating between 0 and -1e-236.

So I will label this ticket as a defect, even though it may not be such (if there is some Modelica prescription it violates).

model commTest0
  model Commutator
    parameter Integer m(final min = 1);
    Modelica.Electrical.Analog.Interfaces.PositivePin pin_pm[m];
    Modelica.Electrical.Analog.Interfaces.PositivePin pin_p;
    Modelica.Blocks.Interfaces.IntegerInput z;
  equation
    pin_p.v = pin_pm[z].v;
    for j in 1:m loop
      pin_pm[j].i = if j == z then -pin_p.i else 0;
    end for;
  end Commutator;

  Commutator commutator(m = 2);
  Modelica.Electrical.Analog.Basic.Resistor resistor(R = 2);
  Modelica.Electrical.Analog.Basic.Ground ground;
  Modelica.Electrical.Analog.Sources.ConstantVoltage E1(V = 100);
  Modelica.Electrical.Analog.Sources.ConstantVoltage E2(V = 200);
  Modelica.Blocks.Sources.IntegerConstant intConst(k = 1);
equation
  connect(commutator.pin_p, resistor.p);
  connect(resistor.n, ground.p);
  connect(E1.p, commutator.pin_pm[1]);
  connect(E2.p, commutator.pin_pm[2]);
  connect(E1.n, ground.p);
  connect(E2.n, ground.p);
  connect(commutator.z, intConst.y);
end commTest0;

Change History (6)

comment:1 by massimo ceraolo, 8 years ago

Summary: A model to dynamical change network topology that does not work with OMA model to dynamically change network topology that does not work with OM

comment:2 by massimo ceraolo, 8 years ago

Description: modified (diff)

comment:3 by massimo ceraolo, 8 years ago

I've checked the instantiated model as given by OMEdit and understood something.
In my model it is intConst=1: it is a function of time being always 1. Therefore commutator.z is always 1.

In this case we should have the following two equations:

commutator.pin_pm[1].i=-commutator.pin_p.i;
commutator.pin_pm[2].i=0;

Instead we have:

  commutator.pin_pm[2].i + E2.p.i = 0.0;
  commutator.pin_pm[1].i + E1.p.i = 0.0;

The first of these equations is evidently wrong.

This part of Dymola's flat modelica is as follows:

   commutator.pin_p.v = commutator.pin_pm[commutator.z].v;
    for j in (1:commutator.m) loop
      commutator.pin_pm[j].i = (if j == commutator.z then  -commutator.pin_p.i
         else 0);
    end for;

comment:4 by Martin Sjölund, 8 years ago

Milestone: 1.11.01.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:5 by Francesco Casella, 7 years ago

Resolution: worksforme
Status: newclosed

I tried with OpenModelica-v1.13.0-dev-63-g453e1c7-64bit, after instantiating I see

  commutator.pin_pm[1].i = if 1 == commutator.z then -commutator.pin_p.i else 0.0;
  commutator.pin_pm[2].i = if 2 == commutator.z then -commutator.pin_p.i else 0.0;

given that commutator.z = intConst.y = 1, this is equivalent to

  commutator.pin_pm[1].i =  -commutator.pin_p.i ;
  commutator.pin_pm[2].i = 0.0;

as you expected.

comment:6 by massimo ceraolo, 7 years ago

A few notes:

1) my comment 3 was partially wrong since all the following equations should be there:

commutator.pin_pm[1].i=-commutator.pin_p.i;
commutator.pin_pm[2].i=0;
commutator.pin_pm[2].i + E2.p.i = 0.0;
commutator.pin_pm[1].i + E1.p.i = 0.0;

2) I verified that these four equations, as mentioned by @casella, are in the flat modelica created with in OM instantiation (i.e. they can be obtained considering that intConst.y=1)

3) I also checked one-by-one the flat modelica equations with Dymola's and found they are exactly the same.

4) However my original model does not work in OM as expected, differently from when using Dymola.

The reason for the issue remains unclear. But I don't see reasons to open now again this ticket.

Maybe in case I find a more clear way to address this problem I will create a brand new one.

Note: See TracTickets for help on using tickets.