gpt4 book ai didi

modelica - OpenModelica 解决 PDE 初始化错误

转载 作者:行者123 更新时间:2023-12-02 21:35:29 27 4
gpt4 key购买 nike

我正在尝试使用 OpenModelica 对边界条件 u(0,t)=t^2 和 u_x(0,t)=0 的非常简单的偏微分方程 du/dx=du/dt 进行数值求解。我写了下面的代码:

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.

enter image description here

如果您能帮助我了解问题所在以及如何解决它,我将不胜感激?

最佳答案

好吧,首先,看到 Modelica 社区对这个话题如此 NumPy ,我感到非常难过。 SO 或 OpenModelica 论坛中有许多与 PDE 相关的问题,但没有多少有正确的答案。我决定做this Github repo收集我可以在互联网上找到的所有相关 Material ,这样至少其他人就不必四处寻找可行的示例。

但是关于上面的代码。代码几乎没问题,问题在于问题的物理原理。 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中的代码来解决问题。我还在 the example 4 of the said github repo 中提到了代码.

关于modelica - OpenModelica 解决 PDE 初始化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45496863/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com