To verifier solution computed with Galerkin method we can use the Euler wavelets collocation method from my answer here. We add boundary conditions at y==0
and y==1
in a form of homogenous Neumann condition or in a form of pde
. First version
UE[m_, t_] := EulerE[m, t];
psi[k_, n_, m_, t_] :=
Piecewise[{{2^(k/2) UE[m, 2^k t - 2 n + 1], (n - 1)/2^(k - 1) <= t <
n/2^(k - 1)}, {0, True}}];
PsiE[k_, M_, t_] :=
Flatten[Table[psi[k, n, m, t], {n, 1, 2^(k - 1)}, {m, 0, M - 1}]]
k0 = 3; M0 = 4; With[{k = k0, M = M0},
nn = Length[Flatten[Table[1, {n, 1, 2^(k - 1)}, {m, 0, M - 1}]]]];
dx = 1/(nn); xl = Table[l*dx, {l, 0, nn}]; zcol =
xcol = Table[(xl[[l - 1]] + xl[[l]])/2, {l, 2, nn + 1}]; Psijk =
With[{k = k0, M = M0}, PsiE[k, M, t1]]; Int1 =
With[{k = k0, M = M0}, Integrate[PsiE[k, M, t1], t1]];
Int2 = Integrate[Int1, t1];
Psi[y_] := Psijk /. t1 -> y; int1[y_] := Int1 /. t1 -> y;
int2[y_] := Int2 /. t1 -> y;
M = nn;
U1 = Array[a, {M, M}]; U2 = Array[b, {M, M}]; G1 =
Array[g1, {M}]; G2 = Array[g2, {M}]; G3 = Array[g3, {M}]; G4 =
Array[g4, {M}];
u1[x_, z_] := int2[x] . U1 . Psi[z] + x G1 . Psi[z] + G4 . Psi[z];
u2[x_, z_] := Psi[x] . U2 . int2[z] + z G2 . Psi[x] + G3 . Psi[x];
uz[x_, z_] := Psi[x] . U2 . int1[z] + G2 . Psi[x];
ux[x_, z_] := int1[x] . U1 . Psi[z] + G1 . Psi[z];
uxx[x_, z_] := Psi[x] . U1 . Psi[z];
uzz[x_, z_] := Psi[x] . U2 . Psi[z];
(*Equations and solution*)
eqn = Join[
Flatten[Table[(uxx[xcol[[i]], zcol[[j]]] -
zcol[[j]]^2 u1[xcol[[i]], zcol[[j]]]), {i, M}, {j, M}]],
Flatten[Table[
u1[xcol[[i]], zcol[[j]]] - u2[xcol[[i]], zcol[[j]]], {i, M}, {j,
M}]]]; bc =
Join[Flatten[Table[ux[1, zcol[[j]]] - 1 == 0, {j, M}]],
Flatten[Table[u1[1, zcol[[j]]] - 1 == 0, {j, 1, M}]],
Flatten[Table[uz[xcol[[j]], 0] == 0, {j, M}]],
Flatten[Table[uz[xcol[[j]], 1] == 0, {j, M}]]]; var =
Join[Flatten[U1], Flatten[U2], G1, G2, G3, G4];
eq = Join[Table[eqn[[i]] == 0, {i, Length[eqn]}],
bc];
{v, m} = CoefficientArrays[eq, var];
sol1 = LinearSolve[m // N, -v];
(*Visualization*)
rul = Table[var[[i]] -> sol1[[i]], {i, Length[var]}];
Plot3D[Evaluate[u1[x, y] /. rul], {x, 0, 1}, {y, 0, 1},
PlotLegends -> Automatic, ColorFunction -> "SunsetColors",
PlotRange -> All, Exclusions -> None]
Plot3D[Evaluate[u2[x, y] /. rul], {x, 0, 1}, {y, 0, 1},
PlotLegends -> Automatic, ColorFunction -> "SunsetColors",
PlotRange -> All, Exclusions -> None, PlotTheme -> "Marketing",
MeshStyle -> White]
In second version we use pde
as follows
eq0 = Join[Table[uxx[xcol[[i]], 0] == 0, {i, M}],
Table[uxx[xcol[[i]], 1] - u1[xcol[[i]], 1] == 0, {i, M}]];
eq1 = eq =
Join[Table[eqn[[i]] == 0, {i, Length[eqn]}], Take[bc, 2 M],
eq0]; sol2 = CoefficientArrays[eq1, var]
sol = LeastSquares[sol2[[2]] // N, -sol2[[1]]]
Solution sol
is not differ from shown above sol1
, which is already obvious.
Update 1. We can compare solution u1[x,y]/.rul
and u1[x,y]/.rul1
with
sol3 = NDSolveValue[{Derivative[2, 0][f][x, y] ==
y^2*f[x, y], {f[1, y] == 1, Derivative[1, 0][f][1, y] == 1}},
f, {x, 0, 1}, {y, 0, 1}]
We have
{Plot[Table[Abs[sol3[x, y] - u1[x, y] /. rul1], {x, 0, 1, .1}] //
Evaluate, {y, 0, 1}, FrameLabel -> {"y", "\[Delta]f"},
PlotLegends -> Automatic, Frame -> True,
PlotLabel -> "Absolute error for `pde` at y=0,1"],
Plot[Table[Abs[sol3[x, y] - u1[x, y] /. rul], {x, 0, 1, .1}] //
Evaluate, {y, 0, 1}, FrameLabel -> {"y", "\[Delta]f"},
PlotLegends -> Automatic, Frame -> True,
PlotLabel -> "Absolute error for NeumannValue[0,y==0||y==1]"]}
DiscretizePDE
functionality to make code run faster... $\endgroup$