Belos Package Browser (Single Doxygen Collection)  Development
BelosOrthoManagerFactory.hpp
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 
42 #ifndef __Belos_OrthoManagerFactory_hpp
43 #define __Belos_OrthoManagerFactory_hpp
44 
45 #include <BelosConfigDefs.hpp>
46 #ifdef HAVE_BELOS_TSQR
47 # include <BelosTsqrOrthoManager.hpp>
48 #endif // HAVE_BELOS_TSQR
53 #include <BelosOutputManager.hpp>
54 
55 #include <Teuchos_StandardCatchMacros.hpp>
56 
57 #include <algorithm>
58 #include <sstream>
59 #include <stdexcept> // #include <string>
60 #include <vector>
61 
63 
64 namespace Belos {
65 
81  template<class Scalar, class MV, class OP>
83  private:
85  std::vector<std::string> theList_;
86 
87  public:
89  static int numOrthoManagers () {
90 #ifdef HAVE_BELOS_TSQR
91  return 5;
92 #else
93  return 4;
94 #endif // HAVE_BELOS_TSQR
95  }
96 
102  static bool isRankRevealing (const std::string& name) {
103 #ifdef HAVE_BELOS_TSQR
104  // Currently only TSQR has a full rank-revealing capability.
105  return (name == "TSQR");
106 #else
107  return false;
108 #endif // HAVE_BELOS_TSQR
109  }
110 
113  {
114  int index = 0;
115  theList_[index++] = "DGKS";
116  theList_[index++] = "ICGS";
117  theList_[index++] = "IMGS";
118 #ifdef HAVE_BELOS_TSQR
119  theList_[index++] = "TSQR";
120 #endif // HAVE_BELOS_TSQR
121  theList_[index++] = "Simple";
122  }
123 
132  const std::vector<std::string>&
133  validNames () const { return theList_; }
134 
136  bool
137  isValidName (const std::string& name) const
138  {
139  return (std::find (theList_.begin(), theList_.end(), name) != theList_.end());
140  }
141 
143  std::ostream&
144  printValidNames (std::ostream& out) const
145  {
146  const int numValid = numOrthoManagers();
147  TEUCHOS_TEST_FOR_EXCEPTION(numValid <= 0, std::logic_error,
148  "Invalid number " << numValid << " of valid MatOrtho"
149  "Manager names. Please report this bug to the Belos "
150  "developers." );
151  if (numValid > 1) {
152  for (int k = 0; k < numValid - 1; ++k)
153  out << "\"" << theList_[k] << "\", ";
154  out << "or ";
155  }
156  out << "\"" << theList_[numValid-1] << "\"";
157  return out;
158  }
159 
164  std::string
166  {
167  std::ostringstream os;
168  (void) printValidNames (os);
169  return os.str();
170  }
171 
178  const std::string& defaultName () const { return theList_[0]; }
179 
189  Teuchos::RCP<const Teuchos::ParameterList>
190  getDefaultParameters (const std::string& name) const
191  {
192  if (name == "DGKS") {
194  return orthoMan.getValidParameters ();
195  }
196 #ifdef HAVE_BELOS_TSQR
197  else if (name == "TSQR") {
199  return orthoMan.getValidParameters ();
200  }
201 #endif // HAVE_BELOS_TSQR
202  else if (name == "ICGS") {
204  return orthoMan.getValidParameters ();
205  }
206  else if (name == "IMGS") {
208  return orthoMan.getValidParameters ();
209  }
210  else if (name == "Simple") {
212  return orthoMan.getValidParameters ();
213  }
214  else {
215  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
216  "Invalid orthogonalization manager name \"" << name
217  << "\": Valid names are " << validNamesString()
218  << ". For many of the test executables, the "
219  "orthogonalization manager name often corresponds "
220  "to the \"ortho\" command-line argument.");
221  // Placate the compiler if necessary; we should never reach
222  // this point.
223  return Teuchos::null;
224  }
225  }
226 
240  Teuchos::RCP<const Teuchos::ParameterList>
241  getFastParameters (const std::string& name) const
242  {
243  if (name == "DGKS") {
245  return orthoMan.getFastParameters ();
246  }
247 #ifdef HAVE_BELOS_TSQR
248  else if (name == "TSQR") {
250  return orthoMan.getFastParameters ();
251  }
252 #endif // HAVE_BELOS_TSQR
253  else if (name == "ICGS") {
255  return orthoMan.getFastParameters ();
256  }
257  else if (name == "IMGS") {
259  return orthoMan.getFastParameters ();
260  }
261  else if (name == "Simple") {
263  return orthoMan.getFastParameters ();
264  }
265  else {
266  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
267  "Invalid orthogonalization manager name \"" << name
268  << "\": Valid names are " << validNamesString()
269  << ". For many of the test executables, the "
270  "orthogonalization manager name often corresponds "
271  "to the \"ortho\" command-line argument.");
272  // Placate the compiler if necessary; we should never reach
273  // this point.
274  return Teuchos::null;
275  }
276  }
277 
297  Teuchos::RCP<Belos::MatOrthoManager<Scalar, MV, OP> >
298  makeMatOrthoManager (const std::string& ortho,
299  const Teuchos::RCP<const OP>& M,
300  const Teuchos::RCP<OutputManager<Scalar> >& outMan,
301  const std::string& label,
302  const Teuchos::RCP<Teuchos::ParameterList>& params)
303  {
304 #ifdef HAVE_BELOS_TSQR
306 #endif // HAVE_BELOS_TSQR
311  using Teuchos::rcp;
312 
313  if (ortho == "DGKS") {
314  typedef DGKSOrthoManager<Scalar, MV, OP> dgks_type;
315  return rcp (new dgks_type (params, label, M));
316  }
317 #ifdef HAVE_BELOS_TSQR
318  else if (ortho == "TSQR") {
319  typedef TsqrMatOrthoManager<Scalar, MV, OP> ortho_type;
320  return rcp (new ortho_type (params, label, M));
321  }
322 #endif // HAVE_BELOS_TSQR
323  else if (ortho == "ICGS") {
324  typedef ICGSOrthoManager<Scalar, MV, OP> ortho_type;
325  return rcp (new ortho_type (params, label, M));
326  }
327  else if (ortho == "IMGS") {
328  typedef IMGSOrthoManager<Scalar, MV, OP> ortho_type;
329  return rcp (new ortho_type (params, label, M));
330  }
331  else if (ortho == "Simple") {
332  TEUCHOS_TEST_FOR_EXCEPTION(ortho == "Simple", std::logic_error,
333  "SimpleOrthoManager does not yet support "
334  "the MatOrthoManager interface");
335  }
336  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
337  "Invalid orthogonalization manager name: Valid names"
338  " are " << validNamesString() << ". For many of "
339  "the test executables, the orthogonalization manager"
340  " name often corresponds to the \"ortho\" command-"
341  "line argument.");
342  return Teuchos::null; // Guard to avoid compiler warnings.
343  }
344 
361  Teuchos::RCP<Belos::OrthoManager<Scalar, MV> >
362  makeOrthoManager (const std::string& ortho,
363  const Teuchos::RCP<const OP>& M,
364  const Teuchos::RCP<OutputManager<Scalar> >& outMan,
365  const std::string& label,
366  const Teuchos::RCP<Teuchos::ParameterList>& params)
367  {
368 #ifdef HAVE_BELOS_TSQR
370 #endif // HAVE_BELOS_TSQR
371  using Teuchos::rcp;
372 
373  if (ortho == "Simple") {
374  TEUCHOS_TEST_FOR_EXCEPTION(! M.is_null(), std::logic_error,
375  "SimpleOrthoManager is not yet supported "
376  "when the operator M is nontrivial (i.e., "
377  "M != null).");
378  return rcp (new SimpleOrthoManager<Scalar, MV> (outMan, label, params));
379  }
380 #ifdef HAVE_BELOS_TSQR
381  // TsqrMatOrthoManager has to store more things and do more work
382  // than TsqrOrthoManager, in order for the former to be correct
383  // for the case of a nondefault (non-Euclidean) inner product.
384  // Thus, it's better to create a TsqrOrthoManager, when we know
385  // the operator is the default operator (M is null). Of course,
386  // a MatOrthoManager is-an OrthoManager, so returning a
387  // TsqrMatOrthoManager would still be correct; this is just an
388  // optimization.
389  else if (ortho == "TSQR" && M.is_null()) {
390  return rcp (new TsqrOrthoManager<Scalar, MV> (params, label));
391  }
392 #endif // HAVE_BELOS_TSQR
393  else {
394  // A MatOrthoManager is-an OrthoManager.
395  return makeMatOrthoManager (ortho, M, outMan, label, params);
396  }
397  }
398  };
399 
400 } // namespace Belos
401 
402 #endif // __Belos_OrthoManagerFactory_hpp
403 
Belos&#39;s basic output manager for sending information of select verbosity levels to the appropriate ou...
const std::vector< std::string > & validNames() const
List of MatOrthoManager subclasses this factory recognizes.
Teuchos::RCP< Belos::OrthoManager< Scalar, MV > > makeOrthoManager(const std::string &ortho, const Teuchos::RCP< const OP > &M, const Teuchos::RCP< OutputManager< Scalar > > &outMan, const std::string &label, const Teuchos::RCP< Teuchos::ParameterList > &params)
Return an instance of the specified OrthoManager subclass.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters() const
Class which manages the output and verbosity of the Belos solvers.
static bool isRankRevealing(const std::string &name)
Is the given MatOrthoManager subclass rank-reealing?
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters()
Get "fast" parameters for TsqrMatOrthoManager.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get default parameters for TsqrMatOrthoManager.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
static int numOrthoManagers()
Number of MatOrthoManager subclasses this factory recognizes.
std::ostream & printValidNames(std::ostream &out) const
Print all recognized MatOrthoManager names to the given ostream.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters() const
"Fast" but possibly unsafe or less accurate parameters.
Iterated Modified Gram-Schmidt (IMGS) implementation of the Belos::OrthoManager class.
Simple OrthoManager implementation for benchmarks.
Teuchos::RCP< Belos::MatOrthoManager< Scalar, MV, OP > > makeMatOrthoManager(const std::string &ortho, const Teuchos::RCP< const OP > &M, const Teuchos::RCP< OutputManager< Scalar > > &outMan, const std::string &label, const Teuchos::RCP< Teuchos::ParameterList > &params)
Return an instance of the specified MatOrthoManager subclass.
std::string validNamesString() const
List (as a string) of recognized MatOrthoManager names.
std::vector< std::string > theList_
List of valid OrthoManager names.
Classical Gram-Schmidt (with DGKS correction) implementation of the Belos::OrthoManager class...
Simple OrthoManager implementation for benchmarks.
const std::string & defaultName() const
Name of the "default" MatOrthoManager subclass.
Teuchos::RCP< const Teuchos::ParameterList > getDefaultParameters(const std::string &name) const
Default parameters for the given MatOrthoManager subclass.
Enumeration of all valid Belos (Mat)OrthoManager classes.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters(const std::string &name) const
"Fast" parameters for the given MatOrthoManager subclass.
bool isValidName(const std::string &name) const
Whether this factory recognizes the MatOrthoManager with the given name.
Iterated Classical Gram-Schmidt (ICGS) implementation of the Belos::OrthoManager class.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters() const
"Fast" but possibly unsafe or less accurate parameters.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
An implementation of the Belos::MatOrthoManager that performs orthogonalization using (potentially) m...
Orthogonalization manager based on Tall Skinny QR (TSQR)
MatOrthoManager subclass using TSQR or DGKS.
Belos header file which uses auto-configuration information to include necessary C++ headers...
TSQR-based OrthoManager subclass.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const