| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Rapid Optimization Library (ROL) Package |
| 4 |
// |
| 5 |
// Copyright 2014 NTESS and the ROL contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
/** @ingroup la_group |
| 11 |
* \class ROL::MultiVector |
| 12 |
* \brief Provides a container and operations on multiple ROL vectors for |
| 13 |
* use with other Trilinos packages which require multivectors |
| 14 |
*/ |
| 15 |
|
| 16 |
|
| 17 |
#ifndef ROL_MULTIVECTOR_HPP |
| 18 |
#define ROL_MULTIVECTOR_HPP |
| 19 |
|
| 20 |
#include <vector> |
| 21 |
|
| 22 |
#include "ROL_Vector.hpp" |
| 23 |
#include "Teuchos_ArrayRCP.hpp" |
| 24 |
#include "Teuchos_SerialDenseMatrix.hpp" |
| 25 |
|
| 26 |
namespace ROL { |
| 27 |
|
| 28 |
template<class Real> |
| 29 |
class MultiVector { |
| 30 |
|
| 31 |
typedef Vector<Real> V; // Single vector |
| 32 |
typedef ROL::Ptr<V> PV; // Pointer to a vector |
| 33 |
typedef MultiVector<Real> MV; // Instance of the base class |
| 34 |
typedef ROL::Ptr<MV> PMV; // Pointer to an instance of the class |
| 35 |
|
| 36 |
public: |
| 37 |
|
| 38 |
virtual ~MultiVector() {} |
| 39 |
|
| 40 |
/** \brief Make a new MultiVector of the same dimensions |
| 41 |
|
| 42 |
@return A reference-counted pointer to the cloned MultiVector |
| 43 |
*/ |
| 44 |
virtual PMV clone() const = 0; |
| 45 |
|
| 46 |
/** \brief Make a new MultiVector of specified "width" |
| 47 |
|
| 48 |
@return A reference-counted pointer to the cloned MultiVector |
| 49 |
*/ |
| 50 |
virtual PMV clone( const int numvecs ) const = 0; |
| 51 |
|
| 52 |
/** \brief Make a deep copy of this MultiVector |
| 53 |
|
| 54 |
@return A reference-counted pointer to a new MultiVector containing |
| 55 |
deep copied values |
| 56 |
*/ |
| 57 |
virtual PMV deepCopy() const = 0; |
| 58 |
|
| 59 |
|
| 60 |
/** \brief Make a deep copy of this MultiVector |
| 61 |
@param[in] Array of indices of the vectors to copy |
| 62 |
@return A reference-counted pointer to a new MultiVector containing |
| 63 |
deep copied values |
| 64 |
*/ |
| 65 |
virtual PMV deepCopy(const std::vector<int> &index) const = 0; |
| 66 |
|
| 67 |
|
| 68 |
/** \brief Make a shallow copy of this MultiVector |
| 69 |
@param[in] Array of indices of the vectors to copy |
| 70 |
@return A reference-counted pointer to a new MultiVector where the |
| 71 |
elements point to the data in *this |
| 72 |
*/ |
| 73 |
virtual PMV shallowCopy(const std::vector<int> &index) = 0; |
| 74 |
|
| 75 |
|
| 76 |
/** \brief Make a shallow copy of this MultiVector |
| 77 |
@param[in] Array of indices of the vectors to copy |
| 78 |
@return A reference-counted pointer to a new MultiVector where the |
| 79 |
elements point to the data in *this |
| 80 |
*/ |
| 81 |
virtual const PMV shallowCopyConst(const std::vector<int> &index) const = 0; |
| 82 |
|
| 83 |
|
| 84 |
/** \brief Get the number of elements of a vector in the MultiVector |
| 85 |
|
| 86 |
@return Number of elements in a vector |
| 87 |
*/ |
| 88 |
virtual ptrdiff_t getLength() const = 0; |
| 89 |
|
| 90 |
|
| 91 |
/** \brief Get the number of vectors in the MultiVector |
| 92 |
|
| 93 |
@return Number of vectors in the MultiVector |
| 94 |
*/ |
| 95 |
virtual int getNumberOfVectors() const = 0; |
| 96 |
|
| 97 |
/** \brief Generic BLAS level 3 matrix multiplication |
| 98 |
\f$\text{this}\leftarrow \alpha A B+\beta\text{*this}\f$ |
| 99 |
@param[in] alpha is a multiplicative factor of @b A |
| 100 |
@param[in] @b A is a MultiVector |
| 101 |
@param[in] @b B is a SerialDenseMatrix applied to A from the right |
| 102 |
@param[in] beta is a multiplicative factor of *this |
| 103 |
*/ |
| 104 |
virtual void gemm(const Real alpha, |
| 105 |
const MV& A, |
| 106 |
const Teuchos::SerialDenseMatrix<int,Real> &B, |
| 107 |
const Real beta) = 0; |
| 108 |
|
| 109 |
/** \brief Perform the axpy operation columnwise on the MultiVector |
| 110 |
\f$ y_i\leftarrow y_i+\alpha x_i\f$ where \f$y\f$ is this MultiVector |
| 111 |
@param[in] alpha is the scaling factor |
| 112 |
@param[in] mv is the |
| 113 |
*/ |
| 114 |
virtual void axpy(const Real alpha, const MV& x) = 0; |
| 115 |
|
| 116 |
|
| 117 |
/** \brief Scale the MultiVector by a single scalar alpha |
| 118 |
\f$\text{this}\leftarrow\alpha\text{this}\f$ |
| 119 |
@param[in] alpha is a scalar multiplicative factor |
| 120 |
*/ |
| 121 |
virtual void scale(const Real alpha) = 0; |
| 122 |
|
| 123 |
|
| 124 |
/** \brief Scale each vector in the MultiVector by a different alpha |
| 125 |
\f$\text{this}[i]\leftarrow\alpha[i]\text{*this}[i]\f$ |
| 126 |
@param[in] alpha is a vector of multiplicative factors |
| 127 |
*/ |
| 128 |
virtual void scale(const std::vector<Real> &alpha) = 0; |
| 129 |
|
| 130 |
|
| 131 |
/** \brief Set the MultiVector equal to another MultiVector |
| 132 |
@param[in] @b A is a MultiVector |
| 133 |
*/ |
| 134 |
virtual void set(const MV &A) = 0; |
| 135 |
|
| 136 |
|
| 137 |
/** \brief Set some of the vectors in this MultiVector equal to corresponding |
| 138 |
vectors in another MultiVector |
| 139 |
@param[in] @b A is a MultiVector |
| 140 |
*/ |
| 141 |
virtual void set(const MV &A, const std::vector<int> &index) = 0; |
| 142 |
|
| 143 |
|
| 144 |
/** \brief Compute \f$\alpha A^\top \text{*this}\f$ |
| 145 |
@param[in] alpha is a multiplicative factor |
| 146 |
@param[in] @b A is a MultiVector |
| 147 |
@param[out] @b B is a SerialDenseMartrix in which to store the alpha-scaled |
| 148 |
dot products of this MultiVector's vectors with those of @b A |
| 149 |
*/ |
| 150 |
virtual void innerProducts(const Real alpha, |
| 151 |
const MV &A, |
| 152 |
Teuchos::SerialDenseMatrix<int,Real> &B) const = 0; |
| 153 |
|
| 154 |
|
| 155 |
/** \brief Compute dot products of pairs of vectors |
| 156 |
@param[in] @b A is a MultiVector |
| 157 |
@param[out] &b b is a vector containing the dot products between |
| 158 |
vectors contained in @b A and this MultiVector |
| 159 |
*/ |
| 160 |
virtual void dots(const MV &A, |
| 161 |
std::vector<Real> &b) const = 0; |
| 162 |
|
| 163 |
|
| 164 |
/** \brief Compute the norm of each vector in the MultiVector |
| 165 |
@param[out] &b b is a vector containing the norms of the vectors |
| 166 |
contained in this MultiVector |
| 167 |
*/ |
| 168 |
virtual void norms(std::vector<Real> &normvec) const = 0; |
| 169 |
|
| 170 |
|
| 171 |
/** \brief Zero each of the vectors in the MultiVector |
| 172 |
*/ |
| 173 |
virtual void zero() = 0; |
| 174 |
|
| 175 |
|
| 176 |
/** \brief Return a pointer to the ith vector |
| 177 |
@param[in] i is the index of the desired vector |
| 178 |
@return A reference-counted pointer to the desired vector |
| 179 |
*/ |
| 180 |
virtual PV getVector(int i) const = 0; |
| 181 |
|
| 182 |
}; |
| 183 |
} |
| 184 |
|
| 185 |
#endif |