我试图将使用 NDSolveValue 求解的偏微分方程生成的插值函数传递给对 NDSolveValue 的第二次调用,以获得简单 ODE 的解。这是我认为可行的代码:
(*First solve the PDE*)
Subscript\[t, cyc\] = 15; d = 0.8; c0 = 0.01;
ic := c\[x, 0\] == 0.01;
bc1 := c\[0, t\] == 0.1;
bc2 := NeumannValue\[0, x == d\];
ics := s\[x, 0\] == 0;
csat = 0.1; v = 0.1; Tamb = 30;
Tadsf := Tamb + 6*t;
\[CapitalOmega\] = Line\[{{0}, {d}}\];
pdec = D\[c\[x, t\], t\] ==
bc2 + v*c\[x, t\]/csat*Tadsf/Tamb*D\[c\[x, t\], {x, 2}\]
solc = First@
NDSolveValue\[{pdec, bc1, ic}, {c}, {t, 0, Subscript\[t, cyc\]},
x \[Element\] \[CapitalOmega\], AccuracyGoal -\> 10,
PrecisionGoal -\> 10\]
(*Compute time derivative*)
mdotc = D\[solc\[x, t\], t\]
(*This line integral is what I was wanting to use in an ODE for NDSolve*)
imdotc\[t\_?NumericQ\] :=
1/d\*NIntegrate\[mdotc, {x, 0, d}, MaxRecursion -\> 50,
Method -\> "LocalAdaptive"\]
(*If you plot it, the function looks fine*)
Plot\[imdotc\[t\], {t, 0, Subscript\[t, cyc\]}, PlotRange -\> Full,
AxesLabel -\> Automatic\]
(*But if passed into this simple ODE, NIntegrate fails with many error messages*)
icTads := Tads\[0\] == 30;
vair = 0.5; dH = 400;
ode := D\[Tads\[t\], t\] == -vair\*(Tads\[t\] - Tamb) + dH\*imdotc\[t\]
solT = NDSolveValue\[{ode, icTads}, Tads, {t, 0, Subscript\[t, cyc\]}\]
我可能做了一些简单的错误,希望得到任何帮助。我能够通过使用 Integrate 而不是 NIntegrate 作为 imdotc 函数来获得 ODE 的解决方案。在 NDSolve 中运行时,会报告 9 次递归二等分后 NIntegrate 收敛失败,但求解已完成,并且 solT[t] 解看起来正常。因为 Integrate 中没有增加 MaxRecursion 的选项,所以无法解决此问题。
任何关于更好的方法来解决这个问题的建议将不胜感激。
解决方案的关键部分是使用 Integrate 而不是 NIntegrate 将线积分 imdotc[t] 传递给 NDSolve。这会将未评估的函数传递给它可以处理的 NDSolve。要解决收敛失败的问题,解决方案是使用 SetOptions 全局设置 NIntegrate 的选项。在开头添加这个小代码片段就可以解决问题:
SetOptions[NIntegrate,MaxRecursion->50,Method->"LocalAdaptive",PrecisionGoal->5]
Subscript[t, cyc]=15;d=0.8;c0=0.01. Runs fine now with no warnings.
代表提问者发帖