/usr/include/deal.II/lac/sparse_decomposition.templates.h is in libdeal.ii-dev 6.3.1-1.1.
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 | //---------------------------------------------------------------------------
// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009 by the deal.II authors
// by the deal.II authors and Stephen "Cheffo" Kolaroff
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
// to the file deal.II/doc/license.html for the text and
// further information on this license.
//
//---------------------------------------------------------------------------
#ifndef __deal2__sparse_decomposition_templates_h
#define __deal2__sparse_decomposition_templates_h
#include <base/memory_consumption.h>
#include <base/template_constraints.h>
#include <lac/sparse_decomposition.h>
#include <algorithm>
#include <cstring>
DEAL_II_NAMESPACE_OPEN
template<typename number>
SparseLUDecomposition<number>::SparseLUDecomposition()
:
SparseMatrix<number>(),
decomposed(false),
own_sparsity(0)
{}
template<typename number>
SparseLUDecomposition<number>::
SparseLUDecomposition (const SparsityPattern& sparsity) :
SparseMatrix<number>(sparsity),
decomposed(false),
own_sparsity(0)
{}
template<typename number>
SparseLUDecomposition<number>::~SparseLUDecomposition()
{
clear();
}
template<typename number>
void SparseLUDecomposition<number>::clear()
{
decomposed = false;
std::vector<const unsigned int*> tmp;
tmp.swap (prebuilt_lower_bound);
SparseMatrix<number>::clear();
if (own_sparsity)
{
delete own_sparsity;
own_sparsity=0;
}
}
template<typename number>
template <typename somenumber>
void SparseLUDecomposition<number>::initialize (
const SparseMatrix<somenumber> &matrix,
const AdditionalData data)
{
const SparsityPattern &matrix_sparsity=matrix.get_sparsity_pattern();
if (data.use_this_sparsity)
reinit(*data.use_this_sparsity);
else if (data.use_previous_sparsity &&
!this->empty() &&
(this->m()==matrix.m()))
{
// Use the sparsity that was
// previously used. This is
// particularly useful when
// matrix entries change but
// not the sparsity, as for the
// case of several Newton
// iteration steps on an
// unchanged grid.
reinit(this->get_sparsity_pattern());
}
else if (data.extra_off_diagonals==0)
{
// Use same sparsity as matrix
reinit(matrix_sparsity);
}
else
{
// Create new sparsity
// for the case that
// own_sparsity wasn't deleted
// before (e.g. by clear()), do
// it here
if (own_sparsity)
{
// release the sparsity
SparseMatrix<number>::clear();
// delete it
delete own_sparsity;
}
// and recreate
own_sparsity=new SparsityPattern(matrix_sparsity,
matrix_sparsity.max_entries_per_row()
+2*data.extra_off_diagonals,
data.extra_off_diagonals);
own_sparsity->compress();
reinit(*own_sparsity);
}
}
template<typename number>
template<typename somenumber>
void
SparseLUDecomposition<number>::
decompose (const SparseMatrix<somenumber> &matrix,
const double strengthen_diagonal)
{
decomposed = false;
this->strengthen_diagonal = strengthen_diagonal;
prebuild_lower_bound ();
copy_from (matrix);
decomposed = true;
}
template <typename number>
void SparseLUDecomposition<number>::reinit (const SparsityPattern& sparsity)
{
Assert (sparsity.optimize_diagonal(),
typename SparsityPattern::ExcDiagonalNotOptimized());
decomposed = false;
if (true)
{
std::vector<const unsigned int*> tmp;
tmp.swap (prebuilt_lower_bound);
};
SparseMatrix<number>::reinit (sparsity);
}
template<typename number>
void
SparseLUDecomposition<number>::prebuild_lower_bound()
{
const unsigned int * const
column_numbers = this->get_sparsity_pattern().get_column_numbers();
const std::size_t * const
rowstart_indices = this->get_sparsity_pattern().get_rowstart_indices();
const unsigned int N = this->m();
prebuilt_lower_bound.resize (N);
for(unsigned int row=0; row<N; row++) {
prebuilt_lower_bound[row]
= std::lower_bound (&column_numbers[rowstart_indices[row]+1],
&column_numbers[rowstart_indices[row+1]],
row);
}
}
template <typename number>
template <typename somenumber>
void
SparseLUDecomposition<number>::copy_from (const SparseMatrix<somenumber>& matrix)
{
// check whether we use the same sparsity
// pattern as the input matrix
if (&this->get_sparsity_pattern() == &matrix.get_sparsity_pattern())
{
const somenumber * input_ptr = matrix.val;
number * this_ptr = this->val;
const number * const end_ptr = this_ptr + this->n_nonzero_elements();
if (types_are_equal<somenumber, number>::value == true)
std::memcpy (this_ptr, input_ptr, this->n_nonzero_elements()*sizeof(number));
else
for ( ; this_ptr != end_ptr; ++input_ptr, ++this_ptr)
*this_ptr = *input_ptr;
return;
}
// preset the elements
std::fill_n (&this->global_entry(0),
this->n_nonzero_elements(),
0);
// note: pointers to the sparsity
// pattern of the old matrix!
const std::size_t * const in_rowstart_indices
= matrix.get_sparsity_pattern().get_rowstart_indices();
const unsigned int * const in_cols
= matrix.get_sparsity_pattern().get_column_numbers();
const unsigned int * cols = this->get_sparsity_pattern().get_column_numbers();
const std::size_t * rowstart_indices =
this->get_sparsity_pattern().get_rowstart_indices();
// both allow more and less entries
// in the new matrix
std::size_t in_index, index;
for (unsigned int row=0; row<this->m(); ++row)
{
index = rowstart_indices[row];
in_index = in_rowstart_indices[row];
this->val[index++] = matrix.val[in_index++];
while (in_index < in_rowstart_indices[row+1] &&
index < rowstart_indices[row+1])
{
while (cols[index] < in_cols[in_index] && index < rowstart_indices[row+1])
++index;
while (in_cols[in_index] < cols[index] && in_index < in_rowstart_indices[row+1])
++in_index;
this->val[index++] = matrix.val[in_index++];
}
}
}
template <typename number>
void
SparseLUDecomposition<number>::strengthen_diagonal_impl ()
{
for (unsigned int row=0; row<this->m(); ++row)
{
// get the length of the row
// (without the diagonal element)
const unsigned int rowlength
= (this->get_sparsity_pattern().get_rowstart_indices()[row+1]
-this->get_sparsity_pattern().get_rowstart_indices()[row]
-1);
// get the global index of the first
// non-diagonal element in this row
const unsigned int rowstart
= this->get_sparsity_pattern().get_rowstart_indices()[row] + 1;
number * const diagonal_element = &this->global_entry(rowstart-1);
number rowsum = 0;
for (unsigned int global_index=rowstart;
global_index<rowstart+rowlength; ++global_index)
rowsum += std::fabs(this->global_entry(global_index));
*diagonal_element += this->get_strengthen_diagonal (rowsum, row) *
rowsum;
}
}
template <typename number>
unsigned int
SparseLUDecomposition<number>::memory_consumption () const
{
unsigned int
res = (SparseMatrix<number>::memory_consumption () +
MemoryConsumption::memory_consumption(prebuilt_lower_bound));
return res;
}
DEAL_II_NAMESPACE_CLOSE
#endif // __deal2__sparse_decomposition_templates_h
|