# How to calculate L2 error between numerical and analytical solution of the PDE?

ClearAll[postProcess]
postProcess = # /.
Line -> Function[{x},
Line /@ Split[x, First[#] != First[#2] &]] &;

<< AceGen; << AceFEM; << MaTeX
name = StringDrop[NotebookFileName[] // FileNameSplit // Last, -3];
plots = {};
h = 1/2;
L = 12000;
name, {"\[Omega] *" -> 0.5, "ff*" -> 0}}];
SMTMesh["\[CapitalOmega]", "L1", {1/h}, {{0, 0}, {L, 0}}];
SMTAddEssentialBoundary["ID" == "AM" && "X" == 0 &, 1 -> 1];
SMTAnalysis[];

tolNR = 10^-8; maxNR = 15; tmax = 9600; \[CapitalDelta]t = 96;
Do[
SMTNextStep["t" -> t, "\[Lambda]" -> 1];
While[step = SMTConvergence[tolNR, maxNR, "Analyze"],
SMTNewtonIteration[];];
If[step =!= False, SMTStatusReport["Analyze"]; Abort[];];
, {t, \[CapitalDelta]t, tmax, \[CapitalDelta]t}]

coor = SMTNodeData["X"][[1/h + 2 ;;]];
\[Phi]value = SMTNodeData["at"][[1/h + 2 ;;]];
plot = Table[{coor[[i, 1]], \[Phi]value[[i, 1]]}, {i, 1,
Length[\[Phi]value]}];
solPlot = ListLinePlot[
plot
, Joined -> True
, BaseStyle -> Directive[20, FontFamily -> "Latin Modern Roman"]
, PlotLegends -> Placed[{"DGFEM"}, {Right, Center}]
, LabelStyle -> Directive[20, FontFamily -> "Latin Modern Roman"]
];
postProcess@solPlot


f = HeavisideTheta[9600 - 2 x]; plot = Table[HeavisideTheta[9600 - 2 x], {x, 0, 12000, 1}]; analyticPlot = ListLinePlot[ plot, PlotRange -> Full, PlotStyle -> Red, PlotLegends -> Placed[{"analytic"}, {Right, Center}], LabelStyle -> Directive[20, FontFamily -> "Latin Modern Roman"]]

finalPlot = Show[{postProcess@solPlot, analyticPlot}
, PlotRange -> {{0, 12000}, {0, 1}}
, ImageSize -> 500
, Epilog -> {{Dashed, Red, Thick, Line[{{9600/2, 0}, {9600/2, 1}}]}}
, AxesStyle ->
Directive[Black, 20, FontFamily -> "Latin Modern Roman"],
BaseStyle -> Directive[20, FontFamily -> "Latin Modern Roman"],
LabelStyle -> Directive[20, FontFamily -> "Latin Modern Roman"],
AxesLabel -> {MaTeX["x", Magnification -> 2],
MaTeX["u", Magnification -> 2]}
]


Error L2 norm need to be calculated. For that numerical solution gives range of x coordinate where every second coordinate is repeating. Similarly I tried for analytic solution. But did not work. Any idea to get analytic solution in the same format like numerical one. So that I can calculate L2 error norm? Or other idea to calculate L2 error norm would be helpful.

Numerical solution looks like:
{{{0., 1.}}, {{0., 1.}, {600., 1.}}, {{600., 1.00001}, {1200.,
0.999986}}, {{1200., 0.999943}, {1800., 0.999876}}, {{1800.,
0.999174}, {2400., 1.00122}}, {{2400., 1.00153}, {3000.,
1.00865}}, {{3000., 1.02244}, {3600., 0.994692}}, {{3600.,
1.02808}, {4200., 0.849194}}, {{4200., 0.867632}, {4800.,
0.510722}}, {{4800., 0.485771}, {5400., 0.155473}}, {{5400.,
0.121336}, {6000., -0.00725738}}, {{6000., -0.0168461}, {6600., \
-0.0141537}}, {{6600., -0.0111894}, {7200., 0.000830749}}, {{7200.,
0.00172592}, {7800., 0.000983074}}, {{7800.,
0.000605767}, {8400., -0.00021974}}, {{8400., -0.000221323}, \
{9000., -0.0000192766}}, {{9000., 9.08045*10^-6}, {9600.,
0.0000185108}}, {{9600.,
0.0000110854}, {10200., -3.85447*10^-6}}, {{10200., \
-3.52462*10^-6}, {10800., 6.91615*10^-8}}, {{10800.,
4.15887*10^-7}, {11400., 1.87128*10^-7}}, {{11400.,
5.74127*10^-8}, {12000., -6.2709*10^-8}}}
`