1
$\begingroup$

I have a time dependant heat diffusion equation here and I would like to plot the result of NDSolveValue.

Here is the code I am using :



ClearAll["Global`*"]
r0 = 0.5;
h = 1;

eq1 = D[u[t, r, z], 
    t] - (D[u[t, r, z], r, r] + 1/r*D[u[t, r, z], r] + 
     D[u[t, r, z], z, z]);

ic = {u[0, r, z] == 1};

bc = {u[t, r0, z] == 0, 
   u[t, 1, z] == 0, (D[u[t, r, z], r] /. r -> r0) == 
    0, (D[u[t, r, z], r] /. r -> 1) == 1, u[t, r, 0] == u[t, r, h]};


sol = NDSolveValue[{eq1 == 0, ic, bc}, 
  u[t, r, z], {t, 0, 10}, {r, r0, 1}, {z, 0, h}, 
  MaxSteps -> Infinity , MaxStepFraction -> 1/10]

Manipulate[Plot3D[sol[t, r, z], {t, 0, 10}, {r, r0, 1}], {z, 0, 1}]

So I end up with something like this : enter image description here

The thing is, I would like to have the function plot over a cylinder centered around r=0 instead of plotting the function in a box with 3 orthogonal axis like shown in these answers here or there.

Therefore i would like to ask, is it possible to have a plot over a cylinder, maybe with with a color function....Is it possible to plot things using cylindrical coordinates in mathematica ?

Thank you in advance for any answer.

$\endgroup$
8
  • 1
    $\begingroup$ you do know that the BC and initial conditions are inconsistent? $\endgroup$
    – Nasser
    Jun 29, 2020 at 2:39
  • 1
    $\begingroup$ My answer here shows a couple of ways to take a axisymmetric transient heat transfer problem and display more 3D like. $\endgroup$
    – Tim Laska
    Jun 29, 2020 at 2:50
  • $\begingroup$ @Nasser yes, tbh I do not really know how to get rid of this .... I've tried several types of conditions but to no avail... $\endgroup$ Jun 29, 2020 at 7:00
  • $\begingroup$ @TimLaska Thank you for the provided answer, I'll be sure to look into it. $\endgroup$ Jun 29, 2020 at 7:28
  • 1
    $\begingroup$ You have likely specified too many boundary conditions. Note that you have specified both Neumann (flux) and Dirichlet (value) type boundary conditions at the inner and outer radius. I am pretty sure you can't do that. You probably want to have one of the boundaries equal to 1 to be consistent with the initial condition and specify a flux on the other. $\endgroup$
    – Tim Laska
    Jun 29, 2020 at 16:14

1 Answer 1

3
$\begingroup$

We can modified boundary condition so that it consistent with initial condition. We take low temperature on inside surface of cylinder and warming outside. Then we can prepare 3D frames and animation to visualize process (to make it more visible put PlotPoints -> 100):

r0 = 0.5;
h = 1;
reg = Rectangle[{.5, 0.}, {1., 1.}]; reg3D = 
 ImplicitRegion[r0^2 <= x^2 + y^2 <= 1 && 0 <= z <= 1, {x, y, z}];
eq1 = D[u[t, r, z], 
    t] - (D[u[t, r, z], r, r] + 1/r*D[u[t, r, z], r] + 
     D[u[t, r, z], z, z]);

ic = u[0, r, z] == 1;

bc = DirichletCondition[u[t, r, z] == Exp[-5 t], r == r0]; nV = 
 NeumannValue[1, r == 1];


sol = NDSolveValue[{eq1 == nV, ic, bc}, 
   u, {t, 0, 2}, {r, z} \[Element] reg];


frames = Table[
  DensityPlot3D[
   sol[t, Sqrt[x^2 + y^2], z], {x, y, z} \[Element] reg3D, 
   ColorFunction -> "Rainbow", OpacityFunction -> None, 
   Boxed -> False, Axes -> False, PlotRange -> {0, 1.5}, 
   PlotPoints -> 50, PlotLabel -> Row[{"t = ", t}], 
   ColorFunctionScaling -> False], {t, .05, 1, .05}]
ListAnimate[frames]

Figure 1

$\endgroup$
5
  • $\begingroup$ Is it possible to get the same answer but for a 4 dimensional function like u[t,r,θ,z] instead of u[t,r,z] but by defining an intermediary function like this : int[t_, r_, z_] := sol[t, r, \[Theta], z == 0.5]; And using the function "int" as the argument for DensityPlot3D ? $\endgroup$ Jun 30, 2020 at 10:48
  • $\begingroup$ @ConfuzzledStudent Yes, it is. Use u[t, Sqrt[x^2+y^2], ArcTan[x,y], z] in this case. $\endgroup$ Jun 30, 2020 at 10:54
  • $\begingroup$ @ConfuzzledStudent Yes, in this case we should define reg=Cuboid[{.5,0.,0.},{1.,2 Pi,1.}] $\endgroup$ Jun 30, 2020 at 22:09
  • $\begingroup$ Ok, ty for your answers, I'll have some fun with the code you gave me. $\endgroup$ Jul 1, 2020 at 17:42
  • $\begingroup$ @ConfuzzledStudent You are welcome! $\endgroup$ Jul 1, 2020 at 18:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.