Reza Malek-Madani

parcl1

psi=Sin[x] Sin[y];
NumOfPoints=50;     (*Number of points on the boundary of parcels*)
radius = 0.1;      (*Radius of each initial parcel*)
(* Initial Centers of individual parcels*) 
centers={{2,1.5}, {2,1.8}, {2, 2.1}, {2, 2.4}, {2, 2.7}}; 
tfin=10;             (*Total Time*)
interval = 0.1;       (*Time between snapshots*)
diffeqn[tfinal_,a_,b_]:=NDSolve[{x'[t]==f[x[t],y[t]],
                                 y'[t]==g[x[t],y[t]],
                                 x[0]==a, y[0]==b},
                                 {x,y}, {t,0,tfinal}, MaxSteps->10000];
f[x_,y_] = D[psi,y]; g[x_, y_] = -D[psi, x];

Do[initdata[i]=N[Table[{centers[[i,1]]+radius*Cos[w], 
                        centers[[i,2]]+radius*Sin[w]}, 
        {w, 0, 2*Pi, 2*Pi/NumOfPoints}]];
     oldsolution[i]=Table[diffeqn[tfin,initdata[i][[j,1]],
                           initdata[i][[j,2]]], {j, Length[initdata[i]]}];
     data[i]=Table[{x[t], y[t]} /. oldsolution[i], {t, 0, tfin, interval}];
     ColoredSnapshots[i]=Table[Graphics[{RGBColor[1-0.1*i, 0.1*i, 0],
     Map[Polygon, Flatten[data[i][[j]],1], {0}]}],  {j, Length[data[i]]}],
{i,Length[centers]}];
graph1=ContourPlot[psi, {x, 0, Pi}, {y, 0, Pi}, PlotPoints->50, Contours->20];
Do[
    giffile[i]=Show[graph1,Table[ColoredSnapshots[k][[i]],
    {k,Length[centers]}],
    PlotRange->{{0,Pi}, {0, Pi}},
    AspectRatio->Automatic],
{i, Length[ColoredSnapshots[1]]}];
graph=Table[giffile[i], {i, Length[ColoredSnapshots[1]]}];
Export["normalmode1a.gif",graph,"GIF",ImageSize->{400,400}]
go to Top