/usr/include/trilinos/BelosSolverManager.hpp is in libtrilinos-belos-dev 12.10.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | //@HEADER
// ************************************************************************
//
// Belos: Block Linear Solvers Package
// Copyright 2004 Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
//
// ************************************************************************
//@HEADER
#ifndef BELOS_SOLVERMANAGER_HPP
#define BELOS_SOLVERMANAGER_HPP
/*! \file BelosSolverManager.hpp
\brief Pure virtual base class which describes the basic interface for a solver manager.
*/
#include "BelosConfigDefs.hpp"
#include "BelosTypes.hpp"
#include "BelosLinearProblem.hpp"
#include "BelosStatusTestCombo.hpp"
#include "Teuchos_ParameterList.hpp"
#include "Teuchos_RCP.hpp"
#include "Teuchos_Describable.hpp"
/*! \class Belos::SolverManager
\brief The Belos::SolverManager is a templated virtual base class that defines the
basic interface that any solver manager will support.
*/
namespace Belos {
template <class ScalarType, class MV, class OP>
class StatusTest;
template<class ScalarType, class MV, class OP>
class SolverManager : virtual public Teuchos::Describable {
public:
//!@name Constructors/Destructor
//@{
//! Empty constructor.
SolverManager() {};
//! Destructor.
virtual ~SolverManager() {};
//@}
//! @name Accessor methods
//@{
//! Return a reference to the linear problem being solved by this solver manager.
virtual const LinearProblem<ScalarType,MV,OP>& getProblem() const = 0;
//! Return the valid parameters for this solver manager.
virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const = 0;
//! Return the current parameters being used for this solver manager.
virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const = 0;
/// \brief Tolerance achieved by the last \c solve() invocation.
///
/// This is the maximum over all right-hand sides' achieved
/// convergence tolerances, and is set whether or not the solve
/// actually managed to achieve the desired convergence tolerance.
///
/// The default implementation throws std::runtime_error. This is
/// in case the idea of a single convergence tolerance doesn't make
/// sense for some solvers. It also serves as a gradual upgrade
/// path (since this method is a later addition to the \c
/// SolverManager interface).
virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType achievedTol() const {
TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "achievedTol() not implemented");
}
//! Get the iteration count for the most recent call to \c solve().
virtual int getNumIters() const = 0;
/*! \brief Returns whether a loss of accuracy was detected in the solver.
* \note This method is normally applicable to GMRES-type solvers.
*/
virtual bool isLOADetected() const = 0;
//@}
//! @name Set methods
//@{
//! Set the linear problem that needs to be solved.
virtual void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) = 0;
/// \brief Set the parameters to use when solving the linear problem.
///
/// \param params [in/out] List of parameters to use when solving
/// the linear problem. This list will be modified as necessary
/// to include default parameters that need not be provided. If
/// params is null, then this method uses default parameters.
///
/// \note The ParameterList returned by \c getValidParameters() has
/// all the parameters that the solver understands, possibly
/// including human-readable documentation and validators.
virtual void setParameters( const Teuchos::RCP<Teuchos::ParameterList> ¶ms ) = 0;
//! Set user-defined convergence status test.
virtual void setUserConvStatusTest(
const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &userConvStatusTest,
const typename StatusTestCombo<ScalarType,MV,OP>::ComboType &comboType =
StatusTestCombo<ScalarType,MV,OP>::SEQ
)
{
TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error, the function setUserConvStatusTest() has not been"
<< " overridden for the class" << this->description() << " yet!");
}
//! Set user-defined debug status test.
virtual void setDebugStatusTest(
const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &debugStatusTest
)
{
TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error, the function setDebugStatusTest() has not been"
<< " overridden for the class" << this->description() << " yet!");
}
//@}
//! @name Reset methods
//@{
/// \brief Reset the solver manager.
///
/// Reset the solver manager in a way specified by the \c
/// ResetType parameter. This informs the solver manager that the
/// solver should prepare for the next call to solve by resetting
/// certain elements of the iterative solver strategy.
virtual void reset( const ResetType type ) = 0;
//@}
//! @name Solver application methods
//@{
/// \brief Iterate until the status test tells us to stop.
//
/// This method performs possibly repeated calls to the underlying
/// linear solver's iterate() routine, until the problem has been
/// solved (as decided by the solver manager via the status
/// test(s)), or the solver manager decides to quit.
///
/// \return A \c Belos::ReturnType enum specifying:
/// - Belos::Converged: the linear problem was solved to the
/// specification required by the solver manager.
/// - Belos::Unconverged: the linear problem was not solved to the
/// specification desired by the solver manager.
virtual ReturnType solve() = 0;
//@}
};
namespace Details {
/// \class RealSolverManager
/// \brief Base class for Belos::SolverManager subclasses which
/// normally can only compile for real ScalarType.
///
/// It can be a lot of trouble to make a solver implementation
/// compile correctly for both real and complex ScalarType. That's
/// why this class exists. If a Belos solver inherits from this
/// class, that indicates that the solver's implementation can only
/// compile if ScalarType is real (not complex). If you attempt to
/// invoke the solver's constructor when <tt>ScalarType</tt> is
/// complex, the constructor will throw an exception.
///
/// The point of this class is to ensure that Belos::SolverFactory
/// will always compile, even if some Belos solvers' implementations
/// cannot compile when ScalarType is complex. See GCRODRSolMgr for
/// an example of how to use this class to avoid compilation of code
/// that only works for real ScalarType.
template<class ScalarType,
class MV,
class OP,
const bool isComplex = Teuchos::ScalarTraits<ScalarType>::isComplex>
class RealSolverManager;
// Specialization for isComplex = true adds nothing to SolverManager.
template<class ScalarType, class MV, class OP>
class RealSolverManager<ScalarType, MV, OP, false> :
public SolverManager<ScalarType, MV, OP> {
public:
RealSolverManager () {}
virtual ~RealSolverManager () {}
};
// Specialization for isComplex = true (ScalarType is complex) adds
// a constructor that always throws std::logic_error. Subclasses
// must always call the base class constructor.
//
// The complex version (isComplex = true) needs to implement all the
// pure virtual methods in SolverManager, even though they can never
// actually be called, since the constructor throws.
template<class ScalarType, class MV, class OP>
class RealSolverManager<ScalarType, MV, OP, true> :
public SolverManager<ScalarType, MV, OP> {
public:
RealSolverManager () {
TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
"This solver is not implemented for complex ScalarType." );
}
virtual ~RealSolverManager () {}
virtual const LinearProblem<ScalarType,MV,OP>& getProblem() const {
TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
"This solver is not implemented for complex ScalarType." );
}
virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
"This solver is not implemented for complex ScalarType." );
}
virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
"This solver is not implemented for complex ScalarType." );
}
virtual int getNumIters() const {
TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
"This solver is not implemented for complex ScalarType." );
}
virtual bool isLOADetected() const {
TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
"This solver is not implemented for complex ScalarType." );
}
virtual void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
"This solver is not implemented for complex ScalarType." );
}
virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
"This solver is not implemented for complex ScalarType." );
}
virtual void reset (const ResetType type) {
TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
"This solver is not implemented for complex ScalarType." );
}
virtual ReturnType solve () {
TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
"This solver is not implemented for complex ScalarType." );
}
};
/// \class LapackSupportsScalar
/// \brief Type traits class that says whether Teuchos::LAPACK
/// has a valid implementation for the given ScalarType.
template<class ScalarType>
class LapackSupportsScalar {
public:
const static bool value = false;
};
template<>
class LapackSupportsScalar<float> {
public:
const static bool value = true;
};
template<>
class LapackSupportsScalar<double> {
public:
const static bool value = true;
};
#ifdef HAVE_TEUCHOS_COMPLEX
template<>
class LapackSupportsScalar<std::complex<float> > {
public:
const static bool value = true;
};
template<>
class LapackSupportsScalar<std::complex<double> > {
public:
const static bool value = true;
};
#endif // HAVE_TEUCHOS_COMPLEX
/// \class SolverManagerRequiresLapack
/// \brief Base class for Belos::SolverManager subclasses which
/// normally can only compile with ScalarType types for which
/// Teuchos::LAPACK has a valid implementation.
template<class ScalarType,
class MV,
class OP,
const bool lapackSupportsScalarType =
Belos::Details::LapackSupportsScalar<ScalarType>::value>
class SolverManagerRequiresLapack;
/// \brief Specialization for ScalarType types for which
/// Teuchos::LAPACK has a valid implementation.
///
/// This specialization adds nothing to SolverManager.
template<class ScalarType, class MV, class OP>
class SolverManagerRequiresLapack<ScalarType, MV, OP, true> :
public SolverManager<ScalarType, MV, OP> {
public:
SolverManagerRequiresLapack () {}
virtual ~SolverManagerRequiresLapack () {}
};
/// \brief Specialization for ScalarType types for which
/// Teuchos::LAPACK does NOT have a valid implementation.
///
/// This is a stub specialization whose constructor always throws
/// std::logic_error. Subclasses must always call the base class
/// constructor.
template<class ScalarType, class MV, class OP>
class SolverManagerRequiresLapack<ScalarType, MV, OP, false> :
public SolverManager<ScalarType, MV, OP> {
public:
SolverManagerRequiresLapack () {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for ScalarType"
" types for which Teuchos::LAPACK does not have a valid implementation. "
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual ~SolverManagerRequiresLapack () {}
virtual const LinearProblem<ScalarType,MV,OP>& getProblem() const {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for ScalarType"
" types for which Teuchos::LAPACK does not have a valid implementation. "
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for ScalarType"
" types for which Teuchos::LAPACK does not have a valid implementation. "
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for ScalarType"
" types for which Teuchos::LAPACK does not have a valid implementation. "
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual int getNumIters() const {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for ScalarType"
" types for which Teuchos::LAPACK does not have a valid implementation. "
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual bool isLOADetected() const {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for ScalarType"
" types for which Teuchos::LAPACK does not have a valid implementation. "
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for ScalarType"
" types for which Teuchos::LAPACK does not have a valid implementation. "
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for ScalarType"
" types for which Teuchos::LAPACK does not have a valid implementation. "
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual void reset (const ResetType type) {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for ScalarType"
" types for which Teuchos::LAPACK does not have a valid implementation. "
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual ReturnType solve () {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for ScalarType"
" types for which Teuchos::LAPACK does not have a valid implementation. "
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
};
/// \class SolverManagerRequiresRealLapack
/// \brief Base class for Belos::SolverManager subclasses which
/// normally can only compile with <i>real</i> ScalarType types
/// for which Teuchos::LAPACK has a valid implementation.
template<class ScalarType,
class MV,
class OP,
const bool supportsScalarType =
Belos::Details::LapackSupportsScalar<ScalarType>::value &&
! Teuchos::ScalarTraits<ScalarType>::isComplex>
class SolverManagerRequiresRealLapack;
/// \brief Non-stub specialization for real ScalarType types for
/// which Teuchos::LAPACK has a valid implementation.
///
/// This specialization adds nothing to SolverManager. Thus, the
/// SolverManager subclass that has the actual specific solver
/// implementation gets to implement any virtual methods of
/// SolverManager.
template<class ScalarType, class MV, class OP>
class SolverManagerRequiresRealLapack<ScalarType, MV, OP, true> :
public SolverManager<ScalarType, MV, OP> {
public:
SolverManagerRequiresRealLapack () {}
virtual ~SolverManagerRequiresRealLapack () {}
};
/// \brief Stub specialization for ScalarType types which are NOT
/// real, or for which Teuchos::LAPACK does NOT have a valid
/// implementation.
///
/// This is a stub specialization whose constructor always throws
/// std::logic_error. Subclasses must always call the base class
/// constructor.
template<class ScalarType, class MV, class OP>
class SolverManagerRequiresRealLapack<ScalarType, MV, OP, false> :
public SolverManager<ScalarType, MV, OP> {
public:
SolverManagerRequiresRealLapack () {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for complex "
"ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
"does not have a valid implementation."
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual ~SolverManagerRequiresRealLapack () {}
virtual const LinearProblem<ScalarType,MV,OP>& getProblem() const {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for complex "
"ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
"does not have a valid implementation."
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for complex "
"ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
"does not have a valid implementation."
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for complex "
"ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
"does not have a valid implementation."
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual int getNumIters() const {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for complex "
"ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
"does not have a valid implementation."
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual bool isLOADetected() const {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for complex "
"ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
"does not have a valid implementation."
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual void
setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> >& /* problem */) {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for complex "
"ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
"does not have a valid implementation."
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for complex "
"ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
"does not have a valid implementation."
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual void reset (const ResetType type) {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for complex "
"ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
"does not have a valid implementation."
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
virtual ReturnType solve () {
TEUCHOS_TEST_FOR_EXCEPTION
(true, std::logic_error, "This solver is not implemented for complex "
"ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
"does not have a valid implementation."
"ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
}
};
} // namespace Details
} // namespace Belos
#endif /* BELOS_SOLVERMANAGER_HPP */
|