10 #ifndef THYRA_MULTI_VECTOR_STD_OPS_HPP
11 #define THYRA_MULTI_VECTOR_STD_OPS_HPP
13 #include "Thyra_MultiVectorStdOps_decl.hpp"
14 #include "Thyra_VectorStdOps.hpp"
15 #include "Thyra_VectorSpaceBase.hpp"
16 #include "Thyra_VectorStdOps.hpp"
17 #include "Thyra_MultiVectorBase.hpp"
18 #include "Thyra_VectorBase.hpp"
19 #include "RTOpPack_ROpSum.hpp"
20 #include "RTOpPack_ROpNorm1.hpp"
21 #include "RTOpPack_ROpNormInf.hpp"
22 #include "Teuchos_Assert.hpp"
23 #include "Teuchos_Assert.hpp"
24 #include "Teuchos_as.hpp"
27 template<
class Scalar>
28 void Thyra::norms(
const MultiVectorBase<Scalar>& V,
32 const int m = V.domain()->dim();
33 Array<Scalar> prods(m);
34 V.range()->scalarProds(V, V, prods());
35 for (
int j = 0; j < m; ++j )
36 norms[j] = ST::magnitude(ST::squareroot(prods[j]));
40 template<
class Scalar>
41 void Thyra::dots(
const MultiVectorBase<Scalar>& V1,
const MultiVectorBase<Scalar>& V2,
42 const ArrayView<Scalar> &
dots )
48 template<
class Scalar>
49 void Thyra::sums(
const MultiVectorBase<Scalar>& V,
const ArrayView<Scalar> &
sums )
51 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
52 const int m = V.domain()->dim();
53 RTOpPack::ROpSum<Scalar> sum_op;
54 Array<RCP<RTOpPack::ReductTarget> > rcp_op_targs(m);
55 Array<Ptr<RTOpPack::ReductTarget> > op_targs(m);
56 for(
int kc = 0; kc < m; ++kc ) {
57 rcp_op_targs[kc] = sum_op.reduct_obj_create();
58 op_targs[kc] = rcp_op_targs[kc].ptr();
60 applyOp<Scalar>(sum_op, tuple(ptrInArg(V)),
61 ArrayView<const Ptr<MultiVectorBase<Scalar> > >(null), op_targs);
62 for(
int kc = 0; kc < m; ++kc ) {
63 sums[kc] = sum_op(*op_targs[kc]);
68 template<
class Scalar>
70 Thyra::norm_1(
const MultiVectorBase<Scalar>& V )
72 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
74 RTOpPack::ROpNorm1<Scalar> sum_abs_op;
76 RTOpPack::ROpNormInf<Scalar> max_op;
78 RCP<RTOpPack::ReductTarget>
79 max_targ = max_op.reduct_obj_create();
81 Thyra::applyOp<Scalar>(sum_abs_op, max_op, tuple(ptrInArg(V))(),
82 ArrayView<
const Ptr<MultiVectorBase<Scalar> > >(null),
85 return max_op(*max_targ);
89 template<
class Scalar>
90 void Thyra::scale( Scalar alpha,
const Ptr<MultiVectorBase<Scalar> > &V )
96 template<
class Scalar>
97 void Thyra::scaleUpdate(
const VectorBase<Scalar>& a,
98 const MultiVectorBase<Scalar>& U,
const Ptr<MultiVectorBase<Scalar> > &V )
101 bool is_compatible = U.range()->isCompatible(*a.space());
103 !is_compatible, Exceptions::IncompatibleVectorSpaces,
104 "update(...), Error, U.range()->isCompatible(*a.space())==false" );
105 is_compatible = U.range()->isCompatible(*V->range());
107 !is_compatible, Exceptions::IncompatibleVectorSpaces,
108 "update(...), Error, U.range()->isCompatible((V->range())==false" );
109 is_compatible = U.domain()->isCompatible(*V->domain());
111 !is_compatible, Exceptions::IncompatibleVectorSpaces,
112 "update(...), Error, U.domain().isCompatible(V->domain())==false" );
114 const int m = U.domain()->dim();
115 for(
int j = 0; j < m; ++j ) {
116 ele_wise_prod<Scalar>( 1.0, a, *U.col(j), V->col(j).ptr() );
121 template<
class Scalar>
122 void Thyra::assign(
const Ptr<MultiVectorBase<Scalar> > &V, Scalar alpha )
128 template<
class Scalar>
129 void Thyra::assign(
const Ptr<MultiVectorBase<Scalar> > &V,
130 const MultiVectorBase<Scalar>& U )
136 template<
class Scalar>
137 void Thyra::update( Scalar alpha,
const MultiVectorBase<Scalar>& U,
138 const Ptr<MultiVectorBase<Scalar> > &V )
144 template<
class Scalar>
145 void Thyra::update(
const ArrayView<const Scalar> &alpha, Scalar beta,
146 const MultiVectorBase<Scalar>& U,
const Ptr<MultiVectorBase<Scalar> > &V )
149 bool is_compatible = U.range()->isCompatible(*V->range());
151 !is_compatible, Exceptions::IncompatibleVectorSpaces,
152 "update(...), Error, U.range()->isCompatible((V->range())==false");
153 is_compatible = U.domain()->isCompatible(*V->domain());
155 !is_compatible, Exceptions::IncompatibleVectorSpaces,
156 "update(...), Error, U.domain().isCompatible(V->domain())==false");
158 const int m = U.domain()->dim();
159 for(
int j = 0; j < m; ++j )
160 Vp_StV<Scalar>( V->col(j).ptr(), alpha[j]*beta, *U.col(j) );
164 template<
class Scalar>
165 void Thyra::update(
const MultiVectorBase<Scalar>& U,
166 const ArrayView<const Scalar> &alpha, Scalar beta,
167 const Ptr<MultiVectorBase<Scalar> > &V )
170 bool is_compatible = U.range()->isCompatible(*V->range());
172 !is_compatible, Exceptions::IncompatibleVectorSpaces,
173 "update(...), Error, U.range()->isCompatible((V->range())==false");
174 is_compatible = U.domain()->isCompatible(*V->domain());
176 !is_compatible, Exceptions::IncompatibleVectorSpaces,
177 "update(...), Error, U.domain().isCompatible(V->domain())==false");
179 const int m = U.domain()->dim();
180 for(
int j = 0; j < m; ++j ) {
181 Vt_S<Scalar>( V->col(j).ptr(), alpha[j]*beta );
182 Vp_StV<Scalar>( V->col(j).ptr(), 1.0, *U.col(j) );
187 template<
class Scalar>
188 void Thyra::linear_combination(
189 const ArrayView<const Scalar> &alpha,
190 const ArrayView<
const Ptr<
const MultiVectorBase<Scalar> > > &X,
192 const Ptr<MultiVectorBase<Scalar> > &Y
195 Y->linear_combination(alpha, X, beta);
199 template<
class Scalar>
200 void Thyra::randomize( Scalar l, Scalar u,
201 const Ptr<MultiVectorBase<Scalar> > &V )
203 const int m = V->domain()->dim();
204 for(
int j = 0; j < m; ++j )
210 template<
class Scalar>
211 void Thyra::Vt_S(
const Ptr<MultiVectorBase<Scalar> > &Z,
212 const Scalar& alpha )
218 template<
class Scalar>
219 void Thyra::Vp_S(
const Ptr<MultiVectorBase<Scalar> > &Z,
220 const Scalar& alpha )
222 const int m = Z->domain()->dim();
223 for(
int j = 0; j < m; ++j )
224 Vp_S( Z->col(j).ptr(), alpha );
229 template<
class Scalar>
230 void Thyra::Vp_V(
const Ptr<MultiVectorBase<Scalar> > &Z,
231 const MultiVectorBase<Scalar>& X )
233 using Teuchos::tuple;
using Teuchos::ptrInArg;
235 linear_combination<Scalar>( tuple(ST::one()), tuple(ptrInArg(X)),
240 template<
class Scalar>
241 void Thyra::V_VpV(
const Ptr<MultiVectorBase<Scalar> > &Z,
242 const MultiVectorBase<Scalar>& X,
const MultiVectorBase<Scalar>& Y )
244 using Teuchos::tuple;
using Teuchos::ptrInArg;
246 linear_combination<Scalar>(
247 tuple(ST::one(), ST::one()), tuple(ptrInArg(X), ptrInArg(Y)),
253 template<
class Scalar>
254 void Thyra::V_VmV(
const Ptr<MultiVectorBase<Scalar> > &Z,
255 const MultiVectorBase<Scalar>& X,
const MultiVectorBase<Scalar>& Y )
257 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::as;
259 linear_combination<Scalar>(
260 tuple(ST::one(), as<Scalar>(-ST::one())), tuple(ptrInArg(X), ptrInArg(Y)),
266 template<
class Scalar>
268 const Ptr<MultiVectorBase<Scalar> > &Z,
const Scalar &alpha,
269 const MultiVectorBase<Scalar>& X,
const MultiVectorBase<Scalar>& Y
272 using Teuchos::tuple;
using Teuchos::ptrInArg;
274 linear_combination<Scalar>(
275 tuple(alpha, ST::one()), tuple(ptrInArg(X), ptrInArg(Y)),
285 #define THYRA_MULTI_VECTOR_STD_OPS_INSTANT(SCALAR) \
287 template void norms( const MultiVectorBase<SCALAR >& V, \
288 const ArrayView<ScalarTraits<SCALAR >::magnitudeType> &norms ); \
290 template void dots( const MultiVectorBase<SCALAR >& V1, const MultiVectorBase<SCALAR >& V2, \
291 const ArrayView<SCALAR > &dots ); \
293 template void sums( const MultiVectorBase<SCALAR >& V, const ArrayView<SCALAR > &sums ); \
295 template Teuchos::ScalarTraits<SCALAR >::magnitudeType \
296 norm_1( const MultiVectorBase<SCALAR >& V ); \
298 template void scale( SCALAR alpha, const Ptr<MultiVectorBase<SCALAR > > &V ); \
300 template void scaleUpdate( const VectorBase<SCALAR >& a, \
301 const MultiVectorBase<SCALAR >& U, const Ptr<MultiVectorBase<SCALAR > > &V ); \
303 template void assign( const Ptr<MultiVectorBase<SCALAR > > &V, SCALAR alpha ); \
305 template void assign( const Ptr<MultiVectorBase<SCALAR > > &V, \
306 const MultiVectorBase<SCALAR >& U ); \
308 template void update( SCALAR alpha, const MultiVectorBase<SCALAR >& U, \
309 const Ptr<MultiVectorBase<SCALAR > > &V ); \
311 template void update( const ArrayView<const SCALAR > &alpha, SCALAR beta, \
312 const MultiVectorBase<SCALAR >& U, const Ptr<MultiVectorBase<SCALAR > > &V ); \
314 template void update( const MultiVectorBase<SCALAR >& U, \
315 const ArrayView<const SCALAR > &alpha, SCALAR beta, \
316 const Ptr<MultiVectorBase<SCALAR > > &V ); \
318 template void linear_combination( \
319 const ArrayView<const SCALAR > &alpha, \
320 const ArrayView<const Ptr<const MultiVectorBase<SCALAR > > > &X, \
321 const SCALAR &beta, \
322 const Ptr<MultiVectorBase<SCALAR > > &Y \
325 template void randomize( SCALAR l, SCALAR u, \
326 const Ptr<MultiVectorBase<SCALAR > > &V ); \
328 template void Vt_S( const Ptr<MultiVectorBase<SCALAR > > &Z, \
329 const SCALAR & alpha ); \
331 template void Vp_S( const Ptr<MultiVectorBase<SCALAR > > &Z, \
332 const SCALAR & alpha ); \
334 template void Vp_V( const Ptr<MultiVectorBase<SCALAR > > &Z, \
335 const MultiVectorBase<SCALAR >& X ); \
337 template void V_VpV( const Ptr<MultiVectorBase<SCALAR > > &Z, \
338 const MultiVectorBase<SCALAR >& X, const MultiVectorBase<SCALAR >& Y ); \
340 template void V_VmV( const Ptr<MultiVectorBase<SCALAR > > &Z, \
341 const MultiVectorBase<SCALAR >& X, const MultiVectorBase<SCALAR >& Y ); \
343 template void V_StVpV( \
344 const Ptr<MultiVectorBase<SCALAR > > &Z, const SCALAR &alpha, \
345 const MultiVectorBase<SCALAR >& X, const MultiVectorBase<SCALAR >& Y \
349 #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.