subroutine solve_no_photo_floating_potential(spec_e, spec_i, inward_normal, phi0_v)
type(sheath_model_species), intent(in) :: spec_e, spec_i
real(dp), intent(in) :: inward_normal(3)
real(dp), intent(out) :: phi0_v
real(dp) :: n_e_inf_m3, n_i_inf_m3, gamma_i, f_low, f_high, f_mid, phi_low, phi_high, phi_mid
integer :: iter
n_e_inf_m3 = spec_e%number_density_m3
n_i_inf_m3 = spec_i%number_density_m3
gamma_i = compute_inflow_flux_from_drifting_maxwellian( &
n_i_inf_m3, spec_i%temperature_k, spec_i%m_particle, spec_i%drift_velocity, inward_normal &
)
if (gamma_i <= 0.0d0) error stop 'floating_no_photo requires a positive ion inflow flux.'
phi_low = -128.0d0*max(1.0d0, temperature_ev_from_species(spec_e))
phi_high = 0.0d0
f_low = no_photo_current_balance(phi_low, n_e_inf_m3, spec_e, inward_normal, gamma_i)
f_high = no_photo_current_balance(phi_high, n_e_inf_m3, spec_e, inward_normal, gamma_i)
if (f_high < 0.0d0) then
error stop 'floating_no_photo could not bracket a negative sheath potential.'
end if
do while (f_low > 0.0d0)
phi_low = 2.0d0*phi_low
f_low = no_photo_current_balance(phi_low, n_e_inf_m3, spec_e, inward_normal, gamma_i)
if (phi_low < -1.0d6) error stop 'floating_no_photo bracket search failed.'
end do
do iter = 1, 80
phi_mid = 0.5d0*(phi_low + phi_high)
f_mid = no_photo_current_balance(phi_mid, n_e_inf_m3, spec_e, inward_normal, gamma_i)
if (abs(f_mid) <= 1.0d-12*max(1.0d0, gamma_i)) exit
if (f_mid > 0.0d0) then
phi_high = phi_mid
else
phi_low = phi_mid
end if
end do
phi0_v = 0.5d0*(phi_low + phi_high)
end subroutine solve_no_photo_floating_potential