Modelica中关联连接器与方程:解决过定系统问题
问题描述
我尝试开发一款MathBox,将微分方程描述的数学模型关联到可接入电路的模型中。作为Modelica新手,我先实现了U=R*I的线性模型并验证可行;但在添加DC/DC Buck变换器平均模型的行为/微分方程后,出现过定系统错误(模型含34个方程、32个变量)。以下为相关代码及报错信息,求问如何实现行为方程且避免过定系统?
原模型代码
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;
测试电路代码
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;
报错信息
[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).
问题分析与解决方案
过定系统的核心原因是重复定义方程+物理逻辑错误,具体修正点如下:
- 移除冗余电压方程:你已经通过
der(iL1)的微分方程定义了电感的电压电流关系,后续的v1 = L1 * der(iL1) + vC1属于重复方程,直接删除。 - 修正电容微分方程:原方程中
v2/p2.i的逻辑错误,电容电压的微分方程应符合KCL,即der(vC1) = (iL1 - p2.i)/C1(电容电流等于电感电流减去负载电流)。 - 删除冗余电流方程:
0 = p1.i + p2.i - C1*der(vC1)和0 = n1.i + n2.i + C1*der(vC1)是重复的KCL约束,且p1.i = iL1已定义电感电流,保留后者即可。 - 利用接口内置约束:
n1.v = n2.v是FourPin接口隐含的公共端等电位约束,无需重复定义,直接删除。
修正后的模型代码
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) = (iL1 - p2.i)/C1; // 修正后的电容电压微分方程 der(iL1) = -1/L1 * vC1 + D * v1 / L1; // 电感电流微分方程 // Voltage connection v2 = vC1; // 输出电压等于电容电压 // Current connection p1.i = iL1; // 输入电流等于电感电流 annotation (uses(Modelica(version="4.0.0"))); end mathBox_buckConverterAVG;
测试电路无需修改,直接运行即可完成正常仿真。
内容的提问来源于stack exchange,提问作者Danakil
相关产品推荐
相关产品推荐

