0
$\begingroup$

I am now dealing with the 1D PDE with periodic boundary condition given by the following:

$$ \partial_{t}u(t,x) = \partial_{x}u(t,x). \quad \text{with}\quad u(0,x)=\frac{1}{\sqrt{2\pi}}e^{-(x-\pi/4)^2/2}\quad u(t,-\pi)=u(t,\pi) $$

ufun = NDSolveValue[{\!\(
\*SubscriptBox[\(\[PartialD]\), \(t\)]\(u[t, \[Theta]]\)\) + \!\(
\*SubscriptBox[\(\[PartialD]\), \(\[Theta]\)]\(u[t, \[Theta]]\)\) == 
 0, u[0, \[Theta]] == Exp[-(\[Theta] - \[Pi]/4)^2], 
u[t, -\[Pi]] == u[t, \[Pi]]}, 
u, {t, 0, 0.1, 20}, {\[Theta], -\[Pi], \[Pi]}, 
Method -> {"MethodOfLines", 
 "SpatialDiscretization" -> {"TensorProductGrid", 
   "MinPoints" -> 200}}, PrecisionGoal -> 1];

plots = Table[Plot[ufun[t, \[Theta]], {\[Theta], -\[Pi], \[Pi]},PlotRange -> {0, 1}, ColorFunction -> "LakeColors"], {t, 0, 
20, .1}];
ListAnimate[plots]

Although there is no error, the solution is not expected.

enter image description here

I have tried the solution here 2D Heat equation: inconsistent boundary and initial conditions.

 Method -> {"MethodOfLines", 
           "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 20}}

It seems doesn't work. Any suggestion?

$\endgroup$
  • $\begingroup$ How about using "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 200, "MaxPoints" -> 200}? That fixed it for me. Also, is PrecisionGoal -> 1 necessary? $\endgroup$ – Chris K Aug 15 '18 at 17:20
  • $\begingroup$ @ChrisK It works! But I still didn't get it how does the these mesh affect the stability and why mathematica does not do these automatically? $\endgroup$ – Bob Lin Aug 15 '18 at 17:47
  • $\begingroup$ I can't say for sure, but when I run your code it gives a warning Using maximum number of grid points 10000. Such a fine mesh size may mean that time steps need to be quite small to satisfy the Courant condition. I suppose numerically solving PDEs is a hard problem for Mathematica to make the right decisions on, so sometimes the user has to make the appropriate choice of numerical parameters. $\endgroup$ – Chris K Aug 15 '18 at 17:58
  • 1
    $\begingroup$ BTW, welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Chris K Aug 15 '18 at 17:59
  • $\begingroup$ Thanks for answering! I am wondering if there is a way to adaptively adjust the mesh to save memory and time (in 2D problem). $\endgroup$ – Bob Lin Aug 15 '18 at 18:04
1
$\begingroup$

As I commented above, without setting "MaxPoints", NDSolve uses 10000 grid points, which makes it hard to solve, maybe due to the Courant condition. Adding "MaxPoints"->200 fixes it. I also removed PrecisionGoal->1 and changed the t range specification in NDSolve.

ufun = NDSolveValue[{
  D[u[t, θ] , t] + D[u[t, θ], θ] == 0, 
  u[0, θ] == Exp[-(θ - π/4)^2], 
  u[t, -π] == u[t, π]}, 
  u, {t, 0, 20}, {θ, -π, π}, 
  Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", 
    "MinPoints" -> 200, "MaxPoints" -> 200}}];
Plot[ufun[20, θ], {θ, -π, π}, ColorFunction -> "LakeColors"]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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