# Solving sine-Gordon equation with boundary condition

I need to numerically solve the sine-Gordon equation $$\partial_{x,x} u(x,t) - \partial_{t,t} u(x,t) - \sin(u(x,t)) -\alpha \partial_t u(x,t) + \gamma =0$$ for $$x\in [0,15]$$ and $$t\in [0,2]$$ with two boundary conditions $$\partial_x u(x,t)\vert_{x=0} = h, \hspace{0.5cm} \partial_x u(x,t)|_{x=15} = h + a_{ext} \sin(\omega_{ext} t).$$

My non-working Mathematica code is

al = 0.08; ga = 0.01; h = 5; aext = 3; omegaext = 1.4;
NDSolve[{D[u[x,t],x,x] - D[u[x,t],t,t] - Sin[u[x,t]] -al*D[u[x,t],t] + ga ==0,
(D[u[x, t],x]/. {x -> 0}) == h, (D[u[x, t], x] /. {x -> 15}) == h + aext Sin[omegaext t] }, u, {x,0,15},{t,0,2}]


I get an error message like this

NDSolve::fembdnl: The dependent variable in (u^(1,0))[0,t]==5 in the boundary condition DirichletCondition[(u^(1,0))[0,t]==5,x==0.] needs to be linear.


Can anyone suggest me how to fix this?

There are several issues. First there need to be sufficient initial conditions for this telegraph type equation. Also you do not specify a Dirichlet type boundary condition. I have added arbitrary (wrong) information to get you started but you'd need to fix that.

Here is a tensor product version - which you should use if you are not familiar with the finite element method given below:

al = 0.08; ga = 0.01; h = 5; aext = 3; omegaext = 1.4;
sol1 = NDSolveValue[{D[u[x, t], x, x] - D[u[x, t], t, t] -
Sin[u[x, t]] - al*D[u[x, t], t] + ga == 0,(*(D[u[x,t],
x]/. {x\[Rule]0})\[Equal]h,*)(D[u[x, t], x] /. {x -> 15}) ==
h + aext Sin[omegaext t]
(* fix these *)
, u[0, t] == 0
, u[x, 0] == 0
, Derivative[0, 1][u][x, 0] == 0
}, u, {x, 0, 15}, {t, 0, 2}]


FEM version:

al = 0.08; ga = 0.01; h = 5; aext = 3; omegaext = 1.4;
sol2 = NDSolveValue[{D[u[x, t], x, x] - D[u[x, t], t, t] -
Sin[u[x, t]] - al*D[u[x, t], t] + ga ==
NeumannValue[h + aext Sin[omegaext t], x == 15]
, u[x, 0] == 0
, Derivative[0, 1][u][x, 0] == 0
, DirichletCondition[u[x, t] == 0, x == 0]
}, u, {x, 0, 15}, {t, 0, 2}]


For this one you probably want to think about the sign in the NeumannValue

Plot3D[{sol1[x, t], sol2[x, t]}, {x, 0, 15}, {t, 0, 2},
PlotRange -> All]


Also note this coupled nonlinear Sine-Gordon example.