Belos  Version of the Day
Belos_Details_EBelosSolverType.cpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 
43 #include "Teuchos_ParameterList.hpp"
44 
45 namespace Belos {
46 namespace Details {
47 
49 getEnumFromCanonicalName (const std::string& canonicalName)
50 {
51  // Mapping from canonical solver name (a string) to its
52  // corresponding enum value. This mapping is one-to-one.
53  //
54  // NOTE (mfh 12 Aug 2015) The keys need to be all uppercase.
55  if (canonicalName == "BLOCK GMRES") {
57  }
58  else if (canonicalName == "PSEUDOBLOCK GMRES") {
60  }
61  else if (canonicalName == "BLOCK CG") {
62  return SOLVER_TYPE_BLOCK_CG;
63  }
64  else if (canonicalName == "PSEUDOBLOCK CG") {
66  }
67  else if (canonicalName == "PSEUDOBLOCK STOCHASTIC CG") {
69  }
70  else if (canonicalName == "GCRODR") {
71  return SOLVER_TYPE_GCRODR;
72  }
73  else if (canonicalName == "RCG") {
74  return SOLVER_TYPE_RCG;
75  }
76  else if (canonicalName == "MINRES") {
77  return SOLVER_TYPE_MINRES;
78  }
79  else if (canonicalName == "LSQR") {
80  return SOLVER_TYPE_LSQR;
81  }
82  else if (canonicalName == "TFQMR") {
83  return SOLVER_TYPE_TFQMR;
84  }
85  else if (canonicalName == "PSEUDOBLOCK TFQMR") {
87  }
88  else if (canonicalName == "HYBRID BLOCK GMRES") {
90  }
91  else if (canonicalName == "PCPG") {
92  return SOLVER_TYPE_PCPG;
93  }
94  else if (canonicalName == "FIXED POINT") {
96  }
97  else if (canonicalName == "BICGSTAB") {
98  return SOLVER_TYPE_BICGSTAB;
99  }
100  else {
101  // An error code; not actually a valid value.
103  }
104 }
105 
106 std::pair<std::string, bool>
107 getCanonicalNameFromAlias (const std::string& candidateAlias)
108 {
109  // NOTE (mfh 29 Nov 2011) Accessing the flexible capability requires
110  // setting a parameter in the solver's parameter list. This affects
111  // the SolverFactory's interface, since using the "Flexible GMRES"
112  // alias requires modifying the user's parameter list if necessary.
113  // This is a good idea because users may not know about the
114  // parameter, or may have forgotten.
115  //
116  // NOTE (mfh 12 Aug 2015) The keys and values need to be all uppercase.
117 
118  if (candidateAlias == "GMRES") {
119  return std::make_pair (std::string ("PSEUDOBLOCK GMRES"), true);
120  }
121  else if (candidateAlias == "BLOCK GMRES") {
122  return std::make_pair (std::string ("BLOCK GMRES"), true);
123  }
124  else if (candidateAlias == "FLEXIBLE GMRES") {
125  return std::make_pair (std::string ("BLOCK GMRES"), true);
126  }
127  else if (candidateAlias == "CG") {
128  return std::make_pair (std::string ("PSEUDOBLOCK CG"), true);
129  }
130  else if (candidateAlias == "PSEUDOBLOCKCG") {
131  return std::make_pair (std::string ("PSEUDOBLOCK CG"), true);
132  }
133  else if (candidateAlias == "STOCHASTIC CG") {
134  return std::make_pair (std::string ("PSEUDOBLOCK STOCHASTIC CG"), true);
135  }
136  else if (candidateAlias == "RECYCLING CG") {
137  return std::make_pair (std::string ("RCG"), true);
138  }
139  else if (candidateAlias == "RECYCLING GMRES") {
140  return std::make_pair (std::string ("GCRODR"), true);
141  }
142  // For compatibility with Stratimikos' Belos adapter.
143  else if (candidateAlias == "PSEUDO BLOCK GMRES") {
144  return std::make_pair (std::string ("PSEUDOBLOCK GMRES"), true);
145  }
146  else if (candidateAlias == "PSEUDOBLOCKGMRES") {
147  return std::make_pair (std::string ("PSEUDOBLOCK GMRES"), true);
148  }
149  else if (candidateAlias == "PSEUDO BLOCK CG") {
150  return std::make_pair (std::string ("PSEUDOBLOCK CG"), true);
151  }
152  else if (candidateAlias == "PSEUDOBLOCKCG") {
153  return std::make_pair (std::string ("PSEUDOBLOCK CG"), true);
154  }
155  else if (candidateAlias == "TRANSPOSE-FREE QMR") {
156  return std::make_pair (std::string ("TFQMR"), true);
157  }
158  else if (candidateAlias == "PSEUDO BLOCK TFQMR") {
159  return std::make_pair (std::string ("PSEUDOBLOCK TFQMR"), true);
160  }
161  else if (candidateAlias == "PSEUDO BLOCK TRANSPOSE-FREE QMR") {
162  return std::make_pair (std::string ("PSEUDOBLOCK TFQMR"), true);
163  }
164  else if (candidateAlias == "GMRESPOLY") {
165  return std::make_pair (std::string ("HYBRID BLOCK GMRES"), true);
166  }
167  else if (candidateAlias == "SEED GMRES") {
168  return std::make_pair (std::string ("HYBRID BLOCK GMRES"), true);
169  }
170  else if (candidateAlias == "CGPOLY") {
171  return std::make_pair (std::string ("PCPG"), true);
172  }
173  else if (candidateAlias == "SEED CG") {
174  return std::make_pair (std::string ("PCPG"), true);
175  }
176  else if (candidateAlias == "FIXED POINT") {
177  return std::make_pair (std::string ("FIXED POINT"), true);
178  }
179  else if (candidateAlias == "BICGSTAB") {
180  return std::make_pair (std::string ("BICGSTAB"), true);
181  }
182  else { // not a known alias
183  return std::make_pair (candidateAlias, false);
184  }
185 }
186 
187 std::vector<std::string>
189 {
190 #ifdef HAVE_TEUCHOSCORE_CXX11
191  return {
192  {"GMRES"},
193  {"BLOCK GMRES"},
194  {"FLEXIBLE GMRES"},
195  {"CG"},
196  {"PSEUDOBLOCKCG"},
197  {"STOCHASTIC CG"},
198  {"RECYCLING CG"},
199  {"RECYCLING GMRES"},
200  {"PSEUDO BLOCK GMRES"},
201  {"PSEUDOBLOCKGMRES"},
202  {"PSEUDO BLOCK CG"},
203  {"PSEUDOBLOCKCG"},
204  {"TRANSPOSE-FREE QMR"},
205  {"PSEUDO BLOCK TFQMR"},
206  {"PSEUDO BLOCK TRANSPOSE-FREE QMR"},
207  {"GMRESPOLY"},
208  {"SEED GMRES"},
209  {"CGPOLY"},
210  {"SEED CG"},
211  {"FIXED POINT"},
212  {"BICGSTAB"}
213  };
214 #else // NOT HAVE_TEUCHOSCORE_CXX11
215  std::vector<std::string> names;
216 
217  names.push_back ("GMRES");
218  names.push_back ("BLOCK GMRES");
219  names.push_back ("FLEXIBLE GMRES");
220  names.push_back ("CG");
221  names.push_back ("PSEUDOBLOCKCG");
222  names.push_back ("STOCHASTIC CG");
223  names.push_back ("RECYCLING CG");
224  names.push_back ("RECYCLING GMRES");
225  names.push_back ("PSEUDO BLOCK GMRES");
226  names.push_back ("PSEUDOBLOCKGMRES");
227  names.push_back ("PSEUDO BLOCK CG");
228  names.push_back ("PSEUDOBLOCKCG");
229  names.push_back ("TRANSPOSE-FREE QMR");
230  names.push_back ("PSEUDO BLOCK TFQMR");
231  names.push_back ("PSEUDO BLOCK TRANSPOSE-FREE QMR");
232  names.push_back ("GMRESPOLY");
233  names.push_back ("SEED GMRES");
234  names.push_back ("CGPOLY");
235  names.push_back ("SEED CG");
236  names.push_back ("FIXED POINT");
237  names.push_back ("BICGSTAB");
238 
239  return names;
240 #endif // HAVE_TEUCHOSCORE_CXX11
241 }
242 
244  return static_cast<int> (SOLVER_TYPE_UPPER_BOUND);
245 }
246 
247 std::vector<std::string>
249 {
250 #ifdef HAVE_TEUCHOSCORE_CXX11
251  return {
252  {"BLOCK GMRES"},
253  {"PSEUDOBLOCK GMRES"},
254  {"BLOCK CG"},
255  {"PSEUDOBLOCK CG"},
256  {"PSEUDOBLOCK STOCHASTIC CG"},
257  {"GCRODR"},
258  {"RCG"},
259  {"MINRES"},
260  {"LSQR"},
261  {"TFQMR"},
262  {"PSEUDOBLOCK TFQMR"},
263  {"HYBRID BLOCK GMRES"},
264  {"PCPG"},
265  {"FIXED POINT"},
266  {"BICGSTAB"}
267  };
268 #else
269  std::vector<std::string> canonicalNames (numSupportedSolvers ());
270 
271  canonicalNames.push_back ("BLOCK GMRES");
272  canonicalNames.push_back ("PSEUDOBLOCK GMRES");
273  canonicalNames.push_back ("BLOCK CG");
274  canonicalNames.push_back ("PSEUDOBLOCK CG");
275  canonicalNames.push_back ("PSEUDOBLOCK STOCHASTIC CG");
276  canonicalNames.push_back ("GCRODR");
277  canonicalNames.push_back ("RCG");
278  canonicalNames.push_back ("MINRES");
279  canonicalNames.push_back ("LSQR");
280  canonicalNames.push_back ("TFQMR");
281  canonicalNames.push_back ("PSEUDOBLOCK TFQMR");
282  canonicalNames.push_back ("HYBRID BLOCK GMRES");
283  canonicalNames.push_back ("PCPG");
284  canonicalNames.push_back ("FIXED POINT");
285  canonicalNames.push_back ("BICGSTAB");
286 
287  return canonicalNames;
288 #endif // HAVE_TEUCHOSCORE_CXX11
289 }
290 
291 void
292 reviseParameterListForAlias (const std::string& aliasName,
293  Teuchos::ParameterList& solverParams)
294 {
295  if (aliasName == "FLEXIBLE GMRES") {
296  // "Gmres" uses title case in this solver's parameter list. For
297  // our alias, we prefer the all-capitals "GMRES" that the
298  // algorithm's authors (Saad and Schultz) used.
299  solverParams.set ("Flexible Gmres", true);
300  }
301 }
302 
303 } // namespace Details
304 } // namespace Belos
305 
EBelosSolverType getEnumFromCanonicalName(const std::string &canonicalName)
Map from canonical solver name to solver enum value.
Declaration of Belos::Details::EBelosSolverType enum, and associated functions.
std::vector< std::string > solverNameAliases()
List of supported aliases (to canonical solver names).
EBelosSolverType
1-to-1 enumeration of all supported SolverManager subclasses.
int numSupportedSolvers()
Number of Belos solvers supported for any linear algebra implementation ("generically").
std::pair< std::string, bool > getCanonicalNameFromAlias(const std::string &candidateAlias)
Get the candidate canonical name for a given candidate alias.
void reviseParameterListForAlias(const std::string &aliasName, Teuchos::ParameterList &solverParams)
Modify the input ParameterList appropriately for the given solver alias.
std::vector< std::string > canonicalSolverNames()
List of canonical solver names.

Generated on Mon Feb 5 2018 15:01:51 for Belos by doxygen 1.8.13