Modelica 矩阵奇异欠定线性系统不可解
下面,我将代码修改为:Modelica 矩阵奇异欠定线性系统不可解,modelica,dymola,openmodelica,jmodelica,Modelica,Dymola,Openmodelica,Jmodelica,下面,我将代码修改为: model test // types type Mass = Real(unit = "Kg", min = 0); type Length = Real(unit = "m"); type Area = Real(unit = "m2", min = 0); type Force = Real(unit = "Kg.m/s2"); type Pressure = Real(unit = "Kg/m/s2"); type Torque = R
model test
// types
type Mass = Real(unit = "Kg", min = 0);
type Length = Real(unit = "m");
type Area = Real(unit = "m2", min = 0);
type Force = Real(unit = "Kg.m/s2");
type Pressure = Real(unit = "Kg/m/s2");
type Torque = Real(unit = "Kg.m2/s2");
type Velocity = Real(unit = "m/s");
type Time = Real(unit = "s");
// constants
constant Real pi = 2 * Modelica.Math.asin(1.0);
parameter Mass Mp = 0.01;
parameter Length r1 = 0.010;
parameter Length r3 = 0.004;
parameter Integer n = 3;
parameter Area A = 0.020 * 0.015;
parameter Time Stepping = 1.0;
parameter Real DutyCycle = 1.0;
parameter Pressure Pin = 500000;
parameter Real Js = 1;
//parameter Real Muk = 0.0;
parameter Real Muk = 0.158;
// variables
Length x[n];
Velocity vx[n];
Real theta;
Real vt;
Pressure P[n];
Force Fnsp[n];
Torque Tfsc;
initial equation
theta = 0;
vt = 0;
algorithm
for i in 1:n loop
if noEvent((i - 1) * Stepping < mod(time, n * Stepping)) and noEvent(mod(time, n * Stepping) < Stepping * ((i - 1) + DutyCycle)) then
P[i] := Pin;
else
P[i] := 0;
end if;
end for;
Tfsc := -r3 * Muk * sign(vt) * abs(sum(Fnsp));
equation
vx = der(x);
vt = der(theta);
x = r1 * {sin(theta + (i - 1) * 2 * pi / n) for i in 1:n};
Mp * der(vx) + P * A = Fnsp;
Js * der(theta) = Tfsc - r1 * Fnsp * {cos(theta + (i - 1) * 2 * pi / n) for i in 1:n};
// Js * der(theta) = - r1 * Fnsp * {cos(theta + (i - 1) * 2 * pi / n) for i in 1:n};
annotation(
experiment(StartTime = 0, StopTime = 30, Tolerance = 1e-06, Interval = 0.03),
__OpenModelica_simulationFlags(lv = "LOG_STATS", outputFormat = "mat", s = "dassl"));
end test;
这毫无意义,但我认为我可以安全地忽略,编译错误:
矩阵奇异
欠定线性系统不可解
此前也有报道。如果我去掉这些线
Torque Tfsc;
及
改变
Js * der(theta) = - r1 * Fnsp * {cos(theta + (i - 1) * 2 * pi / n) for i in 1:n};
很好用。但是,将Muk
设置为零,这在理论上会导致与上述相同的错误!如果您能帮助我了解问题所在以及如何解决,我将不胜感激
p.S.1.在Dymola演示版上,模拟测试完成时没有错误,只有警告:
Some variables are iteration variables of the initialization problem:
but they are not given any explicit start values. Zero will be used.
Iteration variables:
der(theta, 2)
P[1]
P[2]
P[3]
p.S.2.使用JModelica,删除noEvent
并使用python代码:
model_name='test'
mo_文件='test.mo'
从pymodelica导入编译
从pyfmi导入加载\u fmu
my_fmu=编译_fmu(型号名称,mo_文件)
myModel=load_fmu('test.fmu'))
res=myModel.simulate(最终时间=30)
θ=res['theta']
t=res[‘时间’]
将matplotlib.pyplot作为plt导入
plt.绘图(t,θ)
plt.show()
对于Muk
的小值(例如0.1
),它可以非常快速地求解模型。但它再一次陷入了更大的价值观。唯一的警告是:
Warning at line 30, column 3, in file 'test.mo':
Iteration variable "Fnsp[2]" is missing start value!
Warning at line 30, column 3, in file 'test.mo':
Iteration variable "Fnsp[3]" is missing start value!
Warning in flattened model:
Iteration variable "der(_der_theta)" is missing start value!
您不需要使用算法来指定方程(即使它们位于for循环和if循环中)。我将它们移到等式部分,并完全删除了算法部分:
model test
// types
type Mass = Real(unit = "Kg", min = 0);
type Length = Real(unit = "m");
type Area = Real(unit = "m2", min = 0);
type Force = Real(unit = "Kg.m/s2");
type Pressure = Real(unit = "Kg/m/s2");
type Torque = Real(unit = "Kg.m2/s2");
type Velocity = Real(unit = "m/s");
type Time = Real(unit = "s");
// constants
constant Real pi = 2 * Modelica.Math.asin(1.0);
parameter Mass Mp = 0.01;
parameter Length r1 = 0.010;
parameter Length r3 = 0.004;
parameter Integer n = 3;
parameter Area A = 0.020 * 0.015;
parameter Time Stepping = 1.0;
parameter Real DutyCycle = 1.0;
parameter Pressure Pin = 500000;
parameter Real Js = 1;
//parameter Real Muk = 0.0;
parameter Real Muk = 0.158;
// variables
Length x[n];
Velocity vx[n];
Real theta;
Real vt;
Pressure P[n];
Force Fnsp[n];
Torque Tfsc;
initial equation
theta = 0;
vt = 0;
equation
for i in 1:n loop
if noEvent((i - 1) * Stepping < mod(time, n * Stepping)) and noEvent(mod(time, n * Stepping) < Stepping * ((i - 1) + DutyCycle)) then
P[i] = Pin;
else
P[i] = 0;
end if;
end for;
Tfsc = -r3 * Muk * sign(vt) * abs(sum(Fnsp));
vx = der(x);
vt = der(theta);
x = r1 * {sin(theta + (i - 1) * 2 * pi / n) for i in 1:n};
Mp * der(vx) + P * A = Fnsp;
Js * der(theta) = Tfsc - r1 * Fnsp * {cos(theta + (i - 1) * 2 * pi / n) for i in 1:n};
// Js * der(theta) = - r1 * Fnsp * {cos(theta + (i - 1) * 2 * pi / n) for i in 1:n};
end test;
模型试验
//类型
类型质量=实际质量(单位=“Kg”,最小值=0);
类型长度=实际长度(单位为m);
类型面积=实际面积(单位=“m2”,最小值=0);
类型力=实际力(单位=“Kg.m/s2”);
类型压力=实际压力(单位=“Kg/m/s2”);
类型扭矩=实际扭矩(单位=“Kg.m2/s2”);
类型速度=实际速度(单位为m/s);
类型时间=实际时间(单位为秒);
//常数
常数实pi=2*Modelica.Math.asin(1.0);
参数质量Mp=0.01;
参数长度r1=0.010;
参数长度r3=0.004;
参数整数n=3;
参数面积A=0.020*0.015;
参数时间步进=1.0;
参数Real DutyCycle=1.0;
参数压力销=500000;
参数Real Js=1;
//参数Real Muk=0.0;
参数Real Muk=0.158;
//变数
长度x[n];
速度vx[n];
真θ;
真实vt;
压力P[n];
力Fnsp[n];
扭矩Tfsc;
初始方程
θ=0;
vt=0;
方程式
对于1:n循环中的i
如果noEvent((i-1)*步进
这使得编译器更容易为强组件找到合理的排序和撕裂。这仍然在19秒打破,但在此之前,它可能只是你正在寻找的。牛顿解算器在该阈值之后发散,因为我不知道您在这里做什么,很遗憾,我无法提供任何结果分析。此外,由if方程触发的事件似乎可以被
示例
操作符干净地替换。你可能想看一下。一些小评论:它是“kg”而不是“kg”,并且不允许有多个分区,所以“kg/m/s2”应该写为“kg/(m.s2)”。@HansOlsson非常感谢。能有你和其他Modelica的人在一起真是太好了。
Warning at line 30, column 3, in file 'test.mo':
Iteration variable "Fnsp[2]" is missing start value!
Warning at line 30, column 3, in file 'test.mo':
Iteration variable "Fnsp[3]" is missing start value!
Warning in flattened model:
Iteration variable "der(_der_theta)" is missing start value!
model test
// types
type Mass = Real(unit = "Kg", min = 0);
type Length = Real(unit = "m");
type Area = Real(unit = "m2", min = 0);
type Force = Real(unit = "Kg.m/s2");
type Pressure = Real(unit = "Kg/m/s2");
type Torque = Real(unit = "Kg.m2/s2");
type Velocity = Real(unit = "m/s");
type Time = Real(unit = "s");
// constants
constant Real pi = 2 * Modelica.Math.asin(1.0);
parameter Mass Mp = 0.01;
parameter Length r1 = 0.010;
parameter Length r3 = 0.004;
parameter Integer n = 3;
parameter Area A = 0.020 * 0.015;
parameter Time Stepping = 1.0;
parameter Real DutyCycle = 1.0;
parameter Pressure Pin = 500000;
parameter Real Js = 1;
//parameter Real Muk = 0.0;
parameter Real Muk = 0.158;
// variables
Length x[n];
Velocity vx[n];
Real theta;
Real vt;
Pressure P[n];
Force Fnsp[n];
Torque Tfsc;
initial equation
theta = 0;
vt = 0;
equation
for i in 1:n loop
if noEvent((i - 1) * Stepping < mod(time, n * Stepping)) and noEvent(mod(time, n * Stepping) < Stepping * ((i - 1) + DutyCycle)) then
P[i] = Pin;
else
P[i] = 0;
end if;
end for;
Tfsc = -r3 * Muk * sign(vt) * abs(sum(Fnsp));
vx = der(x);
vt = der(theta);
x = r1 * {sin(theta + (i - 1) * 2 * pi / n) for i in 1:n};
Mp * der(vx) + P * A = Fnsp;
Js * der(theta) = Tfsc - r1 * Fnsp * {cos(theta + (i - 1) * 2 * pi / n) for i in 1:n};
// Js * der(theta) = - r1 * Fnsp * {cos(theta + (i - 1) * 2 * pi / n) for i in 1:n};
end test;