Belos Package Browser (Single Doxygen Collection) Development
Loading...
Searching...
No Matches
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
48#endif // HAVE_BELOS_TSQR
54
55#include <Teuchos_StandardCatchMacros.hpp>
56
57#include <algorithm>
58#include <sstream>
59#include <stdexcept> // #include <string>
60#include <vector>
61
63
64namespace 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++] = "ICGS";
116 theList_[index++] = "IMGS";
117 theList_[index++] = "DGKS";
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") {
193 return Belos::getDGKSDefaultParameters<Scalar, MV, OP> ();
194 }
195#ifdef HAVE_BELOS_TSQR
196 else if (name == "TSQR") {
198 return orthoMan.getValidParameters ();
199 }
200#endif // HAVE_BELOS_TSQR
201 else if (name == "ICGS") {
202 return Belos::getICGSDefaultParameters<Scalar, MV, OP> ();
203 }
204 else if (name == "IMGS") {
205 return Belos::getIMGSDefaultParameters<Scalar, MV, OP> ();
206 }
207 else if (name == "Simple") {
209 return orthoMan.getValidParameters ();
210 }
211 else {
212 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
213 "Invalid orthogonalization manager name \"" << name
214 << "\": Valid names are " << validNamesString()
215 << ". For many of the test executables, the "
216 "orthogonalization manager name often corresponds "
217 "to the \"ortho\" command-line argument.");
218 // Placate the compiler if necessary; we should never reach
219 // this point.
220 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
221 }
222 }
223
237 Teuchos::RCP<const Teuchos::ParameterList>
238 getFastParameters (const std::string& name) const
239 {
240 if (name == "DGKS") {
241 return Belos::getDGKSFastParameters<Scalar, MV, OP> ();
242 }
243#ifdef HAVE_BELOS_TSQR
244 else if (name == "TSQR") {
246 return orthoMan.getFastParameters ();
247 }
248#endif // HAVE_BELOS_TSQR
249 else if (name == "ICGS") {
250 return Belos::getICGSFastParameters<Scalar, MV, OP> ();
251 }
252 else if (name == "IMGS") {
253 return Belos::getIMGSFastParameters<Scalar, MV, OP> ();
254 }
255 else if (name == "Simple") {
257 return orthoMan.getFastParameters ();
258 }
259 else {
260 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
261 "Invalid orthogonalization manager name \"" << name
262 << "\": Valid names are " << validNamesString()
263 << ". For many of the test executables, the "
264 "orthogonalization manager name often corresponds "
265 "to the \"ortho\" command-line argument.");
266 // Placate the compiler if necessary; we should never reach
267 // this point.
268 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
269 }
270 }
271
291 Teuchos::RCP<Belos::MatOrthoManager<Scalar, MV, OP> >
292 makeMatOrthoManager (const std::string& ortho,
293 const Teuchos::RCP<const OP>& M,
294 const Teuchos::RCP<OutputManager<Scalar> >& /* outMan */,
295 const std::string& label,
296 const Teuchos::RCP<Teuchos::ParameterList>& params)
297 {
298#ifdef HAVE_BELOS_TSQR
300#endif // HAVE_BELOS_TSQR
305 using Teuchos::rcp;
306
307 if (ortho == "DGKS") {
308 typedef DGKSOrthoManager<Scalar, MV, OP> ortho_type;
309 return rcp (new ortho_type (params, label, M));
310 }
311#ifdef HAVE_BELOS_TSQR
312 else if (ortho == "TSQR") {
313 typedef TsqrMatOrthoManager<Scalar, MV, OP> ortho_type;
314 return rcp (new ortho_type (params, label, M));
315 }
316#endif // HAVE_BELOS_TSQR
317 else if (ortho == "ICGS") {
318 typedef ICGSOrthoManager<Scalar, MV, OP> ortho_type;
319 return rcp (new ortho_type (params, label, M));
320 }
321 else if (ortho == "IMGS") {
322 typedef IMGSOrthoManager<Scalar, MV, OP> ortho_type;
323 return rcp (new ortho_type (params, label, M));
324 }
325 else if (ortho == "Simple") {
326 TEUCHOS_TEST_FOR_EXCEPTION(ortho == "Simple", std::logic_error,
327 "SimpleOrthoManager does not yet support "
328 "the MatOrthoManager interface");
329 }
330 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
331 "Invalid orthogonalization manager name: Valid names"
332 " are " << validNamesString() << ". For many of "
333 "the test executables, the orthogonalization manager"
334 " name often corresponds to the \"ortho\" command-"
335 "line argument.");
336 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null); // Guard to avoid compiler warnings.
337 }
338
355 Teuchos::RCP<Belos::OrthoManager<Scalar, MV> >
356 makeOrthoManager (const std::string& ortho,
357 const Teuchos::RCP<const OP>& M,
358 const Teuchos::RCP<OutputManager<Scalar> >& outMan,
359 const std::string& label,
360 const Teuchos::RCP<Teuchos::ParameterList>& params)
361 {
362#ifdef HAVE_BELOS_TSQR
364#endif // HAVE_BELOS_TSQR
365 using Teuchos::rcp;
366
367 if (ortho == "Simple") {
368 TEUCHOS_TEST_FOR_EXCEPTION(! M.is_null(), std::logic_error,
369 "SimpleOrthoManager is not yet supported "
370 "when the operator M is nontrivial (i.e., "
371 "M != null).");
372 return rcp (new SimpleOrthoManager<Scalar, MV> (outMan, label, params));
373 }
374#ifdef HAVE_BELOS_TSQR
375 // TsqrMatOrthoManager has to store more things and do more work
376 // than TsqrOrthoManager, in order for the former to be correct
377 // for the case of a nondefault (non-Euclidean) inner product.
378 // Thus, it's better to create a TsqrOrthoManager, when we know
379 // the operator is the default operator (M is null). Of course,
380 // a MatOrthoManager is-an OrthoManager, so returning a
381 // TsqrMatOrthoManager would still be correct; this is just an
382 // optimization.
383 else if (ortho == "TSQR" && M.is_null()) {
384 return rcp (new TsqrOrthoManager<Scalar, MV> (params, label));
385 }
386#endif // HAVE_BELOS_TSQR
387 else {
388 // A MatOrthoManager is-an OrthoManager.
389 return makeMatOrthoManager (ortho, M, outMan, label, params);
390 }
391 }
392 };
393
394} // namespace Belos
395
396#endif // __Belos_OrthoManagerFactory_hpp
397
Belos header file which uses auto-configuration information to include necessary C++ headers.
Classical Gram-Schmidt (with DGKS correction) implementation of the Belos::OrthoManager class.
Iterated Classical Gram-Schmidt (ICGS) implementation of the Belos::OrthoManager class.
Iterated Modified Gram-Schmidt (IMGS) implementation of the Belos::OrthoManager class.
Class which manages the output and verbosity of the Belos solvers.
Simple OrthoManager implementation for benchmarks.
Orthogonalization manager based on Tall Skinny QR (TSQR)
An implementation of the Belos::MatOrthoManager that performs orthogonalization using (potentially) m...
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
Enumeration of all valid Belos (Mat)OrthoManager classes.
std::vector< std::string > theList_
List of valid OrthoManager names.
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.
const std::vector< std::string > & validNames() const
List of MatOrthoManager subclasses this factory recognizes.
std::ostream & printValidNames(std::ostream &out) const
Print all recognized MatOrthoManager names to the given ostream.
const std::string & defaultName() const
Name of the "default" MatOrthoManager subclass.
bool isValidName(const std::string &name) const
Whether this factory recognizes the MatOrthoManager with the given name.
static int numOrthoManagers()
Number of MatOrthoManager subclasses this factory recognizes.
std::string validNamesString() const
List (as a string) of recognized MatOrthoManager names.
Teuchos::RCP< Belos::MatOrthoManager< Scalar, MV, OP > > makeMatOrthoManager(const std::string &ortho, const Teuchos::RCP< const OP > &M, const Teuchos::RCP< OutputManager< Scalar > > &, const std::string &label, const Teuchos::RCP< Teuchos::ParameterList > &params)
Return an instance of the specified MatOrthoManager subclass.
Teuchos::RCP< const Teuchos::ParameterList > getDefaultParameters(const std::string &name) const
Default parameters for the given MatOrthoManager subclass.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters(const std::string &name) const
"Fast" parameters for the given MatOrthoManager subclass.
static bool isRankRevealing(const std::string &name)
Is the given MatOrthoManager subclass rank-reealing?
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
Simple OrthoManager implementation for benchmarks.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a default list of parameters.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters()
Get a "fast" list of parameters.
MatOrthoManager subclass using TSQR or DGKS.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters()
Get "fast" parameters for TsqrMatOrthoManager.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get default parameters for TsqrMatOrthoManager.
TSQR-based OrthoManager subclass.