// @HEADER // ***************************************************************************** // Rapid Optimization Library (ROL) Package // // Copyright 2014 NTESS and the ROL contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /** * \class ROL::Belos::MultiVector * \brief Specializes the Belos::MultiVecTraits to use ROL::MultiVector */ #ifndef ROL_BELOS_MULTIVECTOR_HPP #define ROL_BELOS_MULTIVECTOR_HPP #include "BelosConfigDefs.hpp" #include "BelosLinearProblem.hpp" #include "BelosMultiVecTraits.hpp" #include "BelosTypes.hpp" #include "ROL_MultiVector.hpp" #ifdef HAVE_BELOS_TSQR namespace { // (anonymous) /// \brief Stub TSQR adapter for the ROL::MultiVector specialization of /// Belos::MultiVecTraits. /// /// This is a stub. All the methods throw. The point is to make /// everything compile if TSQR is enabled. template class RolStubTsqrAdapter { public: RolStubTsqrAdapter (const Teuchos::RCP&) { ROL_TEST_FOR_EXCEPTION(false, std::logic_error, "Not implemented"); } RolStubTsqrAdapter () { ROL_TEST_FOR_EXCEPTION(false, std::logic_error, "Not implemented"); } Teuchos::RCP getValidParameters () const { return Teuchos::rcp(new Teuchos::ParameterList>()); } void setParameterList (const Teuchos::RCP&) {} void factorExplicit (ROL::MultiVector& /* A */, ROL::MultiVector& /* Q */, Teuchos::SerialDenseMatrix& /* R */, const bool forceNonnegativeDiagonal = false) { (void) forceNonnegativeDiagonal; // forestall "unused" warning ROL_TEST_FOR_EXCEPTION(false, std::logic_error, "Not implemented"); } int revealRank (ROL::MultiVector& /* Q */, Teuchos::SerialDenseMatrix& /* R */, const typename ROL::ScalarTraits::magnitudeType& /* tol */) { return 0; } }; } // namespace (anonymous) #endif // HAVE_BELOS_TSQR namespace Belos { template class MultiVecTraits > { typedef ROL::MultiVector MV; // ROL::MultiVector object typedef Teuchos::RCP PMV; // Pointer to ROL::MultiVector object typedef Teuchos::SerialDenseMatrix Matrix; typedef typename ROL::ScalarTraits::magnitudeType magnitudeType; public: /** \brief Make a new MultiVector containing a specified number of vectors @return A reference-counted pointer to the cloned MultiVector */ static PMV Clone(const MV& mv, const int numVecs) { return mv.clone(numVecs); } /** \brief Make a new MultiVector of the same size and containing a deep copy of the original MultiVector's data @return A reference-counted pointer to the cloned MultiVector */ static PMV CloneCopy(const MV& mv) { return mv.deepCopy(); } /** \brief Make a new MultiVector containing a deep copy of specified columns of the original MultiVector's data @return A reference-counted pointer to the cloned MultiVector */ static PMV CloneCopy(const MV& mv, const std::vector& index) { return mv.deepCopy(index); } /** \brief Make a new MultiVector containing a deep copy of specified contiguous block of columns of the original MultiVector's data @return A reference-counted pointer to the cloned MultiVector */ static PMV CloneCopy(const MV& mv, const Teuchos::Range1D& index) { int n = index.size(); int l = index.lbound(); std::vector stdex(n); for( int i=0; i& index) { return mv.shallowCopy(index); } /** \brief Make a new MultiVector containing pointers to a contiguous block of columns of the original MultiVector's data @return A reference-counted pointer to the cloned MultiVector */ static PMV CloneViewNonConst(MV& mv, const Teuchos::Range1D& index) { int n = index.size(); int l = index.lbound(); std::vector stdex(n); for( int i=0; i& index) { return mv.shallowCopyConst(index); } /** \brief Make a new const MultiVector containing pointers to a contiguous block of columns of the original MultiVector's data @return A reference-counted pointer to the cloned MultiVector */ static PMV CloneView(const MV& mv, const Teuchos::Range1D& index) { int n = index.size(); int l = index.lbound(); std::vector stdex(n); for( int i=0; i& alphas) { mv.scale(alphas); } /** \brief Compute \f$\alpha A^\top B$\f$ and store the result in the matrix\f$C\f$ */ static void MvTransMv(const Scalar alpha, const MV& A, const MV& B, Matrix& C) { B.innerProducts(alpha,A,C); } /** \brief Compute the columnwise dot products of A and B and store the result in dots */ static void MvDot(const MV& A, const MV& B, std::vector &dots) { A.dots(B,dots); } /** \brief Compute the columnwise norms of mv and store the result in dots */ static void MvNorm(const MV& mv, std::vector& normvec, NormType type=TwoNorm) { ROL_TEST_FOR_EXCEPTION( (type !=TwoNorm) , std::invalid_argument, "Belos::MultiVecTraits >::MvNorm()\n" "ROL::MultiVector supports only Euclidean norm"); mv.norms(normvec); } /** \brief Copy the specified columns of A into mv */ static void SetBlock(const MV& A, const std::vector& index, MV& mv) { mv.set(A,index); } /** \brief Copy the contiguous block of columns of A into mv */ static void SetBlock(const MV& A, Teuchos::Range1D& index, MV& mv) { int n = index.size(); int l = index.lbound(); std::vector stdex(n); for( int i=0; i >::Random()\n" "Random initialization not implemented for ROL::MultiVector"); } static void MvInit(MV& mv, const Scalar alpha = ROL::ScalarTraits::zero()) { ROL_TEST_FOR_EXCEPTION(alpha != 0,std::invalid_argument, "Belos::MultiVecTraits >::MvInit()\n"); mv.zero(); } static void MvPrint(const MV& mv, std::ostream& os) { ROL_TEST_FOR_EXCEPTION(true,std::logic_error, "Belos::MultiVecTraits >::MvPrint()\n" "Print not implemented for ROL::MultiVector"); } #ifdef HAVE_BELOS_TSQR /// \typedef tsqr_adaptor_type /// \brief TsqrAdaptor specialization for ROL::MultiVector typedef RolStubTsqrAdapter tsqr_adaptor_type; #endif // HAVE_BELOS_TSQR }; } #endif