00001 subroutine adjust_charge_bisection(flag_bis)
00002 use grid_parameter, only : mass_eps, eps
00003 use def_quantities, only : charge, charge_asymp
00004 use integrability_fnc_MHD, only : MHDpar_charge
00005 implicit none
00006 integer :: flag_bis
00007 real(8), save :: delta, x_bis(0:1), f_bis(0:1)
00008 real(8) :: error_bis, charge_hope = 0.0d0, small = 1.0d-10
00009
00010
00011
00012 call calc_charge_MHD
00013
00014
00015 if (flag_bis.ne.0) then
00016 x_bis(0) = x_bis(1)
00017 f_bis(0) = f_bis(1)
00018 end if
00019
00020 error_bis = charge - charge_hope
00021 write(6,'(1a24,2(7x,i5))') ' -- charge flag # -- ',flag_bis
00022 write(6,'(1a24,1p,2e12.4)')' -- charge and param -- ',charge,MHDpar_charge
00023
00024 if (dabs(error_bis).gt.small) then
00025 x_bis(1) = MHDpar_charge
00026 f_bis(1) = error_bis
00027 else
00028 write(6,*) ' -- charge converged --'
00029 return
00030 end if
00031
00032 if (flag_bis.eq.0) then
00033 delta = MHDpar_charge*0.5d0
00034 if (delta.eq.0.0d0) delta = 0.1d0
00035 flag_bis = +1
00036 end if
00037
00038 if (flag_bis.ne.0) then
00039 if (f_bis(1)*f_bis(0).ge.0) then
00040 if (dabs(f_bis(1)).gt.dabs(f_bis(0))) then
00041 delta = - delta
00042 flag_bis = - flag_bis
00043 end if
00044 else
00045 delta = - delta
00046 flag_bis = - flag_bis
00047 if (delta.gt.0.0d0.and.dabs(error_bis).gt.small) delta = 0.5d0*delta
00048 end if
00049 end if
00050
00051 MHDpar_charge = MHDpar_charge + delta
00052
00053
00054
00055
00056 return
00057 end subroutine adjust_charge_bisection