# Periodic extrapolation out of the domain of the solution of a PDE in two directions

As a prototypic problem

reg = Rectangle[{-1, -1}, {1, 1}];
eqn = -Laplacian[u[x, y], {x, y}] == 1;
bc = {
DirichletCondition[u[x, y] == 0, True]
};
sol = NDSolveValue[{eqn, bc}, u, {x, y} \[Element] reg, Method -> {"FiniteElement"}]


code above runs normally. But the result obtained sol as an InterpolatingFunction is only defined within reg, e.g., sol[2, 2] issues a reasonable "InterpolatingFunction::femdmval" error message. Also, the obtained InterpolatingFunction has shown some properties like "Domain: {{-1., 1.}, {-1., 1.}}", "Output: scalar" and "Order: 2", etc.. Especially, there is one "Periodic: False".

This visualizes the result

Plot3D[sol[x, y], {x, y} \[Element] reg, PlotRange -> All]


So this makes me can't help asking that is it possible to make modifications to above code to make sol a periodic function, e.g., by using PeriodicBoundaryCondition (which I have tried but I was not able to make it work)?

Were that implemented, the above hump should forms a square lattice and sol[2, 2] should have the value of sol[0, 0].

• I'm afraid the question itself is wrong, or at least the problem doesn't have a solution in classical sense. It's easy to show that you can't make $u$ and derivative of $u$ be periodic and continuous at the same time. – xzczd Jul 25 '20 at 7:39
• The wording of the title is missleading : The word "condition" let think that you mean "boundary condition of the PDE". Apparently, you simply want to extrapolate the domain of sol from [-1,1][-1,1] with a periodic extrapolation (it implies that the derivative can't be continuous at the boundaries) – andre314 Jul 25 '20 at 8:21
• @andre314 Sorry for that. If possible, please help correct the title with more appropriate terms, thank you! – Αλέξανδρος Ζεγγ Jul 25 '20 at 8:24
• Done ! - Hope there no other problem – andre314 Jul 25 '20 at 8:32

sol a periodic function, e.g.

I am not sure I understood the question, so I do not know if this is what you mean. If not, will be happy to delete it. Hard to show this in comment.

reg = Rectangle[{-1, -1}, {1, 1}];
eqn = -Laplacian[u[x, y], {x, y}] == 1;
bc = {DirichletCondition[u[x, y] == 0, True]};
sol = NDSolveValue[{eqn, bc}, u, {x, y} \[Element] reg, Method -> {"FiniteElement"}]
Plot3D[sol[x, y], {x, y} \[Element] reg, PlotRange -> All,  AxesLabel -> {"x", "y", "z"}]


To make the solution "periodic"

solPeriodic[x_, y_] := Module[{x0 = x, y0 = y},
If[x > 1, x0 = x - 2];
If[x < -1, x0 = x + 2];
If[y > 1, y0 = y - 2];
If[y < -1, y0 = y + 2];
If[Abs[x0] > 1 || Abs[y0] > 1, solPeriodic[x0, y0], sol[x0, y0]]
];


Check:

solPeriodic[2, 2]
(*0.294685*)
sol[0, 0]
(*0.294685*)

Plot3D[solPeriodic[x, y], {x, -3, 3}, {y, -3, 3},
AxesLabel -> {"x", "y", "z"}, BoxRatios -> Automatic]


Plot3D[solPeriodic[x, y], {x, -3, 3}, {y, -3, 3}, AxesLabel -> {"x", "y", "z"}]


• Yes, this is the desired result. But is it possible to implement it in the process of PED solution? – Αλέξανδρος Ζεγγ Jul 25 '20 at 8:07
• @ΑλέξανδροςΖεγγ I do not know how to do the above directly by chnaging BC in the NDSolve call itself, and not sure if it is possible now. May be someone will have an idea. – Nasser Jul 25 '20 at 8:12