@@ -2073,11 +2073,27 @@ def F_optimize(mu):
2073
2073
# check for lowercase matching for the method variable
2074
2074
if method .lower () == "dichotomy" :
2075
2075
mpi .report ("\n sumk calc_mu: Using dichtomy adjustment to find chemical potential\n " )
2076
- self .chemical_potential = dichotomy .dichotomy (function = F_bisection ,
2077
- x_init = self .chemical_potential , y_value = density ,
2078
- precision_on_y = precision , delta_x = delta , max_loops = max_loops ,
2079
- x_name = "Chemical Potential" , y_name = "Total Density" ,
2080
- verbosity = 3 )[0 ]
2076
+ result = dichotomy .dichotomy (function = F_bisection ,
2077
+ x_init = self .chemical_potential ,
2078
+ y_value = density ,
2079
+ precision_on_y = precision ,
2080
+ delta_x = delta ,
2081
+ max_loops = max_loops ,
2082
+ x_name = "Chemical Potential" ,
2083
+ y_name = "Total Density" ,
2084
+ verbosity = 3 )
2085
+ if result [0 ] is None :
2086
+ raise ValueError (
2087
+ f"\n sumk calc_mu: Failed to find chemical potential using dichotomy method.\n "
2088
+ f" Target total density: { density } \n "
2089
+ f" Starting guess for chemical potential: { self .chemical_potential } \n "
2090
+ f" Step size (delta): { delta } , Precision required: { precision } \n "
2091
+ f" Maximum iterations allowed: { max_loops } \n "
2092
+ f" The method could not converge: no value of mu found such that |F(mu) - { density } | < { precision } .\n "
2093
+ f" Suggestion:\n "
2094
+ f" Adjust the initial guess or increase delta."
2095
+ )
2096
+ self .chemical_potential = result [0 ]
2081
2097
elif method .lower () == "newton" :
2082
2098
mpi .report ("\n sumk calc_mu: Using Newton method to find chemical potential\n " )
2083
2099
self .chemical_potential = newton (func = F_optimize ,
0 commit comments