| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020, 2023 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "defs.h" // for FALSE, TRUE |
| 10 |
#include "structs.h" |
| 11 |
#include <stdio.h> // for fprintf, NULL, FILE, stdout |
| 12 |
|
| 13 |
/* Post various warnings about computation */ |
| 14 |
void warnings(double *workn, /* work vector (1..n) */ |
| 15 |
struct vtx_data **A, /* graph */ |
| 16 |
double **y, /* eigenvectors */ |
| 17 |
int n, /* number of vtxs */ |
| 18 |
double *lambda, /* ritz approximation to eigenvals of A */ |
| 19 |
double *vwsqrt, /* square roots of vertex weights */ |
| 20 |
double *Ares, /* how well Lanczos calc. eigpair lambda,y */ |
| 21 |
double *bound, /* on ritz pair approximations to eig pairs of A */ |
| 22 |
int *index, /* the Ritz index of an eigenpair */ |
| 23 |
int d, /* problem dimension = number of eigvecs to find */ |
| 24 |
int j, /* number of Lanczos iterations used */ |
| 25 |
int maxj, /* maximum number of Lanczos iterations */ |
| 26 |
double Sres_max, /* Max value of Sres */ |
| 27 |
double eigtol, /* tolerance on eigenvectors */ |
| 28 |
double *u, /* Lanczos vector; here used as workspace */ |
| 29 |
double Anorm, /* Gershgorin bound on eigenvalue */ |
| 30 |
FILE *out_file /* output file */ |
| 31 |
) |
| 32 |
{ |
| 33 |
extern int DEBUG_EVECS; /* print debugging output? */ |
| 34 |
extern int WARNING_EVECS; /* print warning messages? */ |
| 35 |
extern double WARNING_ORTHTOL; /* Warning: modest loss of orthogonality */ |
| 36 |
extern double WARNING_MISTOL; /* Warning: serious loss of orthogonality */ |
| 37 |
extern double SRESTOL; /* limit on relative residual tol for evec of T */ |
| 38 |
extern int LANCZOS_CONVERGENCE_MODE; /* type of Lanczos convergence test */ |
| 39 |
extern int SRES_SWITCHES; /* # switches to backup routine for computing s */ |
| 40 |
int warning1 = 0; /* warning1 cond. (eigtol not achieved) true? */ |
| 41 |
int warning2 = 0; /* warning2 cond. (premature orth. loss) true? */ |
| 42 |
int warning3 = 0; /* warning3 cond. (suspected misconvergence) true? */ |
| 43 |
int i; /* loop index */ |
| 44 |
int hosed; /* flag for serious Lanczos problems */ |
| 45 |
int pass; /* which time through we are on */ |
| 46 |
FILE *outfile = NULL; /* set to output file or stdout */ |
| 47 |
|
| 48 |
hosed = FALSE; |
| 49 |
for (pass = 1; pass <= 2; pass++) { |
| 50 |
|
| 51 |
if (pass == 1) { |
| 52 |
outfile = stdout; |
| 53 |
} |
| 54 |
if (pass == 2) { |
| 55 |
if (out_file != NULL) { |
| 56 |
outfile = out_file; |
| 57 |
} |
| 58 |
else if (hosed) { |
| 59 |
bail(NULL, 1); |
| 60 |
} |
| 61 |
else { |
| 62 |
return; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
if (DEBUG_EVECS > 0 || WARNING_EVECS > 0) { |
| 67 |
if (LANCZOS_CONVERGENCE_MODE == 1) { |
| 68 |
fprintf(outfile, "Note about warnings: in partition convergence monitoring mode.\n"); |
| 69 |
} |
| 70 |
for (i = 1; i <= d; i++) { |
| 71 |
Ares[i] = checkeig(workn, A, y[i], n, lambda[i], vwsqrt, u); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
if (DEBUG_EVECS > 0) { |
| 76 |
if (pass == 1) { |
| 77 |
fprintf(outfile, "Lanczos itns. = %d\n", j); |
| 78 |
} |
| 79 |
fprintf(outfile, |
| 80 |
" lambda Ares est. Ares index\n"); |
| 81 |
for (i = 1; i <= d; i++) { |
| 82 |
fprintf(outfile, "%2d.", i); |
| 83 |
doubleout_file(outfile, lambda[i], 1); |
| 84 |
doubleout_file(outfile, bound[i], 1); |
| 85 |
doubleout_file(outfile, Ares[i], 1); |
| 86 |
fprintf(outfile, " %3d\n", index[i]); |
| 87 |
} |
| 88 |
fprintf(outfile, "\n"); |
| 89 |
} |
| 90 |
|
| 91 |
if (WARNING_EVECS > 0) { |
| 92 |
warning1 = FALSE; |
| 93 |
warning2 = FALSE; |
| 94 |
warning3 = FALSE; |
| 95 |
for (i = 1; i <= d; i++) { |
| 96 |
if (Ares[i] > eigtol) { |
| 97 |
warning1 = TRUE; |
| 98 |
} |
| 99 |
if (Ares[i] > WARNING_ORTHTOL * bound[i] && Ares[i] > .01 * eigtol) { |
| 100 |
warning2 = TRUE; |
| 101 |
} |
| 102 |
if (Ares[i] > WARNING_MISTOL * bound[i] && Ares[i] > .01 * eigtol) { |
| 103 |
warning3 = TRUE; |
| 104 |
} |
| 105 |
} |
| 106 |
if (j == maxj) { |
| 107 |
fprintf(outfile, "WARNING: Maximum number of Lanczos iterations reached.\n"); |
| 108 |
} |
| 109 |
if (warning2 && !warning3) { |
| 110 |
fprintf(outfile, "WARNING: Minor loss of orthogonality (Ares/est. > %g).\n", |
| 111 |
WARNING_ORTHTOL); |
| 112 |
} |
| 113 |
if (warning3) { |
| 114 |
fprintf(outfile, "WARNING: Substantial loss of orthogonality (Ares/est. > %g).\n", |
| 115 |
WARNING_MISTOL); |
| 116 |
} |
| 117 |
if (warning1) { |
| 118 |
fprintf(outfile, "WARNING: Eigen pair tolerance (%g) not achieved.\n", eigtol); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
if (WARNING_EVECS > 1) { |
| 123 |
if (warning1 || warning2 || warning3) { |
| 124 |
if (DEBUG_EVECS <= 0) { |
| 125 |
fprintf(outfile, |
| 126 |
" lambda Ares est. Ares index\n"); |
| 127 |
for (i = 1; i <= d; i++) { |
| 128 |
fprintf(outfile, "%2d.", i); |
| 129 |
doubleout_file(outfile, lambda[i], 1); |
| 130 |
doubleout_file(outfile, bound[i], 1); |
| 131 |
doubleout_file(outfile, Ares[i], 1); |
| 132 |
fprintf(outfile, " %3d\n", index[i]); |
| 133 |
} |
| 134 |
} |
| 135 |
/* otherwise gets printed above */ |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
if (warning1 || warning2 || warning3 || WARNING_EVECS > 2) { |
| 140 |
if (Sres_max > SRESTOL) { |
| 141 |
fprintf(outfile, "WARNING: Maximum eigen residual of T (%g) exceeds SRESTOL.\n", Sres_max); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
if (WARNING_EVECS > 2) { |
| 146 |
if (SRES_SWITCHES > 0) { |
| 147 |
fprintf(outfile, "WARNING: Switched routine for computing evec of T %d times.\n", |
| 148 |
SRES_SWITCHES); |
| 149 |
SRES_SWITCHES = 0; |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
/* Put the best face on things ... */ |
| 154 |
for (i = 1; i <= d; i++) { |
| 155 |
if (lambda[i] < 0 || lambda[i] > Anorm + eigtol) { |
| 156 |
hosed = TRUE; |
| 157 |
} |
| 158 |
} |
| 159 |
if (hosed) { |
| 160 |
fprintf(outfile, "ERROR: Sorry, out-of-bounds eigenvalue indicates serious breakdown.\n"); |
| 161 |
fprintf(outfile, " Try different parameters or another eigensolver.\n"); |
| 162 |
if (pass == 2) { |
| 163 |
bail(NULL, 1); |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
} /* Pass loop */ |
| 168 |
} |