00001 subroutine adjust_charge_bisection(flag_bis,charge_type)
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_adjust, charge_hope = 0.0d0, small = 1.0d-10
00009 character(len=6) :: charge_type
00010
00011
00012
00013 if (charge_type.eq.'asympt') then
00014 call calc_charge_asympto('ns')
00015 charge_adjust = charge_asymp
00016 else if (charge_type.eq.'volume') then
00017 call calc_charge_MHD
00018 charge_adjust = charge
00019 else
00020 write(6,*) 'charge type wrong'
00021 stop
00022 end if
00023
00024 if (flag_bis.ne.0) then
00025 x_bis(0) = x_bis(1)
00026 f_bis(0) = f_bis(1)
00027 end if
00028
00029 error_bis = charge_adjust - charge_hope
00030 write(6,'(1a24,2(7x,i5))') ' -- charge flag # -- ',flag_bis
00031 write(6,'(1a24,1p,2e12.4)')' -- charge and param -- ',charge_adjust, &
00032 & MHDpar_charge
00033
00034 if (dabs(error_bis).gt.small) then
00035 x_bis(1) = MHDpar_charge
00036 f_bis(1) = error_bis
00037 else
00038 write(6,'(1a24)') ' -- charge converged -- '
00039 return
00040 end if
00041
00042 if (flag_bis.eq.0) then
00043 delta = MHDpar_charge*0.5d0
00044 if (delta.eq.0.0d0) delta = 0.1d0
00045 flag_bis = +1
00046 end if
00047
00048 if (flag_bis.ne.0) then
00049 if (f_bis(1)*f_bis(0).ge.0) then
00050 if (dabs(f_bis(1)).gt.dabs(f_bis(0))) then
00051 delta = - delta
00052 flag_bis = - flag_bis
00053 end if
00054 else
00055 delta = - delta
00056 flag_bis = - flag_bis
00057 if (delta.gt.0.0d0.and.dabs(error_bis).gt.small) delta = 0.5d0*delta
00058 end if
00059 end if
00060
00061 MHDpar_charge = MHDpar_charge + delta
00062
00063 write(6,'(1a6,1p,3e12.4)')'charge', x_bis(0),x_bis(1)
00064 write(6,'(1a6,1p,3e12.4)')'charge', f_bis(0),f_bis(1)
00065 write(6,'(1a6,1p,3e12.4)')'charge', delta
00066
00067
00068
00069 return
00070 end subroutine adjust_charge_bisection