28.01.2013 Views

Transport: Non-diffusive, flux conservative initial value problems and ...

Transport: Non-diffusive, flux conservative initial value problems and ...

Transport: Non-diffusive, flux conservative initial value problems and ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Transport</strong> equations 73<br />

An example of this algorithm in Matlab using a mid-point scheme with first<br />

order interpolation for velocity <strong>and</strong> cubic interpolation for the <strong>value</strong>s can be written<br />

it=1; % iteration counter (toggles between 1 <strong>and</strong> 2)<br />

nit=2; % next iteration counter (toggles between 2 <strong>and</strong> 1)<br />

for n=1:nstep<br />

t=dt*n; % set the time<br />

vm=.5*(v(:,it)+v(:,nit)); % find mean velocity at mid time<br />

vi=v(:,nit); % set <strong>initial</strong> velocity to the future velocity on the grid points<br />

for k=1:kit<br />

xp=x-.5*dt*vi; % get new points<br />

xp=makeperiodic(xp,xmin,xmax); % patch up boundary conditions<br />

vi=interp1(x,vm,xp,’linear’); % find centered velocities at mid-time<br />

end<br />

xp=x-dt*vi; % get points at minus a whole step;<br />

xp=makeperiodic(xp,xmin,xmax); % patch up boundary conditions<br />

c(:,nit)=interp1(x,c(:,it),xp,’cubic’); % use cubic interpolation to get the new point<br />

end<br />

The function makeperiodic implements the periodic boundary conditions<br />

by simply mapping points that extend beyond the domain xmin ≤ x ≤ xmax back<br />

into the domain. Other boundary conditions are easily implemented in 1-D.<br />

These matlab routines demonstrate the algorithm rather cleanly, <strong>and</strong> make considerable<br />

use of the object oriented nature of Matlab. Unfortunately, Matlab is<br />

nowhere near as efficient in performance as a compiled language such as fortran.<br />

Moreover, if there are many fields that require interpolation, it is often more sensible<br />

to calculate the weights separately <strong>and</strong> update the function point-by-point. The<br />

following routines implement the same problem but in f77.<br />

The following subroutines implement this scheme for a problem where the<br />

velocities are constant in time. This algorithm uses linear interpolation for the velocities<br />

at the half times <strong>and</strong> cubic polynomial interpolation for the concentration<br />

at time step n. This version does cheat a little in that it only calculates the interpolating<br />

coefficients once during the run in subroutine calcintrp. But this is a<br />

smart thing to do if the velocities do not change with time. The results are shown<br />

in Fig. 5.8d for constant velocity. For any integer <strong>value</strong> of the courant condition,<br />

this scheme is a perfect scroller. Fig. 5.8d has a courant number of 2, thus every<br />

time step shifts the solution around the grid by 2 grid points.<br />

c***********************************************************************<br />

c upsemlag1: 1-D semi-lagrangian updating scheme for updating an<br />

c array without a source term. Uses cubic interpolation for the <strong>initial</strong><br />

c <strong>value</strong> at time -\Delta t Assumes that all the interpolation<br />

c weightings have been precomputed using calcintrp1d01 (which<br />

c calls getweights1d01 in semlagsubs1d.f)<br />

c arguments are<br />

c arn(ni): real array for new <strong>value</strong>s<br />

c aro(ni): real array of old <strong>value</strong>s<br />

c ni: full array dimensions<br />

c wta : array of nterpolation weights for bicubic interpolation at<br />

c the n-1 step, precalculated in calcintrp1d01<br />

c ina : array of coordinates for interpolating 4 points at the n-1<br />

c step precalculated in calcintrp1d01<br />

c is,ie: bounds of domain for updating<br />

c***********************************************************************<br />

subroutine upsemlag1(arn,aro,wta,ina,ni,is,ie)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!