00001 subroutine bh_boundary_d_potx(sou_surf,Bfun,dBfundx)
00002   use phys_constant, only  : long, pi
00003   use grid_parameter, only : nrg, ntg, npg, rgin
00004   use trigonometry_grav_theta, only : hsinthg, hcosthg
00005   use trigonometry_grav_phi,   only : hsinphig, hcosphig
00006   use def_binary_parameter,    only : sepa
00007   implicit none
00008   real(long), pointer :: sou_surf(:,:), Bfun(:,:,:), dBfundx(:,:,:)
00009   real(long) :: dBdx,dBdy,dBdz, bf
00010   real(long) :: st, ct, sp, cp, xa,ya,za, rcm2, xycm2, rcm, tcm, pcm
00011   integer    :: itg, ipg
00012 
00013   do ipg = 1, npg
00014     do itg = 1, ntg
00015       st = hsinthg(itg)
00016       ct = hcosthg(itg)
00017       sp = hsinphig(ipg)
00018       cp = hcosphig(ipg)
00019 
00020       xa = rgin*st*cp
00021       ya = rgin*st*sp
00022       za = rgin*ct
00023 
00024       rcm2 = (xa-0.5d0*sepa)**2 + ya**2 + za**2
00025       xycm2= (xa-0.5d0*sepa)**2 + ya**2
00026 
00027       rcm = sqrt(rcm2)
00028       tcm = atan2(sqrt(xycm2),za)
00029       pcm = dmod(2.0d0*pi+datan2(ya,xa-0.5d0*sepa),2.0d0*pi)
00030 
00031       dBdx = 0.25d0*(dBfundx(0,itg,ipg)   + dBfundx(0,itg-1,ipg)  &
00032                    + dBfundx(0,itg,ipg-1) + dBfundx(0,itg-1,ipg-1) )
00033 
00034       bf = 0.25d0*(Bfun(0,itg,ipg)   + Bfun(0,itg-1,ipg)  &
00035                  + Bfun(0,itg,ipg-1) + Bfun(0,itg-1,ipg-1) )
00036 
00037 
00038 
00039       sou_surf(itg,ipg) = -0.08d0*(-rcm*sin(tcm)*sin(pcm))
00040 
00041     end do
00042   end do
00043 
00044 end subroutine bh_boundary_d_potx