| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Thyra: Interfaces and Support for Abstract Numerical Algorithms |
| 4 |
// |
| 5 |
// Copyright 2004 NTESS and the Thyra contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef THYRA_TPETRA_VECTOR_DECL_HPP |
| 11 |
#define THYRA_TPETRA_VECTOR_DECL_HPP |
| 12 |
|
| 13 |
|
| 14 |
#include "Thyra_SpmdVectorDefaultBase.hpp" |
| 15 |
#include "Thyra_TpetraVectorSpace_decl.hpp" |
| 16 |
#include "Tpetra_Vector.hpp" |
| 17 |
#include "Teuchos_ConstNonconstObjectContainer.hpp" |
| 18 |
|
| 19 |
|
| 20 |
namespace Thyra { |
| 21 |
|
| 22 |
|
| 23 |
/** \brief Concrete Thyra::SpmdVectorBase using Tpetra::Vector. |
| 24 |
* |
| 25 |
* \ingroup Tpetra_Thyra_Op_Vec_adapters_grp |
| 26 |
*/ |
| 27 |
template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> |
| 28 |
class TpetraVector |
| 29 |
: virtual public SpmdVectorDefaultBase<Scalar> |
| 30 |
{ |
| 31 |
public: |
| 32 |
|
| 33 |
/** @name Constructors/initializers */ |
| 34 |
//@{ |
| 35 |
|
| 36 |
/** \brief Construct to uninitialized. */ |
| 37 |
TpetraVector(); |
| 38 |
|
| 39 |
/** \brief Initialize. */ |
| 40 |
void initialize( |
| 41 |
const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace, |
| 42 |
const RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector |
| 43 |
); |
| 44 |
|
| 45 |
/** \brief Initialize. */ |
| 46 |
void constInitialize( |
| 47 |
const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace, |
| 48 |
const RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector |
| 49 |
); |
| 50 |
|
| 51 |
/** \brief Get the embedded non-const Tpetra::Vector. */ |
| 52 |
RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > |
| 53 |
getTpetraVector(); |
| 54 |
|
| 55 |
/** \brief Get the embedded non-const Tpetra::Vector. */ |
| 56 |
RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > |
| 57 |
getConstTpetraVector() const; |
| 58 |
|
| 59 |
//@} |
| 60 |
|
| 61 |
/** @name Overridden from VectorDefaultBase */ |
| 62 |
//@{ |
| 63 |
/** \brief . */ |
| 64 |
RCP<const VectorSpaceBase<Scalar> > domain() const; |
| 65 |
//@} |
| 66 |
|
| 67 |
// Should these Impl functions should alsp be protected??? |
| 68 |
//protected: |
| 69 |
|
| 70 |
/** @name Overridden from SpmdMultiVectorBase */ |
| 71 |
//@{ |
| 72 |
/** \brief . */ |
| 73 |
RCP<const SpmdVectorSpaceBase<Scalar> > spmdSpaceImpl() const; |
| 74 |
//@} |
| 75 |
|
| 76 |
/** @name Overridden from SpmdVectorBase */ |
| 77 |
//@{ |
| 78 |
/** \brief . */ |
| 79 |
void getNonconstLocalVectorDataImpl(const Ptr<ArrayRCP<Scalar> > &localValues); |
| 80 |
/** \brief . */ |
| 81 |
void getLocalVectorDataImpl(const Ptr<ArrayRCP<const Scalar> > &localValues) const; |
| 82 |
//@} |
| 83 |
|
| 84 |
protected: |
| 85 |
|
| 86 |
/** @name Overridden protected functions from VectorBase */ |
| 87 |
//@{ |
| 88 |
|
| 89 |
/** \brief . */ |
| 90 |
virtual void randomizeImpl(Scalar l, Scalar u); |
| 91 |
|
| 92 |
/** \brief . */ |
| 93 |
virtual void absImpl(const VectorBase<Scalar>& x); |
| 94 |
|
| 95 |
/** \brief . */ |
| 96 |
virtual void reciprocalImpl(const VectorBase<Scalar>& x); |
| 97 |
|
| 98 |
/** \brief . */ |
| 99 |
virtual void eleWiseScaleImpl(const VectorBase<Scalar>& x); |
| 100 |
|
| 101 |
/** \brief . */ |
| 102 |
virtual typename Teuchos::ScalarTraits<Scalar>::magnitudeType |
| 103 |
norm2WeightedImpl(const VectorBase<Scalar>& x) const; |
| 104 |
|
| 105 |
/** \brief . */ |
| 106 |
virtual void applyOpImpl( |
| 107 |
const RTOpPack::RTOpT<Scalar> &op, |
| 108 |
const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs, |
| 109 |
const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs, |
| 110 |
const Ptr<RTOpPack::ReductTarget> &reduct_obj, |
| 111 |
const Ordinal global_offset |
| 112 |
) const; |
| 113 |
|
| 114 |
/** \brief . */ |
| 115 |
void acquireDetachedVectorViewImpl( |
| 116 |
const Range1D& rng, |
| 117 |
RTOpPack::ConstSubVectorView<Scalar>* sub_vec |
| 118 |
) const; |
| 119 |
|
| 120 |
/** \brief . */ |
| 121 |
void acquireNonconstDetachedVectorViewImpl( |
| 122 |
const Range1D& rng, |
| 123 |
RTOpPack::SubVectorView<Scalar>* sub_vec |
| 124 |
); |
| 125 |
|
| 126 |
/** \brief . */ |
| 127 |
void commitNonconstDetachedVectorViewImpl( |
| 128 |
RTOpPack::SubVectorView<Scalar>* sub_vec |
| 129 |
); |
| 130 |
|
| 131 |
//@} |
| 132 |
|
| 133 |
/** @name Overridden protected functions from MultiVectorBase */ |
| 134 |
//@{ |
| 135 |
/** \brief . */ |
| 136 |
virtual void assignImpl(Scalar alpha); |
| 137 |
|
| 138 |
/** \brief . */ |
| 139 |
virtual void assignMultiVecImpl(const MultiVectorBase<Scalar>& mv); |
| 140 |
|
| 141 |
/** \brief . */ |
| 142 |
virtual void scaleImpl(Scalar alpha); |
| 143 |
|
| 144 |
/** \brief . */ |
| 145 |
virtual void updateImpl( |
| 146 |
Scalar alpha, |
| 147 |
const MultiVectorBase<Scalar>& mv |
| 148 |
); |
| 149 |
|
| 150 |
/** \brief . */ |
| 151 |
virtual void linearCombinationImpl( |
| 152 |
const ArrayView<const Scalar>& alpha, |
| 153 |
const ArrayView<const Ptr<const MultiVectorBase<Scalar> > >& mv, |
| 154 |
const Scalar& beta |
| 155 |
); |
| 156 |
|
| 157 |
/** \brief . */ |
| 158 |
virtual void dotsImpl( |
| 159 |
const MultiVectorBase<Scalar>& mv, |
| 160 |
const ArrayView<Scalar>& prods |
| 161 |
) const; |
| 162 |
|
| 163 |
/** \brief . */ |
| 164 |
virtual void norms1Impl( |
| 165 |
const ArrayView<typename ScalarTraits<Scalar>::magnitudeType>& norms |
| 166 |
) const; |
| 167 |
|
| 168 |
/** \brief . */ |
| 169 |
virtual void norms2Impl( |
| 170 |
const ArrayView<typename ScalarTraits<Scalar>::magnitudeType>& norms |
| 171 |
) const; |
| 172 |
|
| 173 |
/** \brief . */ |
| 174 |
virtual void normsInfImpl( |
| 175 |
const ArrayView<typename ScalarTraits<Scalar>::magnitudeType>& norms |
| 176 |
) const; |
| 177 |
|
| 178 |
//@} |
| 179 |
|
| 180 |
/** @name Overridden protected functions from LinearOpBase */ |
| 181 |
//@{ |
| 182 |
|
| 183 |
/** \brief . */ |
| 184 |
void applyImpl( |
| 185 |
const EOpTransp M_trans, |
| 186 |
const MultiVectorBase<Scalar> &X, |
| 187 |
const Ptr<MultiVectorBase<Scalar> > &Y, |
| 188 |
const Scalar alpha, |
| 189 |
const Scalar beta |
| 190 |
) const; |
| 191 |
|
| 192 |
//@} |
| 193 |
|
| 194 |
private: |
| 195 |
|
| 196 |
// /////////////////////////////////////// |
| 197 |
// Private data members |
| 198 |
|
| 199 |
RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > |
| 200 |
tpetraVectorSpace_; |
| 201 |
|
| 202 |
mutable RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > |
| 203 |
domainSpace_; |
| 204 |
|
| 205 |
Teuchos::ConstNonconstObjectContainer<Tpetra::Vector<Scalar, LocalOrdinal,GlobalOrdinal,Node> > |
| 206 |
tpetraVector_; |
| 207 |
|
| 208 |
typedef Tpetra::MultiVector<Scalar, LocalOrdinal,GlobalOrdinal,Node> TpetraMultiVector_t; |
| 209 |
|
| 210 |
// //////////////////////////////////// |
| 211 |
// Private member functions |
| 212 |
|
| 213 |
template<class TpetraVector_t> |
| 214 |
void initializeImpl( |
| 215 |
const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace, |
| 216 |
const RCP<TpetraVector_t> &tpetraVector |
| 217 |
); |
| 218 |
|
| 219 |
// Non-throwing Tpetra Vector/MultiVector extraction methods. |
| 220 |
// Return null if casting failed. |
| 221 |
RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > |
| 222 |
getTpetraMultiVector(const RCP<MultiVectorBase<Scalar> >& mv) const; |
| 223 |
|
| 224 |
RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > |
| 225 |
getConstTpetraMultiVector(const RCP<const MultiVectorBase<Scalar> >& mv) const; |
| 226 |
|
| 227 |
RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > |
| 228 |
getTpetraVector(const RCP<VectorBase<Scalar> >& v) const; |
| 229 |
|
| 230 |
RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > |
| 231 |
getConstTpetraVector(const RCP<const VectorBase<Scalar> >& v) const; |
| 232 |
|
| 233 |
}; |
| 234 |
|
| 235 |
|
| 236 |
/** \brief Nonmember constructor for TpetraVector. |
| 237 |
* |
| 238 |
* \relates TpetraVector |
| 239 |
*/ |
| 240 |
template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> |
| 241 |
inline |
| 242 |
RCP<TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > |
| 243 |
tpetraVector( |
| 244 |
const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace, |
| 245 |
const RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector |
| 246 |
) |
| 247 |
{ |
| 248 |
RCP<TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > v = |
| 249 |
Teuchos::rcp(new TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>); |
| 250 |
v->initialize(tpetraVectorSpace, tpetraVector); |
| 251 |
return v; |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
/** \brief Nonmember constructor for TpetraVector. |
| 256 |
* |
| 257 |
* \relates TpetraVector |
| 258 |
*/ |
| 259 |
template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> |
| 260 |
inline |
| 261 |
RCP<const TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > |
| 262 |
constTpetraVector( |
| 263 |
const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace, |
| 264 |
const RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector |
| 265 |
) |
| 266 |
{ |
| 267 |
RCP<TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > v = |
| 268 |
Teuchos::rcp(new TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>); |
| 269 |
v->constInitialize(tpetraVectorSpace, tpetraVector); |
| 270 |
return v; |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
} // end namespace Thyra |
| 275 |
|
| 276 |
|
| 277 |
#endif // THYRA_TPETRA_VECTOR_DECL_HPP |