@@ -12,8 +12,9 @@ bool Line_Search::line_search(const bool restart,
1212 double & xnew, // the next point that we want to try
1313 const double conv_thr)
1414{
15- if (restart)
15+ if (restart) {
1616 ls_step = 0 ;
17+ }
1718
1819 if (ls_step == 0 ) // first point: make a trial step into trial direction
1920 {
@@ -99,8 +100,9 @@ bool Line_Search::third_order(const double x, const double y, const double f, do
99100 }
100101
101102 dmoveh = -fa / (fab - fa) / 2.0 ;
102- if (dmoveh < 0 )
103+ if (dmoveh < 0 ) {
103104 dmoveh = 4.0 ;
105+ }
104106
105107 if (dmove > 2.0 * dmoveh || dmoveh > 2.0 * dmove || (fa * fb > 0 && dmove < 1.0 )
106108 || (fa * fb < 0 && dmove > 1.0 ))
@@ -109,13 +111,15 @@ bool Line_Search::third_order(const double x, const double y, const double f, do
109111 }
110112 } // end anharmonic case
111113
112- if (dmove > 4.0 )
114+ if (dmove > 4.0 ) {
113115 dmove = 4.0 ;
116+ }
114117 xnew = dmove + xa;
115118
116119 double dy = (fb + (fab - fb) / (xa - xb) * (dmove - xb)) * (dmove - xb);
117- if (std::abs (dy) < conv_thr)
120+ if (std::abs (dy) < conv_thr) {
118121 return true ;
122+ }
119123
120124 ls_step++;
121125 return false ;
@@ -133,8 +137,9 @@ void Line_Search::init_brent(const double x, const double y, const double f)
133137 xb = x;
134138 yb = y;
135139 fb = f;
136- if (fa * fb > 0 )
140+ if (fa * fb > 0 ) {
137141 bracked = false ;
142+ }
138143 fstart = fa;
139144 }
140145 else // x < b
@@ -228,8 +233,9 @@ bool Line_Search::brent(const double x, const double y, const double f, double&
228233 p = s * (2.0 * xm * qq * (qq - r) - (xb - xa) * (r - 1.0 ));
229234 qq = (qq - 1.0 ) * (r - 1.0 ) * (s - 1.0 );
230235 }
231- if (p > 0.0 )
236+ if (p > 0.0 ) {
232237 qq = -qq;
238+ }
233239 p = std::abs (p);
234240
235241 if (p < std::min (2.0 * (xb - xa) * qq - std::abs (tol1 * qq), std::abs (xe * qq) / 2.0 ))
@@ -267,8 +273,9 @@ bool Line_Search::brent(const double x, const double y, const double f, double&
267273 }
268274
269275 xnew = xb;
270- if (std::abs (dy) < conv_thr)
276+ if (std::abs (dy) < conv_thr) {
271277 return true ;
278+ }
272279 if (ls_step == 4 ) // I'm not sure if this is a good choice, but the idea is there should not be so many line
273280 // search steps I feel if the line search does not converge, we'd better change the direction
274281 // and restart line search
@@ -328,8 +335,9 @@ bool Line_Search::brent(const double x, const double y, const double f, double&
328335 p = s * (2.0 * xm * qq * (qq - r) - (xb - xa) * (r - 1.0 ));
329336 qq = (qq - 1.0 ) * (r - 1.0 ) * (s - 1.0 );
330337 }
331- if (p > 0.0 )
338+ if (p > 0.0 ) {
332339 qq = -qq;
340+ }
333341 p = std::abs (p);
334342
335343 if (2.0 * p < std::min (3.0 * xm * qq - std::abs (tol1 * qq), std::abs (xe * qq)))
@@ -373,8 +381,9 @@ bool Line_Search::brent(const double x, const double y, const double f, double&
373381 }
374382
375383 xnew = xb;
376- if (std::abs (dy) < conv_thr)
384+ if (std::abs (dy) < conv_thr) {
377385 return true ;
386+ }
378387 if (ls_step == 4 )
379388 {
380389 GlobalV::ofs_running << " Too many Brent steps, let's do next CG step" << std::endl;
0 commit comments