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[[1]]/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[[1]]/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}]

enter image description here

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.


  • $\begingroup$ 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? $\endgroup$ Jul 25, 2019 at 11:50
  • $\begingroup$ @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. $\endgroup$ Jul 25, 2019 at 12:35
  • $\begingroup$ 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. $\endgroup$ Jul 25, 2019 at 13:51
  • $\begingroup$ @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. $\endgroup$ Jul 25, 2019 at 13:59
  • $\begingroup$ 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"] $\endgroup$
    – user21
    Jul 29, 2019 at 4:46

1 Answer 1


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


Include x==1inside the boundary condition

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


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

<< NDSolve`FEM`
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" ]

enter image description here

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[[1]] }]]}; to realize the condition u[x,t==1-x/2 ]==u[x,t==x/2] still doesn't work...


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.