Modelica: Link connectors with equations

42 Views Asked by At

I tried to make circuit model using only equations (no graphical representation), for later add differential equation for example.

I tried to make a simple circuit (voltage divider) to test my understanding, and I got errors.

The code:

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

  parameter Modelica.Units.SI.Resistance R1 = 1;
  parameter Modelica.Units.SI.Resistance R2 = 1;

  Modelica.Units.SI.Current iR1 "Current through resistor";
  Modelica.Units.SI.Current iR2 "Current through resistor";

/*     p1       R1          p2
i1 ->  x------|||||---------x  <- i2
                      |
                     |||
                     |||  R2                    
                     |||
       n1             |     n2
i1 <-  x--------------------x  -> i2
*/
equation 

  n1.v = n2.v;

  v1 = iR2*R2 + iR1*R1;
  v2 = iR2*R2;  
  p1.i = iR1;

  0 = p1.i + p2.i - iR2;
  0 = n1.i + n2.i + iR2;

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

Then I connected my model into a circuit with a constant voltage source on v1 side and a resistor on v2 side, but I got this error message enter image description here

21:05:25 Translation Error Internal error IndexReduction.pantelidesIndexReduction failed! Found empty set of continuous equations. Use -d=bltdump to get more information.

[3] 21:05:25 Symbolic Error [Modelica.Electrical.Analog.Interfaces.TwoPin: 10:3-10:16]: Model is structurally singular, error found sorting equations 3: constantVoltage.V = 0.0 for variables 1: mathBox_resistorBridge.n2.i:VARIABLE(flow=true unit = "A" ) "Current flowing into the pin" type: Real

[4] 21:05:25 Translation Error Internal error Transformation Module PFPlusExt index Reduction Method Pantelides failed!

I guess there is a problem in the current equation, but I can't figure it out. What am I missing?

1

There are 1 best solutions below

2
Markus A. On

Posting this as an answer, although it is rather a comment, because I wanted to add pictures and code...

It is a bit strange that the model does not work for you, as the following model

Test Circuit for resistor bridge

or the respective code

model Test_resistorBridge
  mathBox_resistorBridge mathBox_resistorBridge1 annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
  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})));
equation 
  connect(constantVoltage.p, mathBox_resistorBridge1.p1)
    annotation (Line(points={{-48,10},{-48,14},{-14,14},{-14,10},{-10,10}}, color={0,0,255}));
  connect(constantVoltage.n, mathBox_resistorBridge1.n1)
    annotation (Line(points={{-48,-10},{-48,-14},{-14,-14},{-14,-10},{-10,-10}}, color={0,0,255}));
  connect(constantVoltage.n, ground.p) annotation (Line(points={{-48,-10},{-48,-14}}, color={0,0,255}));
  connect(resistor.p, mathBox_resistorBridge1.p2)
    annotation (Line(points={{40,10},{40,14},{14,14},{14,10},{10,10}}, color={0,0,255}));
  connect(mathBox_resistorBridge1.n2, resistor.n)
    annotation (Line(points={{10,-10},{14,-10},{14,-14},{40,-14},{40,-10}}, color={0,0,255}));
  annotation (
    Icon(coordinateSystem(preserveAspectRatio=false)),
    Diagram(coordinateSystem(preserveAspectRatio=false)),
    uses(Modelica(version="4.0.0")));
end Test_resistorBridge;

works in both, OpenModelica v1.20.0 and Dymola 2024x for me. From the visual appearance of the circuit they should be similar. The only difference I can imagine is some invisible mistake in the test-circuit, which is why I posted the code above...