%
%   UNSTEADY_FLOW1.M Plots some functions associated with an unsteady flow problem
%
%   The purpose of this file is to help one understand the difference between 
%   some parameters associated with the visualization of flow fields.
%
%   This case is very simple, since the flow field is spatially constant. However,
%   it does vary with time -- thus, this is an unsteady flow problem.  The time-
%   dependent velocity profile is defined by the components of the 2-D flow field:
%       u = 5 m/s     and     v = -2t m/s
%  
%   With this time-dependent (but spatially independent) flow field, we will compute
%   the following:
%      1. Magnitude and direction of the velocity vector versus time.
%      2. Pathline for a particle starting at the origin  --  this is the path
%         followed if a single droplet of dye released at t = 0 at the origin.
%      3. Streakline at tf  --  this is the spatial distribution at tf of a 
%         continuous stream of dye particles emitted at the origin starting at t = 0.
%
%   File prepared by J. R. White, UMass-Lowell (last update: Feb. 2017)
%
      
      clear all;   close all;   nfig = 0;
%
%   define the velocity vector field and plot magnitude and direction vs time
      Nt = 51;  tf = 5; t = linspace(0,tf,Nt);
      u = 5;  v = -2*t;
      vmag = sqrt(u.*u + v.*v);  vdir = atan(v./u)*180/pi;
%
      nfig = nfig+1;   figure(nfig)
      subplot(2,1,1),plot(t,vmag,'r-','LineWidth',2),grid
      title('Unsteady\_Flow1:   Velocity Magnitude and Direction')
      ylabel('Speed (m/s)')
      subplot(2,1,2),plot(t,vdir,'g--','LineWidth',2),grid
      xlabel('Time (sec)'),ylabel('Direction (degrees)')
%
%   plot the path of a single particle (a pathline) and the distribution of points at
%   tf = 5 sec made by a continuous stream of particles emitted at t (a streakline)
      x1 = 5*t;         y1 = -t.*t;             % defines pathline
      x2 = 5*(tf - t);  y2 = -(tf*tf - t.*t);   % defines the streakline at tf
%
      nfig = nfig+1;   figure(nfig)
      plot(x1,y1,'r-',x2,y2,'g--','LineWidth',2),grid
      title('Unsteady\_Flow1:   Pathline and Streakline at t_f = 5 sec')
      xlabel('x position (m)'),ylabel('y position (m)')
      legend('Pathline for 0 < t < t_f = 5 sec','Streakline at t_f = 5 sec')
%
%   add some more plots to help in the visualization of the PATHLINE
      nfig = nfig+1;   figure(nfig)
      plot(x1,y1,'r-','LineWidth',2),grid
      title('Unsteady\_Flow1:   Pathline for 0 < t < 5 sec')
      xlabel('x position (m)'),ylabel('y position (m)')
%
      nfig = nfig+1;   figure(nfig)
      plot(t,x1,'r-','LineWidth',2),grid
      title('Unsteady\_Flow1:   x-position vs. time of single tagged particle')
      xlabel('time (s)'),ylabel('x position (m)')
%
      nfig = nfig+1;   figure(nfig)
      plot(t,y1,'r-','LineWidth',2),grid
      title('Unsteady\_Flow1:   y-position vs. time of single tagged particle')
      xlabel('time (s)'),ylabel('y position (m)')
%
%   add some more plots to help in the visualization of the STREAKLINE
      nfig = nfig+1;   figure(nfig)
      plot(x2,y2,'r-','LineWidth',2),grid
      title('Unsteady\_Flow1:   Streakline at t_f = 5 sec')
      xlabel('x position (m)'),ylabel('y position (m)')
%
      nfig = nfig+1;   figure(nfig)
      plot(t,x2,'r-','LineWidth',2),grid
      title('Unsteady\_Flow1:   x-position at t_f of tagged particle released at time t')
      xlabel('time (s)'),ylabel('x position (m)')
%
      nfig = nfig+1;   figure(nfig)
      plot(t,y2,'r-','LineWidth',2),grid
      title('Unsteady\_Flow1:   y-position at t_f of tagged particle released at time t')
      xlabel('time (s)'),ylabel('y position (m)')
%
%   end of demo
