This file is indexed.

/usr/include/deal.II/lac/matrix_lib.h is in libdeal.ii-dev 8.1.0-6ubuntu1.

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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
// ---------------------------------------------------------------------
// $Id: matrix_lib.h 30036 2013-07-18 16:55:32Z maier $
//
// Copyright (C) 2002 - 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__matrix_lib_h
#define __deal2__matrix_lib_h

#include <deal.II/base/subscriptor.h>
#include <deal.II/lac/vector_memory.h>
#include <deal.II/lac/pointer_matrix.h>
#include <deal.II/lac/solver_richardson.h>

DEAL_II_NAMESPACE_OPEN

template<typename number> class Vector;
template<typename number> class BlockVector;
template<typename number> class SparseMatrix;

/*! @addtogroup Matrix2
 *@{
 */


/**
 * Poor man's matrix product of two quadratic matrices. Stores two
 * quadratic matrices #m1 and #m2 of arbitrary types and implements
 * matrix-vector multiplications for the product
 * <i>M<sub>1</sub>M<sub>2</sub></i> by performing multiplication with
 * both factors consecutively.
 *
 * Here an example multiplying two different FullMatrix objects:
 * @include product_matrix.cc
 *
 * @author Guido Kanschat, 2000, 2001, 2002, 2005
 */
template<class VECTOR>
class ProductMatrix : public PointerMatrixBase<VECTOR>
{
public:
  /**
   * Standard constructor. Matrices
   * and the memory pool must be
   * added later using
   * initialize().
   */
  ProductMatrix();

  /**
   * Constructor only assigning the
   * memory pool. Matrices must be
   * added by reinit() later.
   */
  ProductMatrix(VectorMemory<VECTOR> &mem);

  /**
   * Constructor.  Additionally to
   * the two constituting matrices, a
   * memory pool for the auxiliary
   * vector must be provided.
   */
  template <class MATRIX1, class MATRIX2>
  ProductMatrix(const MATRIX1 &m1,
                const MATRIX2 &m2,
                VectorMemory<VECTOR> &mem);

  /**
   * Change the matrices.
   */
  template <class MATRIX1, class MATRIX2>
  void reinit(const MATRIX1 &m1, const MATRIX2 &m2);

  /**
   * Change the matrices and memory pool.
   */
  template <class MATRIX1, class MATRIX2>
  void initialize(const MATRIX1 &m1, const MATRIX2 &m2,
                  VectorMemory<VECTOR> &mem);

  /**
   * Destructor.
   */
  ~ProductMatrix();

  // Doc in PointerMatrixBase
  void clear();

  /**
   * Matrix-vector product <i>w =
   * m1 * m2 * v</i>.
   */
  virtual void vmult (VECTOR       &w,
                      const VECTOR &v) const;

  /**
   * Tranposed matrix-vector
   * product <i>w = m2<sup>T</sup> *
   * m1<sup>T</sup> * v</i>.
   */
  virtual void Tvmult (VECTOR       &w,
                       const VECTOR &v) const;

  /**
   * Adding matrix-vector product
   * <i>w += m1 * m2 * v</i>
   */
  virtual void vmult_add (VECTOR       &w,
                          const VECTOR &v) const;

  /**
   * Adding, tranposed
   * matrix-vector product <i>w +=
   * m2<sup>T</sup> *
   * m1<sup>T</sup> * v</i>.
   */
  virtual void Tvmult_add (VECTOR       &w,
                           const VECTOR &v) const;

private:
  /**
   * The left matrix of the product.
   */
  PointerMatrixBase<VECTOR> *m1;

  /**
   * The right matrix of the product.
   */
  PointerMatrixBase<VECTOR> *m2;

  /**
   * Memory for auxiliary vector.
   */
  SmartPointer<VectorMemory<VECTOR>,ProductMatrix<VECTOR> > mem;
  /**
   * Return some kind of
   * identifier.
   */
  virtual const void *get() const;
};


/**
 * A matrix that is the scaled version of another matrix.
 *
 * Matrix-vector products of this matrix are composed of those of the
 * original matrix and scaling by a constant factor.
 *
 * @author Guido Kanschat, 2007
 */
template<class VECTOR>
class ScaledMatrix : public Subscriptor
{
public:
  /**
   * Constructor leaving an
   * uninitialized object.
   */
  ScaledMatrix ();
  /**
   * Constructor with initialization.
   */
  template <class MATRIX>
  ScaledMatrix (const MATRIX &M, const double factor);

  /**
   * Destructor
   */
  ~ScaledMatrix ();
  /**
   * Initialize for use with a new
   * matrix and factor.
   */
  template <class MATRIX>
  void initialize (const MATRIX &M, const double factor);

  /**
   * Delete internal matrix pointer.
   */
  void clear ();

  /**
   * Matrix-vector product.
   */
  void vmult (VECTOR &w, const VECTOR &v) const;

  /**
   * Tranposed matrix-vector
   * product.
   */
  void Tvmult (VECTOR &w, const VECTOR &v) const;

private:
  /**
   * The matrix.
   */
  PointerMatrixBase<VECTOR> *m;
  /**
   * The scaling factor;
   */
  double factor;
};



/**
 * Poor man's matrix product of two sparse matrices. Stores two
 * matrices #m1 and #m2 of arbitrary type SparseMatrix and implements
 * matrix-vector multiplications for the product
 * <i>M<sub>1</sub>M<sub>2</sub></i> by performing multiplication with
 * both factors consecutively.
 *
 * The documentation of ProductMatrix applies with exception that
 * these matrices here may be rectangular.
 *
 * @author Guido Kanschat, 2000, 2001, 2002, 2005
 */
template<typename number, typename vector_number>
class ProductSparseMatrix : public PointerMatrixBase<Vector<vector_number> >
{
public:
  /**
   * Define the type of matrices used.
   */
  typedef SparseMatrix<number> MatrixType;

  /**
   * Define the type of vectors we
   * plly this matrix to.
   */
  typedef Vector<vector_number> VectorType;

  /**
   * Constructor.  Additionally to
   * the two constituting matrices, a
   * memory pool for the auxiliary
   * vector must be provided.
   */
  ProductSparseMatrix(const MatrixType &m1,
                      const MatrixType &m2,
                      VectorMemory<VectorType> &mem);

  /**
   * Constructor leaving an
   * unitialized
   * matrix. initialize() must be
   * called, before the matrix can
   * be used.
   */
  ProductSparseMatrix();

  void initialize(const MatrixType &m1,
                  const MatrixType &m2,
                  VectorMemory<VectorType> &mem);

  // Doc in PointerMatrixBase
  void clear();

  /**
   * Matrix-vector product <i>w =
   * m1 * m2 * v</i>.
   */
  virtual void vmult (VectorType       &w,
                      const VectorType &v) const;

  /**
   * Tranposed matrix-vector
   * product <i>w = m2<sup>T</sup> *
   * m1<sup>T</sup> * v</i>.
   */
  virtual void Tvmult (VectorType       &w,
                       const VectorType &v) const;

  /**
   * Adding matrix-vector product
   * <i>w += m1 * m2 * v</i>
   */
  virtual void vmult_add (VectorType       &w,
                          const VectorType &v) const;

  /**
   * Adding, tranposed
   * matrix-vector product <i>w +=
   * m2<sup>T</sup> *
   * m1<sup>T</sup> * v</i>.
   */
  virtual void Tvmult_add (VectorType       &w,
                           const VectorType &v) const;

private:
  /**
   * The left matrix of the product.
   */
  SmartPointer<const MatrixType,ProductSparseMatrix<number,vector_number> > m1;

  /**
   * The right matrix of the product.
   */
  SmartPointer<const MatrixType,ProductSparseMatrix<number,vector_number> > m2;

  /**
   * Memory for auxiliary vector.
   */
  SmartPointer<VectorMemory<VectorType>,ProductSparseMatrix<number,vector_number>  > mem;
  /**
   * Return some kind of
   * identifier.
   */
  virtual const void *get() const;
};


/**
 * Mean value filter.  The vmult() functions of this matrix filter
 * out mean values of the vector.  If the vector is of type
 * BlockVector, then an additional parameter selects a single
 * component for this operation.
 *
 * @author Guido Kanschat, 2002, 2003
 */
class MeanValueFilter : public Subscriptor
{
public:
  /**
   * Declare type for container size.
   */
  typedef types::global_dof_index size_type;

  /**
   * Constructor, optionally
   * selecting a component.
   */
  MeanValueFilter(size_type component = numbers::invalid_size_type);

  /**
   * Subtract mean value from @p v.
   */
  template <typename number>
  void filter (Vector<number> &v) const;

  /**
   * Subtract mean value from @p v.
   */
  template <typename number>
  void filter (BlockVector<number> &v) const;

  /**
   * Return the source vector with
   * subtracted mean value.
   */
  template <typename number>
  void vmult (Vector<number> &dst,
              const Vector<number> &src) const;

  /**
   * Add source vector with
   * subtracted mean value to dest.
   */
  template <typename number>
  void vmult_add (Vector<number> &dst,
                  const Vector<number> &src) const;

  /**
   * Return the source vector with
   * subtracted mean value in
   * selected component.
   */
  template <typename number>
  void vmult (BlockVector<number> &dst,
              const BlockVector<number> &src) const;

  /**
   * Add a soruce to dest, where
   * the mean value in the selected
   * component is subtracted.
   */
  template <typename number>
  void vmult_add (BlockVector<number> &dst,
                  const BlockVector<number> &src) const;


  /**
   * Not implemented.
   */
  template <typename VECTOR>
  void Tvmult(VECTOR &, const VECTOR &) const;

  /**
   * Not implemented.
   */
  template <typename VECTOR>
  void Tvmult_add(VECTOR &, const VECTOR &) const;

private:
  /**
   * Component for filtering block vectors.
   */
  size_type component;
};



/**
 * Inverse matrix computed approximately by using the SolverRichardson
 * iterative solver. In particular, the function
 * SolverRichardson::Tsolve() allows for the implementation of
 * transpose matrix vector products.
 *
 * The functions vmult() and Tvmult() appoximate the inverse
 * iteratively starting with the vector <tt>dst</tt>. Functions
 * vmult_add() and Tvmult_add() start the iteration with a zero
 * vector.
 *
 * @note Instantiations for this template are provided for <tt>@<float@> and
 * @<double@></tt>; others can be generated in application programs (see the
 * section on @ref Instantiations in the manual).
 *
 * @author Guido Kanschat, 2005
 */
template<class VECTOR>
class InverseMatrixRichardson : public Subscriptor
{
public:
  /**
   * Constructor, initializing the
   * solver with a control and
   * memory object. The inverted
   * matrix and the preconditioner
   * are added in initialize().
   */
  InverseMatrixRichardson (SolverControl &control,
                           VectorMemory<VECTOR> &mem);
  /**
   * Since we use two pointers, we
   * must implement a destructor.
   */
  ~InverseMatrixRichardson();

  /**
   * Initialization
   * function. Provide a solver
   * object, a matrix, and another
   * preconditioner for this.
   */
  template <class MATRIX, class PRECONDITION>
  void initialize (const MATRIX &,
                   const PRECONDITION &);

  /**
   * Access to the SolverControl
   * object used by the solver.
   */
  SolverControl &control() const;
  /**
   * Execute solver.
   */
  void vmult (VECTOR &, const VECTOR &) const;

  /**
   * Execute solver.
   */
  void vmult_add (VECTOR &, const VECTOR &) const;

  /**
   * Execute transpose solver.
   */
  void Tvmult (VECTOR &, const VECTOR &) const;

  /**
   * Execute transpose solver.
   */
  void Tvmult_add (VECTOR &, const VECTOR &) const;

private:
  /**
   * A reference to the provided
   * VectorMemory object.
   */
  VectorMemory<VECTOR> &mem;

  /**
   * The solver object.
   */
  mutable SolverRichardson<VECTOR> solver;

  /**
   * The matrix in use.
   */
  PointerMatrixBase<VECTOR> *matrix;

  /**
   * The preconditioner to use.
   */
  PointerMatrixBase<VECTOR> *precondition;
};




/*@}*/
//---------------------------------------------------------------------------


template<class VECTOR>
inline
ScaledMatrix<VECTOR>::ScaledMatrix()
  :
  m(0)
{}



template<class VECTOR>
template<class MATRIX>
inline
ScaledMatrix<VECTOR>::ScaledMatrix(const MATRIX &mat, const double factor)
  :
  m(new_pointer_matrix_base(mat, VECTOR())),
  factor(factor)
{}



template<class VECTOR>
template<class MATRIX>
inline
void
ScaledMatrix<VECTOR>::initialize(const MATRIX &mat, const double f)
{
  if (m) delete m;
  m = new_pointer_matrix_base(mat, VECTOR());
  factor = f;
}



template<class VECTOR>
inline
void
ScaledMatrix<VECTOR>::clear()
{
  if (m) delete m;
  m = 0;
}



template<class VECTOR>
inline
ScaledMatrix<VECTOR>::~ScaledMatrix()
{
  clear ();
}


template<class VECTOR>
inline
void
ScaledMatrix<VECTOR>::vmult (VECTOR &w, const VECTOR &v) const
{
  m->vmult(w, v);
  w *= factor;
}


template<class VECTOR>
inline
void
ScaledMatrix<VECTOR>::Tvmult (VECTOR &w, const VECTOR &v) const
{
  m->Tvmult(w, v);
  w *= factor;
}


//---------------------------------------------------------------------------

template<class VECTOR>
ProductMatrix<VECTOR>::ProductMatrix ()
  : m1(0), m2(0), mem(0)
{}


template<class VECTOR>
ProductMatrix<VECTOR>::ProductMatrix (VectorMemory<VECTOR> &m)
  : m1(0), m2(0), mem(&m)
{}


template<class VECTOR>
template<class MATRIX1, class MATRIX2>
ProductMatrix<VECTOR>::ProductMatrix (
  const MATRIX1 &mat1,
  const MATRIX2 &mat2,
  VectorMemory<VECTOR> &m)
  : mem(&m)
{
  m1 = new PointerMatrix<MATRIX1, VECTOR>(&mat1, typeid(*this).name());
  m2 = new PointerMatrix<MATRIX2, VECTOR>(&mat2, typeid(*this).name());
}


template<class VECTOR>
template<class MATRIX1, class MATRIX2>
void
ProductMatrix<VECTOR>::reinit (
  const MATRIX1 &mat1,
  const MATRIX2 &mat2)
{
  if (m1) delete m1;
  if (m2) delete m2;
  m1 = new PointerMatrix<MATRIX1, VECTOR>(&mat1, typeid(*this).name());
  m2 = new PointerMatrix<MATRIX2, VECTOR>(&mat2, typeid(*this).name());
}


template<class VECTOR>
template<class MATRIX1, class MATRIX2>
void
ProductMatrix<VECTOR>::initialize (
  const MATRIX1 &mat1,
  const MATRIX2 &mat2,
  VectorMemory<VECTOR> &memory)
{
  mem = &memory;
  if (m1) delete m1;
  if (m2) delete m2;
  m1 = new PointerMatrix<MATRIX1, VECTOR>(&mat1, typeid(*this).name());
  m2 = new PointerMatrix<MATRIX2, VECTOR>(&mat2, typeid(*this).name());
}


template<class VECTOR>
ProductMatrix<VECTOR>::~ProductMatrix ()
{
  if (m1) delete m1;
  if (m2) delete m2;
}


template<class VECTOR>
void
ProductMatrix<VECTOR>::clear ()
{
  if (m1) delete m1;
  m1 = 0;
  if (m2) delete m2;
  m2 = 0;
}


template<class VECTOR>
void
ProductMatrix<VECTOR>::vmult (VECTOR &dst, const VECTOR &src) const
{
  Assert (mem != 0, ExcNotInitialized());
  Assert (m1 != 0, ExcNotInitialized());
  Assert (m2 != 0, ExcNotInitialized());

  VECTOR *v = mem->alloc();
  v->reinit(dst);
  m2->vmult (*v, src);
  m1->vmult (dst, *v);
  mem->free(v);
}


template<class VECTOR>
void
ProductMatrix<VECTOR>::vmult_add (VECTOR &dst, const VECTOR &src) const
{
  Assert (mem != 0, ExcNotInitialized());
  Assert (m1 != 0, ExcNotInitialized());
  Assert (m2 != 0, ExcNotInitialized());

  VECTOR *v = mem->alloc();
  v->reinit(dst);
  m2->vmult (*v, src);
  m1->vmult_add (dst, *v);
  mem->free(v);
}


template<class VECTOR>
void
ProductMatrix<VECTOR>::Tvmult (VECTOR &dst, const VECTOR &src) const
{
  Assert (mem != 0, ExcNotInitialized());
  Assert (m1 != 0, ExcNotInitialized());
  Assert (m2 != 0, ExcNotInitialized());

  VECTOR *v = mem->alloc();
  v->reinit(dst);
  m1->Tvmult (*v, src);
  m2->Tvmult (dst, *v);
  mem->free(v);
}


template<class VECTOR>
void
ProductMatrix<VECTOR>::Tvmult_add (VECTOR &dst, const VECTOR &src) const
{
  Assert (mem != 0, ExcNotInitialized());
  Assert (m1 != 0, ExcNotInitialized());
  Assert (m2 != 0, ExcNotInitialized());

  VECTOR *v = mem->alloc();
  v->reinit(dst);
  m1->Tvmult (*v, src);
  m2->Tvmult_add (dst, *v);
  mem->free(v);
}


template<class VECTOR>
const void *
ProductMatrix<VECTOR>::get () const
{
  return (void *) m1;
}


//---------------------------------------------------------------------------

template <class VECTOR>
inline void
MeanValueFilter::Tvmult(VECTOR &, const VECTOR &) const
{
  Assert(false, ExcNotImplemented());
}


template <class VECTOR>
inline void
MeanValueFilter::Tvmult_add(VECTOR &, const VECTOR &) const
{
  Assert(false, ExcNotImplemented());
}

//-----------------------------------------------------------------------//

template <class VECTOR>
template <class MATRIX, class PRECONDITION>
inline void
InverseMatrixRichardson<VECTOR>::initialize (const MATRIX &m, const PRECONDITION &p)
{
  if (matrix != 0)
    delete matrix;
  matrix = new PointerMatrix<MATRIX, VECTOR>(&m);
  if (precondition != 0)
    delete precondition;
  precondition = new PointerMatrix<PRECONDITION, VECTOR>(&p);
}


DEAL_II_NAMESPACE_CLOSE

#endif