# Wave equation: Understanding PeriodicBoundaryCondition

Inspired by the interesting question 202542 I try to solve the wave equation with coupled boundary conditions

u[x,t==1 ]==u[x,t==x/2]

I tried

PeriodicBoundaryCondition[u[x, t],t == 1 && 0 < x < 1,Function[xy, xy - {0, 1- xy[]/2}]]

with x-dependent time shift

pde = D[u[x, t], {t, 2}] ==D[u[x, t], {x, 2}] + NeumannValue[0, x == 1];
bc = {u[0, t] == 0};
ic = {u[x, 0] == x^2 - 2*x};
pbc = {PeriodicBoundaryCondition[u[x, t],t == 1  && 0 < x < 1,Function[xy, xy - {0, 1 - xy[]/2}]]}

U = NDSolveValue[{ pde, ic, bc, pbc}, u, {x, 0, 1}, {t, 0, 1}]


But the solution doesn't fullfill the required u[x,t==1 ]==u[x,t==x/2]

Plot[U[x, 1] - U[x, x/2], {x, 0, 1}] Any idea what's going wrong here?

In the next step I would like to solve the boundary conditions u[x,t==1-x/2 ]==u[x,t==x/2] but NDSolve doesn't find a solution.

Thanks!

• This may just be an issue with the order of the InterpolatingFunction and how it's plotted. Have you tried using InterpolatingFunctionAnatomy to see what the actual discrete grid values of the function are? – Michael Seifert Jul 25 '19 at 11:50
• @Michael Seifert Thanks, the boundary condition seems to be fullfilled only pointwise. I believe NDSolve uses Method -> {"PDEDiscretization" -> {"FiniteElement"}} but I don't know how to force "smooth" finite elements, because the documentation concerning "PDEDiscretization" is rare. – Ulrich Neumann Jul 25 '19 at 12:35
• It appears that you can control the properties of the mesh via Method -> {"PDEDiscretization" -> {"FiniteElement", "MeshOptions" -> { (* list of options *)}}}]. This along with the tutorial here might get you somewhere. Alternately, you could try forcing "PDEDiscretization" -> "TensorProductGrid", since your domain is fairly simple (though who knows if it'll work for the antiperiodic BCs you want to do next.) I'd play around with this more if I have time over the next few days. – Michael Seifert Jul 25 '19 at 13:51
• @MichaelSeifert "TensorPoructGrid" is no alternative because NDSolve doesn't run in this case. I tried succesfully "MeshOptions"->{"MaxCellMeasure" -> .0004}. Thanks again for your effort, I'm curious about your next messages concerning antiperiodic BC. – Ulrich Neumann Jul 25 '19 at 13:59
• Note that for this to be a wave equation you'd need to specify a derivative of the initial condition. Without it this is solved as a pure spatial PDE. Look at U["ElementMesh"] – user21 Jul 29 '19 at 4:46

## 1 Answer

Trying to improve the first result in my question I found some interesting points:

First

Include x==1inside the boundary condition

pbc = {PeriodicBoundaryCondition[u[x, t],t == 1  && 0 < x <= 1,Function[xy, xy - {0, 1 - xy[]/2}]]


Second

Choose "<< NDSolveFEM" and a predefined mesh as simple as possible(triangle elements not quad!)

<< NDSolveFEM
netz = ToElementMesh[ Rectangle[{0, 0}, {1, 1}],"MeshElementType" -> TriangleElement]


=>Improved solution

U = NDSolveValue[{ pde, ic, bc, pbc}, u, Element[{x, t}, netz]];
Plot[{ U[x, 1] - U[x, x/2]}, {x, 0, 1},AxesLabel -> {t, " U[x,1]-U[x,x/2]"},PlotLabel -> "(a)periodic boundary condition" ] interim conclusion:

It's worth to use a predefined mesh
The simple triangle mesh gives "better" results than quad mesh.

Unfortunately the obvious generalization pbc = {PeriodicBoundaryCondition[u[x, t],t == 1 - x/2 && 0 < x < 1,Function[xy, xy - {0, 1 -xy[] }]]}; to realize the condition u[x,t==1-x/2 ]==u[x,t==x/2]` still doesn't work...