OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
MueLuPreconditioner.hpp
Go to the documentation of this file.
1 #include <AMReX.H>
2 
3 #include <MueLu_CreateTpetraPreconditioner.hpp>
4 
5 template <class Level>
7  const std::string& reuse)
8  : prec_mp(Teuchos::null),
9  coords_mp(Teuchos::null),
10  rebalance_m(rebalance)
11 {
12  this->init_m(reuse);
13 }
14 
15 
16 template <class Level>
17 void MueLuPreconditioner<Level>::create(const Teuchos::RCP<amr::matrix_t>& A,
18  Level* level_p)
19 {
20 
21  coords_mp = Teuchos::null;
22 
23  if ( rebalance_m ) {
24 
25  const scalar_t* domain = level_p->geom.ProbLo();
26  const scalar_t* dx = level_p->cellSize();
27 
28  coords_mp = Teuchos::rcp(
29  new amr::multivector_t(A->getDomainMap(), AMREX_SPACEDIM, false)
30  );
31 
32  for (amrex::MFIter mfi(level_p->grids, level_p->dmap, true);
33  mfi.isValid(); ++mfi)
34  {
35  const AmrBox_t& tbx = mfi.tilebox();
36  const lo_t* lo = tbx.loVect();
37  const lo_t* hi = tbx.hiVect();
38 
39  for (lo_t i = lo[0]; i <= hi[0]; ++i) {
40  for (lo_t j = lo[1]; j <= hi[1]; ++j) {
41 #if AMREX_SPACEDIM == 3
42  for (lo_t k = lo[2]; k <= hi[2]; ++k) {
43 #endif
44  AmrIntVect_t iv(D_DECL(i, j, k));
45  go_t gidx = level_p->serialize(iv);
46 
47  coords_mp->replaceGlobalValue(gidx, 0, domain[0] + (0.5 + i) * dx[0]);
48  coords_mp->replaceGlobalValue(gidx, 1, domain[1] + (0.5 + j) * dx[1]);
49 #if AMREX_SPACEDIM == 3
50  coords_mp->replaceGlobalValue(gidx, 2, domain[2] + (0.5 + k) * dx[2]);
51  }
52 #endif
53  }
54  }
55  }
56  }
57 
58  prec_mp = MueLu::CreateTpetraPreconditioner(A, params_m, coords_mp);
59 
60  coords_mp = Teuchos::null;
61 }
62 
63 
64 template <class Level>
65 Teuchos::RCP<amr::operator_t> MueLuPreconditioner<Level>::get() {
66  return prec_mp;
67 }
68 
69 
70 template <class Level>
72  map["SA"] = Preconditioner::SA;
73 }
74 
75 
76 template <class Level>
77 std::string
79 
80  std::map<std::string, std::string> map;
81  map["NONE"] = "none";
82  map["RP"] = "RP";
83  map["RAP"] = "RAP";
84  map["S"] = "S";
85  map["FULL"] = "full";
86 
87  auto muelu = map.find(Util::toUpper(reuse));
88 
89  if ( muelu == map.end() )
90  throw OpalException("MueLuPreconditioner::convertToMueLuReuseOption()",
91  "No MueLu reuse option '" + reuse + "'.");
92 
93  return muelu->second;
94 }
95 
96 
97 template <class Level>
98 void MueLuPreconditioner<Level>::init_m(const std::string& reuse) {
99  params_m.set("problem: type", "Poisson-3D");
100  params_m.set("verbosity", "none");
101  params_m.set("number of equations", 1);
102  params_m.set("max levels", 8);
103  params_m.set("cycle type", "V");
104 
105  params_m.set("coarse: max size", 200);
106  params_m.set("multigrid algorithm", "sa");
107  params_m.set("sa: damping factor", 1.33); // default: 1.33
108  params_m.set("sa: use filtered matrix", true);
109  params_m.set("filtered matrix: reuse eigenvalue", false); // false: more expensive
110 
111  params_m.set("repartition: enable", rebalance_m);
112  params_m.set("repartition: rebalance P and R", rebalance_m);
113  params_m.set("repartition: partitioner", "zoltan2");
114  params_m.set("repartition: min rows per proc", 800);
115  params_m.set("repartition: start level", 2);
116 
117  Teuchos::ParameterList reparms;
118  reparms.set("algorithm", "multijagged"); // rcb
119  // reparms.set("partitioning_approach", "partition");
120 
121  params_m.set("repartition: params", reparms);
122 
123 
124  params_m.set("smoother: type", "CHEBYSHEV");
125  params_m.set("smoother: pre or post", "both");
126  Teuchos::ParameterList smparms;
127  smparms.set("chebyshev: degree", 3);
128  smparms.set("chebyshev: assume matrix does not change", false);
129  smparms.set("chebyshev: zero starting solution", true);
130  params_m.set("smoother: params", smparms);
131 
132  params_m.set("smoother: type", "CHEBYSHEV");
133  params_m.set("smoother: pre or post", "both");
134 
135  params_m.set("coarse: type", "KLU2");
136 
137  params_m.set("aggregation: type", "uncoupled");
138  params_m.set("aggregation: min agg size", 3);
139  params_m.set("aggregation: max agg size", 27);
140 
141  params_m.set("transpose: use implicit", false);
142 
143  params_m.set("reuse: type", reuse); // none
144 }
amr::local_ordinal_t lo_t
MueLuPreconditioner(const bool &rebalance, const std::string &reuse)
static void fillMap(map_t &map)
void init_m(const std::string &reuse)
The base class for all OPAL exceptions.
Definition: OpalException.h:28
std::string toUpper(const std::string &str)
Definition: Util.cpp:130
amr::global_ordinal_t go_t
std::map< std::string, Preconditioner > map_t
smoothed aggregation multigrid
void create(const Teuchos::RCP< amr::matrix_t > &A, Level *level_p=nullptr)
static std::string convertToMueLuReuseOption(const std::string &reuse)
amr::AmrIntVect_t AmrIntVect_t
Tpetra::MultiVector< scalar_t, local_ordinal_t, global_ordinal_t, node_t > multivector_t
Teuchos::RCP< amr::operator_t > get()