How to make a initial condition of a wave equation as a gaussian wave packet travelling to the right?

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}]


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


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}]


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?

• There are examples of this in the documentation, see for example the Acoustics in the time domain tutorial Feb 16, 2022 at 6:56
• 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? Feb 16, 2022 at 15:41
• What version do you have? Can you look at PDEModels/tutorial/Acoustics/AcousticsTimeDomain in the help system (not online)? Feb 16, 2022 at 19:07
• 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. Feb 17, 2022 at 4:26
• 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. Feb 17, 2022 at 6:28

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}} .

• 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? Feb 18, 2022 at 5:34