Opened 10 years ago

Closed 4 years ago

#2902 closed defect (fixed)

Complex parameter binding lost

Reported by: mengjia@… Owned by: Adrian Pop
Priority: high Milestone: 1.16.0
Component: Frontend Version: trunk
Keywords: Cc: Lennart Ochel, Willi Braun

Description (last modified by Lennart Ochel)

Hi look,

model Test
  model Complex_bindinglost
    constant Real pi = Modelica.Constants.pi;
    parameter Real eterm = 0.999999 "terminal voltage";
    //1.0
    parameter Real anglev0 = 4.0463 "Power flow, node angle in degree";
    parameter Real pelec = 0.399989 * 100 "active power MVA";
    //80.0
    parameter Real qelec = 5.41649 "reactive power MVA";
    //50.0
    parameter Real wbase = 2 * pi * 50 "system base speed";
    parameter Real mbase = 100 "system base power rating MVA";
    parameter Real Ra = 0 "amature resistance";
    parameter Real Xpp = 1;
    parameter Real anglev_rad = anglev0 * pi / 180 "initial value of bus anglev in rad";
    parameter Real p0 = pelec / mbase "initial value of bus active power in p.u.";
    parameter Real q0 = qelec / mbase "initial value of bus reactive power in p.u.";
    parameter Complex Zs(re = Ra, im = Xpp) "Equivation impedance";
    parameter Complex VT(re = eterm * cos(anglev_rad), im = eterm * sin(anglev_rad));
    parameter Complex S(re = p0, im = q0);
    parameter Complex It = conj(S / VT);
    //Initialize current and voltage components of rotor reference fram (dq axes).
  end Complex_bindinglost;

  model Complex_bindingOK
    constant Real pi = Modelica.Constants.pi;
    parameter Complex ZsOK(re = 1, im = 1) "Equivation impedance";
    parameter Complex VTOK(re = cos(pi), im = sin(pi));
    parameter Complex SOK(re = 1, im = 1);
    parameter Complex ItOK = conj(S / VT);
    annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
  end Complex_bindingOK;
  annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end Test;

Check that the value of It is zero but ItOK got its value (not zero)
why ?
Thanks :)

Attachments (3)

Example.mo (5.2 KB ) - added by anonymous 10 years ago.
Run this example. Thanks
Example.2.mo (5.2 KB ) - added by anonymous 10 years ago.
Run this example. Thanks
Example.3.mo (5.2 KB ) - added by anonymous 10 years ago.
Run this example. Thanks

Download all attachments as: .zip

Change History (14)

comment:1 by Lennart Ochel, 10 years ago

Cc: Lennart Ochel added; Lennart Ochel [lennart.ochel@… removed
Description: modified (diff)

comment:2 by Lennart Ochel, 10 years ago

The function conj is missing, but seem to be essential.

comment:3 by Lennart Ochel, 10 years ago

I just wrote my own function conj. Maybe the way it is written has something to do with the error, so please provide also yours.

Now, I get the following error:

[<interactive>:38:5-38:42:writable] Error: Variable S not found in scope Test.Complex_bindingOK.
Error: Error occurred while flattening model Test.Complex_bindingOK

by anonymous, 10 years ago

Attachment: Example.mo added

Run this example. Thanks

by anonymous, 10 years ago

Attachment: Example.2.mo added

Run this example. Thanks

by anonymous, 10 years ago

Attachment: Example.3.mo added

Run this example. Thanks

comment:4 by Lennart Ochel, 10 years ago

I did some slight changes to the model to get it compile. For me, both models are working properly:

loadString("
model Test
  function conj
    input Complex a;
    output Complex b;
  algorithm
    b := Complex(a.re, -a.im);
  end conj;

  model Complex_bindinglost
    constant Real pi = Modelica.Constants.pi;
    parameter Real eterm = 0.999999 \"terminal voltage\";
    //1.0
    parameter Real anglev0 = 4.0463 \"Power flow, node angle in degree\";
    parameter Real pelec = 0.399989 * 100 \"active power MVA\";
    //80.0
    parameter Real qelec = 5.41649 \"reactive power MVA\";
    //50.0
    parameter Real wbase = 2 * pi * 50 \"system base speed\";
    parameter Real mbase = 100 \"system base power rating MVA\";
    parameter Real Ra = 0 \"amature resistance\";
    parameter Real Xpp = 1;
    parameter Real anglev_rad = anglev0 * pi / 180 \"initial value of bus anglev in rad\";
    parameter Real p0 = pelec / mbase \"initial value of bus active power in p.u.\";
    parameter Real q0 = qelec / mbase \"initial value of bus reactive power in p.u.\";
    parameter Complex Zs(re = Ra, im = Xpp) \"Equivation impedance\";
    parameter Complex VT(re = eterm * cos(anglev_rad), im = eterm * sin(anglev_rad));
    parameter Complex S(re = p0, im = q0);
    parameter Complex It = conj(S / VT);
    //Initialize current and voltage components of rotor reference fram (dq axes).
  end Complex_bindinglost;

  model Complex_bindingOK
    constant Real pi = Modelica.Constants.pi;
    parameter Complex ZsOK(re = 1, im = 1) \"Equivation impedance\";
    parameter Complex VTOK(re = cos(pi), im = sin(pi));
    parameter Complex SOK(re = 1, im = 1);
    parameter Complex ItOK = conj(SOK / VTOK);
    annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserv$
  end Complex_bindingOK;
  annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveA$
end Test;
"); getErrorString();

instantiateModel(Test.Complex_bindinglost); getErrorString();
instantiateModel(Test.Complex_bindingOK); getErrorString();

The output is:

class Test.Complex_bindinglost
  constant Real pi = 3.141592653589793;
  parameter Real eterm = 0.999999 \"terminal voltage\";
  parameter Real anglev0 = 4.0463 \"Power flow, node angle in degree\";
  parameter Real pelec = 39.9989 \"active power MVA\";
  parameter Real qelec = 5.41649 \"reactive power MVA\";
  parameter Real wbase = 314.1592653589793 \"system base speed\";
  parameter Real mbase = 100.0 \"system base power rating MVA\";
  parameter Real Ra = 0.0 \"amature resistance\";
  parameter Real Xpp = 1.0;
  parameter Real anglev_rad = 0.0174532925199433 * anglev0 \"initial value of bus anglev in rad\";
  parameter Real p0 = pelec / mbase \"initial value of bus active power in p.u.\";
  parameter Real q0 = qelec / mbase \"initial value of bus reactive power in p.u.\";
  parameter Real Zs.re = Ra \"Real part of complex number\";
  parameter Real Zs.im = Xpp \"Imaginary part of complex number\";
  parameter Real VT.re = eterm * cos(anglev_rad) \"Real part of complex number\";
  parameter Real VT.im = eterm * sin(anglev_rad) \"Imaginary part of complex number\";
  parameter Real S.re = p0 \"Real part of complex number\";
  parameter Real S.im = q0 \"Imaginary part of complex number\";
  parameter Real It.re = 0.4028143868651517 \"Real part of complex number\";
  parameter Real It.im = -0.02580566019352643 \"Imaginary part of complex number\";
end Test.Complex_bindinglost;


class Test.Complex_bindingOK  
  constant Real pi = 3.141592653589793;
  parameter Real ZsOK.re = 1.0 \"Real part of complex number\";
  parameter Real ZsOK.im = 1.0 \"Imaginary part of complex number\";
  parameter Real VTOK.re = -1.0 \"Real part of complex number\";
  parameter Real VTOK.im = 1.224646799147353e-16 \"Imaginary part of complex number\";
  parameter Real SOK.re = 1.0 \"Real part of complex number\";
  parameter Real SOK.im = 1.0 \"Imaginary part of complex number\";
  parameter Real ItOK.re = -0.9999999999999999 \"Real part of complex number\";
  parameter Real ItOK.im = 1.0 \"Imaginary part of complex number\";
end Test.Complex_bindingOK;

comment:5 by Lennart Ochel, 10 years ago

I get the same result for Example3.mo.

comment:6 by Willi Braun, 10 years ago

Cc: Willi Braun added
Component: UnknownFrontend

You can use even the following easier model:

loadModel(Complex);
loadString("
model A
  parameter Real r = 1.0;
  parameter Real i = 1.0;
  parameter Complex a(re=r, im=i);
  parameter Complex b(re=r, im=i);
  parameter Complex c = a * b;
end A;

model B
  A a(r=2.0, i=4.0);
end B;
");
getErrorString();
simulate(B);
getErrorString();

val(a.c.re, 0.0);
val(a.c.im, 0.0);

comment:7 by Lennart Ochel, 10 years ago

Owner: changed from somebody to Martin Sjölund
Status: newassigned

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

Weird. Ceval.ceval DAE.CALL failed: Complex.'*'.multiply(a, b) is the only thing in the failtrace...

comment:9 by Martin Sjölund, 10 years ago

Owner: changed from Martin Sjölund to Adrian Pop

I was able to add it like this:

class B
  parameter Real a.r = 2.0;
  parameter Real a.i = 4.0;
  parameter Real a.axy.re = a.r "Real part of complex number";
  parameter Real a.axy.im = a.i "Imaginary part of complex number";
  parameter Real a.bxy.re = a.r "Real part of complex number";
  parameter Real a.bxy.im = a.i "Imaginary part of complex number";
  parameter Real a.c.re "Real part of complex number";
  parameter Real a.c.im "Imaginary part of complex number";
initial equation
  a.c = Complex.'*'.multiply(a.axy, a.bxy);
end B;

The equation is only added correctly for non-parameters. And this "fix" is wrong since it needs to be a binding equation.

comment:10 by Per Östlund, 4 years ago

This seems to work fine now, both the old and the new frontend correctly gives a.c.re = -12.0 and a.c.im = 16.0 for the model in comment 6.

comment:11 by Per Östlund, 4 years ago

Milestone: Future1.16.0
Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.