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