Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Too many equations in algorithm section

Too many equations in algorithm section

Hi,
I wanted to control some switches. However, if you read the algorithm section below. The compiler told me, that there are too many equations (74 instead of 73).

algorithm
  SineValue:=sin(2 * 2*Modelica.Math.asin(1.0) / Frequenz * time);
  when SineValue>0 then
  if SineValue<ACOutVSensor.v then
    idealOpeningSwitchUpperHalf.control := true;
  end if;
  end when;
  when SineValue<0 then
  if SineValue>ACOutVSensor.v then
    idealOpeningSwitchLowerHalf.control := true;
  end if;
  end when;


If I change the section to

algorithm
  SineValue:=sin(2 * 2*Modelica.Math.asin(1.0) / Frequenz * time);
  when SineValue>0 then
  if SineValue<ACOutVSensor.v then
    idealOpeningSwitchUpperHalf.control := true;
  end if;
end when;

I have no precompiler issues, but the behavior of the switches are not correct.

I think I have a problem in understanding the concept of equations and if then else structures. Can anybody provide me some help?

Thanks.

Re: Too many equations in algorithm section


Try using elsewhen instead of having two separate mutual excluding equations.

Re: Too many equations in algorithm section

Thanks for your fast reply. I change it to

  SineValue:=sin(2 * 2*Modelica.Math.asin(1.0) / Frequenz * time);
  when SineValue>0 then
  if SineValue<ACOutVSensor.v then
    idealOpeningSwitchUpperHalf.control := true;
  end if;
  elsewhen SineValue<0 then
  if SineValue>ACOutVSensor.v then
    idealOpeningSwitchLowerHalf.control := true;
  end if;
  end when;

but still I have 74 equations instead of 73.

Re: Too many equations in algorithm section

Hmm, is a bit complicated to understand what you want to do without having the entire model.

Maybe you can try without the when equations:

Code:


idealOpeningSwitchUpperHalf.control :=  if SineValue>0 and SineValue<ACOutVSensor.v then true else false;
idealOpeningSwitchLowerHalf.control :=  if SineValue<0 and SineValue>ACOutVSensor.v then true else false;

Re: Too many equations in algorithm section

I tried, but it is the same error picture ?!?

Here is the whole model. Maybe the issue is more subtil.

model BasicSinglePhaseDCACConverter
  Modelica.Electrical.Analog.Basic.Ground ground1 annotation(Placement(visible = true, transformation(origin = {-90, 4}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor UpperHalfCap annotation(Placement(visible = true, transformation(origin = {-36, 24}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Basic.Capacitor LowerHalfCap annotation(Placement(visible = true, transformation(origin = {-36, 4}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Ideal.IdealOpeningSwitch idealOpeningSwitchUpperHalf annotation(Placement(visible = true, transformation(origin = {-10, 34}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Ideal.IdealOpeningSwitch idealOpeningSwitchLowerHalf annotation(Placement(visible = true, transformation(origin = {-6, -6}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Inductor FilterL(L = 0.01) annotation(Placement(visible = true, transformation(origin = {28, 34}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor FilterC(C = 0.001)  annotation(Placement(visible = true, transformation(origin = {52, 24}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Basic.Resistor Load(R = 10000)  annotation(Placement(visible = true, transformation(origin = {92, 24}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage1(V = 600) annotation(Placement(visible = true, transformation(origin = {-70, 24}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage2(V = 600) annotation(Placement(visible = true, transformation(origin = {-70, 4}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Sensors.VoltageSensor ACOutVSensor annotation(Placement(visible = true, transformation(origin = {118, 24}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
 
  parameter Real pi=2*Modelica.Math.asin(1.0);
  parameter Real Frequenz = 50;
  parameter Real A0 = 230;
  Real SineValue=0;
equation
  connect(ACOutVSensor.n, Load.n) annotation(Line(points = {{118, 14}, {92, 14}, {92, 14}, {92, 14}}, color = {0, 0, 255}));
  connect(ACOutVSensor.p, Load.p) annotation(Line(points = {{118, 34}, {92, 34}, {92, 34}, {92, 34}}, color = {0, 0, 255}));
  connect(FilterC.p, Load.p) annotation(Line(points = {{52, 34}, {92, 34}, {92, 34}, {92, 34}}, color = {0, 0, 255}));
  connect(FilterC.n, Load.n) annotation(Line(points = {{52, 14}, {92, 14}, {92, 14}, {92, 14}}, color = {0, 0, 255}));
  connect(LowerHalfCap.p, FilterC.n) annotation(Line(points = {{-36, 14}, {52, 14}, {52, 14}, {52, 14}}, color = {0, 0, 255}));
  connect(FilterC.p, FilterL.n) annotation(Line(points = {{52, 34}, {38, 34}, {38, 34}, {38, 34}}, color = {0, 0, 255}));
  connect(idealOpeningSwitchUpperHalf.n, FilterL.p) annotation(Line(points = {{0, 34}, {18, 34}}, color = {0, 0, 255}));
  connect(idealOpeningSwitchLowerHalf.n, FilterL.p) annotation(Line(points = {{4, -6}, {18, -6}, {18, 34}}, color = {0, 0, 255}));
  connect(LowerHalfCap.n, idealOpeningSwitchLowerHalf.p) annotation(Line(points = {{-36, -6}, {-18, -6}, {-18, -6}, {-16, -6}}, color = {0, 0, 255}));
  connect(UpperHalfCap.p, idealOpeningSwitchUpperHalf.p) annotation(Line(points = {{-36, 34}, {-20, 34}, {-20, 34}, {-20, 34}}, color = {0, 0, 255}));
  connect(constantVoltage1.p, UpperHalfCap.p) annotation(Line(points = {{-70, 34}, {-36, 34}, {-36, 34}, {-36, 34}}, color = {0, 0, 255}));
  connect(constantVoltage2.n, LowerHalfCap.n) annotation(Line(points = {{-70, -6}, {-36, -6}, {-36, -6}, {-36, -6}}, color = {0, 0, 255}));
  connect(constantVoltage2.p, LowerHalfCap.p) annotation(Line(points = {{-70, 14}, {-36, 14}, {-36, 14}, {-36, 14}}, color = {0, 0, 255}));
  connect(ground1.p, constantVoltage2.p) annotation(Line(points = {{-90, 14}, {-70, 14}, {-70, 14}, {-70, 14}}, color = {0, 0, 255}));

algorithm
  SineValue:=sin(2 * 2*Modelica.Math.asin(1.0) / Frequenz * time);
// when SineValue>0 then
// if SineValue<ACOutVSensor.v then
//   idealOpeningSwitchUpperHalf.control := true;
// end if;
// elsewhen SineValue<0 then
// if SineValue>ACOutVSensor.v then
//   idealOpeningSwitchLowerHalf.control := true;
// end if;
// end when;

idealOpeningSwitchUpperHalf.control :=  if SineValue>0 and SineValue<ACOutVSensor.v then true else false;
idealOpeningSwitchLowerHalf.control :=  if SineValue<0 and SineValue>ACOutVSensor.v then true else false;

  annotation(uses(Modelica(version = "3.2.1")));
end BasicSinglePhaseDCACConverter;

Re: Too many equations in algorithm section

Hi again,

Very good you posted the entire model, the problem was in the component section current/smile
The problem is with SineValue = 0, it should be SineValue(start = 0) as if you have
SineValue = 0 it means an additional equation, that's why you have 76.

Code:


model BasicSinglePhaseDCACConverter
  Modelica.Electrical.Analog.Basic.Ground ground1 annotation(Placement(visible = true, transformation(origin = {-90, 4}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor UpperHalfCap annotation(Placement(visible = true, transformation(origin = {-36, 24}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Basic.Capacitor LowerHalfCap annotation(Placement(visible = true, transformation(origin = {-36, 4}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Ideal.IdealOpeningSwitch idealOpeningSwitchUpperHalf annotation(Placement(visible = true, transformation(origin = {-10, 34}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Ideal.IdealOpeningSwitch idealOpeningSwitchLowerHalf annotation(Placement(visible = true, transformation(origin = {-6, -6}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Inductor FilterL(L = 0.01) annotation(Placement(visible = true, transformation(origin = {28, 34}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor FilterC(C = 0.001)  annotation(Placement(visible = true, transformation(origin = {52, 24}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Basic.Resistor Load(R = 10000)  annotation(Placement(visible = true, transformation(origin = {92, 24}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage1(V = 600) annotation(Placement(visible = true, transformation(origin = {-70, 24}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage2(V = 600) annotation(Placement(visible = true, transformation(origin = {-70, 4}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Sensors.VoltageSensor ACOutVSensor annotation(Placement(visible = true, transformation(origin = {118, 24}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
 
  parameter Real pi=2*Modelica.Math.asin(1.0);
  parameter Real Frequenz = 50;
  parameter Real A0 = 230;
  Real SineValue(start = 0); // NOTE HERE: it was SineValue = 0 which means an additional equation for SineValue!
equation
  connect(ACOutVSensor.n, Load.n) annotation(Line(points = {{118, 14}, {92, 14}, {92, 14}, {92, 14}}, color = {0, 0, 255}));
  connect(ACOutVSensor.p, Load.p) annotation(Line(points = {{118, 34}, {92, 34}, {92, 34}, {92, 34}}, color = {0, 0, 255}));
  connect(FilterC.p, Load.p) annotation(Line(points = {{52, 34}, {92, 34}, {92, 34}, {92, 34}}, color = {0, 0, 255}));
  connect(FilterC.n, Load.n) annotation(Line(points = {{52, 14}, {92, 14}, {92, 14}, {92, 14}}, color = {0, 0, 255}));
  connect(LowerHalfCap.p, FilterC.n) annotation(Line(points = {{-36, 14}, {52, 14}, {52, 14}, {52, 14}}, color = {0, 0, 255}));
  connect(FilterC.p, FilterL.n) annotation(Line(points = {{52, 34}, {38, 34}, {38, 34}, {38, 34}}, color = {0, 0, 255}));
  connect(idealOpeningSwitchUpperHalf.n, FilterL.p) annotation(Line(points = {{0, 34}, {18, 34}}, color = {0, 0, 255}));
  connect(idealOpeningSwitchLowerHalf.n, FilterL.p) annotation(Line(points = {{4, -6}, {18, -6}, {18, 34}}, color = {0, 0, 255}));
  connect(LowerHalfCap.n, idealOpeningSwitchLowerHalf.p) annotation(Line(points = {{-36, -6}, {-18, -6}, {-18, -6}, {-16, -6}}, color = {0, 0, 255}));
  connect(UpperHalfCap.p, idealOpeningSwitchUpperHalf.p) annotation(Line(points = {{-36, 34}, {-20, 34}, {-20, 34}, {-20, 34}}, color = {0, 0, 255}));
  connect(constantVoltage1.p, UpperHalfCap.p) annotation(Line(points = {{-70, 34}, {-36, 34}, {-36, 34}, {-36, 34}}, color = {0, 0, 255}));
  connect(constantVoltage2.n, LowerHalfCap.n) annotation(Line(points = {{-70, -6}, {-36, -6}, {-36, -6}, {-36, -6}}, color = {0, 0, 255}));
  connect(constantVoltage2.p, LowerHalfCap.p) annotation(Line(points = {{-70, 14}, {-36, 14}, {-36, 14}, {-36, 14}}, color = {0, 0, 255}));
  connect(ground1.p, constantVoltage2.p) annotation(Line(points = {{-90, 14}, {-70, 14}, {-70, 14}, {-70, 14}}, color = {0, 0, 255}));

algorithm
  SineValue:=sin(2 * 2*Modelica.Math.asin(1.0) / Frequenz * time);
// when SineValue>0 then
// if SineValue<ACOutVSensor.v then
//   idealOpeningSwitchUpperHalf.control := true;
// end if;
// elsewhen SineValue<0 then
// if SineValue>ACOutVSensor.v then
//   idealOpeningSwitchLowerHalf.control := true;
// end if;
// end when;

idealOpeningSwitchUpperHalf.control :=  if SineValue>0 and SineValue<ACOutVSensor.v then true else false;
idealOpeningSwitchLowerHalf.control :=  if SineValue<0 and SineValue>ACOutVSensor.v then true else false;

  annotation(uses(Modelica(version = "3.2.1")));
end BasicSinglePhaseDCACConverter;

Cheers,
Adrian Pop/

There are 0 guests and 0 other users also viewing this topic
You are here: