00001 subroutine iteration_BBH_CF(iter_count)
00002 use phys_constant, only : long
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 make_array_2d
00009 use make_array_3d
00010 use make_array_4d
00011 use def_metric
00012
00013 use def_metric_excurve_grid, only : tfkij_grid, tfkijkij_grid
00014 use def_matter
00015 use def_bh_parameter, only : bh_bctype
00016 use def_vector_bh
00017 use interface_poisson_solver_binary_bhex_homosol
00018 use interface_sourceterm_exsurf_eqm_binary
00019 use interface_sourceterm_surface_int
00020 use interface_compute_shift
00021 use interface_compute_alps2alph
00022 use interface_update_grfield
00023 use interface_update_parameter
00024 use interface_error_metric_type0
00025 use interface_error_metric_type2
00026 use interface_interpolation_fillup_binary
00027
00028 use interface_bh_boundary_d_psi
00029 use interface_bh_boundary_nh_psi_test
00030 use interface_bh_boundary_d_alps
00031 use interface_bh_boundary_CF
00032 use interface_bh_boundary_AH_d_psi
00033 use interface_bh_boundary_AH_n_psi
00034 use interface_bh_boundary_AH_r_psi
00035 use interface_bh_boundary_AH_d_alps
00036 use interface_bh_boundary_AH_n_alps
00037 use interface_outer_boundary_d_psi
00038 use interface_outer_boundary_d_alps
00039 use interface_outer_boundary_d_bvxd
00040 use interface_outer_boundary_d_bvyd
00041 use interface_outer_boundary_d_bvzd
00042 use interface_outer_boundary_d_Bfun
00043 use interface_outer_boundary_n_Bfun
00044 use interface_outer_boundary_d_potx
00045 use interface_outer_boundary_d_poty
00046 use interface_outer_boundary_d_potz
00047 use interface_sourceterm_HaC_CF
00048 use interface_sourceterm_trG_CF
00049 use interface_sourceterm_MoC_CF
00050 use interface_sourceterm_MoC_CF_type1_bhex
00051 use interface_sourceterm_Bfun
00052 use interface_interpolation_fillup_binary_parity
00053 use interface_sourceterm_exsurf_eqm_binary_parity
00054 use interface_compute_shift_v2
00055 use interface_compute_dBfun
00056 use gnufor2
00057
00058 implicit none
00059 real(long), pointer :: sou(:,:,:), pot(:,:,:)
00060 real(long), pointer :: Bfun(:,:,:), potx(:,:,:), poty(:,:,:), potz(:,:,:)
00061 real(long), pointer :: pot_bak(:,:,:), work(:,:,:)
00062 real(long), pointer :: potx_bak(:,:,:), poty_bak(:,:,:), potz_bak(:,:,:)
00063 real(long), pointer :: dBfundx(:,:,:), dBfundy(:,:,:), dBfundz(:,:,:)
00064 real(long), pointer :: souvec(:,:,:,:)
00065 real(long), pointer :: sou_exsurf(:,:), dsou_exsurf(:,:)
00066 real(long), pointer :: sou_bhsurf(:,:), dsou_bhsurf(:,:)
00067 real(long), pointer :: sou_outsurf(:,:), dsou_outsurf(:,:)
00068 real(long) :: count, error_psi,error_alph, error_bvxd, error_bvyd, error_bvzd
00069 real(long) :: error_potx, error_poty, error_potz, error_Bfun
00070 real(long) :: pari
00071 integer :: iter_count, flag_psi=0, flag_alph=0,
00072 flag_bvxd=0, flag_bvyd=0, flag_bvzd=0
00073 integer :: flag_potx=0, flag_poty=0, flag_potz=0, flag_Bfun=0
00074 integer :: irg, itg, ipg, ihy, nn, ii
00075 character(2) :: chgreen
00076 character(30) :: char1, char2, char3
00077
00078 call alloc_array4d(souvec,0,nrg,0,ntg,0,npg,1,3)
00079 call alloc_array3d(sou,0,nrg,0,ntg,0,npg)
00080
00081
00082
00083
00084 call alloc_array3d(pot,0,nrg,0,ntg,0,npg)
00085 call alloc_array3d(potx,0,nrg,0,ntg,0,npg)
00086 call alloc_array3d(poty,0,nrg,0,ntg,0,npg)
00087 call alloc_array3d(potz,0,nrg,0,ntg,0,npg)
00088 call alloc_array3d(pot_bak,0,nrg,0,ntg,0,npg)
00089 call alloc_array3d(potx_bak,0,nrg,0,ntg,0,npg)
00090 call alloc_array3d(poty_bak,0,nrg,0,ntg,0,npg)
00091 call alloc_array3d(potz_bak,0,nrg,0,ntg,0,npg)
00092 call alloc_array3d(work,0,nrg,0,ntg,0,npg)
00093 call alloc_array2d(sou_exsurf,0,ntg,0,npg)
00094 call alloc_array2d(dsou_exsurf,0,ntg,0,npg)
00095 call alloc_array2d(sou_bhsurf,0,ntg,0,npg)
00096 call alloc_array2d(dsou_bhsurf,0,ntg,0,npg)
00097 call alloc_array2d(sou_outsurf,0,ntg,0,npg)
00098 call alloc_array2d(dsou_outsurf,0,ntg,0,npg)
00099
00100 iter_count = 0
00101
00102 souvec(0:nrg,0:ntg,0:npg,1:3) = 0.0d0
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 do
00118 iter_count = iter_count + 1
00119 count = dble(iter_count)
00120 conv_gra = dmin1(conv0_gra,conv_ini*count)
00121 conv_den = dmin1(conv0_den,conv_ini*count)
00122
00123
00124
00125
00126
00127 call calc_vector_bh(2)
00128 call excurve
00129 call excurve_CF_gridpoint_bhex
00130
00131 sou(0:nrg,0:ntg,0:npg) = 0.0d0
00132 call sourceterm_HaC_CF(sou)
00133 call sourceterm_exsurf_eqm_binary(psi,sou_exsurf,dsou_exsurf)
00134 call sourceterm_surface_int(psi,0,sou_bhsurf,dsou_bhsurf)
00135 call sourceterm_surface_int(psi,nrg,sou_outsurf,dsou_outsurf)
00136
00137 call bh_boundary_CF(sou_bhsurf,dsou_bhsurf,'psi ')
00138 call outer_boundary_d_psi(sou_outsurf)
00139 if (bh_bctype.eq.'TU') chgreen = 'dd'
00140 if (bh_bctype.eq.'AH'.or.bh_bctype.eq.'PG') chgreen = 'nd'
00141 call poisson_solver_binary_bhex_homosol('nd',sou, &
00142
00143 & sou_exsurf,dsou_exsurf, &
00144 & sou_bhsurf,dsou_bhsurf, &
00145 & sou_outsurf,dsou_outsurf,pot)
00146 pot_bak = psi
00147 call update_grfield(pot,psi,conv_gra)
00148 call interpolation_fillup_binary(psi)
00149 call error_metric_type0(psi,pot_bak,error_psi,flag_psi,'bh')
00150
00151 sou(0:nrg,0:ntg,0:npg) = 0.0d0
00152 alps(0:nrg,0:ntg,0:npg) = alph(0:nrg,0:ntg,0:npg)*psi(0:nrg,0:ntg,0:npg)
00153 call sourceterm_trG_CF(sou)
00154 call sourceterm_exsurf_eqm_binary(alps,sou_exsurf,dsou_exsurf)
00155 call sourceterm_surface_int(alps,0,sou_bhsurf,dsou_bhsurf)
00156 call sourceterm_surface_int(alps,nrg,sou_outsurf,dsou_outsurf)
00157
00158 call bh_boundary_CF(sou_bhsurf,dsou_bhsurf,'alps')
00159 call outer_boundary_d_alps(sou_outsurf)
00160 call poisson_solver_binary_bhex_homosol('dd',sou, &
00161 & sou_exsurf,dsou_exsurf, &
00162 & sou_bhsurf,dsou_bhsurf, &
00163 & sou_outsurf,dsou_outsurf,pot)
00164 call compute_alps2alph(pot,psi)
00165 pot_bak = alph
00166 call update_grfield(pot,alph,conv_gra)
00167 call interpolation_fillup_binary(alph)
00168 call error_metric_type0(alph,pot_bak,error_alph,flag_alph,'bh')
00169
00170 call sourceterm_MoC_CF_type1_bhex(souvec)
00171 do ii = 1, 3
00172 sou(0:nrg,0:ntg,0:npg) = souvec(0:nrg,0:ntg,0:npg,ii)
00173 if (ii.eq.1) then
00174 work(0:nrg,0:ntg,0:npg) = bvxd(0:nrg,0:ntg,0:npg)
00175 pari = -1.0d0
00176 else if (ii.eq.2) then
00177 work(0:nrg,0:ntg,0:npg) = bvyd(0:nrg,0:ntg,0:npg)
00178 pari = -1.0d0
00179 else if (ii.eq.3) then
00180 work(0:nrg,0:ntg,0:npg) = bvzd(0:nrg,0:ntg,0:npg)
00181 pari = 1.0d0
00182 end if
00183 call sourceterm_exsurf_eqm_binary_parity(work,sou_exsurf,dsou_exsurf,&
00184 & pari)
00185 call sourceterm_surface_int(work,0,sou_bhsurf,dsou_bhsurf)
00186 call sourceterm_surface_int(work,nrg,sou_outsurf,dsou_outsurf)
00187 if (ii.eq.1) then
00188 call bh_boundary_CF(sou_bhsurf,dsou_bhsurf,'bvxd')
00189 call outer_boundary_d_bvxd(sou_outsurf)
00190 else if (ii.eq.2) then
00191 call bh_boundary_CF(sou_bhsurf,dsou_bhsurf,'bvyd')
00192 call outer_boundary_d_bvyd(sou_outsurf)
00193 else if (ii.eq.3) then
00194 call bh_boundary_CF(sou_bhsurf,dsou_bhsurf,'bvzd')
00195 call outer_boundary_d_bvzd(sou_outsurf)
00196 end if
00197
00198 call poisson_solver_binary_bhex_homosol('dd',sou, &
00199 & sou_exsurf,dsou_exsurf, &
00200 & sou_bhsurf,dsou_bhsurf, &
00201 & sou_outsurf,dsou_outsurf,pot)
00202 if (ii.eq.1) potx(0:nrg,0:ntg,0:npg) = pot(0:nrg,0:ntg,0:npg)
00203 if (ii.eq.2) poty(0:nrg,0:ntg,0:npg) = pot(0:nrg,0:ntg,0:npg)
00204 if (ii.eq.3) potz(0:nrg,0:ntg,0:npg) = pot(0:nrg,0:ntg,0:npg)
00205 end do
00206
00207 potx_bak = bvxd
00208 poty_bak = bvyd
00209 potz_bak = bvzd
00210 call update_grfield(potx,bvxd,conv_gra)
00211 call update_grfield(poty,bvyd,conv_gra)
00212 call update_grfield(potz,bvzd,conv_gra)
00213
00214 call interpolation_fillup_binary_parity(bvxd,-1.0d0)
00215 call interpolation_fillup_binary_parity(bvyd,-1.0d0)
00216 call interpolation_fillup_binary_parity(bvzd,1.0d0)
00217 if (bh_bctype.eq.'TU') call reset_metric_CF
00218
00219
00220
00221
00222 call error_metric_type0(bvxd,potx_bak,error_bvxd,flag_bvxd,'bh')
00223 call error_metric_type0(bvyd,poty_bak,error_bvyd,flag_bvyd,'bh')
00224 call error_metric_type0(bvzd,potz_bak,error_bvzd,flag_bvzd,'bh')
00225
00226 call printout_error_metric_combined(iter_count,error_psi,error_alph,&
00227 & error_bvxd,error_bvyd,error_bvzd)
00228
00229 if ((flag_psi==0).and.(flag_alph==0).and. &
00230 & (flag_bvxd==0).and.(flag_bvyd==0).and.(flag_bvzd==0)) exit
00231 if (iter_count >= iter_max) exit
00232
00233
00234
00235
00236
00237
00238
00239 flag_psi = 0
00240 flag_alph = 0
00241 flag_bvxd = 0
00242 flag_bvyd = 0
00243 flag_bvzd = 0
00244 flag_Bfun = 0
00245 end do
00246
00247 deallocate(souvec)
00248 deallocate(sou)
00249
00250
00251
00252
00253
00254
00255
00256 deallocate(pot)
00257 deallocate(potx)
00258 deallocate(poty)
00259 deallocate(potz)
00260 deallocate(pot_bak)
00261 deallocate(potx_bak)
00262 deallocate(poty_bak)
00263 deallocate(potz_bak)
00264 deallocate(work)
00265 deallocate(sou_exsurf)
00266 deallocate(dsou_exsurf)
00267 deallocate(sou_bhsurf)
00268 deallocate(dsou_bhsurf)
00269 deallocate(sou_outsurf)
00270 deallocate(dsou_outsurf)
00271
00272 end subroutine iteration_BBH_CF