This file is indexed.

/usr/include/deal.II/lac/arpack_solver.h is in libdeal.ii-dev 8.1.0-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
// ---------------------------------------------------------------------
// $Id: arpack_solver.h 31932 2013-12-08 02:15:54Z heister $
//
// Copyright (C) 2010 - 2013 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------

#ifndef __deal2__arpack_solver_h
#define __deal2__arpack_solver_h

#include <deal.II/base/config.h>
#include <deal.II/base/smartpointer.h>
#include <deal.II/lac/solver_control.h>

#include <cstring>


#ifdef DEAL_II_WITH_ARPACK

DEAL_II_NAMESPACE_OPEN


extern "C" void dnaupd_(int *ido, char *bmat, const unsigned int *n, char *which,
                        const unsigned int *nev, const double *tol, double *resid, int *ncv,
                        double *v, int *ldv, int *iparam, int *ipntr,
                        double *workd, double *workl, int *lworkl,
                        int *info);

extern "C" void dneupd_(int *rvec, char *howmany, int *select, double *d,
                        double *di, double *z, int *ldz, double *sigmar,
                        double *sigmai, double *workev, char *bmat,const unsigned int *n, char *which,
                        const unsigned int *nev, const double *tol, double *resid, int *ncv,
                        double *v, int *ldv, int *iparam, int *ipntr,
                        double *workd, double *workl, int *lworkl, int *info);

/**
 * Interface for using ARPACK. ARPACK is a collection of Fortran77 subroutines
 * designed to solve large scale eigenvalue problems.  Here we interface to
 * the routines <code>dneupd</code> and <code>dnaupd</code> of ARPACK.  The
 * package is designed to compute a few eigenvalues and corresponding
 * eigenvectors of a general n by n matrix A. It is most appropriate for large
 * sparse matrices A.
 *
 * In this class we make use of the method applied to the
 * generalized eigenspectrum problem $(A-\lambda B)x=0$, for
 * $x\neq0$; where $A$ is a system matrix, $B$ is a mass matrix,
 * and $\lambda, x$ are a set of eigenvalues and eigenvectors
 * respectively.
 *
 * The ArpackSolver can be used in application codes in the
 * following way:
 @code
  SolverControl solver_control (1000, 1e-9);
  ArpackSolver (solver_control);
  system.solve (A, B, P, lambda, x, size_of_spectrum);
 @endcode
 * for the generalized eigenvalue problem $Ax=B\lambda x$, where
 * the variable <code>size_of_spectrum</code>
 * tells ARPACK the number of eigenvector/eigenvalue pairs to
 * solve for. Here, <code>lambda</code> is a vector that will contain
 * the eigenvalues computed, <code>x</code> a vector that will
 * contain the eigenvectors computed, and <code>P</code> is
 * a preconditioner for the matrix <code>A</code>.
 *
 * Through the AdditionalData the user can specify some of the
 * parameters to be set.
 *
 * For further information on how the ARPACK routines <code>dneupd</code> and
 * <code>dnaupd</code> work and also how to set the parameters appropriately
 * please take a look into the ARPACK manual.
 *
 * @author Baerbel Janssen, Agnieszka Miedlar, 2010.
 */
class ArpackSolver : public Subscriptor
{
public:
  /**
   * Declare the type for container size.
   */
  typedef types::global_dof_index size_type;


  /**
   * An enum that lists the possible
   * choices for which eigenvalues to
   * compute in the solve() function.
   */
  enum WhichEigenvalues
  {
    algebraically_largest,
    algebraically_smallest,
    largest_magnitude,
    smallest_magnitude,
    largest_real_part,
    smallest_real_part,
    largest_imaginary_part,
    smallest_imaginary_part,
    both_ends
  };

  /**
   * Standardized data struct to pipe
   * additional data to the solver,
   * should it be needed.
   */
  struct AdditionalData
  {
    const unsigned int number_of_arnoldi_vectors;
    const WhichEigenvalues eigenvalue_of_interest;
    AdditionalData(
      const unsigned int number_of_arnoldi_vectors = 15,
      const WhichEigenvalues eigenvalue_of_interest = largest_magnitude);
  };

  /**
   * Access to the object that
   * controls convergence.
   */
  SolverControl &control () const;

  /**
   * Constructor.
   */
  ArpackSolver(SolverControl &control,
               const AdditionalData &data = AdditionalData());

  /**
   * Solve the generalized eigensprectrum
   * problem $A x=\lambda B x$ by calling
   * the <code>dneupd</code> and <code>dnaupd</code>
   * functions of ARPACK.
   */
  template <typename VECTOR, typename MATRIX1,
            typename MATRIX2, typename INVERSE>
  void solve(
    const MATRIX1 &A,
    const MATRIX2 &B,
    const INVERSE &inverse,
    std::vector<std::complex<double> > &eigenvalues,
    std::vector<VECTOR> &eigenvectors,
    const unsigned int n_eigenvalues);

protected:

  /**
   * Reference to the object that
   * controls convergence of the
   * iterative solver.
   */
  SolverControl &solver_control;

  /**
   * Store a copy of the flags for
   * this particular solver.
   */
  const AdditionalData additional_data;

private:

  /**
   * Exceptions.
   */
  DeclException2 (ExcInvalidNumberofEigenvalues, int, int,
                  << "Number of wanted eigenvalues " << arg1
                  << " is larger that the size of the matrix " << arg2);

  DeclException2 (ExcInvalidNumberofArnoldiVectors, int, int,
                  << "Number of Arnoldi vectors " << arg1
                  << " is larger that the size of the matrix " << arg2);

  DeclException2 (ExcSmallNumberofArnoldiVectors, int, int,
                  << "Number of Arnoldi vectors " << arg1
                  << " is too small to obtain " << arg2
                  << " eigenvalues");

  DeclException1 (ExcArpackIdo, int, << "This ido " << arg1
                  << " is not supported. Check documentation of ARPACK");

  DeclException1 (ExcArpackMode, int, << "This mode " << arg1
                  << " is not supported. Check documentation of ARPACK");

  DeclException1 (ExcArpackInfodsaupd, int,
                  << "Error with dsaupd, info " << arg1
                  << ". Check documentation of ARPACK");

  DeclException1 (ExcArpackInfodneupd, int,
                  << "Error with dneupd, info " << arg1
                  << ". Check documentation of ARPACK");

  DeclException1 (ExcArpackInfoMaxIt, int,
                  << "Maximum number " << arg1
                  << " of iterations reached.");

  DeclException1 (ExcArpackNoShifts, int,
                  << "No shifts could be applied during implicit"
                  << " Arnoldi update, try increasing the number of"
                  << " Arnoldi vectors.");
};


inline
ArpackSolver::AdditionalData::
AdditionalData (const unsigned int number_of_arnoldi_vectors,
                const WhichEigenvalues eigenvalue_of_interest)
  :
  number_of_arnoldi_vectors(number_of_arnoldi_vectors),
  eigenvalue_of_interest(eigenvalue_of_interest)
{}


inline
ArpackSolver::ArpackSolver (SolverControl &control,
                            const AdditionalData &data)
  :
  solver_control (control),
  additional_data (data)

{}


template <typename VECTOR, typename MATRIX1,
          typename MATRIX2, typename INVERSE>
inline
void ArpackSolver::solve (
  const MATRIX1 &system_matrix,
  const MATRIX2 &mass_matrix,
  const INVERSE &inverse,
  std::vector<std::complex<double> > &eigenvalues,
  std::vector<VECTOR> &eigenvectors,
  const unsigned int n_eigenvalues)
{
  //inside the routines of ARPACK the
  //values change magically, so store
  //them here

  const unsigned int n = system_matrix.m();
  const unsigned int n_inside_arpack = system_matrix.m();

  /*
  if(n < 0 || nev <0 || p < 0 || maxit < 0 )
       std:cout << "All input parameters have to be positive.\n";
       */
  Assert (n_eigenvalues < n,
          ExcInvalidNumberofEigenvalues(n_eigenvalues, n));

  Assert (additional_data.number_of_arnoldi_vectors < n,
          ExcInvalidNumberofArnoldiVectors(
            additional_data.number_of_arnoldi_vectors, n));

  Assert (additional_data.number_of_arnoldi_vectors > 2*n_eigenvalues+1,
          ExcSmallNumberofArnoldiVectors(
            additional_data.number_of_arnoldi_vectors, n_eigenvalues));
  // ARPACK mode for dnaupd, here only mode 3
  int mode = 3;

  // reverse communication parameter
  int ido = 0;

  /**
   * 'G' generalized eigenvalue problem
   * 'I' standard eigenvalue problem
   */
  char bmat[2] = "G";

  /** Specify the eigenvalues of interest,
   *  possible parameters
   *  "LA" algebraically largest
   *  "SA" algebraically smallest
   *  "LM" largest magnitude
   *  "SM" smallest magnitude
   *  "LR" largest real part
   *  "SR" smallest real part
   *  "LI" largest imaginary part
   *  "SI" smallest imaginary part
   *  "BE" both ends of spectrum simultaneous
   */
  char which[3];
  switch (additional_data.eigenvalue_of_interest)
    {
    case algebraically_largest:
      std::strcpy (which, "LA");
      break;
    case algebraically_smallest:
      std::strcpy (which, "SA");
      break;
    case largest_magnitude:
      std::strcpy (which, "LM");
      break;
    case smallest_magnitude:
      std::strcpy (which, "SM");
      break;
    case largest_real_part:
      std::strcpy (which, "LR");
      break;
    case smallest_real_part:
      std::strcpy (which, "SR");
      break;
    case largest_imaginary_part:
      std::strcpy (which, "LI");
      break;
    case smallest_imaginary_part:
      std::strcpy (which, "SI");
      break;
    case both_ends:
      std::strcpy (which, "BE");
      break;
    }

  // tolerance for ARPACK
  const double tol = control().tolerance();

  // if the starting vector is used it has to be in resid
  std::vector<double> resid(n, 1.);

  // number of Arnoldi basis vectors specified
  // in additional_data
  int ncv = additional_data.number_of_arnoldi_vectors;

  int ldv = n;
  std::vector<double> v (ldv*ncv, 0.0);

  //information to the routines
  std::vector<int> iparam (11, 0);

  iparam[0] = 1;        // shift strategy

  // maximum number of iterations
  iparam[2] = control().max_steps();

  /** Sets the mode of dsaupd.
   *  1 is exact shifting,
   *  2 is user-supplied shifts,
   *  3 is shift-invert mode,
   *  4 is buckling mode,
   *  5 is Cayley mode.
   */

  iparam[6] = mode;
  std::vector<int> ipntr (14, 0);

  // work arrays for ARPACK
  double *workd;
  workd = new double[3*n];

  for (unsigned int i=0; i<3*n; ++i)
    workd[i] = 0.0;

  int lworkl = 3*ncv*(ncv + 6);
  std::vector<double> workl (lworkl, 0.);
  //information out of the iteration
  int info = 1;

  const unsigned int nev = n_eigenvalues;
  while (ido != 99)
    {
      // call of ARPACK dnaupd routine
      dnaupd_(&ido, bmat, &n_inside_arpack, which, &nev, &tol,
              &resid[0], &ncv, &v[0], &ldv, &iparam[0], &ipntr[0],
              workd, &workl[0], &lworkl, &info);

      if (ido == 99)
        break;

      switch (mode)
        {
        case 3:
        {
          switch (ido)
            {
            case -1:
            {

              VECTOR src,dst,tmp;
              src.reinit(eigenvectors[0]);
              dst.reinit(src);
              tmp.reinit(src);


              for (size_type i=0; i<src.size(); ++i)
                src(i) = *(workd+ipntr[0]-1+i);

              // multiplication with mass matrix M
              mass_matrix.vmult(tmp, src);
              // solving linear system
              inverse.vmult(dst,tmp);

              for (size_type i=0; i<dst.size(); ++i)
                *(workd+ipntr[1]-1+i) = dst(i);
            }
            break;

            case  1:
            {

              VECTOR src,dst,tmp, tmp2;
              src.reinit(eigenvectors[0]);
              dst.reinit(src);
              tmp.reinit(src);
              tmp2.reinit(src);

              for (size_type i=0; i<src.size(); ++i)
                {
                  src(i) = *(workd+ipntr[2]-1+i);
                  tmp(i) = *(workd+ipntr[0]-1+i);
                }
              // solving linear system
              inverse.vmult(dst,src);

              for (size_type i=0; i<dst.size(); ++i)
                *(workd+ipntr[1]-1+i) = dst(i);
            }
            break;

            case  2:
            {

              VECTOR src,dst;
              src.reinit(eigenvectors[0]);
              dst.reinit(src);

              for (size_type i=0; i<src.size(); ++i)
                src(i) = *(workd+ipntr[0]-1+i);

              // Multiplication with mass matrix M
              mass_matrix.vmult(dst, src);

              for (size_type i=0; i<dst.size(); ++i)
                *(workd+ipntr[1]-1+i) = dst(i);

            }
            break;

            default:
              Assert (false, ExcArpackIdo(ido));
              break;
            }
        }
        break;
        default:
          Assert (false, ExcArpackMode(mode));
          break;
        }
    }

  if (info<0)
    {
      Assert (false, ExcArpackInfodsaupd(info));
    }
  else
    {
      /** 1 - compute eigenvectors,
       *  0 - only eigenvalues
       */
      int rvec = 1;

      // which eigenvectors
      char howmany[4] = "All";

      std::vector<int> select (ncv, 0);

      int ldz = n;

      std::vector<double> z (ldz*ncv, 0.);

      double sigmar = 0.0; // real part of the shift
      double sigmai = 0.0; // imaginary part of the shift

      int lworkev = 3*ncv;
      std::vector<double> workev (lworkev, 0.);

      std::vector<double> eigenvalues_real (n_eigenvalues, 0.);
      std::vector<double> eigenvalues_im (n_eigenvalues, 0.);

      // call of ARPACK dneupd routine
      dneupd_(&rvec, howmany, &select[0], &eigenvalues_real[0],
              &eigenvalues_im[0], &z[0], &ldz, &sigmar, &sigmai,
              &workev[0], bmat, &n_inside_arpack, which, &nev, &tol,
              &resid[0], &ncv, &v[0], &ldv,
              &iparam[0], &ipntr[0], workd, &workl[0], &lworkl, &info);

      if (info == 1)
        {
          Assert (false, ExcArpackInfoMaxIt(control().max_steps()));
        }
      else if (info == 3)
        {
          Assert (false, ExcArpackNoShifts(1));
        }
      else if (info!=0)
        {
          Assert (false, ExcArpackInfodneupd(info));
        }

      for (size_type i=0; i<eigenvectors.size(); ++i)
        for (unsigned int j=0; j<n; ++j)
          eigenvectors[i](j) = v[i*n+j];

      delete[] workd;

      AssertDimension (eigenvalues.size(), eigenvalues_real.size());
      AssertDimension (eigenvalues.size(), eigenvalues_im.size());

      for (size_type i=0; i<eigenvalues.size(); ++i)
        eigenvalues[i] = std::complex<double> (eigenvalues_real[i],
                                               eigenvalues_im[i]);
    }
}


inline
SolverControl &ArpackSolver::control () const
{
  return solver_control;
}

DEAL_II_NAMESPACE_CLOSE


#endif
#endif