c***********************  problem name: ob      ************************
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine a1xy(x,y,u,ux,uy,rl,itag,values)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            real(kind=rknd), dimension(*) :: values
            common /val0/k0,ku,kx,ky,kl
cy
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine a2xy(x,y,u,ux,uy,rl,itag,values)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            real(kind=rknd), dimension(*) :: values
            common /val0/k0,ku,kx,ky,kl
cy
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine fxy(x,y,u,ux,uy,rl,itag,values)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            real(kind=rknd), dimension(*) :: values
            common /val0/k0,ku,kx,ky,kl
cy
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine gnxy(x,y,u,rl,itag,values)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            real(kind=rknd), dimension(*) :: values
            common /val1/k0,ku,kl
cy
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine gdxy(x,y,rl,itag,values)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            real(kind=rknd), dimension(*) :: values
            common /val2/k0,kl,klb,kub,kic,kim,kil
cy
        call lbxy(x,y,rl,itag,values(klb))
        call ubxy(x,y,rl,itag,values(kub))
        values(kic)=(values(klb)+values(kub))/2.0e0_rknd
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine p1xy(x,y,u,ux,uy,rl,itag,values)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            real(kind=rknd), dimension(*) :: values
            character(len=80) :: su
            common /val0/k0,ku,kx,ky,kl
            common /atest2/ig,ix,iy,ixl,iyl,ixu,iyu,iu(93),
     +          ax,ay,cu,bdlw,bdup,cflw,cfup,ru(93),su(100)
cy
        call uexact(x,y,itag,r,rx,ry,rxx,ryy,rxy)
        s=-ax*rxx-ay*ryy+cu*r
        values(k0)=(ax*ux**2+ay*uy**2+cu*u**2)/2.0e0_rknd-s*u
        values(kx)=ax*ux
        values(ky)=ay*uy
        values(ku)=cu*u-s
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine p2xy(x,y,dx,dy,u,ux,uy,rl,itag,jtag,values)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            real(kind=rknd), dimension(*) :: values
            common /val0/k0,ku,kx,ky,kl
cy
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine qxy(x,y,u,ux,uy,rl,itag,values)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            real(kind=rknd), dimension(*) :: values
            character(len=80) :: su
            common /atest2/ig,ix,iy,ixl,iyl,ixu,iyu,iu(93),
     +          ax,ay,cu,bdlw,bdup,cflw,cfup,ru(93),su(100)
            common /val3/kf,kf1,kf2,kad
cy
        if(ig==0) then
            call lbxy(x,y,rl,itag,values(kf))
        else
            call ubxy(x,y,rl,itag,values(kf))
        endif
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine sxy(rl,s,itag,values)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            real(kind=rknd), dimension(2,*) :: values
            common /val4/j0,js,jl
cy
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine lbxy(x,y,rl,itag,value)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            character(len=80) :: su
            common /atest2/ig,ix,iy,ixl,iyl,ixu,iyu,iu(93),
     +          ax,ay,cu,bdlw,bdup,cflw,cfup,ru(93),su(100)
cy
        pi=3.141592653589793e0_rknd
        axl=pi*real(ixl,rknd)*x
        ayl=pi*real(iyl,rknd)*y
        value=bdlw+cflw*sin(axl)*sin(ayl)
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine ubxy(x,y,rl,itag,value)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            character(len=80) :: su
            common /atest2/ig,ix,iy,ixl,iyl,ixu,iyu,iu(93),
     +          ax,ay,cu,bdlw,bdup,cflw,cfup,ru(93),su(100)
cy
        pi=3.141592653589793e0_rknd
        axu=pi*real(ixu,rknd)*x
        ayu=pi*real(iyu,rknd)*y
        value=bdup+cfup*sin(axu)*sin(ayu)
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine uexact(x,y,itag,u,ux,uy,uxx,uyy,uxy)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            character(len=80) :: su
            common /atest2/ig,ix,iy,ixl,iyl,ixu,iyu,iu(93),
     +          ax,ay,cu,bdlw,bdup,cflw,cfup,ru(93),su(100)
cy
        pi=3.141592653589793e0_rknd
        px=pi*real(ix,rknd)
        py=pi*real(iy,rknd)
        sx=sin(px*x)
        sy=sin(py*y)
        cx=cos(px*x)
        cy=cos(py*y)
        u=sx*sy
        ux=px*cx*sy
        uy=py*sx*cy
        uxx=-px**2*u
        uxy=px*py*cx*cy
        uyy=-py**2*u
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine usrcmd(vx,vy,sf,itnode,ibndry,ip,rp,sp,iu,ru,su)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            integer(kind=iknd), dimension(5,*) :: itnode
            integer(kind=iknd), dimension(7,*) :: ibndry
            integer(kind=iknd), dimension(100) :: ip,iu
            real(kind=rknd), dimension(*) :: vx,vy
            real(kind=rknd), dimension(2,*) :: sf
            real(kind=rknd), dimension(100) :: rp,ru
            character(len=80), dimension(100) :: sp,su
cy
c       enter input mode
c
        call usrset(iu,ru,su)
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine usrfil(file,len)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            integer(kind=iknd), save :: len0
            character(len=80), save, dimension(100) :: file0
            character(len=80), dimension(*) :: file
cy
            data (file0(i),i=  1, 10)/
     +  'n i= 1,n=ig,    a=ig,t=i',
     1  'n i= 2,n=ix,    a=ix,t=i',
     2  'n i= 3,n=iy,    a=iy,t=i',
     3  'n i= 4,n=ixl,   a=xl,t=i',
     4  'n i= 5,n=iyl,   a=yl,t=i',
     5  'n i= 6,n=ixu,   a=xu,t=i',
     6  'n i= 7,n=iyu,   a=yu,t=i',
     7  'n i= 1,n=ax,    a=ax,t=r',
     8  'n i= 2,n=ay,    a=ay,t=r',
     9  'n i= 3,n=cu,    a=cu,t=r'/
            data (file0(i),i= 11, 16)/
     +  'n i= 4,n=bdlw,  a=bl,t=r',
     1  'n i= 5,n=bdup,  a=bu,t=r',
     2  'n i= 6,n=cflw,  a=cl,t=r',
     3  'n i= 7,n=cfup,  a=cu,t=r',
     4  's n=ig    ,v=0,l="lower bound"',
     5  's n=ig    ,v=1,l="upper bound"'/
c
            data len0/16/
c
        len=len0
        do i=1,len
            file(i)=file0(i)
        enddo
        return
        end
c-----------------------------------------------------------------------
c
c            piecewise lagrange triangle multi grid package
c
c                  edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
        subroutine gdata(vx,vy,sf,itnode,ibndry,ip,rp,sp,iu,ru,su,sxy)
cx
            use mthdef
            implicit real(kind=rknd) (a-h,o-z)
            implicit integer(kind=iknd) (i-n)
            integer(kind=iknd), dimension(5,*) :: itnode
            integer(kind=iknd), dimension(7,*) :: ibndry
            integer(kind=iknd), dimension(100) :: ip,iu
            integer(kind=iknd), save, dimension(9) :: ix,iy
            integer(kind=iknd), save :: ntf,nvf,nbf,ispd,iprob
            integer(kind=iknd), save :: iadapt,irefn,ifirst
            real(kind=rknd), dimension(*) :: vx,vy
            real(kind=rknd), dimension(2,*) :: sf
            real(kind=rknd), dimension(100) :: rp,ru
            character(len=80), dimension(100) :: sp,su
cy
            external sxy
            data ix/0,0,1,2,2,2,1,0,1/
            data iy/1,2,2,2,1,0,0,0,1/
            data ntf,nvf,nbf,ispd/8,9,8,1/
            data iprob,iadapt,irefn,ifirst/2,4,2,1/
c
c           common /atest2/ig,ix,iy,ixl,iyl,ixu,iyu,iu(93),
c    +          ax,ay,cu,bdlw,bdup,cflw,cfup,ru(93),su(100)
c
        if(ip(41)==1) then
            sp(1)='obstacle'
            sp(2)='obstacle'
            sp(3)='obstacle'
            sp(4)='obstacle'
            sp(5)='ob_figxxx.ext'
            sp(6)='ob_mpixxx.rw'
            sp(7)='ob.jnl'
            sp(9)='ob_mpixxx.out'
c
            ru(1)=1.0e0_rknd
            ru(2)=1.0e0_rknd
            ru(3)=0.0e0_rknd
            ru(4)=-0.25e0_rknd
            ru(5)=0.25e0_rknd
            ru(6)=0.1e0_rknd
            ru(7)=-0.1e0_rknd
            iu(1)=0
            iu(2)=3
            iu(3)=3
            iu(4)=1
            iu(5)=1
            iu(6)=1
            iu(7)=1
        endif
c
        rp(3)=1.0e-1_rknd
        ip(20)=iadapt
        ip(21)=irefn
        ip(1)=ntf
        ip(2)=nvf
        ip(3)=nbf
        ip(5)=max(ip(5),ifirst)
        ip(6)=iprob
        ip(8)=ispd
        do i=1,ntf
            itnode(1,i)=9
            itnode(2,i)=i
            itnode(3,i)=i-1
            itnode(4,i)=0
            itnode(5,i)=i
ccc         if(i>4) itnode(5,i)=1
            ibndry(1,i)=i
            ibndry(2,i)=i-1
            ibndry(3,i)=0
            k=(i+1)/2
            ibndry(4,i)=2
            ibndry(5,i)=0
            ibndry(6,i)=0
            ibndry(7,i)=(i+1)/2
            sf(1,i)=0.0e0_rknd
            sf(2,i)=0.0e0_rknd
        enddo
        itnode(3,1)=8
        ibndry(2,1)=8
c
        do i=1,nvf
            vx(i)=real(ix(i),rknd)/2.0e0_rknd
            vy(i)=real(iy(i),rknd)/2.0e0_rknd
        enddo
c
        return
        end
