OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
AmrSmoother.cpp
Go to the documentation of this file.
1 //
2 // Class AmrSmoother
3 // Interface to Ifpack2 smoothers of the Trilinos package.
4 //
5 // Copyright (c) 2017 - 2020, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // All rights reserved
7 //
8 // Implemented as part of the PhD thesis
9 // "Precise Simulations of Multibunches in High Intensity Cyclotrons"
10 //
11 // This file is part of OPAL.
12 //
13 // OPAL is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20 //
21 #include "AmrSmoother.h"
22 
23 #include <map>
24 #include <utility>
25 
27 
28 AmrSmoother::AmrSmoother(const Teuchos::RCP<const matrix_t>& A,
29  const Smoother& smoother,
30  lo_t nSweeps)
31 {
32  const std::string type = "RELAXATION";
33 
34  Ifpack2::Factory factory;
35  prec_mp = factory.create(type, A);
36 
37  params_mp = Teuchos::rcp( new Teuchos::ParameterList );
38 
39  this->initParameter_m(smoother, nSweeps);
40 
41 
42  prec_mp->setParameters(*params_mp);
43  prec_mp->initialize();
44  prec_mp->compute();
45 }
46 
47 
49  prec_mp = Teuchos::null;
50  params_mp = Teuchos::null;
51 }
52 
53 
54 void AmrSmoother::smooth(const Teuchos::RCP<vector_t>& x,
55  const Teuchos::RCP<vector_t>& b)
56 {
57  prec_mp->apply(*b, *x, Teuchos::NO_TRANS,
58  Teuchos::ScalarTraits<scalar_t>::one(),
59  Teuchos::ScalarTraits<scalar_t>::zero());
60 }
61 
62 
64 AmrSmoother::convertToEnumSmoother(const std::string& smoother) {
65  std::map<std::string, Smoother> map;
66 
67  map["GS"] = Smoother::GAUSS_SEIDEL;
68  map["SGS"] = Smoother::SGS;
69  map["JACOBI"] = Smoother::JACOBI;
70 
71  auto sm = map.find(smoother);
72 
73  if ( sm == map.end() )
74  throw OpalException("AmrMultiGrid::convertToEnumNorm_m()",
75  "No smoother '" + smoother + "'.");
76  return sm->second;
77 }
78 
79 
81  lo_t nSweeps)
82 {
83  if ( params_mp == Teuchos::null )
84  params_mp = Teuchos::rcp( new Teuchos::ParameterList );
85 
86 
87  std::string type = "";
88  scalar_t damping = 1.0;
89  std::pair<bool, scalar_t> l1 = std::make_pair(true, 1.5);
90 
91  bool backward = false;
92  std::pair<bool, scalar_t> fix = std::make_pair(true, 1.0e-5);
93  bool check = true;
94 
95  switch ( smoother ) {
96 
97  case GAUSS_SEIDEL:
98  {
99  type = "Gauss-Seidel";
100  backward = false;
101  damping = 1.0;
102  break;
103  }
104  case SGS:
105  {
106  type = "Symmetric Gauss-Seidel";
107  damping = 1.0;
108  break;
109  }
110  case JACOBI:
111  {
112  type = "Jacobi";
113  damping = 6.0 / 7.0;
114  break;
115  }
116  default:
117  break;
118  };
119 
120  params_mp->set("relaxation: type", type);
121  params_mp->set("relaxation: sweeps", nSweeps);
122  params_mp->set("relaxation: zero starting solution", false);
123  params_mp->set("relaxation: damping factor", damping);
124  params_mp->set("relaxation: use l1", l1.first);
125  params_mp->set("relaxation: l1 eta", l1.second);
126  params_mp->set("relaxation: backward mode", backward);
127  params_mp->set("relaxation: fix tiny diagonal entries", fix.first);
128  params_mp->set("relaxation: min diagonal value", fix.second);
129  params_mp->set("relaxation: check diagonal entries", check);
130 }
@ JACOBI
Jacobi point relaxation.
boost::function< boost::tuple< double, bool >arguments_t)> type
Definition: function.hpp:21
Smoother
All supported Ifpack2 smoothers.
Definition: AmrSmoother.h:46
AmrSmoother(const Teuchos::RCP< const matrix_t > &A, const Smoother &smoother, lo_t nSweeps)
Definition: AmrSmoother.cpp:28
amr::local_ordinal_t lo_t
Definition: AmrSmoother.h:34
Teuchos::RCP< preconditioner_t > prec_mp
Preconditioner instance.
Definition: AmrSmoother.h:91
Teuchos::RCP< Teuchos::ParameterList > params_mp
Parameters of preconditioner.
Definition: AmrSmoother.h:94
void initParameter_m(const Smoother &smoother, lo_t nSweeps)
Definition: AmrSmoother.cpp:80
void smooth(const Teuchos::RCP< vector_t > &x, const Teuchos::RCP< vector_t > &b)
Definition: AmrSmoother.cpp:54
amr::scalar_t scalar_t
Definition: AmrSmoother.h:35
static Smoother convertToEnumSmoother(const std::string &smoother)
Definition: AmrSmoother.cpp:64
The base class for all OPAL exceptions.
Definition: OpalException.h:28