~ubuntu-branches/debian/squeeze/gmsh/squeeze

« back to all changes in this revision

Viewing changes to contrib/Chaco/eigen/get_extval.c

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2009-01-07 16:02:08 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090107160208-vklhtj69br5yw5bh
Tags: 2.2.6.dfsg-2
* debian/control: fixed lintian warning "debhelper-but-no-misc-depends"
* debian/watch: fixed lintian warning
  "debian-watch-file-should-mangle-version"

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This software was developed by Bruce Hendrickson and Robert Leland   *
 
2
 * at Sandia National Laboratories under US Department of Energy        *
 
3
 * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
 
4
 
 
5
#include <math.h>
 
6
#include <stdio.h>
 
7
#include "Gmsh_printf.h"
 
8
 
 
9
/* Finds first extended eigenpair of system corresponding to
 
10
   tridiagonal T using using Rafael's bisection technique. */
 
11
 
 
12
void      get_extval(alpha, beta, j, ritzval, s, eigtol, wnorm_g, sigma, extval, v, work1, work2)
 
13
double   *alpha;        /* j-vector of Lanczos scalars (using elements 1 to j) */
 
14
double   *beta;         /* (j+1)-vector of " " (has 0 element but using 1 to j-1) */
 
15
int       j;            /* number of Lanczos iterations taken */
 
16
double    ritzval;      /* Ritz value */
 
17
double   *s;            /* Ritz vector (length n, re-computed in this routine) */
 
18
double    eigtol;       /* tolerance on eigenpair */
 
19
double    wnorm_g;      /* W-norm of n-vector g, the rhs in the extended eig. problem */
 
20
double    sigma;        /* the norm constraint on the extended eigenvector */
 
21
double   *extval;       /* the extended eigenvalue this routine computes */
 
22
double   *v;            /* the j-vector solving the extended eig problem in T */
 
23
double   *work1;        /* j-vector of workspace */
 
24
double   *work2;        /* j-vector of workspace */
 
25
{
 
26
    extern int DEBUG_EVECS;     /* debug flag for eigen computation */
 
27
    double    lambda_low;       /* lower bound on extended eval */
 
28
    double    lambda_high;      /* upper bound on extended eval */
 
29
    double    tol;              /* bisection tolerance */
 
30
    double    norm_v;           /* norm of the extended T eigenvector v */
 
31
    double    lambda;           /* the parameter that iterates to extval */
 
32
    int       cnt;              /* debug iteration counter */
 
33
    double    diff;             /* distance between lambda limits */
 
34
    double    norm(), Tevec();
 
35
    void      tri_solve(), cpvec();
 
36
 
 
37
    /* Compute the Ritz vector */
 
38
    Tevec(alpha, beta - 1, j, ritzval, s);
 
39
 
 
40
    /* Shouldn't happen, but just in case ... */
 
41
    if (wnorm_g == 0.0) {
 
42
        *extval = ritzval;
 
43
        cpvec(v, 1, j, s);
 
44
        if (DEBUG_EVECS > 0) {
 
45
            printf("Degenerate extended eigenvector problem (g = 0).\n");
 
46
        }
 
47
        return;
 
48
        /* ... not really an extended eigenproblem; just return Ritz pair */
 
49
    }
 
50
 
 
51
    /* Set up the bisection parameters */
 
52
    lambda_low = ritzval - wnorm_g / sigma;
 
53
    lambda_high = ritzval - (wnorm_g / sigma) * s[1];
 
54
    lambda = 0.5 * (lambda_low + lambda_high);
 
55
    tol = eigtol * eigtol * (1 + fabs(lambda_low) + fabs(lambda_high));
 
56
 
 
57
    if (DEBUG_EVECS > 2) {
 
58
        printf("Computing extended eigenpairs of T\n");
 
59
        printf("  target norm_v (= sigma) %g\n", sigma);
 
60
        printf("  bisection tolerance %g\n", tol);
 
61
    }
 
62
    if (DEBUG_EVECS > 3) {
 
63
        printf("  lambda iterates to the extended eigenvalue\n");
 
64
        printf("         lambda_low           lambda            lambda_high      norm_v\n");
 
65
    }
 
66
 
 
67
    /* Bisection loop - iterate until norm constraint is satisfied */
 
68
    cnt = 1;
 
69
    diff = 2*tol;
 
70
    while (diff > tol) {
 
71
        lambda = 0.5 * (lambda_low + lambda_high);
 
72
        tri_solve(alpha, beta, j, lambda, v, wnorm_g, work1, work2);
 
73
        norm_v = norm(v, 1, j);
 
74
        if (DEBUG_EVECS > 3) {
 
75
            printf("%2i   %18.16f  %18.16f  %18.16f  %g\n",
 
76
                   cnt++, lambda_low, lambda, lambda_high, norm_v);
 
77
        }
 
78
        if (norm_v <= sigma)
 
79
            lambda_low = lambda;
 
80
        if (norm_v >= sigma)
 
81
            lambda_high = lambda;
 
82
        diff = lambda_high - lambda_low;
 
83
    }
 
84
 
 
85
    /* Return the extended eigenvalue (eigvec is automatically returned) */
 
86
    *extval = lambda;
 
87
}