I'm trying to solve the 2D axisymmetric heat equation, where only one section of the tube is being heated up. I have written the following code below:
q=Piecewise[{{0,z<=0},{10000t,0<=z}}]
bc1=q==1.38(D[T[r,z,t],r]/.r->0.03);
bc2=(D[T[r,z,t],r]/.r->0.00001)==0;
ic1=T[r,z,0]==273.15;
heat=(1521740*D[T[r,z,t],t])==D[T[r,z,t],r,r]+D[T[r,z,t],r]+D[T[r,z,t],z,z];
sol=NDSolve[{heat,bc1,bc2,ic1},{T},{r,0.00001,0.03},{z,-0.2,0.2},{t,0,100}]
However, I get the error NDSolve: Encountered non-numerical value for a derivative at t==0`. The code works when I change q=10000t instead. I think something is likely wrong with the piecewise boundary condition but I'm not sure what is wrong.
Edit: After updating q, the code is able to run but the result seems unphysical (The temperature in some section decreases). It seems like the boundary condition bc1 isnt being properly obeyed.
q=Simplify`PWToUnitStep@Piecewise[{{0,z<=0},{10000t,0<=z}}]
bc1=q==1.38(D[T[r,z,t],r]/.r->0.03);
bc2=(D[T[r,z,t],r]/.r->0.00001)==0;
bc3 = (D[T[r, z, t], z] /. z -> 0.2) == 0;
bc4 = (D[T[r, z, t], z] /. z -> -0.2) == 0;
ic1=T[r,z,0]==273.15;
heat=(1521740*D[T[r,z,t],t])==D[T[r,z,t],r,r]+D[T[r,z,t],r]+D[T[r,z,t],z,z];
sol=NDSolve[{heat,bc1,bc2,bc3,bc4,ic1},{T},{r,0.00001,0.03},{z,-0.2,0.2},{t,0,100}]
Interpolation[Table[{r, sol[[1, 1, 2]][r, -0.01, 10]}, {r, 0.0001, 0.03,
0.0001}]]'[0.03]
The interpolation helps to evaluate the partial derivative of r at z=-0.01. Based on the Piecewise function bc1, this should be 0. However, the interpolation gives me -6247.
qtoq = Simplify`PWToUnitStep@Piecewise[{{0, z <= 0}, {10000 t, 0 <= z}}]avoids thendnumwarning. You still need to fix thebcartwarning, though. Please noticebcartis a serious problem: https://mathematica.stackexchange.com/q/73961/1871 – xzczd Mar 07 '23 at 09:4310000 t /1.38 NeumannValue[1, r == .03 && z <= 0 ]in your pde.. – Ulrich Neumann Mar 07 '23 at 10:24NeumannValuesimply solves the problem I think. No need to use the link! That's why I propose to reopen the question – Ulrich Neumann Mar 07 '23 at 10:48zdirection, but at the moment we just don't know what b.c.s OP needs inzdirection. – xzczd Mar 07 '23 at 11:21qdoesn't work because of a bug ofNDSolve, it's not your fault. (This might be related to the improper differentiation ofPiecewise[…]. ) – xzczd Mar 08 '23 at 12:59Piecewisefunction is approximated with finite difference formula in this case. (If you choose FEM for spatial discretization, the situ will be slightly different, but similar. ) Related: https://mathematica.stackexchange.com/q/10055/1871 – xzczd Mar 09 '23 at 05:59