MFEM  v3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
sparsesmoothers.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.googlecode.com.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 // Implementation of data types for sparse matrix smoothers
13 
14 #include <iostream>
15 #include "vector.hpp"
16 #include "matrix.hpp"
17 #include "sparsemat.hpp"
18 #include "sparsesmoothers.hpp"
19 
20 namespace mfem
21 {
22 
24 {
25  oper = dynamic_cast<const SparseMatrix*>(&a);
26  if (oper == NULL)
27  mfem_error("SparseSmoother::SetOperator : not a SparseMatrix!");
28  height = oper->Height();
29  width = oper->Width();
30 }
31 
33 void GSSmoother::Mult(const Vector &x, Vector &y) const
34 {
35  if (!iterative_mode)
36  y = 0.0;
37  for (int i = 0; i < iterations; i++)
38  {
39  if (type != 2)
40  oper->Gauss_Seidel_forw(x, y);
41  if (type != 1)
42  oper->Gauss_Seidel_back(x, y);
43  }
44 }
45 
47 DSmoother::DSmoother(const SparseMatrix &a, int t, double s, int it)
48  : SparseSmoother(a)
49 {
50  type = t;
51  scale = s;
52  iterations = it;
53 }
54 
56 void DSmoother::Mult(const Vector &x, Vector &y) const
57 {
58  if (!iterative_mode && type == 0 && iterations == 1)
59  {
60  oper->DiagScale(x, y, scale);
61  return;
62  }
63 
64  z.SetSize(width);
65 
66  Vector *r = &y, *p = &z;
67 
68  if (iterations % 2 == 0)
69  Swap<Vector*>(r, p);
70 
71  if (!iterative_mode)
72  *p = 0.0;
73  else if (iterations % 2)
74  *p = y;
75  for (int i = 0; i < iterations; i++)
76  {
77  if (type == 0)
78  oper->Jacobi(x, *p, *r, scale);
79  else if (type == 1)
80  oper->Jacobi2(x, *p, *r, scale);
81  else if (type == 2)
82  oper->Jacobi3(x, *p, *r, scale);
83  else
84  mfem_error("DSmoother::Mult wrong type");
85  Swap<Vector*>(r, p);
86  }
87 }
88 
89 }
void DiagScale(const Vector &b, Vector &x, double sc=1.0) const
Definition: sparsemat.cpp:1388
void SetSize(int s)
Resizes the vector if the new size is different.
Definition: vector.hpp:248
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols.
Definition: operator.hpp:41
virtual void SetOperator(const Operator &a)
Set/update the solver for the given operator.
bool iterative_mode
If true, use the second argument of Mult as an initial guess.
Definition: operator.hpp:106
Data type sparse matrix.
Definition: sparsemat.hpp:38
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows.
Definition: operator.hpp:35
void Jacobi(const Vector &b, const Vector &x0, Vector &x1, double sc) const
Definition: sparsemat.cpp:1357
virtual void Mult(const Vector &x, Vector &y) const
Matrix vector multiplication with Jacobi smoother.
void mfem_error(const char *msg)
Definition: error.cpp:23
virtual void Mult(const Vector &x, Vector &y) const
Matrix vector multiplication with GS Smoother.
void Gauss_Seidel_back(const Vector &x, Vector &y) const
Definition: sparsemat.cpp:1249
void Gauss_Seidel_forw(const Vector &x, Vector &y) const
Gauss-Seidel forward and backward iterations over a vector x.
Definition: sparsemat.cpp:1174
DSmoother(int t=0, double s=1., int it=1)
Create Jacobi smoother.
Vector data type.
Definition: vector.hpp:29
void Jacobi2(const Vector &b, const Vector &x0, Vector &x1, double sc=1.0) const
Definition: sparsemat.cpp:1420
void Jacobi3(const Vector &b, const Vector &x0, Vector &x1, double sc=1.0) const
Definition: sparsemat.cpp:1444
Abstract operator.
Definition: operator.hpp:21
const SparseMatrix * oper