00001 subroutine iteration_helmholtz_solver_binary_test_mpt(iter_count)
00002   use phys_constant, only :  long, nnrg, nntg, nnpg, nmpt
00003   use grid_parameter
00004   use coordinate_grav_r
00005   use coordinate_grav_phi
00006   use coordinate_grav_theta
00007   use weight_midpoint_grav
00008   use def_metric, only : psi
00009   use def_matter, only : emd, emdg
00010   use def_binary_parameter, only : mass_ratio
00011   use make_array_2d
00012   use make_array_3d
00013   use interface_update_grfield
00014   use interface_error_metric_type0
00015   use interface_interpo_fl2gr
00016   use interface_sourceterm_helmholtz_solver_test
00017   use interface_sourceterm_exsurf_binary_COCP
00018   use interface_sourceterm_outsurf_COCP_from_ARCP
00019   use interface_sourceterm_insurf_ARCP_from_COCP
00020   use interface_helmholtz_solver_binary
00021   use interface_helmholtz_solver_asymptotic_patch_homosol
00022   use interface_helmholtz_solver_asymptotic_patch_homosol_outgoing
00023   use interface_poisson_solver_binary_star_homosol
00024   implicit none
00025   real(long), pointer :: sou(:,:,:), pot(:,:,:), psi_bak(:,:,:)
00026   real(long), pointer :: sou_exsurf(:,:), dsou_exsurf(:,:)
00027   real(long), pointer :: sou_insurf(:,:), dsou_insurf(:,:)
00028   real(long), pointer :: sou_outsurf(:,:), dsou_outsurf(:,:)
00029   real(long) :: error_psi, error_tmp, count
00030   integer    :: iter_count, iter_extra = 0, istep_niq = -1, 
00031                flag = 0, flag0 = 0, flag_param = 99
00032   integer    :: impt, impt_bin, impt_ex
00033   integer    ::  irg, itg, ipg, ihy
00034   character(len=2) :: chgreen, chpa, chpB
00035   character(len=4) :: chbe
00036 
00037   call set_allocate_size_mpt
00038 
00039   call alloc_array2d(sou_insurf,0,ntg,0,npg)
00040   call alloc_array2d(dsou_insurf,0,ntg,0,npg)
00041   call alloc_array2d(sou_exsurf,0,ntg,0,npg)
00042   call alloc_array2d(dsou_exsurf,0,ntg,0,npg)
00043   call alloc_array3d(sou,0,nrg,0,ntg,0,npg)
00044   call alloc_array3d(pot,0,nrg,0,ntg,0,npg)
00045   call alloc_array2d(sou_outsurf,0,ntg,0,npg)
00046   call alloc_array2d(dsou_outsurf,0,ntg,0,npg)
00047   call alloc_array3d(psi_bak,0,nrg,0,ntg,0,npg)
00048 
00049   iter_count = 0
00050   do
00051     iter_count = iter_count + 1      
00052     count = dble(iter_count) 
00053 
00054     do impt = 1, nmpt
00055       write(6,'(a10,i2)')" Patch # =", impt
00056       call copy_grid_parameter_from_mpt(impt)
00057       conv_gra = dmin1(conv0_gra,conv_ini*count)
00058       conv_den = dmin1(conv0_den,conv_ini*count)
00059       call copy_grid_parameter_to_mpt(impt)
00060 
00061       call copy_from_mpatch_all_BBH_CF(impt)
00062       call copy_metric_and_matter_BHNS_test_from_mpt(impt)
00063       call calc_vector_x_grav(2)
00064       call calc_vector_x_matter(2)
00065       call calc_vector_phi_grav(2)
00066       call calc_vector_phi_matter(2)
00067       call copy_to_mpatch_all_BBH_CF(impt)
00068 
00069 
00070       sou(0:nrg,0:ntg,0:npg)  = 0.0d0
00071       sou_exsurf(0:ntg,0:npg) = 0.0d0 ; dsou_exsurf(0:ntg,0:npg) = 0.0d0
00072       sou_insurf(0:ntg,0:npg) = 0.0d0 ; dsou_insurf(0:ntg,0:npg) = 0.0d0
00073       sou_outsurf(0:ntg,0:npg)= 0.0d0 ; dsou_outsurf(0:ntg,0:npg)= 0.0d0
00074 
00075       if (impt.ne.nmpt) then
00076 
00077         call sourceterm_helmholtz_solver_test(sou,'po')
00078         call sourceterm_exsurf_binary_COCP(impt,'psi ','ev',sou_exsurf, &
00079         &                                                  dsou_exsurf)
00080         call sourceterm_outsurf_COCP_from_ARCP(impt,'psi ','ev',sou_outsurf, &
00081         &                                                      dsou_outsurf)
00082         chgreen = 'sd'
00083         call poisson_solver_binary_star_homosol(chgreen,sou, &
00084         &                                       sou_exsurf,dsou_exsurf, &
00085         &                                       sou_outsurf,dsou_outsurf,pot)
00086 
00087 
00088       else if (impt.eq.nmpt) then
00089         call sourceterm_insurf_ARCP_from_COCP(impt,'psi ','ev',sou_insurf, &
00090         &                                                     dsou_insurf)
00091 
00092 
00093         call helmholtz_solver_asymptotic_patch_homosol_outgoing &
00094         &                       (sou,sou_insurf,dsou_insurf,pot)
00095       end if
00096 
00097 
00098       psi_bak(0:nrg,0:ntg,0:npg) = psi(0:nrg,0:ntg,0:npg)
00099       call update_grfield(pot,psi,conv_gra)
00100       if (impt.eq.1) call error_metric_type0(psi,psi_bak,error_psi,flag0,'ns')
00101       if (impt.eq.2) call error_metric_type0(psi,psi_bak,error_psi,flag0,'ns')
00102       if (impt.eq.3) call error_metric_type0(psi,psi_bak,error_psi,flag0,'bh')
00103       flag = flag + flag0
00104       error_tmp = dmax1(error_psi,error_tmp)
00105       call printout_error_metric(iter_count,error_psi)
00106       call copy_to_mpatch_all_BBH_CF(impt)
00107       call copy_metric_and_matter_BHNS_test_to_mpt(impt)
00108     end do
00109 
00110 
00111     if (mass_ratio.ne.1.0d0.and.error_tmp.le.eps) then
00112 
00113 
00114       iter_extra = 0
00115       call calc_physical_quantities_helm_test_mpt
00116       call adjust_multi_parameter_helm_test_mpt(flag_param,istep_niq)
00117       flag = flag + flag_param
00118       call update_coordinates_mpt
00119     end if
00120 
00121 
00122 
00123     if (flag == 0) exit
00124     if (iter_count >= iter_max) exit
00125 
00126     flag  = 0
00127     flag0 = 0
00128     flag_param = 0
00129     error_psi = 0.0d0
00130     error_tmp = 0.0d0
00131   end do
00132 
00133   deallocate(sou)
00134   deallocate(sou_exsurf)
00135   deallocate(dsou_exsurf)
00136   deallocate(sou_insurf)
00137   deallocate(dsou_insurf)
00138   deallocate(pot)
00139   deallocate(psi_bak)
00140   deallocate(sou_outsurf)
00141   deallocate(dsou_outsurf)
00142 end subroutine iteration_helmholtz_solver_binary_test_mpt