I want to use ElementMeshInterpolation to generate interpolation function with periodic boundary condition.
I use below data as an example
data=Flatten[Table[{i,j,Sin[i+j]},{i,0,2\[Pi],2\[Pi]/50},{j,0,2\[Pi],2\[Pi]/50}],1];
ListContourPlot[data]
which gives
This data is periodic along x and y direction.
Using Interpolation
f = Interpolation[data, PeriodicInterpolation -> True];
{ContourPlot[f[x, y], {x, 0, 2 \[Pi]}, {y, 0, 2 \[Pi]}],
ContourPlot[f[x, y], {x, 0, 4 \[Pi]}, {y, 0, 4 \[Pi]}]}
gives
We can see the Interpolation function is fine with periodic condition as wanted.
using ElementMeshInterpolation
Though Interpolation works fine for this data set. But Interpolation has problem that it frequently run into "femimq" problem. So ElementMeshInterpolation on a refined mesh is necessary sometimes.
mesh = ToElementMesh[data[[;; , 1 ;; 2]]];
f = ElementMeshInterpolation[{mesh}, data[[;; , -1]],
PeriodicInterpolation -> {True, True}];
{ContourPlot[f[x, y], {x, 0, 2 \[Pi]}, {y, 0, 2 \[Pi]}],
ContourPlot[f[x, y], {x, 0, 4 \[Pi]}, {y, 0, 4 \[Pi]}]}
this gives
You see the generated Interpolation function has no periodicity.
using ListInterpolation
mesh can also be used in ListInterpolation
mesh = ToElementMesh[data[[;; , 1 ;; 2]]];
f = ListInterpolation[data[[;; , -1]], mesh,
PeriodicInterpolation -> {True, True}];
{ContourPlot[f[x, y], {x, 0, 2 \[Pi]}, {y, 0, 2 \[Pi]}],
ContourPlot[f[x, y], {x, 0, 4 \[Pi]}, {y, 0, 4 \[Pi]}]}
but this gives the same result as ElementMeshInterpolation.
So the question is how to correctly make periodic interpolation function using ElementMeshInterpolation.







ContourPlotof f2 is even faster than f. However,Table[Quiet@f2[x,y],{x,100.,150.,1},{y,100.,150.,1}];//AbsoluteTimingis much slower thanTable[f[x,y],{x,100.,150.,1},{y,100.,150.,1}];//AbsoluteTiming. Why is that? – matheorem Feb 04 '21 at 08:22PeriodicInterpolationdoes not support rectangular region? I actually need to interpolate on a parallelpiped region. I am thinking how to pull points outside region back by periodic condition. Do you have any good solution already exists in Mathematica? – matheorem Feb 04 '21 at 09:40ElementMeshInterpolationdoes not (can not in general) supportPeriodicInterpolation. I don't know about the timing. I would have to take a closer look. MaybeFindGeometricTansformis useful. – user21 Feb 04 '21 at 10:12ExtrapolationHandler, then "outside the range " warning message is redundent and should be removed internally, then we won't have to suppress the message which may cause performance issue – matheorem Feb 04 '21 at 13:22{AbsoluteTiming[ ContourPlot[f[x, y], {x, 0, 4 \[Pi]}, {y, 0, 4 \[Pi]}]], AbsoluteTiming[ ContourPlot[f2[x, y], {x, 0, 4 \[Pi]}, {y, 0, 4 \[Pi]}]], AbsoluteTiming[ ContourPlot[f3[x, y], {x, 0, 4 \[Pi]}, {y, 0, 4 \[Pi]}]]}I do not see any difference between f2 and f3. So the warning message may not be as expensive as I thought it was. – user21 Feb 05 '21 at 09:51