/usr/include/deal.II/multigrid/multigrid.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 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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 | //---------------------------------------------------------------------------
// $Id: multigrid.h 21220 2010-06-17 04:01:18Z kanschat $
// Version: $Name$
//
// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 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__multigrid_h
#define __deal2__multigrid_h
#include <base/config.h>
#include <base/subscriptor.h>
#include <base/smartpointer.h>
#include <numerics/data_out.h>
#include <lac/sparse_matrix.h>
#include <lac/vector.h>
#include <multigrid/mg_base.h>
#include <base/mg_level_object.h>
#include <multigrid/mg_dof_handler.h>
#include <vector>
DEAL_II_NAMESPACE_OPEN
/*!@addtogroup mg */
/*@{*/
/**
* Implementation of the multigrid method.
*
* @warning multigrid on locally refined meshes only works with
* <b>discontinuous finite elements</b> right now. It is not clear,
* whether the paradigm of local smoothing we use is applicable to
* continuous elements with hanging nodes; in fact, most people you
* meet on conferences seem to deny this.
*
* The function which starts a multigrid cycle on the finest level is
* cycle(). Depending on the cycle type chosen with the constructor
* (see enum Cycle), this function triggers one of the cycles
* level_v_step() or level_step(), where the latter one can do
* different types of cycles.
*
* Using this class, it is expected that the right hand side has been
* converted from a vector living on the locally finest level to a
* multilevel vector. This is a nontrivial operation, usually
* initiated automatically by the class PreconditionMG and performed
* by the classes derived from MGTransferBase.
*
* @note The interface of this class is still very clumsy. In
* particular, you will have to set up quite a few auxiliary objects
* before you can use it. Unfortunately, it seems that this can be
* avoided only be restricting the flexibility of this class in an
* unacceptable way.
*
* @author Guido Kanschat, 1999 - 2005
*/
template <class VECTOR>
class Multigrid : public Subscriptor
{
public:
/**
* List of implemented cycle types.
*/
enum Cycle
{
/// The V-cycle
v_cycle,
/// The W-cycle
w_cycle,
/// The F-cycle
f_cycle
};
typedef VECTOR vector_type;
typedef const VECTOR const_vector_type;
/**
* Constructor. The
* MGDoFHandler is used to
* determine the highest possible
* level. <tt>transfer</tt> is an
* object performing prolongation
* and restriction.
*
* This function already
* initializes the vectors which
* will be used later in the
* course of the
* computations. You should
* therefore create objects of
* this type as late as possible.
*/
template <int dim>
Multigrid(const MGDoFHandler<dim>& mg_dof_handler,
const MGMatrixBase<VECTOR>& matrix,
const MGCoarseGridBase<VECTOR>& coarse,
const MGTransferBase<VECTOR>& transfer,
const MGSmootherBase<VECTOR>& pre_smooth,
const MGSmootherBase<VECTOR>& post_smooth,
Cycle cycle = v_cycle);
/**
* Experimental constructor for
* cases in which no MGDoFHandler
* is available.
*
* @warning Not intended for general use.
*/
Multigrid(const unsigned int minlevel,
const unsigned int maxlevel,
const MGMatrixBase<VECTOR>& matrix,
const MGCoarseGridBase<VECTOR>& coarse,
const MGTransferBase<VECTOR>& transfer,
const MGSmootherBase<VECTOR>& pre_smooth,
const MGSmootherBase<VECTOR>& post_smooth,
Cycle cycle = v_cycle);
/**
* Reinit this class according to
* #minlevel and #maxlevel.
*/
void reinit (const unsigned int minlevel,
const unsigned int maxlevel);
/**
* Execute one multigrid
* cycle. The type of cycle is
* selected by the constructor
* argument cycle. See the enum
* Cycle for available types.
*/
void cycle ();
/**
* Execute one step of the
* V-cycle algorithm. This
* function assumes, that the
* multilevel vector #defect is
* filled with the residual of an
* outer defect correction
* scheme. This is usually taken
* care of by
* PreconditionMG). After
* vcycle(), the result is in the
* multilevel vector
* #solution. See
* <tt>copy_*_mg</tt> in class
* MGTools if you want to use
* these vectors yourself.
*
* The actual work for this
* function is done in
* level_v_step().
*/
void vcycle ();
/**
* @deprecated This function is
* purely experimental and will
* probably never be implemented
* in a way that it can be
* released.
*
* Perform a multigrid cycle with
* a vector which is already a
* level vector. Use of this
* function assumes that there is
* NO local refinement and that
* both vectors are on the finest
* level of this Multigrid
* object.
*/
void vmult(VECTOR& dst, const VECTOR& src) const;
/**
* @deprecated This function is
* purely experimental and will
* probably never be implemented
* in a way that it can be
* released.
*
* Perform a multigrid cycle with
* a vector which is already a
* level vector. Use of this
* function assumes that there is
* NO local refinement and that
* both vectors are on the finest
* level of this Multigrid
* object.
*/
void vmult_add(VECTOR& dst, const VECTOR& src) const;
/**
* @deprecated Even worse than
* vmult(), this function is not
* even implemented, but just
* declared such that certain
* objects relying on it can be
* constructed.
*/
void Tvmult(VECTOR& dst, const VECTOR& src) const;
/**
* @deprecated Even worse than
* vmult(), this function is not
* even implemented, but just
* declared such that certain
* objects relying on it can be
* constructed.
*/
void Tvmult_add(VECTOR& dst, const VECTOR& src) const;
/**
* Set additional matrices to
* correct residual computation
* at refinement edges. Since we
* only smoothen in the interior
* of the refined part of the
* mesh, the coupling across the
* refinement edge is
* missing. This coupling is
* provided by these two
* matrices.
*
* @note While
* <tt>edge_out.vmult</tt> is
* used, for the second argument,
* we use
* <tt>edge_in.Tvmult</tt>. Thus,
* <tt>edge_in</tt> should be
* assembled in transposed
* form. This saves a second
* sparsity pattern for
* <tt>edge_in</tt>. In
* particular, for symmetric
* operators, both arguments can
* refer to the same matrix,
* saving assembling of one of
* them.
*/
void set_edge_matrices (const MGMatrixBase<VECTOR>& edge_out,
const MGMatrixBase<VECTOR>& edge_in);
/**
* Set additional matrices to
* correct residual computation
* at refinement edges. These
* matrices originate from
* discontinuous Galerkin methods
* (see FE_DGQ etc.), where they
* correspond to the edge fluxes
* at the refinement edge between
* two levels.
*
* @note While
* <tt>edge_down.vmult</tt> is
* used, for the second argument,
* we use
* <tt>edge_up.Tvmult</tt>. Thus,
* <tt>edge_up</tt> should be
* assembled in transposed
* form. This saves a second
* sparsity pattern for
* <tt>edge_up</tt>. In
* particular, for symmetric
* operators, both arguments can
* refer to the same matrix,
* saving assembling of one of
* them.
*/
void set_edge_flux_matrices (const MGMatrixBase<VECTOR>& edge_down,
const MGMatrixBase<VECTOR>& edge_up);
/**
* Return the finest level for
* multigrid.
*/
unsigned int get_maxlevel() const;
/**
* Return the coarsest level for
* multigrid.
*/
unsigned int get_minlevel() const;
/**
* Set the highest level for
* which the multilevel method is
* performed. By default, this is
* the finest level of the
* Triangulation; therefore, this
* function will only accept
* arguments smaller than the
* current #maxlevel and not
* smaller than the current
* #minlevel.
*/
void set_maxlevel (const unsigned int);
/**
* Set the coarse level for which
* the multilevel method is
* performed. By default, this is
* zero. Accepted are
* non-negative values not larger than
* than the current #maxlevel.
*
* If <tt>relative</tt> ist
* <tt>true</tt>, then this
* function determins the number
* of levels used, that is, it
* sets #minlevel to
* #maxlevel-<tt>level</tt>.
*
* @note The mesh on the coarsest
* level must cover the whole
* domain. There may not be
* hanging nodes on #minlevel.
*
* @note If #minlevel is set to a
* nonzero value, do not forget
* to adjust your coarse grid
* solver!
*/
void set_minlevel (const unsigned int level,
bool relative = false);
/**
* Chance #cycle_type used in cycle().
*/
void set_cycle(Cycle);
/**
* Set the debug level. Higher
* values will create more
* debugging output during the
* multigrid cycles.
*/
void set_debug (const unsigned int);
private:
/**
* The V-cycle multigrid method.
* <tt>level</tt> is the level the
* function starts on. It
* will usually be called for the
* highest level from outside,
* but will then call itself
* recursively for <tt>level-1</tt>,
* unless we are on #minlevel
* where the coarse grid solver
* solves the problem exactly.
*/
void level_v_step (const unsigned int level);
/**
* The actual W-cycle or F-cycle
* multigrid method.
* <tt>level</tt> is the level
* the function starts on. It
* will usually be called for the
* highest level from outside,
* but will then call itself
* recursively for
* <tt>level-1</tt>, unless we
* are on #minlevel where the
* coarse grid solver solves the
* problem exactly.
*/
void level_step (const unsigned int level, Cycle cycle);
/**
* Cycle type performed by the method cycle().
*/
Cycle cycle_type;
/**
* Level for coarse grid solution.
*/
unsigned int minlevel;
/**
* Highest level of cells.
*/
unsigned int maxlevel;
public:
/**
* Input vector for the
* cycle. Contains the defect of
* the outer method projected to
* the multilevel vectors.
*/
MGLevelObject<VECTOR> defect;
/**
* The solution update after the
* multigrid step.
*/
MGLevelObject<VECTOR> solution;
private:
/**
* Auxiliary vector.
*/
MGLevelObject<VECTOR> t;
/**
* Auxiliary vector for W- and
* F-cycles. Left uninitialized
* in V-cycle.
*/
MGLevelObject<VECTOR> defect2;
/**
* The matrix for each level.
*/
SmartPointer<const MGMatrixBase<VECTOR>,Multigrid<VECTOR> > matrix;
/**
* The matrix for each level.
*/
SmartPointer<const MGCoarseGridBase<VECTOR>,Multigrid<VECTOR> > coarse;
/**
* Object for grid tranfer.
*/
SmartPointer<const MGTransferBase<VECTOR>,Multigrid<VECTOR> > transfer;
/**
* The pre-smoothing object.
*/
SmartPointer<const MGSmootherBase<VECTOR>,Multigrid<VECTOR> > pre_smooth;
/**
* The post-smoothing object.
*/
SmartPointer<const MGSmootherBase<VECTOR>,Multigrid<VECTOR> > post_smooth;
/**
* Edge matrix from the interior
* of the refined part to the
* refinement edge.
*
* @note Only <tt>vmult</tt> is
* used for these matrices.
*/
SmartPointer<const MGMatrixBase<VECTOR> > edge_out;
/**
* Transpose edge matrix from the
* refinement edge to the
* interior of the refined part.
*
* @note Only <tt>Tvmult</tt> is
* used for these matrices.
*/
SmartPointer<const MGMatrixBase<VECTOR> > edge_in;
/**
* Edge matrix from fine to coarse.
*
* @note Only <tt>vmult</tt> is
* used for these matrices.
*/
SmartPointer<const MGMatrixBase<VECTOR>,Multigrid<VECTOR> > edge_down;
/**
* Transpose edge matrix from coarse to fine.
*
* @note Only <tt>Tvmult</tt> is
* used for these matrices.
*/
SmartPointer<const MGMatrixBase<VECTOR>,Multigrid<VECTOR> > edge_up;
/**
* Level for debug
* output. Defaults to zero and
* can be set by set_debug().
*/
unsigned int debug;
template<int dim, class VECTOR2, class TRANSFER> friend class PreconditionMG;
};
/**
* Multi-level preconditioner.
* Here, we collect all information needed for multi-level preconditioning
* and provide the standard interface for LAC iterative methods.
*
* Furthermore, it needs functions <tt>void copy_to_mg(const VECTOR&)</tt>
* to store @p src in the right hand side of the multi-level method and
* <tt>void copy_from_mg(VECTOR&)</tt> to store the result of the v-cycle in @p dst.
*
* @author Guido Kanschat, 1999, 2000, 2001, 2002
*/
template<int dim, class VECTOR, class TRANSFER>
class PreconditionMG : public Subscriptor
{
public:
/**
* Constructor.
* Arguments are the multigrid object,
* pre-smoother, post-smoother and
* coarse grid solver.
*/
PreconditionMG(const MGDoFHandler<dim>& mg_dof,
Multigrid<VECTOR>& mg,
const TRANSFER& transfer);
/**
* Dummy function needed by other classes.
*/
bool empty () const;
/**
* Preconditioning operator.
* Calls the @p vcycle function
* of the @p MG object passed to
* the constructor.
*
* This is the operator used by
* LAC iterative solvers.
*/
template<class VECTOR2>
void vmult (VECTOR2 &dst,
const VECTOR2 &src) const;
/**
* Preconditioning operator.
* Calls the @p vcycle function
* of the @p MG object passed to
* the constructor.
*/
template<class VECTOR2>
void vmult_add (VECTOR2 &dst,
const VECTOR2 &src) const;
/**
* Tranposed preconditioning operator.
*
* Not implemented, but the
* definition may be needed.
*/
template<class VECTOR2>
void Tvmult (VECTOR2 &dst,
const VECTOR2 &src) const;
/**
* Tranposed preconditioning operator.
*
* Not implemented, but the
* definition may be needed.
*/
template<class VECTOR2>
void Tvmult_add (VECTOR2 &dst,
const VECTOR2 &src) const;
private:
/**
* Associated @p MGDoFHandler.
*/
SmartPointer<const MGDoFHandler<dim>,PreconditionMG<dim,VECTOR,TRANSFER> > mg_dof_handler;
/**
* The multigrid object.
*/
SmartPointer<Multigrid<VECTOR>,PreconditionMG<dim,VECTOR,TRANSFER> > multigrid;
/**
* Object for grid tranfer.
*/
SmartPointer<const TRANSFER,PreconditionMG<dim,VECTOR,TRANSFER> > transfer;
};
/*@}*/
#ifndef DOXYGEN
/* --------------------------- inline functions --------------------- */
template <class VECTOR>
template <int dim>
Multigrid<VECTOR>::Multigrid (const MGDoFHandler<dim>& mg_dof_handler,
const MGMatrixBase<VECTOR>& matrix,
const MGCoarseGridBase<VECTOR>& coarse,
const MGTransferBase<VECTOR>& transfer,
const MGSmootherBase<VECTOR>& pre_smooth,
const MGSmootherBase<VECTOR>& post_smooth,
Cycle cycle)
:
cycle_type(cycle),
minlevel(0),
maxlevel(mg_dof_handler.get_tria().n_levels()-1),
defect(minlevel,maxlevel),
solution(minlevel,maxlevel),
t(minlevel,maxlevel),
defect2(minlevel,maxlevel),
matrix(&matrix, typeid(*this).name()),
coarse(&coarse, typeid(*this).name()),
transfer(&transfer, typeid(*this).name()),
pre_smooth(&pre_smooth, typeid(*this).name()),
post_smooth(&post_smooth, typeid(*this).name()),
edge_down(0, typeid(*this).name()),
edge_up(0, typeid(*this).name()),
debug(0)
{}
template <class VECTOR>
inline
unsigned int
Multigrid<VECTOR>::get_maxlevel () const
{
return maxlevel;
}
template <class VECTOR>
inline
unsigned int
Multigrid<VECTOR>::get_minlevel () const
{
return minlevel;
}
/* --------------------------- inline functions --------------------- */
template<int dim, class VECTOR, class TRANSFER>
PreconditionMG<dim, VECTOR, TRANSFER>
::PreconditionMG(const MGDoFHandler<dim>& mg_dof_handler,
Multigrid<VECTOR>& mg,
const TRANSFER& transfer)
:
mg_dof_handler(&mg_dof_handler),
multigrid(&mg),
transfer(&transfer)
{}
template<int dim, class VECTOR, class TRANSFER>
inline bool
PreconditionMG<dim, VECTOR, TRANSFER>::empty () const
{
return false;
}
template<int dim, class VECTOR, class TRANSFER>
template<class VECTOR2>
void
PreconditionMG<dim, VECTOR, TRANSFER>::vmult (
VECTOR2& dst,
const VECTOR2& src) const
{
#ifdef BAERBEL_MG_TEST
const unsigned int min_l = multigrid->solution.get_minlevel();
const unsigned int max_l = multigrid->solution.get_maxlevel();
deallog << "PreconditionMG in " << src.l2_norm() << std::endl;
#endif
transfer->copy_to_mg(*mg_dof_handler,
multigrid->defect,
src);
#ifdef BAERBEL_MG_TEST
for(unsigned int l=min_l; l<max_l; ++l)
deallog << "defect [" << l << "] " << multigrid->defect[l].l2_norm() << std::endl;
#endif
multigrid->cycle();
#ifdef BAERBEL_MG_TEST
for(unsigned int l=min_l; l<max_l; ++l)
deallog << "solution [" << l << "] " << multigrid->solution[l].l2_norm() << std::endl;
#endif
transfer->copy_from_mg(*mg_dof_handler,
dst,
multigrid->solution);
#ifdef BAERBEL_MG_TEST
deallog << "PreconditionMG out " << dst.l2_norm() << std::endl;
/*
DataOut<dim> data_out;
data_out.attach_dof_handler (*mg_dof_handler);
VECTOR2 tmp;
tmp.reinit(dst);
tmp = dst;
transfer->constraints->distribute(tmp);
data_out.add_data_vector (tmp, "mg");
data_out.build_patches ();
std::ostringstream filename;
filename << "mg.gpl";
std::ofstream output (filename.str().c_str());
data_out.write_gnuplot (output);
*/
#endif
}
template<int dim, class VECTOR, class TRANSFER>
template<class VECTOR2>
void
PreconditionMG<dim, VECTOR, TRANSFER>::vmult_add (
VECTOR2& dst,
const VECTOR2& src) const
{
transfer->copy_to_mg(*mg_dof_handler,
multigrid->defect,
src);
multigrid->cycle();
transfer->copy_from_mg_add(*mg_dof_handler,
dst,
multigrid->solution);
}
template<int dim, class VECTOR, class TRANSFER>
template<class VECTOR2>
void
PreconditionMG<dim, VECTOR, TRANSFER>::Tvmult (
VECTOR2&,
const VECTOR2&) const
{
Assert(false, ExcNotImplemented());
}
template<int dim, class VECTOR, class TRANSFER>
template<class VECTOR2>
void
PreconditionMG<dim, VECTOR, TRANSFER>::Tvmult_add (
VECTOR2&,
const VECTOR2&) const
{
Assert(false, ExcNotImplemented());
}
#endif // DOXYGEN
DEAL_II_NAMESPACE_CLOSE
#endif
|