@@ -54,8 +54,9 @@ class Opt_TN
5454 void refresh (int nx_new = 0 )
5555 {
5656 this ->iter_ = 0 ;
57- if (nx_new != 0 )
57+ if (nx_new != 0 ) {
5858 this ->nx_ = nx_new;
59+ }
5960 this ->cg_ .refresh (nx_new);
6061 }
6162
@@ -169,18 +170,21 @@ void Opt_TN::next_direct(double* px,
169170 // Hcgd = (df(temp_x)/dx - df(x)/x) / epsilon, where temp_x = x + step * cg_direct
170171 epsilon = this ->get_epsilon (px, cg_direct);
171172 // epsilon = 1e-9;
172- for (int i = 0 ; i < this ->nx_ ; ++i)
173+ for (int i = 0 ; i < this ->nx_ ; ++i) {
173174 temp_x[i] = px[i] + epsilon * cg_direct[i];
175+ }
174176 (t->*p_calGradient)(temp_x, temp_gradient, ucell);
175- for (int i = 0 ; i < this ->nx_ ; ++i)
177+ for (int i = 0 ; i < this ->nx_ ; ++i) {
176178 temp_Hcgd[i] = (temp_gradient[i] - pgradient[i]) / epsilon;
179+ }
177180
178181 // get CG step length and update rdirect
179182 cg_alpha = cg_.step_length (temp_Hcgd, cg_direct, cg_ifPD);
180183 if (cg_ifPD == -1 ) // Hessian is not positive definite, and cgiter = 1.
181184 {
182- for (int i = 0 ; i < this ->nx_ ; ++i)
185+ for (int i = 0 ; i < this ->nx_ ; ++i) {
183186 rdirect[i] += cg_alpha * cg_direct[i];
187+ }
184188 flag = -1 ;
185189 break ;
186190 }
@@ -190,15 +194,17 @@ void Opt_TN::next_direct(double* px,
190194 break ;
191195 }
192196
193- for (int i = 0 ; i < this ->nx_ ; ++i)
197+ for (int i = 0 ; i < this ->nx_ ; ++i) {
194198 rdirect[i] += cg_alpha * cg_direct[i];
199+ }
195200
196201 // store residuals used in truncated conditions
197202 last_residual = curr_residual;
198203 curr_residual = cg_.get_residual ();
199204 cg_iter = cg_.get_iter ();
200- if (cg_iter == 1 )
205+ if (cg_iter == 1 ) {
201206 init_residual = curr_residual;
207+ }
202208
203209 // check truncated conditions
204210 // if (curr_residual < 1e-12)
0 commit comments