@@ -12,7 +12,8 @@ bool Line_Search::line_search(
1212 double & xnew, // the next point that we want to try
1313 const double conv_thr)
1414{
15- if (restart) ls_step = 0 ;
15+ if (restart) { ls_step = 0 ;
16+ }
1617
1718 if (ls_step == 0 ) // first point: make a trial step into trial direction
1819 {
@@ -105,7 +106,8 @@ bool Line_Search::third_order(
105106 }
106107
107108 dmoveh = -fa/(fab-fa)/2.0 ;
108- if (dmoveh<0 ) dmoveh = 4.0 ;
109+ if (dmoveh<0 ) { dmoveh = 4.0 ;
110+ }
109111
110112 if (dmove > 2.0 *dmoveh || dmoveh > 2.0 *dmove ||
111113 (fa*fb > 0 && dmove < 1.0 ) ||
@@ -115,11 +117,13 @@ bool Line_Search::third_order(
115117 }
116118 } // end anharmonic case
117119
118- if (dmove > 4.0 ) dmove = 4.0 ;
120+ if (dmove > 4.0 ) { dmove = 4.0 ;
121+ }
119122 xnew = dmove +xa;
120123
121124 double dy = (fb+(fab-fb)/(xa-xb)*(dmove-xb))*(dmove-xb);
122- if (std::abs (dy)<conv_thr) return true ;
125+ if (std::abs (dy)<conv_thr) { return true ;
126+ }
123127
124128 ls_step ++;
125129 return false ;
@@ -140,7 +144,8 @@ void Line_Search::init_brent(
140144 xb = x;
141145 yb = y;
142146 fb = f;
143- if (fa*fb>0 ) bracked = false ;
147+ if (fa*fb>0 ) { bracked = false ;
148+ }
144149 fstart = fa;
145150 }
146151 else // x < b
@@ -239,7 +244,8 @@ bool Line_Search::brent(
239244 p=s*(2.0 *xm*qq*(qq-r)-(xb-xa)*(r-1.0 ));
240245 qq=(qq-1.0 )*(r-1.0 )*(s-1.0 );
241246 }
242- if (p>0.0 ) qq=-qq;
247+ if (p>0.0 ) { qq=-qq;
248+ }
243249 p = std::abs (p);
244250
245251 if ( p < std::min (2.0 *(xb-xa)*qq-std::abs (tol1*qq) , std::abs (xe*qq)/2.0 ) )
@@ -277,7 +283,8 @@ bool Line_Search::brent(
277283 }
278284
279285 xnew = xb;
280- if (std::abs (dy)<conv_thr) return true ;
286+ if (std::abs (dy)<conv_thr) { return true ;
287+ }
281288 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 search steps
282289 // I feel if the line search does not converge, we'd better change the direction and restart line search
283290 {
@@ -336,7 +343,8 @@ bool Line_Search::brent(
336343 p=s*(2.0 *xm*qq*(qq-r)-(xb-xa)*(r-1.0 ));
337344 qq=(qq-1.0 )*(r-1.0 )*(s-1.0 );
338345 }
339- if (p>0.0 ) qq=-qq;
346+ if (p>0.0 ) { qq=-qq;
347+ }
340348 p = std::abs (p);
341349
342350 if (2.0 *p < std::min ( 3.0 *xm*qq-std::abs (tol1*qq), std::abs (xe*qq) ) )
@@ -380,7 +388,8 @@ bool Line_Search::brent(
380388 }
381389
382390 xnew = xb;
383- if (std::abs (dy)<conv_thr) return true ;
391+ if (std::abs (dy)<conv_thr) { return true ;
392+ }
384393 if (ls_step == 4 )
385394 {
386395 GlobalV::ofs_running << " Too many Brent steps, let's do next CG step" << std::endl;
0 commit comments