0

I am stuck in an attempt to pass an interpolating function that was generated from a PDE solved using NDSolveValue to a second call to NDSolveValue for a solution to a simple ODE. Here is my code for what I thought would work:

(*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\]}\]

I am probably doing something simple wrong and would appreciate any help. I was able to get a solution for the ODE by using Integrate instead of NIntegrate for the imdotc function. With that running in NDSolve, NIntegrate convergence failures after 9 recursive bisections are reported but the solve completes and the solT[t] solution looks OK. Because there are no options to increase the MaxRecursion in Integrate, there is no way to fix this.

Any advice on a better way to approach this would be appreciated.

0

1 Answer 1

0

Key part of the solution is to pass the line integral imdotc[t] to NDSolve using Integrate instead of NIntegrate. This passes an unevaluated function to NDSolve that it can handle. To fix the issues with convergence failures, the solution is to globally set options for NIntegrate using the SetOptions. Adding this little code snippet at the beginning does the trick:

SetOptions[NIntegrate,MaxRecursion->50,Method->"LocalAdaptive",PrecisionGoal->5]
Subscript[t, cyc]=15;d=0.8;c0=0.01. Runs fine now with no warnings.

Posted on behalf of the question asker

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.