42 #ifndef THYRA_MULTI_VECTOR_STD_OPS_HPP
43 #define THYRA_MULTI_VECTOR_STD_OPS_HPP
45 #include "Thyra_MultiVectorStdOps_decl.hpp"
46 #include "Thyra_VectorStdOps.hpp"
47 #include "Thyra_VectorSpaceBase.hpp"
48 #include "Thyra_VectorStdOps.hpp"
49 #include "Thyra_MultiVectorBase.hpp"
50 #include "Thyra_VectorBase.hpp"
51 #include "RTOpPack_ROpSum.hpp"
52 #include "RTOpPack_ROpNorm1.hpp"
53 #include "RTOpPack_ROpNormInf.hpp"
54 #include "Teuchos_Assert.hpp"
55 #include "Teuchos_Assert.hpp"
56 #include "Teuchos_as.hpp"
59 template<
class Scalar>
60 void Thyra::norms(
const MultiVectorBase<Scalar>& V,
64 const int m = V.domain()->dim();
65 Array<Scalar> prods(m);
66 V.range()->scalarProds(V, V, prods());
67 for (
int j = 0; j < m; ++j )
68 norms[j] = ST::magnitude(ST::squareroot(prods[j]));
72 template<
class Scalar>
73 void Thyra::dots(
const MultiVectorBase<Scalar>& V1,
const MultiVectorBase<Scalar>& V2,
74 const ArrayView<Scalar> &
dots )
80 template<
class Scalar>
81 void Thyra::sums(
const MultiVectorBase<Scalar>& V,
const ArrayView<Scalar> &
sums )
83 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
84 const int m = V.domain()->dim();
85 RTOpPack::ROpSum<Scalar> sum_op;
86 Array<RCP<RTOpPack::ReductTarget> > rcp_op_targs(m);
87 Array<Ptr<RTOpPack::ReductTarget> > op_targs(m);
88 for(
int kc = 0; kc < m; ++kc ) {
89 rcp_op_targs[kc] = sum_op.reduct_obj_create();
90 op_targs[kc] = rcp_op_targs[kc].ptr();
92 applyOp<Scalar>(sum_op, tuple(ptrInArg(V)),
93 ArrayView<const Ptr<MultiVectorBase<Scalar> > >(null), op_targs);
94 for(
int kc = 0; kc < m; ++kc ) {
95 sums[kc] = sum_op(*op_targs[kc]);
100 template<
class Scalar>
102 Thyra::norm_1(
const MultiVectorBase<Scalar>& V )
104 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
106 RTOpPack::ROpNorm1<Scalar> sum_abs_op;
108 RTOpPack::ROpNormInf<Scalar> max_op;
110 RCP<RTOpPack::ReductTarget>
111 max_targ = max_op.reduct_obj_create();
113 Thyra::applyOp<Scalar>(sum_abs_op, max_op, tuple(ptrInArg(V))(),
114 ArrayView<
const Ptr<MultiVectorBase<Scalar> > >(null),
117 return max_op(*max_targ);
121 template<
class Scalar>
122 void Thyra::scale( Scalar alpha,
const Ptr<MultiVectorBase<Scalar> > &V )
128 template<
class Scalar>
129 void Thyra::scaleUpdate(
const VectorBase<Scalar>& a,
130 const MultiVectorBase<Scalar>& U,
const Ptr<MultiVectorBase<Scalar> > &V )
133 bool is_compatible = U.range()->isCompatible(*a.space());
135 !is_compatible, Exceptions::IncompatibleVectorSpaces,
136 "update(...), Error, U.range()->isCompatible(*a.space())==false" );
137 is_compatible = U.range()->isCompatible(*V->range());
139 !is_compatible, Exceptions::IncompatibleVectorSpaces,
140 "update(...), Error, U.range()->isCompatible((V->range())==false" );
141 is_compatible = U.domain()->isCompatible(*V->domain());
143 !is_compatible, Exceptions::IncompatibleVectorSpaces,
144 "update(...), Error, U.domain().isCompatible(V->domain())==false" );
146 const int m = U.domain()->dim();
147 for(
int j = 0; j < m; ++j ) {
148 ele_wise_prod<Scalar>( 1.0, a, *U.col(j), V->col(j).ptr() );
153 template<
class Scalar>
154 void Thyra::assign(
const Ptr<MultiVectorBase<Scalar> > &V, Scalar alpha )
160 template<
class Scalar>
161 void Thyra::assign(
const Ptr<MultiVectorBase<Scalar> > &V,
162 const MultiVectorBase<Scalar>& U )
168 template<
class Scalar>
169 void Thyra::update( Scalar alpha,
const MultiVectorBase<Scalar>& U,
170 const Ptr<MultiVectorBase<Scalar> > &V )
176 template<
class Scalar>
177 void Thyra::update(
const ArrayView<const Scalar> &alpha, Scalar beta,
178 const MultiVectorBase<Scalar>& U,
const Ptr<MultiVectorBase<Scalar> > &V )
181 bool is_compatible = U.range()->isCompatible(*V->range());
183 !is_compatible, Exceptions::IncompatibleVectorSpaces,
184 "update(...), Error, U.range()->isCompatible((V->range())==false");
185 is_compatible = U.domain()->isCompatible(*V->domain());
187 !is_compatible, Exceptions::IncompatibleVectorSpaces,
188 "update(...), Error, U.domain().isCompatible(V->domain())==false");
190 const int m = U.domain()->dim();
191 for(
int j = 0; j < m; ++j )
192 Vp_StV<Scalar>( V->col(j).ptr(), alpha[j]*beta, *U.col(j) );
196 template<
class Scalar>
197 void Thyra::update(
const MultiVectorBase<Scalar>& U,
198 const ArrayView<const Scalar> &alpha, Scalar beta,
199 const Ptr<MultiVectorBase<Scalar> > &V )
202 bool is_compatible = U.range()->isCompatible(*V->range());
204 !is_compatible, Exceptions::IncompatibleVectorSpaces,
205 "update(...), Error, U.range()->isCompatible((V->range())==false");
206 is_compatible = U.domain()->isCompatible(*V->domain());
208 !is_compatible, Exceptions::IncompatibleVectorSpaces,
209 "update(...), Error, U.domain().isCompatible(V->domain())==false");
211 const int m = U.domain()->dim();
212 for(
int j = 0; j < m; ++j ) {
213 Vt_S<Scalar>( V->col(j).ptr(), alpha[j]*beta );
214 Vp_StV<Scalar>( V->col(j).ptr(), 1.0, *U.col(j) );
219 template<
class Scalar>
220 void Thyra::linear_combination(
221 const ArrayView<const Scalar> &alpha,
222 const ArrayView<
const Ptr<
const MultiVectorBase<Scalar> > > &X,
224 const Ptr<MultiVectorBase<Scalar> > &Y
227 Y->linear_combination(alpha, X, beta);
231 template<
class Scalar>
232 void Thyra::randomize( Scalar l, Scalar u,
233 const Ptr<MultiVectorBase<Scalar> > &V )
235 const int m = V->domain()->dim();
236 for(
int j = 0; j < m; ++j )
242 template<
class Scalar>
243 void Thyra::Vt_S(
const Ptr<MultiVectorBase<Scalar> > &Z,
244 const Scalar& alpha )
250 template<
class Scalar>
251 void Thyra::Vp_S(
const Ptr<MultiVectorBase<Scalar> > &Z,
252 const Scalar& alpha )
254 const int m = Z->domain()->dim();
255 for(
int j = 0; j < m; ++j )
256 Vp_S( Z->col(j).ptr(), alpha );
261 template<
class Scalar>
262 void Thyra::Vp_V(
const Ptr<MultiVectorBase<Scalar> > &Z,
263 const MultiVectorBase<Scalar>& X )
265 using Teuchos::tuple;
using Teuchos::ptrInArg;
267 linear_combination<Scalar>( tuple(ST::one()), tuple(ptrInArg(X)),
272 template<
class Scalar>
273 void Thyra::V_VpV(
const Ptr<MultiVectorBase<Scalar> > &Z,
274 const MultiVectorBase<Scalar>& X,
const MultiVectorBase<Scalar>& Y )
276 using Teuchos::tuple;
using Teuchos::ptrInArg;
278 linear_combination<Scalar>(
279 tuple(ST::one(), ST::one()), tuple(ptrInArg(X), ptrInArg(Y)),
285 template<
class Scalar>
286 void Thyra::V_VmV(
const Ptr<MultiVectorBase<Scalar> > &Z,
287 const MultiVectorBase<Scalar>& X,
const MultiVectorBase<Scalar>& Y )
289 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::as;
291 linear_combination<Scalar>(
292 tuple(ST::one(), as<Scalar>(-ST::one())), tuple(ptrInArg(X), ptrInArg(Y)),
298 template<
class Scalar>
300 const Ptr<MultiVectorBase<Scalar> > &Z,
const Scalar &alpha,
301 const MultiVectorBase<Scalar>& X,
const MultiVectorBase<Scalar>& Y
304 using Teuchos::tuple;
using Teuchos::ptrInArg;
306 linear_combination<Scalar>(
307 tuple(alpha, ST::one()), tuple(ptrInArg(X), ptrInArg(Y)),
317 #define THYRA_MULTI_VECTOR_STD_OPS_INSTANT(SCALAR) \
319 template void norms( const MultiVectorBase<SCALAR >& V, \
320 const ArrayView<ScalarTraits<SCALAR >::magnitudeType> &norms ); \
322 template void dots( const MultiVectorBase<SCALAR >& V1, const MultiVectorBase<SCALAR >& V2, \
323 const ArrayView<SCALAR > &dots ); \
325 template void sums( const MultiVectorBase<SCALAR >& V, const ArrayView<SCALAR > &sums ); \
327 template Teuchos::ScalarTraits<SCALAR >::magnitudeType \
328 norm_1( const MultiVectorBase<SCALAR >& V ); \
330 template void scale( SCALAR alpha, const Ptr<MultiVectorBase<SCALAR > > &V ); \
332 template void scaleUpdate( const VectorBase<SCALAR >& a, \
333 const MultiVectorBase<SCALAR >& U, const Ptr<MultiVectorBase<SCALAR > > &V ); \
335 template void assign( const Ptr<MultiVectorBase<SCALAR > > &V, SCALAR alpha ); \
337 template void assign( const Ptr<MultiVectorBase<SCALAR > > &V, \
338 const MultiVectorBase<SCALAR >& U ); \
340 template void update( SCALAR alpha, const MultiVectorBase<SCALAR >& U, \
341 const Ptr<MultiVectorBase<SCALAR > > &V ); \
343 template void update( const ArrayView<const SCALAR > &alpha, SCALAR beta, \
344 const MultiVectorBase<SCALAR >& U, const Ptr<MultiVectorBase<SCALAR > > &V ); \
346 template void update( const MultiVectorBase<SCALAR >& U, \
347 const ArrayView<const SCALAR > &alpha, SCALAR beta, \
348 const Ptr<MultiVectorBase<SCALAR > > &V ); \
350 template void linear_combination( \
351 const ArrayView<const SCALAR > &alpha, \
352 const ArrayView<const Ptr<const MultiVectorBase<SCALAR > > > &X, \
353 const SCALAR &beta, \
354 const Ptr<MultiVectorBase<SCALAR > > &Y \
357 template void randomize( SCALAR l, SCALAR u, \
358 const Ptr<MultiVectorBase<SCALAR > > &V ); \
360 template void Vt_S( const Ptr<MultiVectorBase<SCALAR > > &Z, \
361 const SCALAR & alpha ); \
363 template void Vp_S( const Ptr<MultiVectorBase<SCALAR > > &Z, \
364 const SCALAR & alpha ); \
366 template void Vp_V( const Ptr<MultiVectorBase<SCALAR > > &Z, \
367 const MultiVectorBase<SCALAR >& X ); \
369 template void V_VpV( const Ptr<MultiVectorBase<SCALAR > > &Z, \
370 const MultiVectorBase<SCALAR >& X, const MultiVectorBase<SCALAR >& Y ); \
372 template void V_VmV( const Ptr<MultiVectorBase<SCALAR > > &Z, \
373 const MultiVectorBase<SCALAR >& X, const MultiVectorBase<SCALAR >& Y ); \
375 template void V_StVpV( \
376 const Ptr<MultiVectorBase<SCALAR > > &Z, const SCALAR &alpha, \
377 const MultiVectorBase<SCALAR >& X, const MultiVectorBase<SCALAR >& Y \
381 #endif // THYRA_MULTI_VECTOR_STD_OPS_HPP
void Vp_S(const Ptr< MultiVectorBase< Scalar > > &Z, const Scalar &alpha)
Z(i,j) += alpha, i = 0...Z->range()->dim()-1, j = 0...Z->domain()->dim()-1.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void sums(const MultiVectorBase< Scalar > &V, const ArrayView< Scalar > &sums)
Multi-vector column sum.
void norms(const MultiVectorBase< Scalar > &V, const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms)
Column-wise multi-vector natural norm.
void randomize(Scalar l, Scalar u, const Ptr< MultiVectorBase< Scalar > > &V)
Generate a random multi-vector with elements uniformly distributed elements.
TypeTo as(const TypeFrom &t)
void dots(const MultiVectorBase< Scalar > &V1, const MultiVectorBase< Scalar > &V2, const ArrayView< Scalar > &dots)
Multi-vector dot product.