OpenModelica 解决 PDE 初始化错误
OpenModelica solving a PDE Initialization error
我正在尝试使用 OpenModelica 对边界条件为 u(0,t)=t^2 和 u_x( 0,t)=0。我写了下面的代码:
model pdetest_1
parameter Real L=1;
parameter Integer N=100;
parameter Real dx=L/(N-1);
parameter Real[N] x=array(i*dx for i in 0:N-1);
Real u[N],ux[N];
initial equation
for i in 1:N loop
u[i]=0;
end for;
equation
u[1]=(time)^2;
ux[1]=0;
for i in 2:N loop
u[i]=u[i-1]+dx*ux[i-1];
der(u[i])=ux[i];
end for;
end pdetest_1;
它确实可以编译,但是它没有完成模拟退出并出现以下错误:
Blocstdout | OMEditInfo |
C:/Users/.../AppData/Local/Temp/OpenModelica/OMEdit/pdetest_1.exe -port=50450 -logFormat=xmltcp -override=startTime=0,stopTime=1,stepSize=0.002,tolerance=1e-6,solver=dassl,outputFormat=mat,variableFilter=.* -r=pdetest_1_res.mat -jacobian=coloredNumerical -w -lv=LOG_STATS
kquote
LOG_INIT | error | The initialization problem is inconsistent due to the following equation: 0 != 0.000204061 = u[4]
stdout | warning | Error in initialization. Storing results and exiting.
Use -lv=LOG_INIT -w for more information.
stdout | error | Simulation process failed. Exited with code -1.
如果您能帮助我了解问题所在以及如何解决,我将不胜感激?
好的,首先,看到 Modelica 社区对这个问题如此麻木,我感到非常难过。在 SO 或 OpenModelica 论坛中有许多与 PDE 相关的问题,没有多少有正确的答案。我决定 this Github repo 收集我可以在 Internet 上找到的所有相关材料,这样至少其他人不必四处寻找工作示例。
但是关于上面的代码。代码几乎没问题,问题在于问题的物理性质。 I asked the question in computational science and got a very good answer.
工作代码是:
model pdetest_1
parameter Real L = 1;
parameter Integer N = 100;
parameter Real dx = L / (N - 1);
parameter Real c = 1;
Real u[N], ux[N];
initial equation
for i in 1:N loop
u[i] = 0;
end for;
equation
if c>0 then
u[N] = time ^ 2;
ux[N] = 0;
for i in 1:N-1 loop
u[i] = u[i + 1] - dx * ux[i];
der(u[i]) = c*ux[i];
end for;
else
u[1] = time ^ 2;
ux[1] = 0;
for i in 2:N loop
u[i] = u[i - 1] + dx * ux[i];
der(u[i]) = c*ux[i];
end for;
end if;
end pdetest_1;
我使用了this presentation by Jan Silar to solve the issue. and I also mentioned the code in the example 4 of the said github repo中的代码。
我正在尝试使用 OpenModelica 对边界条件为 u(0,t)=t^2 和 u_x( 0,t)=0。我写了下面的代码:
model pdetest_1
parameter Real L=1;
parameter Integer N=100;
parameter Real dx=L/(N-1);
parameter Real[N] x=array(i*dx for i in 0:N-1);
Real u[N],ux[N];
initial equation
for i in 1:N loop
u[i]=0;
end for;
equation
u[1]=(time)^2;
ux[1]=0;
for i in 2:N loop
u[i]=u[i-1]+dx*ux[i-1];
der(u[i])=ux[i];
end for;
end pdetest_1;
它确实可以编译,但是它没有完成模拟退出并出现以下错误:
Blocstdout | OMEditInfo |
C:/Users/.../AppData/Local/Temp/OpenModelica/OMEdit/pdetest_1.exe -port=50450 -logFormat=xmltcp -override=startTime=0,stopTime=1,stepSize=0.002,tolerance=1e-6,solver=dassl,outputFormat=mat,variableFilter=.* -r=pdetest_1_res.mat -jacobian=coloredNumerical -w -lv=LOG_STATS
kquote LOG_INIT | error |The initialization problem is inconsistent due to the following equation: 0 != 0.000204061 = u[4]
stdout | warning |Error in initialization. Storing results and exiting.
stdout | error |
Use -lv=LOG_INIT -w for more information.Simulation process failed. Exited with code -1.
如果您能帮助我了解问题所在以及如何解决,我将不胜感激?
好的,首先,看到 Modelica 社区对这个问题如此麻木,我感到非常难过。在 SO 或 OpenModelica 论坛中有许多与 PDE 相关的问题,没有多少有正确的答案。我决定 this Github repo 收集我可以在 Internet 上找到的所有相关材料,这样至少其他人不必四处寻找工作示例。
但是关于上面的代码。代码几乎没问题,问题在于问题的物理性质。 I asked the question in computational science and got a very good answer.
工作代码是:
model pdetest_1
parameter Real L = 1;
parameter Integer N = 100;
parameter Real dx = L / (N - 1);
parameter Real c = 1;
Real u[N], ux[N];
initial equation
for i in 1:N loop
u[i] = 0;
end for;
equation
if c>0 then
u[N] = time ^ 2;
ux[N] = 0;
for i in 1:N-1 loop
u[i] = u[i + 1] - dx * ux[i];
der(u[i]) = c*ux[i];
end for;
else
u[1] = time ^ 2;
ux[1] = 0;
for i in 2:N loop
u[i] = u[i - 1] + dx * ux[i];
der(u[i]) = c*ux[i];
end for;
end if;
end pdetest_1;
我使用了this presentation by Jan Silar to solve the issue. and I also mentioned the code in the example 4 of the said github repo中的代码。