U-CHAIN POST-PROCESSING

POST-PROCESSING

n = 8;
SetDirectory @ NotebookDirectory[];
inputfile = "export/simulations/"<>ToString[2n]<>"-chain.csv";
SIM = Import[inputfile,"CSV"];

SIM//Dimensions

SetOptions[Plot, BaseStyle -> {FontFamily -> "Arial", FontSize -> 16}];
SetOptions[Plot3D, BaseStyle -> {FontFamily -> "Arial", FontSize -> 14}];
SetOptions[ParametricPlot, BaseStyle -> {FontFamily -> "Arial", FontSize -> 16}];
SetOptions[ParametricPlot3D, BaseStyle -> {FontFamily -> "Arial", FontSize -> 14}];
SetOptions[ListPlot, BaseStyle -> {FontFamily -> "Arial", FontSize -> 16}];

nel = 2 n;
nvar= 6n;
nt = SIM//Dimensions//First;
(*(Partition[SIM[[1,2;;nvar+1]],4][[All,{3,1}]])*)

Manipulate[
	(Join[{{0,0}},(Partition[SIM[[t,2;;nvar+1]],3][[All,{1,2}]])] //ListPlot[#,PlotRange->{{-0.7,0.7}(*{0,1.1}*),{0,1}(*{-0.02,0.02}*)},AspectRatio->1/1.4, Joined->True, PlotStyle->{Red, Thick},ScalingFunctions->{Identity,"Reverse"}]&),
	{t,1,nt,10}
	]

Pl["Trajectories"]= Show[
	(
	ListPlot[
		Join[{{0,0}},Partition[SIM[[#,1+1;;nvar+1]],3][[All,{2,1}]]],
		Joined-> True,
		PlotStyle-> {GrayLevel[.8],Thick},
		AspectRatio-> 1.4,
		ImageSize-> 1.15{500, 500},
		Axes-> False,
		PlotRange-> {{-0.01,1.01},{-0.7,0.7}}
		]
	)&/@Range[1,nt,10],
	(
	Function[
		point,
		ListPlot[
			Re/@(SIM[[#,{point+1,point}]]&/@ Range[nt]),
			AspectRatio->1.4,
			Joined->True,
			PlotRange->{{0,1},{-0.7,0.7}}, 
			PlotStyle->{Hue[point/nvar], Thick}
			]
		] /@ Range[2,(nvar),3]
	)
] // Rotate[#,-Pi/2]&

Pl["Configurations"]= Show[
	(
	ListPlot[
		Join[{{0,0}},Partition[SIM[[#,1+1;;nvar+1]],3][[All,{2,1}]]],
		Joined-> True,
		PlotStyle-> {Hue[# (1/nt)],Thick},
		AspectRatio-> 1.4,
		ImageSize-> 1.15{500, 500},
		Axes-> False,
		PlotRange-> {{-0.01,1.01},{-0.7,0.7}}
		]
	)&/@Range[1,nt,25]
	]// Rotate[#,-Pi/2]&

ych=NDSolve[{y''[t]==1+(((y'[t])^2)/(2(1-y[t]))),y[0]==0,y'[0]==0},y,{t,0,1.5}]//Quiet;
rch=NDSolve[{r''[t]==(1/2)+(((r'[t])^2)/(2(1-r[t]))),r[0]==(1/2),r'[0]==0},r,{t,0,1.4}]//Quiet;
Pl["z"] = Show[
	Function[
		point,
		ListPlot[
			{SIM[[#,1]],Re/@(SIM[[#,point]])}& /@ Range[nt],
			AspectRatio-> 1, 
			Joined-> True,
			PlotRange-> {All,{-0.01,1.01}}, 
			PlotStyle-> {Hue[point/nvar], Thick},
			ImageSize-> 1.15{500, 500},
			Frame-> True,
			FrameLabel-> {"t","(Subscript[y, k])"},
			PlotLabel-> "Time history of (Subscript[y, k])",
			GridLines-> Automatic
			]
		] /@ Range[3, nvar+1, 3],
	Plot[(t^2)/2, {t,0,(Sqrt[2])}, PlotStyle->{Gray, Dashed, Thick}],
	Plot[y[t]/.ych, {t,0,1.19813(*(Sqrt[2])-.001*)}, PlotRange-> {0,1}, PlotStyle->{Black, Dashed, Thick}],
	Plot[r[t]/.rch, {t,0,1.19813}, PlotRange-> {0,1}, PlotStyle->{Black, Dashed, Thick}]
	]

Pl["x"] = Show[
	Function[
		point,
		ListPlot[
			{SIM[[#,1]],Re/@(SIM[[#,point]])}& /@ Range[nt],
			AspectRatio-> 1, 
			Joined-> True,
			(*PlotRange-> {All,{-.05,.05}},*)
			PlotRange-> {All,{-.3,.3}}, 
			PlotStyle-> {Hue[point/nvar], Thick},
			ImageSize-> 1.15{500, 500},
			Frame-> True,
			FrameLabel-> {"t","(Subscript[x, k])"},
			PlotLabel-> "Time history of (Subscript[x, k])",
			GridLines-> Automatic
			]
		] /@ Range[2, nvar+1,3]
	]

Pl["dz"] = Show[
	Function[
		point,
		ListPlot[
			{SIM[[#,1]],Re/@(SIM[[#,point]])}& /@ Range[nt],
			AspectRatio-> 1, 
			Joined-> True,
			PlotRange-> {All,{-3.01,6.01}}, 
			PlotStyle-> {Hue[point/nvar], Thick},
			ImageSize-> 1.15{500, 500},
			Frame-> True,
			FrameLabel-> {"t","(Subscript[(OverDot[y]), k])"},
			PlotLabel-> "Time history of (Subscript[(OverDot[y]), k])",
			GridLines-> Automatic
			]
		] /@ Range[nvar+3, 2nvar+1,3],
	Plot[t, {t,0,1.19813}, PlotStyle->{Gray, Dashed, Thick}],
	Plot[y'[t]/.ych, {t,0,1.19813}, PlotStyle->{Black, Dashed, Thick}],
	Plot[r'[t]/.rch, {t,0,1.19813}, PlotStyle->{Black, Dashed, Thick}]
	]

Pl["dx"] = Show[
	Function[
		point,
		ListPlot[
			{SIM[[#,1]],Re/@(SIM[[#,point]])}& /@ Range[nt],
			AspectRatio-> 1, 
			Joined-> True,
			PlotRange-> {All,{-2,2}},
			(*PlotRange-> {All,{-.7,.7}},*) 
			PlotStyle-> {Hue[point/nvar], Thick},
			ImageSize-> 1.15{500, 500},
			Frame-> True,
			FrameLabel-> {"t","(Subscript[(OverDot[x]), k])"},
			PlotLabel-> "Time history of (Subscript[(OverDot[x]), k])",
			GridLines-> Automatic
			]
		] /@ Range[nvar+2, 2nvar+1,3]
	]

EXPORT ZONE

folder = "export/u-chain/";

explots= Function[t, 
	(Join[{{0,0}},(Partition[SIM[[t,2;;nvar+1]],3][[All,{1,2}]])] //ListPlot[#,PlotRange->{{-0.7,0.7}(*{0,1.1}*),{0,1}(*{-0.02,0.02}*)},AspectRatio->1/1.4, Joined->True, PlotStyle->{Red, Thick},ScalingFunctions->{Identity,"Reverse"}]&)
	]/@Range[1,nt,5];
Export[folder<>"out.gif",explots]

{Export[folder<>"out-traj.pdf",#],Export[folder<>"out-traj.png",#]}&@Pl["Trajectories"]
{Export[folder<>"out-conf.pdf",#],Export[folder<>"out-conf.png",#]}&@Pl["Configurations"]
{Export[folder<>"out-x.pdf",#],Export[folder<>"out-x.png",#]}&@Pl["x"]
{Export[folder<>"out-z.pdf",#],Export[folder<>"out-z.png",#]}&@Pl["z"]
{Export[folder<>"out-dx.pdf",#],Export[folder<>"out-dx.png",#]}&@Pl["dx"]
{Export[folder<>"out-dz.pdf",#],Export[folder<>"out-dz.png",#]}&@Pl["dz"]