(*This Mathematica notebook load the FORTRAN program*) (*advection output and generate the plots and animation*) (*by Nasser Abbasi, June 13, 2006*) Remove["Global`*"] << Graphics`Graphics` << Graphics`MultipleListPlot` << Graphics`Colors` Needs["Graphics`Legend`"] SetDirectory["c:/nasser/nabbasi_Web_page/my_courses/UCI_COURSES/CREDIT_\ COURSES/spring_2006/spring_TA_MAE_185/exams/final/my_solution"] makeString[time_, rmse_] := Module[{cpu, dt, dx, mode, method}, "current time = " <> ToString[time] <> " min.\n\current RMSE = " <> ToString[rmse] ]; makeString2[rest_, maxRmse_] := Module[{cpu, dt, dx, mode, method}, cpu = rest[[1]]; dt = rest[[2]]; dx = rest[[3]]; If[rest[[4]] == 1, mode = "speed U=2 ft/min", mode = "speed U=t/20 ft/min" ]; If[rest[[5]] == 1, method = "FTCS"]; If[rest[[5]] == 2, method = "LAX"]; If[rest[[5]] == 3, method = "Implicit FTCS"]; If[rest[[5]] == 4, method = "C-N"]; Return[method <> "\n" <> "Max RMSE=" <> ToString[maxRmse] <> "\n" <> mode <> "\nCPU=" <> ToString[cpu] <> " sec.\n" <> "dt=" <> ToString[dt] <> " min.\n" <> "dx=" <> ToString[dx] <> " ft" ] ]; \$TextStyle = {FontFamily -> "Times", FontSize -> 11} process[fileName_] := Module[{}, A = Import[fileName <> ".txt", "Table"]; {nRow, nCol} = Dimensions[A]; a = Max[A[[Range[1, nRow - 1], Range[3, nCol]]]]; Print["Max.element=", a]; Print["Length[a]=", Length[a]]; If[Length[a] > 1 || a > 1000, Return[]]; b = Min[ A[[ Range[1, nRow - 1], Range[3, nCol] ]] ]; maxRmse = Max[ A[[ Range[1, nRow - 1], 2 ]] ]; p = Table[MultipleListPlot[ A[[1, Range[3, nCol] ]], A[[i, Range[3, nCol] ]], PlotRange -> {All, {b, a}} , PlotLabel -> makeString[ A[[i,1]], A[[i, 2]]], PlotJoined -> {True, True}, Frame -> False, PlotStyle -> {{Red}, {Black}}, SymbolShape -> None, AxesLabel -> {"X ft", "C(x,t)"}, DisplayFunction -> Identity, Ticks -> { Table[{x, x/10.}, {x, 0, 1000, 100} ], Automatic }, Epilog ->Text[ makeString2[ A[[ nRow, Range[1, 5] ]],maxRmse], {155, .8*a} ] ],{i, 1, nRow - 1} ]; Export[fileName <> ".gif", p, ConversionOptions ->{"AnimationDisplayTime" -> 0.5, "Loop" -> False, "GlobalColorReduction" -> True }, ImageSize -> {460, Automatic} ]; ]; makeString3[name_] := Module[{}, If[name == "exp" || name == "exp_extra", Return["Explicit FTCS"]]; If[name == "lax" || name == "lax_extra", Return["LAX solution"]]; If[name == "imp" || name == "imp_extra", Return["Implicit FTCS"]]; If[name == "cr" || name == "cr_extra", Return["Crank-Nicolson"]]; ]; makeString4[rest_] := Module[{cpu, dt, dx, mode, method}, cpu = rest[[1]]; dt = rest[[2]]; dx = rest[[3]]; If[ rest[[4]] == 1, mode = "speed U=2 ft/min, ", mode = "speed U=t/20 ft/min, " ]; mode <> "dt=" <> ToString[dt] <> " min. " <> "dx=" <> ToString[dx] <> " ft." ]; processSnaps[name_] := Module[{}, A = Import[name <> "All.txt", "Table"]; {nRow, nCol} = Dimensions[A]; a = Max[A[[Range[1, nRow - 1], Range[3, nCol]]]]; If[Length[a] > 1 || a > 1000, Return[ ListPlot[{{0, 0}, {1,1}}, PlotLabel -> makeString3[name] <> " Blows Up, Not Shown !", DisplayFunction -> Identity]] ]; e1 = Import[name <> "0.txt", "Table"]; e2 = Import[name <> "15.txt", "Table"]; e3 = Import[name <> "30.txt", "Table"]; p = MultipleListPlot[ e1[[All, All]], e2[[All, All]], e3[[All, All]], PlotRange -> {All, All} , PlotLabel -> makeString3[name], PlotJoined -> {True, True, True}, Frame -> False, PlotStyle -> {{Red}, {Black}, {Blue}}, SymbolShape -> None, AxesLabel -> {"X ft", "C(x,t)"}, DisplayFunction -> Identity ]; Return[p]; ]; processAll[case_] := Module[{}, SetDirectory[case]; A = Import["expAll.txt", "Table"]; {nRow, nCol} = Dimensions[A]; p1 = processSnaps["exp"]; p2 = processSnaps["lax"]; p3 = processSnaps["imp"]; p4 = processSnaps["cr"]; p = DisplayTogetherArray[{{p1, p2}, {p3, p4}}, PlotLabel -> "Solution at t=0,15,30 minutes.\n" <> makeString4[ A[[ nRow, Range[1, 5] ]] ] ]; Export[case <> "_SNAP.gif", p , ImageSize -> {720, Automatic} ]; A = Import["exp_extraAll.txt", "Table"]; {nRow, nCol} = Dimensions[A]; p1 = processSnaps["exp_extra"]; p2 = processSnaps["lax_extra"]; p3 = processSnaps["imp_extra"]; p4 = processSnaps["cr_extra"]; p = DisplayTogetherArray[{{p1, p2}, {p3, p4}}, PlotLabel -> "Solution at t=0,15,30 minutes.\n" <> makeString4[ A[[ nRow, Range[1, 5] ]] ] ]; Export[case <> "_SNAP_extra.gif", p , ImageSize -> {720, Automatic} ]; process["expAll"]; process["exp_extraAll"]; process["laxAll"]; process["lax_extraAll"]; process["impAll"]; process["imp_extraAll"]; process["crAll"]; process["cr_extraAll"]; SetDirectory[".."]; ]; processAll["CASE_1"]; processAll["CASE_2"]; processAll["CASE_3"]; processAll["CASE_4"]; processAll["CASE_5"]; processAll["CASE_6"]; processAll["CASE_7"]; processAll["CASE_8"]; processAll["CASE_9"]; (*processAll["CASE_10"];*)