\input tgrindmac
%\File{rhs.f},{14:32},{Jul  5 1993}
\L{\LB{}}
\L{\LB{      \K{subroutine} rhs(neq,v,rhsf)}}
\L{\LB{      \K{save}}}
\L{\LB{c}}
\L{\LB{c This \K{subroutine} computes the \K{function} values. Inputs are neq and }}
\L{\LB{c v, and on output the values of f are stored in the array of rhsf}}
\L{\LB{c}}
\L{\LB{      \K{include} \S{}\'parabolic.inc\'\SE{}}}
\L{\LB{}}
\L{\LB{      \K{integer} neq}}
\L{\LB{      \K{integer} i}}
\L{\LB{      \K{integer} j}}
\L{\LB{      \K{integer} k}}
\L{\LB{      \K{integer} ind}}
\L{\LB{      \K{integer} inde}}
\L{\LB{      \K{integer} indw}}
\L{\LB{      \K{integer} indn}}
\L{\LB{      \K{integer} inds}}
\L{\LB{      \K{integer} ind0}}
\L{\LB{      \K{integer} ind1}}
\L{\LB{      \K{integer} ind2}}
\L{\LB{}}
\L{\LB{      \K{double} \K{precision} v(neq)}}
\L{\LB{      \K{double} \K{precision} rhsf(neq)}}
\L{\LB{      \K{double} \K{precision} u(nv)}}
\L{\LB{      \K{double} \K{precision} diff}}
\L{\LB{      \K{double} \K{precision} diffn}}
\L{\LB{      \K{double} \K{precision} diffxn}}
\L{\LB{      \K{double} \K{precision} diffyn}}
\L{\LB{      \K{double} \K{precision} nl}}
\L{\LB{}}
\L{\LB{c      \K{write}(*,*)\S{}\'funct begin\'\SE{}}}
\L{\LB{}}
\L{\LB{c}}
\L{\LB{c     Compute F for the local dynamics, written as  F(u)= \-du\/dt + f(u)}}
\L{\LB{c     }}
\L{\LB{c}}
\L{\LB{c the system parameters}}
\L{\LB{c}}
\L{\LB{c      p1              ! \K{parameter} F}}
\L{\LB{c      p2              ! \K{parameter} k}}
\L{\LB{}}
\L{\LB{      \K{do} j = 1, ny }}
\L{\LB{         \K{do} i = 1, nx}}
\L{\LB{c}}
\L{\LB{c set up index}}
\L{\LB{c}}
\L{\LB{            ind = (i\-1)*nv + (j\-1)*meq}}
\L{\LB{c}}
\L{\LB{c Extract the jth component at current time}}
\L{\LB{c}}
\L{\LB{            nl = v(1+ind)*v(2+ind)*v(2+ind)}}
\L{\LB{}}
\L{\LB{            rhsf(1+ind) =  (\- nl + p1*(1.0d0 \- v(1+ind)))*local}}
\L{\LB{            rhsf(2+ind) =  (  nl \- (p1+p2)*v(2+ind))*local}}
\L{\LB{}}
\L{\LB{         \K{end} \K{do}}}
\L{\LB{      \K{end} \K{do}}}
\L{\LB{}}
\L{\LB{c \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-}}
\L{\LB{c}}
\L{\LB{c     add diffusion for all species (zero diffusion }}
\L{\LB{c     coefficient takes care of those that \K{do} not diffuse). }}
\L{\LB{c }}
\L{\LB{c
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
}}
\L{\LB{}}
\L{\LB{      \K{do} j = 1, ny}}
\L{\LB{         \K{do} i = 1, nx}}
\L{\LB{}}
\L{\LB{c indexing}}
\L{\LB{c}}
\L{\LB{            ind0 = (i\-1)*nv + (j\-1)*meq   ! point}}
\L{\LB{            indw = (i\-2)*nv + (j\-1)*meq   ! west point}}
\L{\LB{            inde = (i)*nv + (j\-1)*meq     ! east point}}
\L{\LB{            indn = (i\-1)*nv + (j)*meq     ! north point}}
\L{\LB{            inds = (i\-1)*nv + (j\-2)*meq   ! south point}}
\L{\LB{}}
\L{\LB{            \K{if}(i.eq.1) indw = (nx\-1)*nv + (j\-1)*meq}}
\L{\LB{            \K{if}(i.eq.nx) inde = (j\-1)*meq }}
\L{\LB{            \K{if}(j.eq.1) inds = (i\-1)*nv + (ny\-1)*meq}}
\L{\LB{            \K{if}(j.eq.ny) indn = (i\-1)*nv}}
\L{\LB{}}
\L{\LB{            \K{do} k = 1, 2}}
\L{\LB{}}
\L{\LB{c}}
\L{\LB{c First compute the contribution within a row at the current time}}
\L{\LB{c and at the preceding time. }}
\L{\LB{c}}
\L{\LB{               ind = k + ind0}}
\L{\LB{               ind1 = k + indw}}
\L{\LB{               ind2 = k + inde}}
\L{\LB{}}
\L{\LB{               diffxn = v(ind1) \- 2.0d0*v(ind) + v(ind2)}}
\L{\LB{}}
\L{\LB{c}}
\L{\LB{c Compute the contribution from the columns}}
\L{\LB{c}}
\L{\LB{               ind1 = k + indn}}
\L{\LB{               ind2 = k + inds}}
\L{\LB{}}
\L{\LB{               diffyn = v(ind1) \- 2.0d0*v(ind) + v(ind2)}}
\L{\LB{}}
\L{\LB{c}}
\L{\LB{c Multiply by  other factors and sum}}
\L{\LB{c}}
\L{\LB{               diff = d(k)*hxx*(diffxn + diffyn)*diffus}}
\L{\LB{}}
\L{\LB{               rhsf(ind) = rhsf(ind) + diff}}
\L{\LB{               }}
\L{\LB{}}
\L{\LB{            \K{end} \K{do}}}
\L{\LB{         \K{end} \K{do}}}
\L{\LB{      \K{end} \K{do}}}
\L{\LB{}}
\L{\LB{       }}
\L{\LB{      \K{return}}}
\L{\LB{      \K{end}}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}}
\vfill\eject
%\end
