Additional code for particle path movies (Session 5)

Particle path movie overlaid on contour plot

Definition

\(pathMovieWithContours[pathSoln_, {t_, tmin_, tmax_}, frames_, 
        contourPlot_] := 
      Table[
		
        Show[contourPlot, 
          Graphics[{RGBColor[1, 0, 0], PointSize[0.02], Point[pathSoln]}], 
          AspectRatio -> Automatic, 
          PlotRange -> \((MeshRange /. contourPlot[\([2]\)])\)], {t, tmin, 
          tmax, \((tmax - tmin)\)/\((frames - 1)\)}]\)

Test

Definitions from Session 5:

\(velocityEquations[streamFunction_] := {
		
        \(x'\)[t] == \((D[streamFunction, y] /. {x -> x[t], y -> y[t]})\), 

        		\(y'\)[t] == 
          \((\(-D[streamFunction, x]\) /. {x -> x[t], y -> y[t]})\)
}\)

pathSolution[
        streamFunction_, {x0_, y0_}, {t_, tmin_, tmax_}] := {x[t], y[t]} /. 
        First[NDSolve[
            Join[velocityEquations[streamFunction], {x[0] == x0, 
                y[0] == y0}], {x[t], y[t]}, {t, tmin, tmax}]]

A stream function to work on (flow past a static cylinder):

ψ1[x_, y_] := 
      v ((Sqrt[(x^2) + (y^2)]) - ((a^2)/(Sqrt[(x^2) + (y^2)]))) 
        Sin[ArcTan[x, y]]

A sample contour plot:

streamlines1 = 
      ContourPlot[
        ψ1[x, y] /. {v -> 10, a -> 0.5}, {x, -2, 2}, {y, -2, 2}, 
        PlotPoints -> 30, ContourShading -> False, 
        Epilog -> {GrayLevel[0.5], Disk[{0, 0}, 0.5]}]

A sample path and its movie:

sf1 = ψ1[x, y] /. {v -> 10, a -> 0.5}

path1 = pathSolution[sf1, {-2.0, 0.25}, {t, 0, 0.5}]

pathMovieWithContours[path1, {t, 0, 0.5}, 20, streamlines1]

Multiple paths movie (with contour plot)

Definition

\(multiplePathsMovie[paths_List, {t_, tmin_, tmax_}, frames_, 
        contourPlot_] := 
      Table[
		
        Show[contourPlot, 
          Graphics[{RGBColor[1, 0, 0], PointSize[0.02], Map[Point, paths]}], 
          AspectRatio -> Automatic, 
          PlotRange -> \((MeshRange /. contourPlot[\([2]\)])\)], {t, tmin, 
          tmax, \((tmax - tmin)\)/\((frames - 1)\)}]\)

Test

Definitions from Session 5:

\(velocityEquations[streamFunction_] := {
		
        \(x'\)[t] == \((D[streamFunction, y] /. {x -> x[t], y -> y[t]})\), 

        		\(y'\)[t] == 
          \((\(-D[streamFunction, x]\) /. {x -> x[t], y -> y[t]})\)
}\)

pathSolution[
        streamFunction_, {x0_, y0_}, {t_, tmin_, tmax_}] := {x[t], y[t]} /. 
        First[NDSolve[
            Join[velocityEquations[streamFunction], {x[0] == x0, 
                y[0] == y0}], {x[t], y[t]}, {t, tmin, tmax}]]

A stream function to work on (flow past a rotating cylinder):

ψ2[x_, y_] := 
      v ((Sqrt[(x^2) + (y^2)]) - ((a^2)/(Sqrt[(x^2) + (y^2)]))) 
          Sin[ArcTan[x, y]] + ω (a^2) Log[(Sqrt[(x^2) + (y^2)])]

A sample contour plot:

streamlines2 = 
      ContourPlot[
        ψ2[x, y] /. {v -> 10, a -> 0.5, ω -> 55}, {x, -2, 
          2}, {y, -2, 2}, PlotPoints -> 30, ContourShading -> False, 
        Contours -> 17, Epilog -> {GrayLevel[0.5], Disk[{0, 0}, 0.5]}]

Sample paths and their movie:

sf2 = ψ2[x, y] /. {v -> 10, a -> 0.5, ω -> 55}

path2 = pathSolution[sf2, {0.0, -1.0}, {t, 0, 1.0}]

path3 = pathSolution[sf2, {0.0, -1.2}, {t, 0, 1.0}]

path4 = pathSolution[sf2, {-0.2, -1.1}, {t, 0, 1.0}]

multiplePathsMovie[{path2, path3, path4}, {t, 0, 1.0}, 30, streamlines2]