/usr/include/deal.II/multigrid/mg_block_smoother.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 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 | //---------------------------------------------------------------------------
// $Id: mg_block_smoother.h 20871 2010-03-21 19:22:22Z kanschat $
// Version: $Name$
//
// Copyright (C) 2005, 2006, 2010 by the deal.II authors
//
// 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__mg_block_smoother_h
#define __deal2__mg_block_smoother_h
#include <base/config.h>
#include <base/smartpointer.h>
#include <lac/pointer_matrix.h>
#include <lac/vector_memory.h>
#include <lac/block_vector.h>
#include <multigrid/mg_base.h>
#include <base/mg_level_object.h>
#include <vector>
DEAL_II_NAMESPACE_OPEN
template <int,int> class MGDoFHandler;
/*
* MGSmootherBase is defined in mg_base.h
*/
/*!@addtogroup mg */
/*@{*/
/**
* General smoother class for block vectors. This class gives complete
* freedom to the choice of a block smoother by being initialized with
* a matrix and a smoother object. Therefore, the smoother object for
* each level must be constructed by hand.
*
* @author Guido Kanschat, 2005
*/
template <class MATRIX, class RELAX, typename number>
class MGSmootherBlock
: public MGSmootherBase<BlockVector<number> >
{
public:
/**
* Constructor. Sets memory and
* smoothing parameters.
*/
MGSmootherBlock(VectorMemory<BlockVector<number> >& mem,
const unsigned int steps = 1,
const bool variable = false,
const bool symmetric = false,
const bool transpose = false,
const bool reverse = false);
/**
* Initialize for matrices. The
* parameter <tt>matrices</tt> can be
* any object having functions
* <tt>get_minlevel()</tt> and
* <tt>get_maxlevel()</tt> as well as
* an <tt>operator[]</tt> returning a
* reference to @p MATRIX.
*
* The same convention is used
* for the parameter
* <tt>smoothers</tt>, such that
* <tt>operator[]</tt> returns
* the object doing the
* block-smoothing on a single
* level.
*
* This function stores pointers
* to the level matrices and
* smoothing operator for each
* level.
*/
template <class MGMATRIX, class MGRELAX>
void initialize (const MGMATRIX& matrices,
const MGRELAX& smoothers);
/**
* Empty all vectors.
*/
void clear ();
/**
* Modify the number of smoothing
* steps on finest level.
*/
void set_steps (const unsigned int);
/**
* Switch on/off variable
* smoothing.
*/
void set_variable (const bool);
/**
* Switch on/off symmetric
* smoothing.
*/
void set_symmetric (const bool);
/**
* Switch on/off transposed. This
* is mutually exclusive with
* reverse().
*/
void set_transpose (const bool);
/**
* Switch on/off reversed. This
* is mutually exclusive with
* transpose().
*/
void set_reverse (const bool);
/**
* Implementation of the
* interface for @p Multigrid.
* This function does nothing,
* which by comparison with the
* definition of this function
* means that the the smoothing
* operator equals the null
* operator.
*/
virtual void smooth (const unsigned int level,
BlockVector<number>& u,
const BlockVector<number>& rhs) const;
private:
/**
* Pointer to the matrices.
*/
MGLevelObject<PointerMatrix<MATRIX, BlockVector<number> > > matrices;
/**
* Pointer to the matrices.
*/
MGLevelObject<PointerMatrix<RELAX, BlockVector<number> > > smoothers;
/**
* Number of smoothing steps.
*/
unsigned int steps;
/**
* Variable smoothing?
*/
bool variable;
/**
* Symmetric smoothing?
*/
bool symmetric;
/*
* Transposed?
*/
bool transpose;
/**
* Reverse?
*/
bool reverse;
/**
* Memory for auxiliary vectors.
*/
VectorMemory<BlockVector<number> >& mem;
};
/**@}*/
//---------------------------------------------------------------------------
#ifndef DOXYGEN
template <class MATRIX, class RELAX, typename number>
inline
MGSmootherBlock<MATRIX, RELAX, number>::MGSmootherBlock(
VectorMemory<BlockVector<number> >& mem,
const unsigned int steps,
const bool variable,
const bool symmetric,
const bool transpose,
const bool reverse)
:
steps(steps),
variable(variable),
symmetric(symmetric),
transpose(transpose),
reverse(reverse),
mem(mem)
{}
template <class MATRIX, class RELAX, typename number>
inline void
MGSmootherBlock<MATRIX, RELAX, number>::clear ()
{
unsigned int i=matrices.get_minlevel(),
max_level=matrices.get_maxlevel();
for (; i<=max_level; ++i)
{
smoothers[i] = 0;
matrices[i] = 0;
}
}
template <class MATRIX, class RELAX, typename number>
template <class MGMATRIX, class MGRELAX>
inline void
MGSmootherBlock<MATRIX, RELAX, number>::initialize (
const MGMATRIX& m,
const MGRELAX& s)
{
const unsigned int min = m.get_minlevel();
const unsigned int max = m.get_maxlevel();
matrices.resize(min, max);
smoothers.resize(min, max);
for (unsigned int i=min;i<=max;++i)
{
matrices[i] = &m[i];
smoothers[i] = &s[i];
}
}
template <class MATRIX, class RELAX, typename number>
inline void
MGSmootherBlock<MATRIX, RELAX, number>::
set_steps (const unsigned int s)
{
steps = s;
}
template <class MATRIX, class RELAX, typename number>
inline void
MGSmootherBlock<MATRIX, RELAX, number>::
set_variable (const bool flag)
{
variable = flag;
}
template <class MATRIX, class RELAX, typename number>
inline void
MGSmootherBlock<MATRIX, RELAX, number>::
set_symmetric (const bool flag)
{
symmetric = flag;
}
template <class MATRIX, class RELAX, typename number>
inline void
MGSmootherBlock<MATRIX, RELAX, number>::
set_transpose (const bool flag)
{
transpose = flag;
}
template <class MATRIX, class RELAX, typename number>
inline void
MGSmootherBlock<MATRIX, RELAX, number>::
set_reverse (const bool flag)
{
reverse = flag;
}
template <class MATRIX, class RELAX, typename number>
inline void
MGSmootherBlock<MATRIX, RELAX, number>::smooth(
const unsigned int level,
BlockVector<number>& u,
const BlockVector<number>& rhs) const
{
deallog.push("Smooth");
unsigned int maxlevel = matrices.get_maxlevel();
unsigned int steps2 = steps;
if (variable)
steps2 *= (1<<(maxlevel-level));
BlockVector<number>* r = mem.alloc();
BlockVector<number>* d = mem.alloc();
r->reinit(u);
d->reinit(u);
bool T = transpose;
if (symmetric && (steps2 % 2 == 0))
T = false;
// cerr << 'S' << level;
// cerr << '(' << matrices[level]->m() << ',' << matrices[level]->n() << ')';
for (unsigned int i=0; i<steps2; ++i)
{
if (T)
{
// cerr << 'T';
matrices[level].vmult(*r,u);
r->sadd(-1.,1.,rhs);
smoothers[level].Tvmult(*d, *r);
} else {
// cerr << 'N';
matrices[level].vmult(*r,u);
r->sadd(-1.,1.,rhs);
smoothers[level].vmult(*d, *r);
}
// cerr << '{' << r->l2_norm() << '}';
u += *d;
if (symmetric)
T = !T;
}
mem.free(r);
mem.free(d);
deallog.pop();
}
#endif // DOXYGEN
DEAL_II_NAMESPACE_CLOSE
#endif
|