Needs["ErrorBarPlots`"]

(* Constants fixed for the 2D square-lattice Ising model *)
Δ:=15/8
γ:=7/4
β:=1/8
ℳ0:=((((2^(5/2))ArcSinh[1]))^β)
Tc:=2/Log[1+Sqrt[2]]
B:=(Tc^2)ℳ0/(16 π)
Ch:=0.838677624411

Dmeta[y_]:=Piecewise[{{Dmetal[7][y],0<y<1.1},{Dmetai[5,1.1][y],1.1<y<2.72},{Dmetag[y],2.72<y}}]

Dmetal[n_][y_]:=Total[Dcoeff[#](y^(#))&/@(Range[n+1]-1)]

Dmetag[y_]:=(0.2161-0.136(y^(-15/8)))V[y]

Dmetai[n_,y1_][y_]:=Total[Pcoeff[#](((y-y1))^(#))&/@(Range[n+1]-1)]V[y]

MapIndexed[Set[Pcoeff[#2[[1]]-1],#1]&,{0.1532863,0.0002611,0.0499557,-0.0209331,-0.004408,0.002672}]

V[y_]:=(y^(1/8))Exp[-π (y^(15/8))/(2 1.35783834)]

Dcoeff[2]:=2/15

Dcoeff[n_]:=Φ[n]Sin[8π(2-n)/15]/;n≠2

MapIndexed[Set[Φ[#2[[1]]-1],#1]&,{−1.1977320,−0.3188192,0.1108915,0.0164252,−2.64 (10^(-4)),−5.14 (10^(-4)),2.09 (10^(-4)),-4.48 (10^(-5)),3.16 (10^(-7)),4.31 (10^(-6)),−1.99 (10^(-6))}]

MapIndexed[Set[tG[#2[[1]]],#1]&,{−1.35783835,−0.0489589,0.0388954,−0.0685060,0.18453,−0.66215,2.952,−15.69,96.76,−6.79×(10^2),5.34×((10 )^3),−4.66×(10^4),4.46×(10^5),−4.66×(10^6)}]

(* Translation between the variables of Mangazeev et al and our own *)
G2C[n_]:=(((2ArcSinh[1]))^2)(((Ch (((2ArcSinh[1]))^(-Δ))))^n)tG[n]
Φ2C[n_]:=(Ch^(2/Δ))(((-2ArcSinh[1](Ch^(-1/Δ))))^n)Φ[n]

Gmeta[X_]:=With[{y=(X^(-8/15))},Dmeta[y]/(y^2)]

Gscaled[X_]:=(((2ArcSinh[1]))^2)Gmeta[(Ch (((2ArcSinh[1]))^(-Δ)))X]

χexp=-Total@MapIndexed[#2[[1]](#2[[1]]-1)#1 (X^(#2[[1]]-2))&,G2C/@Range[14]]

Plot[Gmeta[y],{y,0,1}]

test1=Table[{y,2/π NIntegrate[(1/(((y+yp))^3))Gscaled[yp],{yp,0,∞}]},{y,0,1,0.01}];

data=Import["~/doc/research/sethna/doc/monte-carlo_doc/data/metastable_raw.dat"];

pp=Show[ErrorListPlot[Map[{{#[[2]],#[[3]]},ErrorBar[#[[4]]]}&,GatherBy[data,#[[1]]&],{2}],PlotRange->{{-0.5,0.5},{0,0.04}}],Plot[χexp,{X,-1,1},PlotStyle->{Black,Dashed}],ListPlot[{#[[1]],#[[2]]}&/@test1,Joined->True,PlotStyle->Black],AxesLabel->{"h (t^(-β δ))","⟨χ⟩_(>)(t^(γ))"},ImageSize->246,LabelStyle->{FontSize->8}]

Export["~/doc/research/sethna/doc/metastable_doc/figs/scaling_function.pdf",pp];

Show[ListPlot[test1,Joined->True,PlotRange->{{-1,1},{0,0.3}}],Plot[-1.6χexp,{X,-1,1},PlotStyle->Dashed]]

int1=Integrate[Dmetal[7][(yp^(-8/15))]/(((y+yp))^3),{yp,(1.1^(-15/8)),∞},Assumptions->{y>0}];

int2[y_]:=NIntegrate[((Dmeta[(yp^(-8/15))][[1,2,1]])/(((y+yp))^3)),{yp,(2.72^(-15/8)),(1.1^(-15/8))}];

int3=Integrate[((Dmetag[(yp^(-8/15))]/(yp^(-2 8/15)))/(((y+yp))^3)),{yp,0,(2.72^(-15/8))},Assumptions->{y>0}];

Dmeta[y][[1,3]]

int3

LogPlot[Re@int3,{y,-0.5,0.5},PlotRange->{0.00001,1}]

R

test=Integrate[((Dmeta[(yp^(-8/15))])/(y+yp)),{yp,0,∞},Assumptions->{y>0}]

d1=Import["/tmp/dl/ising-data.txt","CSV",HeaderLines->1];

p1=ListPlot[d1[[All,{1,3}]],Joined->True,PlotRange->{{0,100},{-1,1}},AspectRatio->1/GoldenRatio/2,LabelStyle->{FontSize->8},PlotStyle->Black]

d2=Import["/tmp/dl/ising-data(2).txt","CSV",HeaderLines->1];

p2=ListPlot[d2[[All,{1,3}]],Joined->True,PlotRange->{{0,100},{-1,1}},AspectRatio->1/GoldenRatio/2,LabelStyle->{FontSize->8},PlotStyle->Black]

p12=GraphicsColumn[{p1,p2},ImageSize->246]

Export["~/doc/research/sethna/doc/metastable_doc/figs/timeseries.pdf",p12];

data=ToExpression/@Import["~/doc/research/sethna/code/wolff/build/out.m","Table"][[All,1]];

a1=Thread[{2(Range[((data[[-1]][L])^2)+1]-((data[[-1]][L])^2)/2-1)/((data[[-1]][L])^2),((data[[-1]][L])^2)/2data[[-1]][S]/Total[data[[-1]][S]]}];

a2=Thread[{2(Range[((data[[-2]][L])^2)+1]-((data[[-2]][L])^2)/2-1)/((data[[-2]][L])^2),((data[[-2]][L])^2)/2data[[-2]][S]/Total[data[[-2]][S]]}];

pd1=ListLinePlot[Evaluate[MovingAverage[#,32]&/@{a1,a2}],PlotRange->All,Filling->Axis,AspectRatio->1/GoldenRatio/2,LabelStyle->{FontSize->10},PlotStyle->{Black,Gray},PlotLegends->Placed[LineLegend[{"p(M | \!H = 0)","p(M | H = 0.001)"},LegendLayout->{"Row",2}],{0.22,0.75}],ImageSize->320]

pd2=ListLinePlot[Evaluate[MovingAverage[#,32]&/@{(*{#1,2#2}&@@@a1[[(64^2)/2;;]],*)Map[x|->{x[[1]],(64^2)/2x[[2]]/Total[#[[All,2]]]},#]&@a2[[(64^2)/2;;]],Map[x|->{x[[1]],(64^2)/2x[[2]]/Total[#[[All,2]]]},#]&@({-#1,#2}&@@@(a2[[;;(64^2)/2+1]]))}],Filling->Axis,AspectRatio->1/GoldenRatio/2,LabelStyle->{FontSize->10},PlotStyle->{{Black,Dashed},{Black,Dotted}},PlotLegends->Placed[LineLegend[{"p(M | \!H = 0.001, M > 0)","p(M | H = 0.001, M < 0)"},LegendLayout->{"Row",2}],{0.32,0.7}],ImageSize->320]

Export["~/doc/research/sethna/doc/metastable_doc/figs/distributions-1.pdf",pd1];

Export["~/doc/research/sethna/doc/metastable_doc/figs/distributions-2.pdf",pd2];

Table[x,{x,0,0.005,0.00005}]

fdat=ToExpression/@Import["~/doc/research/sethna/code/wolff/build/data/out.m","Table"][[All,1]];

pmag=ListPlot[{Sort@Join[{-#[H][[1]],-2(#[M][[1]]-0.5)}&/@fdat,{#[H][[1]],2(#[M][[1]]-0.5)}&/@fdat],Sort@Join[{-#[H][[1]],-2(#[(Subscript[M, 1])][[1]]-0.5)}&/@fdat,{#[H][[1]],2(#[(Subscript[M, 0])][[1]]-0.5)}&/@fdat],Sort@Join[{-#[H][[1]],-2(#[(Subscript[M, 0])][[1]]-0.5)}&/@fdat,{#[H][[1]],2(#[(Subscript[M, 1])][[1]]-0.5)}&/@fdat],{#[H][[1]],#[aM]}&/@fdat},Joined->True,PlotRange->{{-0.004,0.004},{-1,1}},LabelStyle->{FontSize->10},PlotLegends->Placed[LineLegend[{⟨M⟩,(Subscript[⟨M⟩, "<"]),(Subscript[⟨M⟩, ">"])},LegendLayout->{"Row",1}],{0.5,1}],AxesLabel->{H,},ImageSize->320,PlotStyle->{Black,{Black,Dotted},{Black,Dashed}}]

Export["~/doc/research/sethna/doc/metastable_doc/figs/magnetization.pdf",pmag];