OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
AmrSmoother.cpp
Go to the documentation of this file.
1 #include "AmrSmoother.h"
2 
3 #include <map>
4 #include <utility>
5 
7 #include "Utilities/Util.h"
8 
9 AmrSmoother::AmrSmoother(const Teuchos::RCP<const matrix_t>& A,
10  const Smoother& smoother,
11  lo_t nSweeps)
12 {
13  const std::string type = "RELAXATION";
14 
15  Ifpack2::Factory factory;
16  prec_mp = factory.create(type, A);
17 
18  params_mp = Teuchos::rcp( new Teuchos::ParameterList );
19 
20  this->initParameter_m(smoother, nSweeps);
21 
22 
23  prec_mp->setParameters(*params_mp);
24  prec_mp->initialize();
25  prec_mp->compute();
26 }
27 
28 
30  prec_mp = Teuchos::null;
31  params_mp = Teuchos::null;
32 }
33 
34 
35 void AmrSmoother::smooth(const Teuchos::RCP<vector_t>& x,
36  const Teuchos::RCP<matrix_t>& A,
37  const Teuchos::RCP<vector_t>& b)
38 {
39  prec_mp->apply(*b, *x, Teuchos::NO_TRANS,
40  Teuchos::ScalarTraits<scalar_t>::one(),
41  Teuchos::ScalarTraits<scalar_t>::zero());
42 }
43 
44 
46 AmrSmoother::convertToEnumSmoother(const std::string& smoother) {
47  std::map<std::string, Smoother> map;
48 
49  map["GS"] = Smoother::GAUSS_SEIDEL;
50  map["SGS"] = Smoother::SGS;
51  map["JACOBI"] = Smoother::JACOBI;
52 
53  auto sm = map.find(Util::toUpper(smoother));
54 
55  if ( sm == map.end() )
56  throw OpalException("AmrMultiGrid::convertToEnumNorm_m()",
57  "No smoother '" + smoother + "'.");
58  return sm->second;
59 }
60 
61 
63  lo_t nSweeps)
64 {
65  if ( params_mp == Teuchos::null )
66  params_mp = Teuchos::rcp( new Teuchos::ParameterList );
67 
68 
69  std::string type = "";
70  scalar_t damping = 1.0;
71  std::pair<bool, scalar_t> l1 = std::make_pair(true, 1.5);
72 
73  bool backward = false;
74  std::pair<bool, scalar_t> fix = std::make_pair(true, 1.0e-5);
75  bool check = true;
76 
77  switch ( smoother ) {
78 
79  case GAUSS_SEIDEL:
80  {
81  type = "Gauss-Seidel";
82  backward = false;
83  damping = 1.0;
84  break;
85  }
86  case SGS:
87  {
88  type = "Symmetric Gauss-Seidel";
89  damping = 1.0;
90  break;
91  }
92  case JACOBI:
93  {
94  type = "Jacobi";
95  damping = 6.0 / 7.0;
96  break;
97  }
98  default:
99  break;
100  };
101 
102  params_mp->set("relaxation: type", type);
103  params_mp->set("relaxation: sweeps", nSweeps);
104  params_mp->set("relaxation: zero starting solution", false);
105  params_mp->set("relaxation: damping factor", damping);
106  params_mp->set("relaxation: use l1", l1.first);
107  params_mp->set("relaxation: l1 eta", l1.second);
108  params_mp->set("relaxation: backward mode", backward);
109  params_mp->set("relaxation: fix tiny diagonal entries", fix.first);
110  params_mp->set("relaxation: min diagonal value", fix.second);
111  params_mp->set("relaxation: check diagonal entries", check);
112 }
constexpr double e
The value of .
Definition: Physics.h:40
The base class for all OPAL exceptions.
Definition: OpalException.h:28
Teuchos::RCP< preconditioner_t > prec_mp
Preconditioner instance.
Definition: AmrSmoother.h:74
std::string toUpper(const std::string &str)
Definition: Util.cpp:130
Smoother
All supported Ifpack2 smoothers.
Definition: AmrSmoother.h:27
void initParameter_m(const Smoother &smoother, lo_t nSweeps)
Definition: AmrSmoother.cpp:62
Teuchos::RCP< Teuchos::ParameterList > params_mp
Parameters of preconditioner.
Definition: AmrSmoother.h:77
amr::scalar_t scalar_t
Definition: AmrSmoother.h:16
static Smoother convertToEnumSmoother(const std::string &smoother)
Definition: AmrSmoother.cpp:46
Jacobi point relaxation.
AmrSmoother(const Teuchos::RCP< const matrix_t > &A, const Smoother &smoother, lo_t nSweeps)
Definition: AmrSmoother.cpp:9
amr::local_ordinal_t lo_t
Definition: AmrSmoother.h:15
void smooth(const Teuchos::RCP< vector_t > &x, const Teuchos::RCP< matrix_t > &A, const Teuchos::RCP< vector_t > &b)
Definition: AmrSmoother.cpp:35