First, let consider a minimal working example of numerical solution at some boundary conditions to use NDSolve
as a solver
g = NDSolveValue[{Derivative[1, 0][\[Gamma]][u,
v]*(6*Cot[\[Gamma][u, v]]*Derivative[0, 1][\[Gamma]][u, v]^2 -
2*Derivative[0, 2][\[Gamma]][u, v] +
3*Cos[\[Gamma][u, v]]*Derivative[1, 1][\[Gamma]][u, v]) ==
Derivative[0, 1][\[Gamma]][u,
v]*(2*(2 + Cos[2*\[Gamma][u, v]])*Csc[\[Gamma][u, v]]*
Derivative[1, 0][\[Gamma]][u, v]^2 +
3*Derivative[1, 1][\[Gamma]][u, v] -
2*Cos[\[Gamma][u, v]]*
Derivative[2, 0][\[Gamma]][u, v]), \[Gamma][0, v] ==
1 + v, \[Gamma][u, 0] == 1 + u,
Derivative[0, 1][\[Gamma]][u, 0] == 1,
Derivative[1, 0][\[Gamma]][1/2, v] == 0}, \[Gamma], {u, 0,
1/2}, {v, 0, 1/2},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"MinPoints" -> 33, "MaxPoints" -> 41, "DifferenceOrder" -> 4}}]
There are 2 messages but final solution looks good
Plot3D[g[u, v], {u, 0, 1/2}, {v, 0, 1/2}, Mesh -> None,
ColorFunction -> "Rainbow"]
Update 1. This is FDM solution, not stably but we can see how it should be if we force Mathematica FEM to solve this problem. Note, we solve Goursat problem
XYgrid[dom_List, pts_List] :=
MapThread[
N@Range[Sequence @@ #1, Abs[Subtract @@ #1]/#2] &, {dom,
pts - 1}];
BoundaryIndex[xgridlen_, ygridlen_] :=
Module[{tmp, left, right, bot, top},
tmp = Table[(n - 1) ygridlen + Range[1, ygridlen], {n, 1,
xgridlen}]; {left, right} = tmp[[{1, -1}]]; {bot, top} =
Transpose[{First[#], Last[#]} & /@ tmp]; {top, right[[2 ;; -2]],
bot, left[[2 ;; -2]]}];
FDMat[deriv_, xygrid_, difforder_] :=
Map[NDSolve`FiniteDifferenceDerivative[#, xygrid,
"DifferenceOrder" -> difforder]["DifferentiationMatrix"] &, deriv]
{tmax, domain, pts, difforder} = {10, {{0, 1/2}, {0, 1/2}}, {12, 12},
4};
xygrid = XYgrid[domain, pts]; {nx, ny} =
Map[Length, xygrid]; {top, right, bot, left} =
BoundaryIndex[nx, ny]; {dx, dy, dx2, dy2, dxy} =
FDMat[{{1, 0}, {0, 1}, {2, 0}, {0, 2}, {1, 1}}, xygrid,
difforder]; boundaries = Join[top, right, bot, left]; sgrid =
Flatten[Outer[List, Sequence @@ xygrid], 1]; g =
Table[uu[i], {i, nx ny}];
eqs = 6 Cot[g] (dy . g)^2 (dx . g) - 2 (dy2 . g) (dx . g) -
4 Csc[g] (dy . g) (dx . g)^2 -
2 Cos[2 g] Csc[g] (dy . g) (dx . g)^2 - 3 (dy . g) (dxy . g) +
3 Cos[g] (dx . g) (dxy . g) + 2 Cos[g] (dy . g) (dx2 . g);
eqs[[left]] = g[[left]] - (1 + Sqrt[sgrid[[left]][[All, 2]]]);
eqs[[bot]] =
g[[bot]] - (1 + sgrid[[bot]][[All, 1]] Sin[sgrid[[bot]][[All, 1]]]);
gini = (1 + Sqrt[#[[2]]] + #[[1]] Sin[#[[1]]]) & /@
sgrid;
sol1 = FindRoot[Table[eqs[[i]] == 0, {i, Length[eqs]}],
Table[{g[[i]], gini[[i]]}, {i, Length[g]}], MaxIterations -> 10000, Method -> {"Newton", "StepControl" -> "TrustRegion"}];
Visualization
{U1} = Map[Interpolation@Join[sgrid, Transpose@List@#, 2] &,
Partition[g /. sol1, Length[sgrid]]];
Plot3D[U1[u, v], {u, 0, 1/2}, {v, 0, 1/2}, Mesh -> None,
ColorFunction -> "Rainbow", PlotRange -> All,
AxesLabel -> {"u", "v", "\[Gamma]"}, Boxed -> False]
Update 2. This is hand made FEM solution using FEM differentiation matrices proposed by user21 (thanks to him) here
Needs["NDSolve`FEM`"]
FiniteElementDerivative[order : {__Integer}, mesh_ElementMesh] /;
1 <= Length[order] <= 3 :=
Block[{dim, nr, vd, sd, mdata, ccoef, pos, dcoef, cdata},
dim = Length[order];
nr = ToNumericalRegion[mesh];
vd = NDSolve`VariableData[{"DependentVariables", "Space"} -> {{u},
Table[Unique[X], {dim}]}];
sd = NDSolve`SolutionData[{"Space"} -> {nr}];
mdata = InitializePDEMethodData[vd, sd];
ccoef = ConstantArray[0, dim];
pos = Flatten[Position[order, 1]];
ccoef[[pos]] = 1;
dcoef = ConstantArray[0, dim];
pos = Flatten[Position[order, 2]];
dcoef[[pos]] = 1;
dcoef = DiagonalMatrix[dcoef];
(*"Pure ConvectionCoefficients" will trigger a warning*)
Quiet[cdata =
InitializePDECoefficients[vd, sd,
"DiffusionCoefficients" -> {{dcoef}},
"ConvectionCoefficients" -> {{ccoef}}], \
{InitializePDECoefficients::femcscd}];
DiscretizePDE[cdata, mdata, sd]];
First we define mesh, matrices and boundary as follows
mesh = ToElementMesh[Rectangle[{0, 0}, {1/2, 1/2}],
MaxCellMeasure -> 1/24^2]
{dx, dy, dx2, dy2, dxy} =
FiniteElementDerivative[#, mesh]["StiffnessMatrix"] & /@ {{1,
0}, {0, 1}, {2, 0}, {0, 2}, {1, 1}};
boundary = mesh["BoundaryElements"][[1, 1]] // Flatten;
coord = mesh["Coordinates"];
bc = coord[[boundary]];
left = Table[
If[coord[[boundary]][[i]][[1]] == 0, boundary[[i]], Nothing], {i,
Length[boundary]}] // DeleteDuplicates;
right = Table[
If[coord[[boundary]][[i]][[1]] == 1/2, boundary[[i]],
Nothing], {i, Length[boundary]}] // DeleteDuplicates;
bot = Table[
If[coord[[boundary]][[i]][[2]] == 0, boundary[[i]], Nothing], {i,
Length[boundary]}] // DeleteDuplicates;
top = Table[
If[coord[[boundary]][[i]][[2]] == 1/2, boundary[[i]],
Nothing], {i, Length[boundary]}] // DeleteDuplicates;
Then we use equations and boundary conditions from FDM shown above
g = Table[uu[i], {i, Length[coord]}];
eqs = 6 Cot[g] (dy . g)^2 (dx . g) - 2 (dy2 . g) (dx . g) -
4 Csc[g] (dy . g) (dx . g)^2 -
2 Cos[2 g] Csc[g] (dy . g) (dx . g)^2 - 3 (dy . g) (dxy . g) +
3 Cos[g] (dx . g) (dxy . g) + 2 Cos[g] (dy . g) (dx2 . g);
eqs[[left]] = g[[left]] - (1 + Sqrt[coord[[left]][[All, 2]]]);
eqs[[bot]] =
g[[bot]] - (1 + coord[[bot]][[All, 1]] Sin[coord[[bot]][[All, 1]]]);
gini = (1 + Sqrt[#[[2]]] + #[[1]] Sin[#[[1]]]) & /@
coord;
Finally we solve equations and plot numerical solution
sol2 = FindRoot[Table[eqs[[i]] == 0, {i, Length[eqs]}],
Table[{g[[i]], gini[[i]]}, {i, Length[g]}],
Method -> {"Newton", "StepControl" -> "TrustRegion"},
MaxIterations -> 10000];
U2 = ElementMeshInterpolation[{mesh}, g /. sol2];
Plot3D[U2[u, v], {u, 0, 1/2}, {v, 0, 1/2}, Mesh -> None,
ColorFunction -> "Rainbow", PlotRange -> All,
AxesLabel -> {"u", "v", "\[Gamma]"}, PlotTheme -> "Scientific"]
It is interesting that FDM solution looks much smoother than FEM solution. This can be explained by the fact that for FDM we use a scheme of 4 orders of accuracy, and for FEM only 2. If we use a mesh with double the number of elements, the solution becomes much smoother.
mesh = ToElementMesh[Rectangle[{0, 0}, {1/2, 1/2}],
MaxCellMeasure -> 1/34^2]
Derivative[0, 2]
andDerivative[2,0 ]
are higher-than-first-order derivatives. $\endgroup$u=0
orv=0
. With this updates we can make several steps using method of lines. $\endgroup$