Heat Transfer: Conduction.
Central Topic in 3.044
3.016 Pset 6			Abdullah Alsalloum

Manipulate[
Graphics[{EdgeForm[{Thick,Black}],
{Red,Opacity[0.005 (Subscript[T, 1])],Rectangle[{-2,-1},{0,1}]},
{Red,Opacity[0.005 (Subscript[T, 2])],Rectangle[{0,-1},{2,1}]},
{EdgeForm[{Thickness[0.01],Black}],Opacity[.01],Rectangle[{-2,-1},{2,1}]},
Text[Style[Row[{Style["(Subscript[T, 1])"]," = ",(Subscript[T, 1])," K"}],22,Black],{-1.1,0.7}],
Text[Style[Row[{Style["(Subscript[T, 2])"]," = ",(Subscript[T, 2])," K"}],22,Black],{1.1,0.7}],
{Darker[Red,0.6],Thickness[.03],Arrowheads[.10],If[(Subscript[T, 1])≠(Subscript[T, 2]),Arrow[{{(Δq/5) ((Subscript[T, 2])-(Subscript[T, 1]))/Abs[(Subscript[T, 2])-(Subscript[T, 1])],0},{-(Δq/5) ((Subscript[T, 2])-(Subscript[T, 1]))/Abs[(Subscript[T, 2])-(Subscript[T, 1])],0}}]]},
Text[Style[Row[{Style["(Subscript[Δq, 1])"]," = ",If[(Subscript[T, 1])-(Subscript[T, 2])==0,0,Δq ((Subscript[T, 2])-(Subscript[T, 1]))/Abs[(Subscript[T, 2])-(Subscript[T, 1])]],"J"}],22,Black],{-0.6,-0.3}],
Text[Style[Row[{Style["ΔS = ((Subscript[Δq, 1])/(Subscript[T, 1]))+((Subscript[Δq, 2])/(Subscript[T, 2])) = "],"(Subscript[Δq, 1])((1/(Subscript[T, 1]))-(1/(Subscript[T, 2]))) = ",If[(Subscript[T, 1])==(Subscript[T, 2]),0,N[Δq((Subscript[T, 2])-(Subscript[T, 1]))/Abs[(Subscript[T, 2])-(Subscript[T, 1])]((1/(Subscript[T, 1]))-(1/(Subscript[T, 2])))]]," ≥ 0"}],22,Black],{-0.1,-1.3}]},
ImageSize->Large,
PlotLabel-> "Heat Transfer between Two Reservoirs",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15}],
{{(Subscript[T, 1]),100},1,200,1},{{(Subscript[T, 2]),50},1,200,1},{{Δq,3},1,9,1}]

Manipulate[
Show[
Graphics[
{ EdgeForm[{Thick,Black}],
{{White,Rectangle[{0,0},{1,100}]}},
Text[Style[Row[{Style["(Subscript[T, 1])"]," = ",(Subscript[T, 1])," K"}],20,Black],{-0.4,(Subscript[T, 1])}],
Text[Style[Row[{Style["(Subscript[T, 2])"]," = ",(Subscript[T, 2])," K"}],20,Black],{1.4,(Subscript[T, 2])}],
Text[Style[Row[{Style["x"]," = ",0}],20,Black],{0,-4}],
Text[Style[Row[{Style["x"]," = ",L}],20,Black],{1,-4}]
},PlotRange->{{-1,2},{-20,100}},AspectRatio->1
],Plot[(((Subscript[T, 2])-(Subscript[T, 1]))/1)x+(Subscript[T, 1]),{x,0,1},Axes->{False,True},PlotStyle->Red],
PlotLabel-> "Steady State Temperature Profile (1D) ",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15}],
{{(Subscript[T, 1]),75},1,100,1},{{(Subscript[T, 2]),50},1,100,1}]

FullSimplify[Solve[(Subscript[k, A]) (((Subscript[T, 2])-(Subscript[T, 1]))/(Subscript[L, A]))==(Subscript[k, B]) (((Subscript[T, 3])-(Subscript[T, 2]))/(Subscript[L, B])),(Subscript[T, 2])]]

Manipulate[
Graphics[
{ EdgeForm[{Thick,Black}],
{White,Rectangle[{0,0},{1,100}]},
{White,Rectangle[{1,0},{2,100}]},
{Red,Thick,Line[{{0,(Subscript[T, 1])},{1,((condA (Subscript[T, 1])+condB  (Subscript[T, 3]))/(condB +condA ))}}]},
{Red,Thick,Line[{{1,((condA  (Subscript[T, 1])+condB  (Subscript[T, 3]))/(condB +condA ))},{2,(Subscript[T, 3])}}]},
Text[Style[Row[{Style["(Subscript[T, 1])"]," = ",(Subscript[T, 1])," K"}],20,Black],{-0.6,(Subscript[T, 1])}],
Text[Style[Row[{Style["(Subscript[T, 3])"]," = ",(Subscript[T, 3])," K"}],20,Black],{2.6,(Subscript[T, 3])}],
Text[Style[Row[{Style["x"]," = ",0}],20,Black],{0,-4}],
Text[Style[Row[{Style["x"]," = ",(Subscript[L, A])}],20,Black],{1,-4}],
Text[Style[StringCases[ToString[condA],{"50.2"-> "Steel","0.8"->"Glass","250"->"Aluminum","385"-> "Copper"}][[1]],22,Black],{0.5,105}],
Text[Style[StringCases[ToString[condB],{"50.2"-> "Steel","0.8"->"Glass","250"->"Aluminum","385"-> "Copper"}][[1]],22,Black],{1.5,105}]
},ImageSize-> 450,PlotRange->{{-1.2,3.2},{-30,120}},AspectRatio->0.9,
PlotLabel-> "Steady State Temperature \nProfile in Composite Walls",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15}],
{{condA,50.2,Style["(Subscript[k, A])",Bold]},{0.8->"Glass, 0.8",50.2->"Stainless Steel 50.2",250->"Aluminum, 250",385->"Copper, 385"}},
{{condB,50.2,Style["(Subscript[k, B])",Bold]},{0.8->"Glass, 0.8",50.2->"Stainless Steel 50.2",250->"Aluminum, 250",385->"Copper, 385"}},
{{(Subscript[T, 1]),80},1,100,1},{{(Subscript[T, 3]),20},1,100,1}]

tempPipeLeft[r_]= (((Subscript[T, 1])-(Subscript[T, 2]))/(Log[1/2]))Log[r]+(Subscript[T, 1])-((((Subscript[T, 1])-(Subscript[T, 2])))/(Log[1/2]))Log[1]

tempPipeRight[r_]= (((Subscript[T, 2])-(Subscript[T, 3]))/(Log[2/3]))Log[r]+(Subscript[T, 2])-((((Subscript[T, 2])-(Subscript[T, 3])))/(Log[2/3]))Log[2]

temp2Pipe=FullSimplify[Solve[condA D[tempPipeLeft[r],r]==condB D[tempPipeRight[r],r],(Subscript[T, 2])]][[1]]

tempPipeLeftMod[r_]=tempPipeLeft[r]/.temp2Pipe//Simplify

tempPipeRightMod[r_]=tempPipeRight[r]/.temp2Pipe//Simplify

Manipulate[
Grid[{{Graphics[
{ EdgeForm[{Thick,Black}],
{Lighter[Blue],Disk[{0,0},3]},
{Red,Disk[{0,0},2]},
{White,Disk[{0,0},1]},
Text[Style[Row[{Style["(Subscript[T, 1])"]," = ","\n",temp1," K"}],20,Black],{0,0}],
Text[Style[Row[{Style["(Subscript[T, 3])"]," = ","\n",temp3," K"}],20,Black],{-2.8,2.7}],
Text[Style[StringCases[ToString[conA],{"50.2"-> "Steel","0.8"->"Glass","250"->"Aluminum","385"-> "Copper"}][[1]],22,Black],{0,1.5}],
Text[Style[StringCases[ToString[conB],{"50.2"-> "Steel","0.8"->"Glass","250"->"Aluminum","385"-> "Copper"}][[1]],22,Black],{0,2.5}]
},ImageSize->250,PlotRange->{{-3.7,3.8},{-3.5,3.5}}],
Plot[(Piecewise[{{tempPipeLeftMod[r],r<2},{tempPipeRightMod[r],r>2}}]/.{condA->conA,condB->conB,(Subscript[T, 1])->temp1,(Subscript[T, 3])->temp3}),{r,1,3},PlotRange->{{1,3},{0,100}},ImageSize->300,
PlotLabel-> "Steady State Temperature \nProfile in Composite Pipes",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15},
PlotStyle->Red,
Frame-> True,
FrameLabel->{"radius","Temperature"}
]
}}]
,
{{conA,250,Style["(Subscript[k, A])",Bold]},{0.8->"Glass, 0.8",50.2->"Stainless Steel 50.2",250->"Aluminum, 250",385->"Copper, 385"}},
{{conB,50.2,Style["(Subscript[k, B])",Bold]},{0.8->"Glass, 0.8",50.2->"Stainless Steel 50.2",250->"Aluminum, 250",385->"Copper, 385"}},
{{temp1,20},1,100,1},{{temp3,80},1,100,1}]

initialCond = 2;

betaK=2*(Integrate[initialCond  Sin[ni Pi x],{x,0,1}])//Simplify

temp[x_,t_]=Sum[betaK Sin[ni Pi x] Exp[-0.001Pi^2 ni^2 t],{ni,1,100}];

Manipulate[
Plot[temp[x,t],{x,0,1},
PlotRange->{0,3},
PlotLabel-> "Temperature vs Time \n for a rod with ends at T=0",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15},
PlotStyle->Red,
Frame-> True,
FrameLabel->{"distance","Temperature"},
ImageSize->400
],
{t,0,400,1}]

pieceWiseLinear[pts_,x_]:= Piecewise[
Table[
{(((pts[[i+1,2]]-pts[[i,2]]))/((pts[[i+1,1]]-pts[[i,1]]))) (x-pts[[i,1]])+pts[[i,2]],
pts[[i,1]]<x<pts[[i+1,1]]},
{i,1,Length[pts]-1}]]

DynamicModule[{pts={{0,0},{0.2,1},{1,0}}},LocatorPane[Dynamic[pts],Dynamic[Plot[pieceWiseLinear[Sort[pts],x],{x,0,1},PlotRange->{{0,1},{0,2}},PlotLabel-> "Temperature vs Time \n in a rod with ends at T=0",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15},
PlotStyle->Red,
Frame-> True,
FrameLabel->{"distance","Temperature"},
ImageSize->400
]],LocatorAutoCreate->All]]

DynamicModule[{pts={{0,0},{0.2,1},{1,0}}},LocatorPane[Dynamic[pts],Dynamic[Plot[InterpolatingPolynomial[Sort[pts],x],{x,0,1},PlotRange->{{0,1},{0,2}},PlotLabel-> "Temperature vs Time \n in a rod with ends at T=0",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15},
PlotStyle->Red,
Frame-> True,
FrameLabel->{"distance","Temperature"},
ImageSize->400]],LocatorAutoCreate->All]]

Manipulate[
pts=points;
initialCon=If[type==1,pieceWiseLinear[Sort[pts],x],InterpolatingPolynomial[Sort[pts],x]];
Plot[initialCon,{x,0,1},PlotRange->{{0,1},{0,2}},
PlotLabel-> "Temperature vs Time \n for a rod with ends at T=0",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15},
PlotStyle->Red,
Frame-> True,
FrameLabel->{"distance","Temperature"},
ImageSize->400
],
{{points,{{1/2,1},{0,0},{1,0}}},Locator,LocatorAutoCreate->{All,{1,10}}},{{type,1},{1->"Piecewise Linear",2->" Polynomial"}}
]

betaK=2*(Integrate[initialCon  Sin[ni Pi x],{x,0,1}]);
list=Table[
Sum[betaK Sin[ni Pi x] Exp[-0.001Pi^2 (ni)^2 time],{ni,1,100}],{time,0,100,1}];

Manipulate[
Plot[Sum[betaK Sin[ni Pi x] Exp[-0.001Pi^2 (ni)^2 t],{ni,1,50}],{x,0,1},PlotRange->{{0,1},{0,2}},
PlotLabel-> "Temperature vs Time \n in a rod with ends at T=0",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15},
PlotStyle->Red,
Frame-> True,
FrameLabel->{"distance","Temperature"},
ImageSize->400
,MaxRecursion->1],
{t,0,100,1}
]

solution=NDSolve[{
 D[temp2D[x,y,t],{t,1}]==0.009 (D[temp2D[x,y,t],{x,2}]+D[temp2D[x,y,t],{y,2}]),
temp2D[x,y,0]== 0,
temp2D[x,0,t]==-10. Ceiling[ (t/100)],
temp2D[x,1,t]== -10. Ceiling[ (t/100)],
temp2D[0,y,t]==10 Ceiling[ (t/100)],
temp2D[1,y,t]==10 Ceiling[ (t/100)]
},
temp2D[x,y,t],{x,0,1},{y,0,1},{t,0,100}]

Manipulate[
ContourPlot[(temp2D[x,y,t]/.solution) /.t-> time,{x,0,1},{y,0,1},
ColorFunction->"TemperatureMap",
PlotLabel->"Temperature Profile in \nSquare Plate vs Time ",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15},
Frame-> True,
FrameTicks->False,
PlotRange->{-10,10},
FrameLabel-> {Style["T = -10",Blue,Bold,FontSize->22],Style["T = 10",Red,Bold,FontSize->22]},
PlotLegends->BarLegend[Automatic,LegendMarkerSize->150,LegendFunction->"Frame",LegendMargins->1,LegendLabel->"Temperature"],
ClippingStyle->Automatic,
Contours->5],
{{time,0,"time"},0,20,1,Appearance-> "Labeled"}]

cellul=ConstantArray[1,{5,5,2}];

cellul[[All,1,All]]=20;
cellul[[All,5,All]]=20;

cellul[[1,All,All]]=20;
cellul[[5,All,All]]=20;

cellul[[2;;4,2;;4,2]]=Table[(15*(cellul[[i+1,j,1]]+cellul[[i-1,j,1]]+cellul[[i,j+1,1]]+cellul[[i,j-1,1]])+10(cellul[[i-1,j-1,1]]+cellul[[i+1,j+1,1]]+cellul[[i-1,j+1,1]]+cellul[[i+1,j-1,1]]))/100.,{i,2,4},{j,2,4}];

Manipulate[ArrayPlot[cellul[[All,All,t]],ColorFunction->"TemperatureMap",Mesh->True],{t,1,2,1}]

tSteps=100;

tem=ConstantArray[0,{35,35,tSteps}];

tem[[All,1,All]]=ConstantArray[10,{Length[tem],tSteps}];
tem[[All,Length[tem],All]]=ConstantArray[10,{Length[tem],tSteps}];

tem[[1,All,All]]=ConstantArray[-10,{Length[tem],tSteps}];
tem[[Length[tem],All,All]]=ConstantArray[-10,{Length[tem],tSteps}];

MatrixPlot[tem[[All,All,1]],ColorFunction->"TemperatureMap",
PlotLabel->"Temperature Profile in \nSquare Plate at time = 1 ",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15},
Frame-> True,
FrameTicks->False,
PlotRange->{-10,10},
FrameLabel-> {Style["T = 10",Red,Bold,FontSize->22],Style["T = -10",Blue,Bold,FontSize->22]},
PlotLegends->BarLegend[Automatic,LegendMarkerSize->150,LegendFunction->"Frame",LegendMargins->1,LegendLabel->"Temperature"]
]

Table[
tem[[2;;Length[tem]-1,2;;Length[tem]-1,t+1]]=Table[(5*(tem[[i+1,j,t]]+tem[[i-1,j,t]]+tem[[i,j+1,t]]+tem[[i,j-1,t]])+tem[[i-1,j-1,t]]+tem[[i+1,j+1,t]]+tem[[i-1,j+1,t]]+tem[[i+1,j-1,t]])/24.,{i,2,Length[tem]-1},{j,2,Length[tem]-1}],
{t,1,tSteps-1}];

MatrixPlot[tem[[All,All,2]],ColorFunction->"TemperatureMap",
PlotLabel->"Temperature Profile in \nSquare Plate at time = 2 ",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15},
Frame-> True,
FrameTicks->False,
PlotRange->{-10,10},
FrameLabel-> {Style["T = 10",Red,Bold,FontSize->22],Style["T = -10",Blue,Bold,FontSize->22]},
PlotLegends->BarLegend[Automatic,LegendMarkerSize->150,LegendFunction->"Frame",LegendMargins->1,LegendLabel->"Temperature"]
]

Manipulate[ArrayPlot[tem[[All,All,t]],
ColorFunction->"TemperatureMap",
Mesh-> All,
PlotLabel->"Temperature Profile in \nSquare Plate vs Time ",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15},
Frame-> True,
FrameTicks->False,
PlotRange->{-10,10},
FrameLabel-> {Style["T = 10",Red,Bold,FontSize->22],Style["T = -10",Blue,Bold,FontSize->22]},
PlotLegends->BarLegend[Automatic,LegendMarkerSize->150,LegendFunction->"Frame",LegendMargins->1,LegendLabel->"Temperature"]
],{t,1,tSteps,1}]

Manipulate[GraphicsRow[{
ContourPlot[(temp2D[x,y,t]/.solution)/.t->time ,{x,0,1},{y,0,1},
ColorFunction->"TemperatureMap",
PlotLabel->"NDSolve",
PlotRange->{-10,10},
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15},
ClippingStyle->Automatic,
ImageSize->200,
Contours->7,
Frame->True,
FrameTicks->False],
ArrayPlot[tem[[All,All,5time-4]],
ColorFunction->"TemperatureMap",
Mesh-> All,
PlotLabel->"Cellular Automaton ",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15},
Frame-> True,
FrameTicks->False,
PlotRange->{-10,10},
PlotLegends->BarLegend[Automatic,LegendMarkerSize->100,LegendFunction->"Frame",LegendMargins->1,LegendLabel->"Temp"],
ImageSize->290,
AspectRatio->1
]
},ImageSize->{800,400},
Spacings->2,
AspectRatio->0.9,
PlotLabel->"Temperature Profile in \nSquare Plate vs Time ",
LabelStyle->Directive[Black,Bold],
BaseStyle-> {Bold,Large, FontSize->15}
],{{time,1,"time"},1,15,1,Appearance-> "Labeled"}]