/usr/include/deal.II/lac/relaxation_block.templates.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 | // ---------------------------------------------------------------------
// $Id: relaxation_block.templates.h 30040 2013-07-18 17:06:48Z maier $
//
// Copyright (C) 1999 - 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__relaxation_block_templates_h
#define __deal2__relaxation_block_templates_h
#include <deal.II/lac/relaxation_block.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/vector_memory.h>
DEAL_II_NAMESPACE_OPEN
template <class MATRIX, typename inverse_type>
inline
RelaxationBlock<MATRIX,inverse_type>::AdditionalData::AdditionalData (
const double relaxation,
const bool invert_diagonal,
const bool same_diagonal)
:
relaxation(relaxation),
invert_diagonal(invert_diagonal),
same_diagonal(same_diagonal),
inversion(PreconditionBlockBase<inverse_type>::gauss_jordan),
threshold(0.)
{}
template <class MATRIX, typename inverse_type>
inline
std::size_t
RelaxationBlock<MATRIX,inverse_type>::AdditionalData::memory_consumption() const
{
std::size_t result = sizeof(*this)
+ - sizeof(block_list) + block_list.memory_consumption();
for (unsigned int i=0; i<order.size(); ++i)
result += MemoryConsumption::memory_consumption(order[i]);
return result;
}
template <class MATRIX, typename inverse_type>
inline
RelaxationBlock<MATRIX,inverse_type>::AdditionalData::AdditionalData (
const BlockList &bl,
const double relaxation,
const bool invert_diagonal,
const bool same_diagonal)
:
relaxation(relaxation),
invert_diagonal(invert_diagonal),
same_diagonal(same_diagonal),
inversion(PreconditionBlockBase<inverse_type>::gauss_jordan),
threshold(0.)
{
bl.create_sparsity_pattern(block_list, 0);
}
template <class MATRIX, typename inverse_type>
inline
void
RelaxationBlock<MATRIX,inverse_type>::initialize (
const MATRIX &M,
const AdditionalData ¶meters)
{
Assert (parameters.invert_diagonal, ExcNotImplemented());
clear();
// Assert (M.m() == M.n(), ExcNotQuadratic());
A = &M;
additional_data = ¶meters;
this->inversion = parameters.inversion;
this->reinit(additional_data->block_list.n_rows(), 0, additional_data->same_diagonal,
additional_data->inversion);
if (additional_data->invert_diagonal)
invert_diagblocks();
}
template <class MATRIX, typename inverse_type>
inline
void
RelaxationBlock<MATRIX,inverse_type>::clear ()
{
A = 0;
PreconditionBlockBase<inverse_type>::clear ();
}
template <class MATRIX, typename inverse_type>
inline
void
RelaxationBlock<MATRIX,inverse_type>::invert_diagblocks ()
{
const MATRIX &M=*A;
FullMatrix<inverse_type> M_cell;
if (this->same_diagonal())
{
Assert(false, ExcNotImplemented());
}
else
{
for (size_type block=0; block<additional_data->block_list.n_rows(); ++block)
{
const size_type bs = additional_data->block_list.row_length(block);
M_cell.reinit(bs, bs);
// Copy rows for this block
// into the matrix for the
// diagonal block
SparsityPattern::iterator row
= additional_data->block_list.begin(block);
for (size_type row_cell=0; row_cell<bs; ++row_cell, ++row)
{
//TODO:[GK] Optimize here
for (typename MATRIX::const_iterator entry = M.begin(row->column());
entry != M.end(row->column()); ++entry)
{
const size_type column = entry->column();
const size_type col_cell = additional_data->block_list.row_position(block, column);
if (col_cell != numbers::invalid_size_type)
M_cell(row_cell, col_cell) = entry->value();
}
}
// Now M_cell contains the
// diagonal block. Now
// store it and its
// inverse, if so requested.
if (this->store_diagonals())
{
this->diagonal(block).reinit(bs, bs);
this->diagonal(block) = M_cell;
}
switch (this->inversion)
{
case PreconditionBlockBase<inverse_type>::gauss_jordan:
this->inverse(block).reinit(bs, bs);
this->inverse(block).invert(M_cell);
break;
case PreconditionBlockBase<inverse_type>::householder:
this->inverse_householder(block).initialize(M_cell);
break;
case PreconditionBlockBase<inverse_type>::svd:
this->inverse_svd(block).reinit(bs, bs);
this->inverse_svd(block) = M_cell;
this->inverse_svd(block).compute_inverse_svd(additional_data->threshold);
break;
default:
Assert(false, ExcNotImplemented());
}
}
}
this->inverses_computed(true);
}
template <class MATRIX, typename inverse_type>
template <typename number2>
inline
void
RelaxationBlock<MATRIX,inverse_type>::do_step (
Vector<number2> &dst,
const Vector<number2> &prev,
const Vector<number2> &src,
const bool backward) const
{
Assert (additional_data->invert_diagonal, ExcNotImplemented());
const MATRIX &M=*this->A;
Vector<number2> b_cell, x_cell;
const bool permutation_empty = additional_data->order.size() == 0;
const unsigned int n_permutations = (permutation_empty)
? 1U : additional_data->order.size();
const size_type n_blocks = additional_data->block_list.n_rows();
if (!permutation_empty)
for (unsigned int i=0; i<additional_data->order.size(); ++i)
AssertDimension(additional_data->order[i].size(), this->size());
for (unsigned int perm=0; perm<n_permutations; ++perm)
{
for (unsigned int bi=0; bi<n_blocks; ++bi)
{
const unsigned int raw_block = backward ? (n_blocks - bi - 1) : bi;
const unsigned int block = permutation_empty
? raw_block
: (backward
? (additional_data->order[n_permutations-1-perm][raw_block])
: (additional_data->order[perm][raw_block]));
const size_type bs = additional_data->block_list.row_length(block);
b_cell.reinit(bs);
x_cell.reinit(bs);
// Collect off-diagonal parts
SparsityPattern::iterator row = additional_data->block_list.begin(block);
for (size_type row_cell=0; row_cell<bs; ++row_cell, ++row)
{
b_cell(row_cell) = src(row->column());
for (typename MATRIX::const_iterator entry = M.begin(row->column());
entry != M.end(row->column()); ++entry)
b_cell(row_cell) -= entry->value() * prev(entry->column());
}
// Apply inverse diagonal
this->inverse_vmult(block, x_cell, b_cell);
#ifdef DEBUG
for (unsigned int i=0; i<x_cell.size(); ++i)
{
Assert(numbers::is_finite(x_cell(i)), ExcNumberNotFinite());
}
#endif
// Store in result vector
row=additional_data->block_list.begin(block);
for (size_type row_cell=0; row_cell<bs; ++row_cell, ++row)
dst(row->column()) = prev(row->column()) + additional_data->relaxation * x_cell(row_cell);
}
}
}
//----------------------------------------------------------------------//
template <class MATRIX, typename inverse_type>
template <typename number2>
void RelaxationBlockJacobi<MATRIX,inverse_type>::step (
Vector<number2> &dst,
const Vector<number2> &src) const
{
GrowingVectorMemory<Vector<number2> > mem;
typename VectorMemory<Vector<number2> >::Pointer aux = mem;
aux->reinit(dst, false);
*aux = dst;
this->do_step(dst, *aux, src, false);
}
template <class MATRIX, typename inverse_type>
template <typename number2>
void RelaxationBlockJacobi<MATRIX,inverse_type>::Tstep (
Vector<number2> &dst,
const Vector<number2> &src) const
{
GrowingVectorMemory<Vector<number2> > mem;
typename VectorMemory<Vector<number2> >::Pointer aux = mem;
aux->reinit(dst, false);
*aux = dst;
this->do_step(dst, *aux, src, true);
}
//----------------------------------------------------------------------//
template <class MATRIX, typename inverse_type>
template <typename number2>
void RelaxationBlockSOR<MATRIX,inverse_type>::step (
Vector<number2> &dst,
const Vector<number2> &src) const
{
this->do_step(dst, dst, src, false);
}
template <class MATRIX, typename inverse_type>
template <typename number2>
void RelaxationBlockSOR<MATRIX,inverse_type>::Tstep (
Vector<number2> &dst,
const Vector<number2> &src) const
{
this->do_step(dst, dst, src, true);
}
//----------------------------------------------------------------------//
template <class MATRIX, typename inverse_type>
template <typename number2>
void RelaxationBlockSSOR<MATRIX,inverse_type>::step (
Vector<number2> &dst,
const Vector<number2> &src) const
{
this->do_step(dst, dst, src, false);
this->do_step(dst, dst, src, true);
}
template <class MATRIX, typename inverse_type>
template <typename number2>
void RelaxationBlockSSOR<MATRIX,inverse_type>::Tstep (
Vector<number2> &dst,
const Vector<number2> &src) const
{
this->do_step(dst, dst, src, true);
this->do_step(dst, dst, src, false);
}
DEAL_II_NAMESPACE_CLOSE
#endif
|