This file is indexed.

/usr/include/deal.II/lac/constrained_linear_operator.h is in libdeal.ii-dev 8.4.2-2+b1.

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
// ---------------------------------------------------------------------
//
// Copyright (C) 2015 - 2016 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__constrained_linear_operator_h
#define dealii__constrained_linear_operator_h

#include <deal.II/lac/linear_operator.h>
#include <deal.II/lac/packaged_operation.h>
#include <deal.II/lac/constraint_matrix.h>

#ifdef DEAL_II_WITH_CXX11

DEAL_II_NAMESPACE_OPEN


/**
 * @name Indirectly applying constraints to LinearOperator
 */
//@{


/**
 * This function takes a ConstraintMatrix @p constraint_matrix and an operator
 * exemplar @p exemplar (this exemplar is usually a linear operator that
 * describes the system matrix - it is only used to create domain and range
 * vectors of appropriate sizes, its action <tt>vmult</tt> is never used). A
 * LinearOperator object associated with the "homogeneous action" of the
 * underlying ConstraintMatrix object is returned:
 *
 * Applying the LinearOperator object on a vector <code>u</code> results in a
 * vector <code>v</code> that stores the result of calling
 * ConstraintMatrix::distribute() on <code>u</code> - with one important
 * difference: inhomogeneities are not applied, but always treated as 0
 * instead.
 *
 * The LinearOperator object created by this function is primarily used
 * internally in constrained_linear_operator() to build up a modified system
 * of linear equations. How to solve a linear system of equations with this
 * approach is explained in detail in the
 * @ref constraints
 * module.
 *
 * @author Mauro Bardelloni, Matthias Maier, 2015
 *
 * @note Currently, this function may not work correctly for distributed data
 * structures.
 *
 * @relates LinearOperator
 * @ingroup constraints
 */
template <typename Range, typename Domain>
LinearOperator<Range, Domain> distribute_constraints_linear_operator(
  const ConstraintMatrix &constraint_matrix,
  const LinearOperator<Range, Domain> &exemplar)
{
  LinearOperator<Range, Domain> return_op = exemplar;

  return_op.vmult_add = [&constraint_matrix](Range &v, const Domain &u)
  {
    Assert(!dealii::PointerComparison::equal(&v, &u),
           dealii::ExcMessage("The domain and range vectors must be different "
                              "storage locations"));

    for (auto i : v.locally_owned_elements())
      {
        if (constraint_matrix.is_constrained(i))
          {
            const auto *entries = constraint_matrix.get_constraint_entries(i);
            for (types::global_dof_index j = 0; j < entries->size(); ++j)
              {
                const auto pos = (*entries)[j].first;
                v(i) += u(pos) * (*entries)[j].second;
              }
          }
        else
          v(i) += u(i);
      }
  };

  return_op.Tvmult_add = [&constraint_matrix](Domain &v, const Range &u)
  {
    Assert(!dealii::PointerComparison::equal(&v, &u),
           dealii::ExcMessage("The domain and range vectors must be different "
                              "storage locations"));

    for (auto i : v.locally_owned_elements())
      {
        if (constraint_matrix.is_constrained(i))
          {
            const auto *entries = constraint_matrix.get_constraint_entries(i);
            for (types::global_dof_index j = 0; j < entries->size(); ++j)
              {
                const auto pos = (*entries)[j].first;
                v(pos) += u(i) * (*entries)[j].second;
              }
          }
        else
          v(i)+=u(i);
      }
  };

  // lambda capture expressions are a C++14 feature...
  const auto vmult_add = return_op.vmult_add;
  return_op.vmult = [vmult_add](Range &v, const Domain &u)
  {
    v = 0.;
    vmult_add(v, u);
  };

  // lambda capture expressions are a C++14 feature...
  const auto Tvmult_add = return_op.Tvmult_add;
  return_op.Tvmult = [Tvmult_add](Domain &v, const Range &u)
  {
    v = 0.;
    Tvmult_add(v, u);
  };

  return return_op;
}


/**
 * Given a ConstraintMatrix @p constraint_matrix and an operator exemplar @p
 * exemplar, return a LinearOperator that is the projection to the subspace of
 * constrained degrees of freedom, i.e. all entries of the result vector that
 * correspond to unconstrained degrees of freedom are set to zero.
 *
 * @author Mauro Bardelloni, Matthias Maier, 2015
 *
 * @relates LinearOperator
 * @ingroup constraints
 */
template <typename Range, typename Domain>
LinearOperator<Range, Domain> project_to_constrained_linear_operator(
  const ConstraintMatrix &constraint_matrix,
  const LinearOperator<Range, Domain> &exemplar)
{
  LinearOperator<Range, Domain> return_op = exemplar;

  return_op.vmult_add = [&constraint_matrix](Range &v, const Domain &u)
  {
    for (auto i : v.locally_owned_elements())
      if (constraint_matrix.is_constrained(i))
        v(i) += u(i);
  };

  return_op.Tvmult_add = [&constraint_matrix](Domain &v, const Range &u)
  {
    for (auto i : v.locally_owned_elements())
      if (constraint_matrix.is_constrained(i))
        v(i) += u(i);
  };

  return_op.vmult = [&constraint_matrix](Range &v, const Domain &u)
  {
    Assert(!dealii::PointerComparison::equal(&v, &u),
           dealii::ExcMessage("The domain and range vectors must be different "
                              "storage locations"));

    v = 0.;
    for (auto i : v.locally_owned_elements())
      if (constraint_matrix.is_constrained(i))
        v(i) = u(i);
  };

  return_op.Tvmult = [&constraint_matrix](Domain &v, const Range &u)
  {
    Assert(!dealii::PointerComparison::equal(&v, &u),
           dealii::ExcMessage("The domain and range vectors must be different "
                              "storage locations"));
    v = 0.;
    for (auto i : v.locally_owned_elements())
      if (constraint_matrix.is_constrained(i))
        v(i) = u(i);
  };

  return return_op;
}


/**
 * Given a ConstraintMatrix object @p constraint_matrix and a LinearOperator
 * @p linop, this function creates a LinearOperator object consisting of the
 * composition of three operations and a regularization:
 * @code
 *   Ct * linop * C + Id_c;
 * @endcode
 * with
 * @code
 *   C = distribute_constraints_linear_operator(constraint_matrix, linop);
 *   Ct = transpose_operator(C);
 *   Id_c = project_to_constrained_linear_operator(constraint_matrix, linop);
 * @endcode
 * and <code>Id_c</code> is the projection to the subspace consisting of all
 * vector entries associated with constrained degrees of freedoms.
 *
 * This LinearOperator object is used together with
 * constrained_right_hand_side() to build up the following modified system of
 * linear equations:
 * @f[
 *   (C^T A C + Id_c) x = C^T (b - A\,k)
 * @f]
 * with a given (unconstrained) system matrix $A$, right hand side $b$, and
 * linear constraints $C$ with inhomogeneities $k$.
 *
 * A detailed explanation of this approach is given in the
 * @ref constraints
 * module.
 *
 * @author Mauro Bardelloni, Matthias Maier, 2015
 *
 * @note Currently, this function may not work correctly for distributed data
 * structures.
 *
 * @relates LinearOperator
 * @ingroup constraints
 */
template <typename Range, typename Domain>
LinearOperator<Range, Domain>
constrained_linear_operator(const ConstraintMatrix &constraint_matrix,
                            const LinearOperator<Range, Domain> &linop)
{
  const auto C =
    distribute_constraints_linear_operator(constraint_matrix, linop);
  const auto Ct = transpose_operator(C);
  const auto Id_c =
    project_to_constrained_linear_operator(constraint_matrix, linop);
  return Ct * linop * C + Id_c;
}


/**
 * Given a ConstraintMatrix object @p constraint_matrix, a LinearOperator @p
 * linop and a right-hand side @p right_hand_side, this function creates a
 * PackagedOperation that stores the following computation:
 * @code
 *   Ct * (right_hand_side - linop * k)
 * @endcode
 * with
 * @code
 *   C = distribute_constraints_linear_operator(constraint_matrix, linop);
 *   Ct = transpose_operator(C);
 * @endcode
 *
 * This LinearOperator object is used together with
 * constrained_right_hand_side() to build up the following modified system of
 * linear equations:
 * @f[
 *   (C^T A C + Id_c) x = C^T (b - A\,k)
 * @f]
 * with a given (unconstrained) system matrix $A$, right hand side $b$, and
 * linear constraints $C$ with inhomogeneities $k$.
 *
 * A detailed explanation of this approach is given in the
 * @ref constraints
 * module.
 *
 * @author Mauro Bardelloni, Matthias Maier, 2015
 *
 * @note Currently, this function may not work correctly for distributed data
 * structures.
 *
 * @relates LinearOperator
 * @ingroup constraints
 */
template <typename Range, typename Domain>
PackagedOperation<Range>
constrained_right_hand_side(const ConstraintMatrix &constraint_matrix,
                            const LinearOperator<Range, Domain> &linop,
                            const Range &right_hand_side)
{
  PackagedOperation<Range> return_comp;

  return_comp.reinit_vector = linop.reinit_range_vector;

  return_comp.apply_add =
    [&constraint_matrix, &linop, &right_hand_side](Range &v)
  {
    const auto C =
      distribute_constraints_linear_operator(constraint_matrix, linop);
    const auto Ct = transpose_operator(C);

    static GrowingVectorMemory<Domain> vector_memory;
    Domain *k = vector_memory.alloc();
    linop.reinit_domain_vector(*k, /*bool fast=*/ false);
    constraint_matrix.distribute(*k);

    v += Ct * (right_hand_side - linop **k);

    vector_memory.free(k);
  };

  // lambda capture expressions are a C++14 feature...
  const auto apply_add = return_comp.apply_add;
  return_comp.apply = [apply_add](Range &v)
  {
    v = 0.;
    apply_add(v);
  };

  return return_comp;
}

//@}

DEAL_II_NAMESPACE_CLOSE

#endif // DEAL_II_WITH_CXX11
#endif