1
$\begingroup$

I am trying to animate the solution of a wave equation with initial condition being a gaussian wave packet travelling the the right. I know that the mathematical equation is something like $e^{\frac{-(x-a-vt)^2}{b^2}}$, where $a$ and $b$ are constants and $v$ is the velocity.

So I try to make the initial condition as $\psi(x,0)=e^{\frac{-(x-a)^2}{b^2}}$ and $\frac{\partial \psi(x,t)}{\partial t}\Bigr|_{t=0}=2v(x-a)/b^2e^{\frac{-(x-a)^2}{b^2}}$

Here is my code (where I have set $a=0.3$, $b=0.1, v=0.2)$:

ydum = x/L[t];
expr1 = 1/c^2 D[\[Psi][ydum, t], {t, 2}] - 
     D[\[Psi][ydum, t], {x, 2}] + (m^2 c^2)/
      h^2 \[Psi][ydum, t] /. \[Psi][ydum, t] -> \[Psi][y, t] /. 
   x -> y L[t] // Expand
m = 1;
c = 1;
h = 1;
\[Omega] = 1;
L[t_] := 2 + Sin[\[Omega] t];
sol = NDSolve[{expr1 == 0, 
   DirichletCondition[\[Psi][y, t] == 0, y > 1], \[Psi][1, t] == 
    0, \[Psi][0, t] == 0, \[Psi][y, 0] == Exp[-(y - 0.3)^2/0.01], 
   D[\[Psi][y, t], t] == 0.4 (y - 0.3)/0.01 Exp[-(y - 0.3)^2/0.01] /. 
    t -> 0}, \[Psi], {y, 0, 1}, {t, 0, 20}]
Manipulate[
 Plot[{Abs@Evaluate[\[Psi][y, t] /. y -> y/L[t]] /. sol, 
   100 Sign[y - L[t]]}, {y, 0, 10}, ExclusionsStyle -> Red, 
  PlotRange -> {{0, 4}, {0, 2}}], {t, 0, 20}]

enter image description here

(This is an animated gif, but not looping)

As can be seen, the wave splits into 2 parts, one going to the right and the other to the left. What I want is for the gaussian wave packet to travel to the right entirely. Can anyone give me a solution to this?

EDIT

Thanks to user21, I have figured out my mistake during the set up of the initial conditions. I should have let $v$ (the speed of the gaussian) to be equal to $c$ (the speed of the wave in the wave equation). Implementing this on Klein-Gordon Equation gives me :

kge = 1/c^2 D[\[Psi][x, t], {t, 2}] - 
   D[\[Psi][x, t], {x, 2}] + \[Psi][x, t];
c = 1;
gaussian = Exp[-(x - 0.3 - c t)^2/0.01];
ic = {\[Psi][x, 0] == gaussian /. t -> 0, 
  D[\[Psi][x, t], t] == D[gaussian, t] /. t -> 0}
sol = NDSolve[{kge == 0, 
   DirichletCondition[\[Psi][x, t] == 0, x >= 1], \[Psi][0, t] == 0, 
   ic}, \[Psi], {x, 0, 1}, {t, 0, 10}]
Manipulate[
 Plot[Evaluate[\[Psi][x, t] /. ss], {x, 0, 2}, 
  PlotRange -> {{0, 3}, {-1, 1}}], {t, 0, 10}]

enter image description here

which is exactly what I want minus the backside of the gaussian descending a little as it moves, probably due to the extra $+ \psi[x,t]$ term in the wave equation, but I am fine with this.

Going back to the original problem, in which I have changed my coordinate system $$(x,t) \to (y,t)$$ where $y=\frac{x}{L(t)}$ and $L(t)=2+sin(\omega t)$, and setting the right boundary to $\psi (1,t)=0$ (in the $(y,t)$ coordinate)

ydum = x/L[t];
expr1 = 1/c^2 D[\[Psi][ydum, t], {t, 2}] - 
         D[\[Psi][ydum, t], {x, 2}] + (m^2 c^2)/
          h^2 \[Psi][ydum, t] /. \[Psi][ydum, t] -> \[Psi][y, t] /. 
       x -> y L[t] // Expand
m = 1;
c = 1;
h = 1;
 \[Omega] = 1;
L[t_] := 2 + Sin[\[Omega] t];
gaussian = Exp[-(x - 0.3 - c t)^2/0.01];
ic = {\[Psi][y, 0] == gaussian /. x -> y L[t] /. t -> 0, 
  D[\[Psi][y, t], t] == D[gaussian /. x -> y L[t], t] /. t -> 0}
sol = NDSolve[{expr1 == 0, 
   DirichletCondition[\[Psi][y, t] == 0, y >= 1], \[Psi][0, t] == 0, 
   ic}, \[Psi], {y, 0, 1}, {t, 0, 10}]
Manipulate[
 Plot[{Abs@Evaluate[\[Psi][y, t]] /. sol}, {y , 0, 3}, 
  AxesLabel -> {y, \[Psi]}, PlotRange -> {{0, 4}, {0, 2}}], {t, 0, 
  10}]

enter image description here

The gaussian makes some wiggly lines at its base. I am very confused as to why it does that. The problem that I am solving is the same as before (at least before the wave hits the right boundary), only that the coordinate has been scaled $x \to \frac{x}{2+sin(\omega t)}$. Is there any error in my code?

$\endgroup$
5
  • $\begingroup$ There are examples of this in the documentation, see for example the Acoustics in the time domain tutorial $\endgroup$
    – user21
    Commented Feb 16, 2022 at 6:56
  • $\begingroup$ I was trying to run the code in that website to see how it works but somehow my mathematica doesn't recognize AcousticPDEComponent. What should I do? $\endgroup$ Commented Feb 16, 2022 at 15:41
  • $\begingroup$ What version do you have? Can you look at PDEModels/tutorial/Acoustics/AcousticsTimeDomain in the help system (not online)? $\endgroup$
    – user21
    Commented Feb 16, 2022 at 19:07
  • $\begingroup$ My version is 12.0 I looked this up in the help system and it's a little bit different from the website. In the help system, the code manually defines the wave equation. $\endgroup$ Commented Feb 17, 2022 at 4:26
  • $\begingroup$ Newer version have the code build in, but the code you have should work correctly. In that tutorial you will find ways to set up the wave equation and the appropriate boundary conditions. $\endgroup$
    – user21
    Commented Feb 17, 2022 at 6:28

1 Answer 1

1
$\begingroup$

Here is an example from the 13.0 ref page of AcousticPDEComponent. I have included the InputForm of the PDE that is generated, which you can use in your version.

vars = {p[t, x], t, {x}};
pars = <|"SoundSpeed" -> 343, "MassDensity" -> 1.2|>;
p0 = D[0.125 Erf[(x - 0.5)/0.15], x];
ics = {p[0, x] == p0, Derivative[1, 0][p][0, x] == -343*D[p0, x]};
eqn = AcousticPDEComponent[vars, pars] == 
   AcousticSoundHardValue[x == 1, vars, pars];
InputForm[eqn]

You'd use this:

(*eqn=Inactive[Div][{{-0.8333333333333334}} . 
    Inactive[Grad][p[t, x], {x}], {x}] + 
  7.083216460261739*^-6*Derivative[2, 0][p][t, 
    x] == NeumannValue[0, x == 1]*)

pfun = NDSolveValue[{eqn, ics}, p, {t, 0, 0.003}, 
   x \[Element] Line[{{0}, {1}}]];
Manipulate[
 Plot[pfun[t, x], {x, 0, 1}, Sequence[
  PlotRange -> {0, 2}, AxesLabel -> {"x", "P"}]], {{t, 0}, 0, 0.003, 
  10^-4}, SaveDefinitions -> True]

enter image description here

$\endgroup$
2
  • $\begingroup$ thanks! Now I have figured out that the problem was that I didn't make $v=c=1$ in my gaussian. However, when I try this in a scaled coordinate system $x \to \frac{x}{L(t)}}, the gaussian makes some wiggly lines at the base (check out the edited question above). Do you have any suggestion on that? $\endgroup$ Commented Feb 18, 2022 at 5:34
  • 1
    $\begingroup$ @ForacleFunacle, I am a freight not. I seems that your peak is decaying and the energy goes into the 'wiggles' $\endgroup$
    – user21
    Commented Feb 18, 2022 at 6:17

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.