This file is indexed.

/usr/include/deal.II/lac/diagonal_matrix.h is in libdeal.ii-dev 8.5.1-3.

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
// ---------------------------------------------------------------------
//
// Copyright (C) 2016 - 2017 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 dealii__diagonal_matrix_h
#define dealii__diagonal_matrix_h


#include <deal.II/lac/vector.h>

DEAL_II_NAMESPACE_OPEN

/**
 * This class represents a <i>n x n</i> diagonal matrix based on a vector of
 * size <i>n</i>. The matrix-vector products are realized by @p
 * VectorType::scale, so the template vector class needs to provide a
 * @p scale() method.
 *
 * When using this class with ConstraintsMatrix::distribute_local_to_global(),
 * the underlying vector needs to provide write access to all entries referenced
 * by cells in an assembly process. This means that this class also needs access
 * to ghost entries that are owned by other processors than the calling one.
 * In practice this requires initialization of the vector as follows
 * @code
 * DiagonalMatrix<LinearAlgebra::distributed::Vector<double> > diagonal_matrix;
 * LinearAlgebra::distributed::Vector<double> &diagonal_vector = diagonal_matrix.get_vector();
 * diagonal_vector.reinit(locally_owned_dofs,
 *                        locally_relevant_dofs,
 *                        mpi_communicator);
 * @endcode
 *
 * @author Martin Kronbichler, 2016
 */
template <typename VectorType=Vector<double> >
class DiagonalMatrix : public Subscriptor
{
public:
  typedef typename VectorType::value_type value_type;
  typedef typename VectorType::size_type size_type;

  /**
   * Constructor.
   */
  DiagonalMatrix();

  /**
   * Initialize with a given vector by copying the content of the vector
   * @p vec.
   */
  void reinit (const VectorType &vec);

  /**
   * Compresses the data structures and allows the resulting matrix to be used
   * in all other operations like matrix-vector products. This is a collective
   * operation, i.e., it needs to be run on all processors when used in parallel.
   */
  void compress (VectorOperation::values operation);

  /**
   * Returns a reference to the underlying vector for manipulation of the
   * entries on the matrix diagonal.
   */
  VectorType &get_vector();

  /**
   * Clear content of this object and reset to the state of default constructor.
   */
  void clear();

  /**
   * Returns a read-only reference to the underlying vector.
   */
  const VectorType &get_vector() const;

  /**
   * Number of rows of this matrix. This number corresponds to the size of the
   * underlying vector.
   */
  size_type m () const;

  /**
   * Number of columns of this matrix. This number corresponds to the size of
   * the underlying vector.
   */
  size_type n () const;

  /**
   * Read-only access to a value. This is restricted to the case where
   * <i>i==j</i> due to the matrix storage.
   *
   * If the vector representing the diagonal is distributed with MPI, not all
   * of the indices <i>i</i> might actually be accessible. Refer to the method
   * <code>get_vector().locally_owned_elements()</code> for the entries that
   * actually are accessible.
   */
  value_type operator()(const size_type i,
                        const size_type j) const;

  /**
   * Read-write access to a value. This is restricted to the case where
   * <i>i==j</i> due to the matrix storage.
   *
   * If the vector representing the diagonal is distributed with MPI, not all
   * of the indices <i>i</i> might actually be accessible. Refer to the method
   * <code>get_vector().locally_owned_elements()</code> for the entries that
   * actually are accessible.
   */
  value_type &operator()(const size_type i,
                         const size_type j);

  /**
   * Add an array of values given by <tt>values</tt> in the given global
   * matrix row at columns specified by col_indices. Due to the storage of
   * this matrix, entries are only added to the diagonal of the matrix. All
   * other entries are ignored and no exception is thrown.
   *
   * This function is for a consistent interface with the other matrix classes
   * in deal.II and can be used in
   * ConstraintMatrix::distribute_local_to_global to get exactly the same
   * diagonal as when assembling into a sparse matrix.
   */
  template <typename number2>
  void add (const size_type  row,
            const size_type  n_cols,
            const size_type *col_indices,
            const number2   *values,
            const bool       elide_zero_values = true,
            const bool       col_indices_are_sorted = false);

  /**
   * Add value to the element (i,j).
   *
   * Due to the storage of this matrix, entries are only added to the diagonal
   * of the matrix. All other entries are ignored and no exception is thrown.
   */
  void add (const size_type i,
            const size_type j,
            const value_type value);

  /**
   * Performs a matrix-vector multiplication with the given matrix.
   */
  void vmult (VectorType       &dst,
              const VectorType &src) const;

  /**
   * Performs a transpose matrix-vector multiplication with the given
   * matrix. Since this represents a diagonal matrix, exactly the same as
   * vmult().
   */
  void Tvmult (VectorType       &dst,
               const VectorType &src) const;

  /**
   * Adds the result of a matrix-vector multiplication into the destination
   * vector dst. Needs to create a temporary vector, which makes performance
   * slower than for @p vmult().
   */
  void vmult_add (VectorType       &dst,
                  const VectorType &src) const;

  /**
   * Adds the result of a transpose matrix-vector multiplication into the
   * destination vector dst. Needs to create a temporary vector, which makes
   * performance slower than for @p Tvmult().
   */
  void Tvmult_add (VectorType       &dst,
                   const VectorType &src) const;

  /**
   * Return the memory consumption of this object.
   */
  std::size_t memory_consumption () const;

private:
  /**
   * The stored vector.
   */
  VectorType diagonal;
};

/* ---------------------------------- Inline functions ------------------- */

#ifndef DOXYGEN

template <typename VectorType>
DiagonalMatrix<VectorType>::DiagonalMatrix()
  :
  Subscriptor()
{}



template <typename VectorType>
void
DiagonalMatrix<VectorType>::clear()
{
  diagonal.reinit(0);
}



template <typename VectorType>
std::size_t
DiagonalMatrix<VectorType>::memory_consumption () const
{
  return diagonal.memory_consumption();
}



template <typename VectorType>
void
DiagonalMatrix<VectorType>::reinit(const VectorType &vec)
{
  diagonal = vec;
}



template <typename VectorType>
void
DiagonalMatrix<VectorType>::compress (VectorOperation::values operation)
{
  diagonal.compress(operation);
}



template <typename VectorType>
VectorType &
DiagonalMatrix<VectorType>::get_vector()
{
  return diagonal;
}



template <typename VectorType>
const VectorType &
DiagonalMatrix<VectorType>::get_vector() const
{
  return diagonal;
}



template <typename VectorType>
typename VectorType::size_type
DiagonalMatrix<VectorType>::m() const
{
  return diagonal.size();
}



template <typename VectorType>
typename VectorType::size_type
DiagonalMatrix<VectorType>::n() const
{
  return diagonal.size();
}



template <typename VectorType>
typename VectorType::value_type
DiagonalMatrix<VectorType>::operator()(const size_type i,
                                       const size_type j) const
{
  Assert (i==j, ExcIndexRange(j,i,i+1));
  (void) j;
  return diagonal(i);
}



template <typename VectorType>
typename VectorType::value_type &
DiagonalMatrix<VectorType>::operator()(const size_type i,
                                       const size_type j)
{
  Assert (i==j, ExcIndexRange(j,i,i+1));
  (void)j;
  return diagonal(i);
}



template <typename VectorType>
template <typename number2>
void
DiagonalMatrix<VectorType>::add (const size_type  row,
                                 const size_type  n_cols,
                                 const size_type *col_indices,
                                 const number2   *values,
                                 const bool       ,
                                 const bool       )
{
  for (size_type i=0; i<n_cols; ++i)
    if (col_indices[i] == row)
      diagonal(row) += values[i];
}



template <typename VectorType>
void
DiagonalMatrix<VectorType>::add (const size_type i,
                                 const size_type j,
                                 const value_type value)
{
  if (i == j)
    diagonal(i) += value;
}



template <typename VectorType>
void
DiagonalMatrix<VectorType>::vmult(VectorType       &dst,
                                  const VectorType &src) const
{
  dst = src;
  dst.scale(diagonal);
}



template <typename VectorType>
void
DiagonalMatrix<VectorType>::Tvmult(VectorType       &dst,
                                   const VectorType &src) const
{
  vmult(dst, src);
}



template <typename VectorType>
void
DiagonalMatrix<VectorType>::vmult_add(VectorType       &dst,
                                      const VectorType &src) const
{
  VectorType tmp(src);
  tmp.scale(diagonal);
  dst += tmp;
}



template <typename VectorType>
void
DiagonalMatrix<VectorType>::Tvmult_add(VectorType       &dst,
                                       const VectorType &src) const
{
  vmult_add(dst, src);
}


#endif

DEAL_II_NAMESPACE_CLOSE

#endif