How can I Link Connectors with equation?

56 Views Asked by At

For a few days, I have been trying to make some kind of mathBox, where I can link a mathematical model (using differential equations), that describe a behaviour into a model that I can later connect to a circuit. I am quite new to Modelica, so I started with simple example which works but with linear behaviour (U = R*I).

Now I want to add some behavioural/differential equations that describe the dynamics of the box, but because I add these eqautions into the model, I now have the problem of over-determined system.

Here is the code (it is the average model of a DC/DC Buck converter, so without PWM switching):

model mathBox_buckConverterAVG
  extends Modelica.Electrical.Analog.Interfaces.FourPin;

  Real D = 0.5; // Duty cycle
  
  parameter Modelica.Units.SI.Inductance L1 = 1e-3; // Inductance (H)
  parameter Modelica.Units.SI.Capacitance C1 = 1e-6; // Capacitance (F)

  Modelica.Units.SI.Current iL1 "Current through inductance L1";
  Modelica.Units.SI.Voltage vC1 "Voltage over capacitor C1";

/*     p1       L1               p2
i1 ->  x------|||||--------------x  <- i2
                    |          
                   |||        
                   |||C1                    
                   |||        
       n1           |            n2
i1 <-  x-------------------------x  -> i2
*/
equation 

  // Behavioural equation
  der(vC1) = -1/((v2/p2.i)*C1)*vC1 + iL1/C1; // Capacitor voltage
  der(iL1) = -1/L1 * vC1 + D * v1 / L1; // Inductor current

  // Voltage connection
  v1 = L1 * der(iL1) + vC1;
  v2 = vC1;  
  n1.v = n2.v;
  
  // Current connection
  p1.i = iL1;
  0 = p1.i + p2.i - C1*der(vC1);
  0 = n1.i + n2.i + C1*der(vC1);

  annotation (uses(Modelica(version="4.0.0")));
end mathBox_buckConverterAVG;

Then I add this "component" into an electrical circuit with a constant DC voltage on v1 side and a resistor on v2 side as follow:

model Test_buckConverterAVG
  Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage(V=10)
    annotation (Placement(transformation(
        extent={{-10,-10},{10,10}},
        rotation=270,
        origin={-48,0})));
  Modelica.Electrical.Analog.Basic.Ground ground annotation (Placement(transformation(extent={{-58,-34},{-38,-14}})));
  Modelica.Electrical.Analog.Basic.Resistor resistor(R=1)
    annotation (Placement(transformation(
        extent={{-10,-10},{10,10}},
        rotation=270,
        origin={40,0})));
  mathBox_buckConverterAVG mathBox_buckConverterAVG1 annotation(
    Placement(visible = true, transformation(extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(constantVoltage.n, ground.p) annotation(
    Line(points = {{-48, -10}, {-48, -14}}, color = {0, 0, 255}));
  connect(mathBox_buckConverterAVG1.n2, resistor.n) annotation(
    Line(points = {{10, -10}, {14, -10}, {14, -14}, {40, -14}, {40, -10}}, color = {0, 0, 255}));
  connect(resistor.p, mathBox_buckConverterAVG1.p2) annotation(
    Line(points = {{40, 10}, {40, 14}, {14, 14}, {14, 10}, {10, 10}}, color = {0, 0, 255}));
  connect(constantVoltage.n, mathBox_buckConverterAVG1.n1) annotation(
    Line(points = {{-48, -10}, {-48, -14}, {-14, -14}, {-14, -10}, {-10, -10}}, color = {0, 0, 255}));
  connect(constantVoltage.p, mathBox_buckConverterAVG1.p1) annotation(
    Line(points = {{-48, 10}, {-48, 14}, {-14, 14}, {-14, 10}, {-10, 10}}, color = {0, 0, 255}));
  annotation (
    Icon(coordinateSystem(preserveAspectRatio=false)),
    Diagram(coordinateSystem(preserveAspectRatio=false)),
    uses(Modelica(version="4.0.0")));
end Test_buckConverterAVG;

And I get this error messages:

[6] 15:27:21 Translation Error
Internal error Transformation Module PFPlusExt index Reduction Method Pantelides failed!

[7] 15:27:21 Translation Error
post-optimization module removeSimpleEquations (simulation) failed.

[1] 15:34:09 Symbolic Error
Too many equations, over-determined system. The model has 34 equation(s) and 32 variable(s).

How to implement the behavioural equations without having an over determined system ?

0

There are 0 best solutions below