MADNESS 0.10.1
molopt.h
Go to the documentation of this file.
1#ifndef MADNESS_MOLOPT_H
2#define MADNESS_MOLOPT_H
3
4#include "Results.h"
6#include <madness/misc/misc.h>
10
11#include <algorithm>
12#include <string>
13
14namespace madness {
15
16// Generalized Optimization using targetT to provide energy and gradient of a
17// molecule targetT must have the following methods:
18// void energy_and_gradient(Molecule& molecule, double& energy, Tensor<double>&
19// gradient) double value(const Tensor<double>& x) // value of target at x
20// Let's express that in code so we can get compile time errors if we don't
21// have the right methods
22//
23//
24//
25
26class MolOpt {
27private:
28 const int maxiter; //< Maximum number of iterations
29 const double maxstep; //< Maximum step in any one coordinate (currently
30 // Cartesian in a.u.)
31 const double etol; //< Convergence test for energy change
32 const double gtol; //< Convergence test for maximum gradient element
33 const double xtol; //< Convergence test for Cartesian step in a.u.
34 const double energy_precision; //< Assumed precision in energy
35 const double gradient_precision; //< Assumed precision in the gradient
36 const int print_level; //< print_level=0 is none; 1 is default; 2 is debug
37 const std::string update; //< update = "bfgs" (default) or "sr1"
38
39 Tensor<double> hessian;
40
41 /// Returns new search direction given gradient and projected/shifted hessian
42 Tensor<double> new_search_direction(const Tensor<double> &g,
43 const Tensor<double> &h) const {
44 Tensor<double> dx, s;
45 double tol = gradient_precision; // threshold for small hessian eigenvalues
46 double trust = std::min(maxstep * g.dim(0), 1.0);
47
48 Tensor<double> v, e;
49 syev(h, v, e);
50 if (print_level > 1)
51 print("hessian eigenvalues", e);
52
53 // Transform gradient into spectral basis
54 Tensor<double> gv = inner(g, v);
55 if (print_level > 1)
56 print("spectral gradient", gv);
57
58 // Take step applying restrictions
59 int nneg = 0, nsmall = 0, nrestrict = 0;
60 for (int i = 0; i < e.dim(0); i++) {
61 if (e[i] > 900.0) {
62 // This must be a translation or rotation ... skip it
63 if (print_level > 1)
64 print("skipping redundant mode", i);
65 } else if (e[i] <
66 -tol) { // BGFS hessian should be positive ... SR1 may not be
67 if (print_level > 0)
68 printf(" forcing negative eigenvalue to be positive %d %.1e\n", i,
69 e[i]);
70 nneg++;
71 e[i] = tol; // or -e[i] ??
72 } else if (e[i] < tol) {
73 if (print_level > 0)
74 printf(" forcing small eigenvalue to be positive %d %.1e\n", i,
75 e[i]);
76 nsmall++;
77 e[i] = tol;
78 }
79
80 gv[i] = -gv[i] / e[i]; // Newton step
81
82 if (std::abs(gv[i]) > trust) { // Step restriction
83 double gvnew = trust * std::abs(gv(i)) / gv[i];
84 if (print_level > 0)
85 printf(" restricting step in spectral direction %d %.1e --> %.1e\n",
86 i, gv[i], gvnew);
87 nrestrict++;
88 gv[i] = gvnew;
89 }
90 }
91 if (print_level > 0 && (nneg || nsmall || nrestrict))
92 printf(" nneg=%d nsmall=%d nrestrict=%d\n", nneg, nsmall, nrestrict);
93
94 // Transform back from spectral basis
95 gv = inner(v, gv);
96
97 if (print_level > 1)
98 print("cartesian dx before restriction", gv);
99
100 // Now apply step restriction in real space
101 bool printing = false;
102 for (int i = 0; i < gv.dim(0); i++) {
103 if (fabs(gv[i]) > maxstep) {
104 gv[i] = maxstep * gv[i] / fabs(gv[i]);
105 if (print_level > 0) {
106 if (!printing)
107 printf(" restricting step in Cartesian direction");
108 printing = true;
109 printf(" %d", i);
110 }
111 }
112 }
113 if (printing)
114 printf("\n");
115
116 return gv;
117 }
118
119public:
120 /// Makes the projector onto independent coordinates
121
122 /// For Cartesians \code P*x removes the rotations and translations;
123 /// eventually will add support for redundant internal coordinates
124 Tensor<double> make_projector(const Molecule &molecule) const {
125 const int natom = molecule.natom();
126 if (natom == 0)
127 return Tensor<double>(0L, 0L);
128 const Tensor<double> coords = molecule.get_all_coords(); // (natom,3)
129
130 // Construct vectors in V in the direction of the translations
131 // and infinitesimal rotations about the centroid
132 Tensor<double> V(6, natom, 3); // First 3 translations, second 3 rotations
133
134 for (int k = 0; k < 3; k++) // Translations already orthonormal
135 V(k, _, k) = 1.0 / std::sqrt(static_cast<double>(natom));
136
137 Tensor<double> centroid(3);
138 for (int k = 0; k < 3; k++)
139 centroid(k) = coords(_, k).sum() / natom;
140 if (print_level > 1)
141 print("centroid", centroid);
142
143 for (int i = 0; i < natom; i++) {
144 double x = coords(i, 0) - centroid[0];
145 double y = coords(i, 1) - centroid[1];
146 double z = coords(i, 2) - centroid[2];
147
148 V(3, i, 0) = 0; // Rotn about x axis
149 V(3, i, 1) = z;
150 V(3, i, 2) = -y;
151
152 V(4, i, 0) = z; // Rotn about y axis
153 V(4, i, 1) = 0;
154 V(4, i, 2) = -x;
155
156 V(5, i, 0) = -y;
157 V(5, i, 1) = x;
158 V(5, i, 2) = 0; // Rotn about z axis
159 }
160
161 V = V.reshape(6, 3 * natom);
162
163 if (print_level > 1) {
164 print("V before orthonormal");
165 print(V);
166 }
167
168 // Remove any floating-point translational residual from the rotation
169 // generators before computing their singular values.
170 for (int i = 3; i < 6; i++) {
171 for (int j = 0; j < 3; j++) {
172 double proj = V(i, _).trace(V(j, _));
173 V(i, _) -= V(j, _) * proj;
174 }
175 }
176
177 // Orthonormalize the rotational subspace via SVD of the (3, 3*natom)
178 // rotation block rather than sequential lab-axis Gram-Schmidt. Under any
179 // 3D rigid rotation of the molecule, the singular values of R are strictly
180 // invariant: linear molecules have one zero singular value (all three for
181 // a single atom), whereas nearly linear bent molecules retain a non-zero
182 // third singular value proportional to the bend displacement regardless of
183 // molecular orientation in space, without amplifying ~1e-15 coordinate
184 // roundoff into a frozen internal bending mode.
185 const Tensor<double> R = copy(V(Slice(3, 5), _));
186 Tensor<double> U, s, VT;
187 svd(R, U, s, VT);
188 if (print_level > 1)
189 print("rotation singular values", s);
190
191 constexpr double rel_tol = 1.0e-12;
192 const double smax = s(0L);
193 for (int m = 0; m < 3; m++) {
194 const int row = 3 + m;
195 if (smax > 0.0 && s(static_cast<long>(m)) > rel_tol * smax) {
196 V(row, _) = VT(m, _);
197 for (int j = 0; j < row; j++) {
198 double proj = V(row, _).trace(V(j, _));
199 V(row, _) -= V(j, _) * proj;
200 }
201 double vnorm = V(row, _).normf();
202 if (vnorm > 0.5) {
203 V(row, _) *= 1.0 / vnorm;
204 } else {
205 V(row, _) = 0.0;
206 }
207 } else {
208 V(row, _) = 0.0;
209 }
210 }
211
212 // The projector is 1 - VT*V
213 V = -inner(transpose(V), V);
214 for (int i = 0; i < 3 * natom; i++)
215 V(i, i) += 1.0;
216
217 return V;
218 }
219
220private:
221 /// print the gradient the optimizer actually works with
222 ///
223 /// This is the PROJECTED gradient, and it is what every convergence test
224 /// below uses. The engines print their own raw derivatives -- a table that
225 /// carries the full spurious net force and torque, typically orders of
226 /// magnitude above the projected residual -- so without this the only
227 /// gradient visible in an optimization log is the one the optimizer does not
228 /// use, which reads as though no projection were happening at all.
229 ///
230 /// The removed net force is printed alongside precisely because it is not a
231 /// defect of the optimizer: translational invariance is broken only by the
232 /// numerics of the underlying gradient, and seeing how much was taken out is
233 /// the honest measure of that error.
234 void print_gradient(const Molecule &molecule, const Tensor<double> &graw,
235 const Tensor<double> &g) const {
236 const size_t natom = molecule.natom();
237 // a plain array, not a Tensor: Tensor::operator()(0) is ambiguous between
238 // the long and the const long* overloads, since 0 is also a null pointer
239 // constant
240 double net[3] = {0.0, 0.0, 0.0};
241 for (size_t i = 0; i < natom; ++i)
242 for (int c = 0; c < 3; ++c)
243 net[c] += graw[i * 3 + c];
244
245 print("\n Gradient (a.u.), translations and rotations projected out\n"
246 " ---------------------------------------------------------\n");
247 print(" atom x y z dE/dx "
248 "dE/dy dE/dz");
249 print(" ------ ------------ ------------ ------------ ------------ "
250 "------------ ------------");
251 for (size_t i = 0; i < natom; ++i) {
252 const Atom &atom = molecule.get_atom(i);
253 printf(" %5d %12.6f %12.6f %12.6f %12.6f %12.6f %12.6f\n", int(i), atom.x,
254 atom.y, atom.z, g[i * 3 + 0], g[i * 3 + 1], g[i * 3 + 2]);
255 }
256 printf(" max element of the projected gradient %12.3e\n", g.absmax());
257 printf(" net force removed by the projection %12.3e %12.3e %12.3e\n",
258 net[0], net[1], net[2]);
259 }
260
261 /// a1 is initial step (usually pick 1)
262 /// energy0 is energy at zero step
263 /// dxgrad is gradient projected onto search dir
264 ///
265 template <typename targetT>
266 double line_search(Molecule &molecule, targetT &target,
267 const Tensor<double> &dx, double energy0, double dxgrad,
268 double a1 = 1.0) {
269 double energy1;
270 double hess, a2;
271 const char *lsmode = "";
272
273 Tensor<double> x = molecule.get_all_coords().flat();
274
275 // Ensure we are walking downhill (BFGS should ensure that, but SR1 may not)
276 if (dxgrad * a1 > 0.0) {
277 if (print_level > 0)
278 print(" line search gradient +ve ", a1, dxgrad);
279 a1 = -a1;
280 }
281
282 // Compute energy at new point
283 energy1 = target.value(x + a1 * dx);
284
285 // Fit to a parabola using energy0, g0, energy1
286 hess = 2.0 * (energy1 - energy0 - a1 * dxgrad) / (a1 * a1);
287 a2 = -dxgrad / hess; // Newton step
288
289 if (std::abs(energy1 - energy0) <
290 energy_precision) { // Insufficient precision
291 a2 = a1;
292 lsmode = "fixed";
293 } else if (hess > 0.0) { // Positive curvature
294 if ((energy1 - energy0) <= -energy_precision) { // a1 step went downhill
295 lsmode = "downhill";
296 if (std::abs(a2) >
297 4.0 * std::abs(a1)) { // Walking down hill but don't go too far
298 lsmode = "restrict";
299 a2 = 4.0 * a1;
300 }
301 } else { // a1 step went uphill ... we have bracketed the minimum.
302 lsmode = "bracket";
303 }
304 } else { // Negative curvature
305 if ((energy1 - energy0) < energy_precision) { // keep walking down hill
306 lsmode = "negative";
307 a2 = 2e0 * a1;
308 } else {
309 lsmode = "punt"; // negative curvature but no apparent progress
310 a2 = a1;
311 }
312 }
313
314 if (std::abs(a2 - a1) <
315 0.2 * std::abs(a1)) { // Take full step to avoid reconverging SCF
316 a2 = a1;
317 lsmode = "fixed2";
318 }
319
320 // Predicted next energy
321 double energy2 = energy0 + dxgrad * a2 + 0.5 * hess * a2 * a2;
322
323 if (print_level > 0) {
324 printf("\n line search grad=%.2e hess=%.2e mode=%s newstep=%.3f\n",
325 dxgrad, hess, lsmode, a2);
326 printf(" predicted %.12e\n\n", energy2);
327 }
328
329 return a2;
330 }
331
332public:
333 MolOpt(int maxiter = 20, double maxstep = 0.1, double etol = 1e-4,
334 double gtol = 1e-3, double xtol = 1e-3, double energy_precision = 1e-5,
335 double gradient_precision = 1e-4, int print_level = 1,
336 std::string update = "BFGS")
337 : maxiter(maxiter), maxstep(maxstep),
338 etol(std::max(etol, energy_precision)),
339 gtol(std::max(gtol, gradient_precision)), xtol(xtol),
340 energy_precision(energy_precision),
341 gradient_precision(gradient_precision), print_level(print_level),
343
344 {
345 if (print_level > 0) {
346 std::cout << endl;
347 print_justified("Molecular Geometry Optimization");
348 std::cout << endl;
349 print(" maximum iterations", maxiter);
350 print(" maximum step", maxstep);
351 print(" energy convergence", etol);
352 print(" gradient convergence", gtol);
353 print(" cartesian convergence", xtol);
354 print(" energy precision", energy_precision);
355 print(" gradient precision", gradient_precision);
356 print(" hessian update", update);
357 }
358 }
359
360 void set_hessian(const Tensor<double> &h) { hessian = h; }
361
362 const Tensor<double> &get_hessian() const { return hessian; }
363
364 void initialize_hessian(const Molecule &molecule) {
365 const int N = 3 * molecule.natom();
366 hessian = Tensor<double>(N, N);
367 for (int i = 0; i < N; i++)
368 hessian(i, i) = 0.5;
369 }
370
371 template <typename targetT>
372 Molecule optimize(Molecule molecule,
373 targetT &target) { ////!!!!!!! pass by value
374 const int natom = molecule.natom();
375
376 // Code structured so it will be straightforward to introduce redundant
377 // internal coordinates
378
379 if (hessian.size() == 0)
380 initialize_hessian(molecule);
381
382 double ep = 0.0; // Previous energy
383 Tensor<double> gp(3 * natom); // Previous gradient
384 Tensor<double> dx(3 * natom); // Current search direction
385 gp = 0.0;
386 dx = 0.0;
387
388 for (int iter = 0; iter < maxiter; iter++) {
389 if (print_level > 0)
390 print("\n\n Geometry optimization iteration", iter, "\n");
391 if (print_level > 0)
392 molecule.print();
393
394 double e;
395 Tensor<double> g;
396
397 target.energy_and_gradient(molecule, e, g);
398
399 // Project out translations and rotations before testing convergence --
400 // the raw gradient carries a spurious net force/torque of the order of
401 // the gradient accuracy, which would keep max-g above gtol forever
402 Tensor<double> P = make_projector(molecule);
403 const Tensor<double> graw = copy(g);
404 g = inner(P, g);
405 // by default, and NOT only at high print levels: this is the gradient
406 // every test below is applied to
407 if (print_level > 0)
408 print_gradient(molecule, graw, g);
409
410 double de = e - ep;
411 double dxmax = dx.absmax();
412 double gmax = g.absmax();
414 "MolOpt::optimize: projected gradient is not finite");
415
416 bool dxconv = (iter > 0) && (dxmax < xtol);
417 bool gconv = gmax < gtol;
418 bool econv = (iter > 0) && (std::abs(de) < etol);
419 bool converged = econv && dxconv && gconv;
420
421 if (!converged && gmax < gradient_precision) {
422 if (print_level > 0)
423 print("\nInsufficient precision in gradient to proceed further -- "
424 "forcing convergence\n");
425 converged = true;
426 }
427
428 if (print_level > 0) {
429 const char *tf[] = {"F", "T"};
430 print(" ");
431 printf(
432 " energy delta-e max-dx max-g e dx g\n");
433 printf(" ---------------- --------- --------- --------- --- --- "
434 "---\n");
435 printf(" %15.6f %9.2e %9.2e %9.2e %s %s %s\n", e, de, dxmax,
436 gmax, tf[econv], tf[dxconv], tf[gconv]);
437 // print(e, de, econv, dxmax, dxconv, dxnorm, gmax, gconv, gnorm,
438 // converged);
439 print(" ");
440 }
441
442 if (converged) {
443 if (print_level > 0)
444 print("\n Geometry optimization converged!\n");
445 if (print_level > 0)
446 molecule.print();
447 break;
448 }
449
450 if (iter > 0) {
451 if ((g - gp).absmax() < 2.0 * gradient_precision) {
452 if (print_level > 0)
453 print(" skipping hessian update due to insufficient precision in "
454 "gradient");
455 } else if (update == "bfgs") {
456 QuasiNewton::hessian_update_bfgs(dx, g - gp, hessian);
457 } else if (update == "sr1") {
458 QuasiNewton::hessian_update_sr1(dx, g - gp, hessian);
459 } else {
460 throw "unknown update";
461 }
462 }
463
464 ep = e;
465 gp = g;
466
467 // Construct the projected and shifted hessian = PHP + shift*(1-P)
468 const double shift = 1000.0; // this value assumed in new_search_dir
469 Tensor<double> PHPS = inner(P, inner(hessian, P)) - shift * P;
470 if (print_level > 1) {
471 print("projector");
472 print(P);
473 }
474 for (int i = 0; i < 3 * natom; i++)
475 PHPS(i, i) += shift;
476 if (print_level > 1) {
477 print("PHPS");
478 print(PHPS);
479 }
480
481 // Construct new search direction by diagonalizing Hessian and taking
482 // spectral step
483 dx = new_search_direction(g, PHPS);
484 if (print_level > 1)
485 print("dx", dx);
486
487 // Line search
488 double alpha = line_search(molecule, target, dx, e, dx.trace(g), 1.0);
489 if (print_level > 1)
490 print("step", alpha);
491 dx.scale(alpha);
492 if (print_level > 1)
493 print("scaled dx", dx);
494
495 // Take the step
496 Tensor<double> x = molecule.get_all_coords().flat();
497 x += dx;
498 molecule.set_all_coords(x.reshape(natom, 3));
499
500 if (print_level > 1)
501 print("new molecular coords");
502 }
503 // return the optimized molecule
504 return molecule;
505 }
506
507 template <typename targetT>
508 auto optimize_app(Molecule molecule,
509 targetT &target)
510 -> OptimizationResults { ////!!!!!!! pass by value
511 const int natom = molecule.natom();
512
513 // Code structured so it will be straightforward to introduce redundant
514 // internal coordinates
515 OptimizationResults results;
516
517 if (hessian.size() == 0)
518 initialize_hessian(molecule);
519
520 double ep = 0.0; // Previous energy
521 Tensor<double> gp(3 * natom); // Previous gradient
522 Tensor<double> dx(3 * natom); // Current search direction
523 gp = 0.0;
524 dx = 0.0;
525
526 int iter = 0;
527 for (iter = 0; iter < maxiter; iter++) {
528 if (print_level > 0)
529 print("\n\n Geometry optimization iteration", iter, "\n");
530 if (print_level > 0)
531 molecule.print();
532
533 double e;
534 Tensor<double> g;
535
536 target.energy_and_gradient(molecule, e, g);
537
538 // Project out translations and rotations before testing convergence --
539 // the raw gradient carries a spurious net force/torque of the order of
540 // the gradient accuracy, which would keep max-g above gtol forever
541 Tensor<double> P = make_projector(molecule);
542 const Tensor<double> graw = copy(g);
543 g = inner(P, g);
544 // by default, and NOT only at high print levels: this is the gradient
545 // every test below is applied to
546 if (print_level > 0)
547 print_gradient(molecule, graw, g);
548
549 double de = e - ep;
550 double dxmax = dx.absmax();
551 results.max_gradient = g.absmax();
552 MADNESS_CHECK_THROW(madness::is_finite(results.max_gradient),
553 "MolOpt::optimize_app: projected gradient is not finite");
554
555 bool dxconv = (iter > 0) && (dxmax < xtol);
556 bool gconv = results.max_gradient < gtol;
557 bool econv = (iter > 0) && (std::abs(de) < etol);
558 bool converged = econv && dxconv && gconv;
559
560 if (!converged && results.max_gradient < gradient_precision) {
561 if (print_level > 0)
562 print("\nInsufficient precision in gradient to proceed further -- "
563 "forcing convergence\n");
564 converged = true;
565 }
566
567 if (print_level > 0) {
568 const char *tf[] = {"F", "T"};
569 print(" ");
570 printf(
571 " energy delta-e max-dx max-g e dx g\n");
572 printf(" ---------------- --------- --------- --------- --- --- "
573 "---\n");
574 printf(" %15.6f %9.2e %9.2e %9.2e %s %s %s\n", e, de, dxmax,
575 results.max_gradient, tf[econv], tf[dxconv], tf[gconv]);
576 // print(e, de, econv, dxmax, dxconv, dxnorm, gmax, gconv, gnorm,
577 // converged);
578 print(" ");
579 }
580
581 if (converged) {
582 if (print_level > 0)
583 print("\n Geometry optimization converged!\n");
584 if (print_level > 0)
585 molecule.print();
586 break;
587 }
588
589 if (iter > 0) {
590 if ((g - gp).absmax() < 2.0 * gradient_precision) {
591 if (print_level > 0)
592 print(" skipping hessian update due to insufficient precision in "
593 "gradient");
594 } else if (update == "bfgs") {
595 QuasiNewton::hessian_update_bfgs(dx, g - gp, hessian);
596 } else if (update == "sr1") {
597 QuasiNewton::hessian_update_sr1(dx, g - gp, hessian);
598 } else {
599 throw "unknown update";
600 }
601 }
602
603 ep = e;
604 gp = g;
605
606 // Construct the projected and shifted hessian = PHP + shift*(1-P)
607 const double shift = 1000.0; // this value assumed in new_search_dir
608 Tensor<double> PHPS = inner(P, inner(hessian, P)) - shift * P;
609 if (print_level > 1) {
610 print("projector");
611 print(P);
612 }
613 for (int i = 0; i < 3 * natom; i++)
614 PHPS(i, i) += shift;
615 if (print_level > 1) {
616 print("PHPS");
617 print(PHPS);
618 }
619
620 // Construct new search direction by diagonalizing Hessian and taking
621 // spectral step
622 dx = new_search_direction(g, PHPS);
623 if (print_level > 1)
624 print("dx", dx);
625
626 // Line search
627 double alpha = line_search(molecule, target, dx, e, dx.trace(g), 1.0);
628 if (print_level > 1)
629 print("step", alpha);
630 dx.scale(alpha);
631 if (print_level > 1)
632 print("scaled dx", dx);
633
634 // Take the step
635 Tensor<double> x = molecule.get_all_coords().flat();
636 x += dx;
637 molecule.set_all_coords(x.reshape(natom, 3));
638
639 if (print_level > 1)
640 print("new molecular coords");
641 }
642
643 results.final_energy = ep;
644 results.nsteps = iter;
645 results.final_geometry = molecule;
646 // return the optimized molecule
647 return results;
648 }
649};
650} // namespace madness
651#endif // MADNESS_MOLOPT_H
double x
Definition mentity.h:73
double y
Definition mentity.h:73
double z
Definition mentity.h:73
void hessian_update_bfgs(const Tensor< double > &dx, const Tensor< double > &dg)
Definition kain.cc:329
void hessian_update_sr1(const Tensor< double > &s, const Tensor< double > &y)
Definition kain.cc:317
T sum() const
Returns the sum of all elements of the tensor.
Definition tensor.h:1667
Tensor< T > reshape(int ndimnew, const long *d)
Returns new view/tensor reshaping size/number of dimensions to conforming tensor.
Definition tensor.h:1389
Tensor< T > flat()
Returns new view/tensor rehshaping to flat (1-d) tensor.
Definition tensor.h:1560
static const double R
Definition csqrt.cc:46
static double shift
Definition dirac-hatom.cc:19
std::complex< double > inner(const Fcwf &psi, const Fcwf &phi)
Definition fcwf.cc:311
Fcwf copy(Fcwf psi)
Definition fcwf.cc:374
Tensor< T > transpose(const Tensor< T > &t)
Returns a new deep copy of the transpose of the input tensor.
Definition tensor.h:2039
const int maxiter
Definition gygi_soltion.cc:68
static const double v
Definition hatom_sf_dirac.cc:20
#define max(a, b)
Definition lda.h:51
#define MADNESS_CHECK_THROW(condition, msg)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:207
void print(const tensorT &t)
Definition mcpfit.cc:140
Header to declare stuff which has not yet found a home.
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
constexpr bool is_finite(double x) noexcept
Definition misc.h:48
void svd(const Tensor< T > &a, Tensor< T > &U, Tensor< typename Tensor< T >::scalar_type > &s, Tensor< T > &VT)
Compute the singluar value decomposition of an n-by-m matrix using *gesvd.
Definition lapack.cc:739
void print_justified(const char *s, int column, bool underline)
Print a string justified on the left to start at the given column with optional underlining.
Definition print.cc:75
void syev(const Tensor< T > &A, Tensor< T > &V, Tensor< typename Tensor< T >::scalar_type > &e)
Real-symmetric or complex-Hermitian eigenproblem.
Definition lapack.cc:979
@ s
Definition gaussian.h:31
static long abs(long a)
Definition tensor.h:214
static const double c
Definition relops.cc:10
static const double m
Definition relops.cc:9
static const double L
Definition rk.cc:46
static const long k
Definition rk.cc:44
Defines interfaces for optimization and non-linear equation solvers.
static double V(const coordT &r)
Definition tdse.cc:288
Defines and implements most of Tensor.
Prototypes for a partial interface from Tensor to LAPACK.
int P
Definition test_binsorter.cc:9
void e()
Definition test_sig.cc:75
#define N
Definition testconv.cc:37
vector_complex_function_3d update(World &world, const vector_complex_function_3d &psi, vector_complex_function_3d &vpsi, const tensor_real &e, int iter)
Definition testcosine.cc:210
static const double alpha
Definition testcosine.cc:10
double g(const coord_t &r)
Definition testgconv.cc:116
double h(const coord_1d &r)
Definition testgconv.cc:175
static Molecule molecule
Definition testperiodicdft.cc:39
const double a2
Definition vnucso.cc:86
const double a1
Definition vnucso.cc:85
FLOAT target(const FLOAT &x)
Definition y.cc:295