|
Thyra Package Browser (Single Doxygen Collection) Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Thyra: Interfaces and Support for Abstract Numerical Algorithms 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef THYRA_VECTOR_STD_OPS_HPP 00030 #define THYRA_VECTOR_STD_OPS_HPP 00031 00032 #include "Thyra_VectorStdOps_decl.hpp" 00033 #include "Thyra_VectorSpaceBase.hpp" 00034 #include "Thyra_VectorBase.hpp" 00035 #include "RTOpPack_ROpDotProd.hpp" 00036 #include "RTOpPack_ROpGetElement.hpp" 00037 #include "RTOpPack_TOpSetElement.hpp" 00038 #include "RTOpPack_ROpMin.hpp" 00039 #include "RTOpPack_ROpMinIndex.hpp" 00040 #include "RTOpPack_ROpMinIndexGreaterThanBound.hpp" 00041 #include "RTOpPack_ROpMax.hpp" 00042 #include "RTOpPack_ROpMaxIndex.hpp" 00043 #include "RTOpPack_ROpMaxIndexLessThanBound.hpp" 00044 #include "RTOpPack_ROpNorm1.hpp" 00045 #include "RTOpPack_ROpNorm2.hpp" 00046 #include "RTOpPack_ROpNormInf.hpp" 00047 #include "RTOpPack_ROpSum.hpp" 00048 #include "RTOpPack_ROpWeightedNorm2.hpp" 00049 #include "RTOpPack_TOpAbs.hpp" 00050 #include "RTOpPack_TOpAddScalar.hpp" 00051 #include "RTOpPack_TOpAssignScalar.hpp" 00052 #include "RTOpPack_TOpAssignVectors.hpp" 00053 #include "RTOpPack_TOpAXPY.hpp" 00054 #include "RTOpPack_TOpEleWiseDivide.hpp" 00055 #include "RTOpPack_TOpEleWiseProd.hpp" 00056 #include "RTOpPack_TOpEleWiseConjProd.hpp" 00057 #include "RTOpPack_TOpEleWiseProdUpdate.hpp" 00058 #include "RTOpPack_TOpLinearCombination.hpp" 00059 #include "RTOpPack_TOpScaleVector.hpp" 00060 #include "RTOpPack_TOpReciprocal.hpp" 00061 #include "RTOpPack_TOpRandomize.hpp" 00062 #include "Teuchos_TestForException.hpp" 00063 #include "Teuchos_Assert.hpp" 00064 00065 00066 // 00067 // All scalar types 00068 // 00069 00070 00071 // Standard text names 00072 00073 00074 // Reduction operations 00075 00076 00077 template<class Scalar> 00078 Scalar Thyra::sum( const VectorBase<Scalar>& v_rhs ) 00079 { 00080 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00081 RTOpPack::ROpSum<Scalar> sum_op; 00082 Teuchos::RCP<RTOpPack::ReductTarget> sum_targ = sum_op.reduct_obj_create(); 00083 applyOp<Scalar>(sum_op, 00084 tuple(ptrInArg(v_rhs)), 00085 ArrayView<Ptr<VectorBase<Scalar> > >(null), 00086 sum_targ.ptr() ); 00087 return sum_op(*sum_targ); 00088 } 00089 00090 00091 template<class Scalar> 00092 typename Teuchos::ScalarTraits<Scalar>::magnitudeType 00093 Thyra::norm_1( const VectorBase<Scalar>& v_rhs ) 00094 { 00095 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00096 RTOpPack::ROpNorm1<Scalar> norm_1_op; 00097 Teuchos::RCP<RTOpPack::ReductTarget> norm_1_targ = norm_1_op.reduct_obj_create(); 00098 applyOp<Scalar>(norm_1_op, tuple(ptrInArg(v_rhs)), 00099 ArrayView<Ptr<VectorBase<Scalar> > >(null), 00100 norm_1_targ.ptr() ); 00101 return norm_1_op(*norm_1_targ); 00102 } 00103 00104 00105 template<class Scalar> 00106 typename Teuchos::ScalarTraits<Scalar>::magnitudeType 00107 Thyra::norm_2( const VectorBase<Scalar>& v_rhs ) 00108 { 00109 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00110 RTOpPack::ROpNorm2<Scalar> norm_2_op; 00111 Teuchos::RCP<RTOpPack::ReductTarget> norm_2_targ = norm_2_op.reduct_obj_create(); 00112 applyOp<Scalar>(norm_2_op, tuple(ptrInArg(v_rhs)), 00113 ArrayView<Ptr<VectorBase<Scalar> > >(null), 00114 norm_2_targ.ptr() ); 00115 return norm_2_op(*norm_2_targ); 00116 } 00117 00118 00119 template<class Scalar> 00120 typename Teuchos::ScalarTraits<Scalar>::magnitudeType 00121 Thyra::norm_2( const VectorBase<Scalar>& w, const VectorBase<Scalar>& v ) 00122 { 00123 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00124 RTOpPack::ROpWeightedNorm2<Scalar> wght_norm_2_op; 00125 Teuchos::RCP<RTOpPack::ReductTarget> wght_norm_2_targ = wght_norm_2_op.reduct_obj_create(); 00126 applyOp<Scalar>(wght_norm_2_op, tuple(ptrInArg(w), ptrInArg(v)), 00127 ArrayView<const Ptr<VectorBase<Scalar> > >(null), 00128 wght_norm_2_targ.ptr()); 00129 return wght_norm_2_op(*wght_norm_2_targ); 00130 } 00131 00132 00133 template<class Scalar> 00134 typename Teuchos::ScalarTraits<Scalar>::magnitudeType 00135 Thyra::norm_inf( const VectorBase<Scalar>& v_rhs ) 00136 { 00137 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00138 RTOpPack::ROpNormInf<Scalar> norm_inf_op; 00139 Teuchos::RCP<RTOpPack::ReductTarget> norm_inf_targ = norm_inf_op.reduct_obj_create(); 00140 applyOp<Scalar>(norm_inf_op, tuple(ptrInArg(v_rhs)), 00141 ArrayView<Ptr<VectorBase<Scalar> > >(null), 00142 norm_inf_targ.ptr() ); 00143 return norm_inf_op(*norm_inf_targ); 00144 } 00145 00146 00147 template<class Scalar> 00148 Scalar Thyra::dot( const VectorBase<Scalar>& v_rhs1, const VectorBase<Scalar>& v_rhs2 ) 00149 { 00150 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00151 RTOpPack::ROpDotProd<Scalar> dot_prod_op; 00152 Teuchos::RCP<RTOpPack::ReductTarget> 00153 dot_prod_targ = dot_prod_op.reduct_obj_create(); 00154 applyOp<Scalar>(dot_prod_op, 00155 tuple(ptrInArg(v_rhs1), ptrInArg(v_rhs2))(), 00156 ArrayView<Ptr<VectorBase<Scalar> > >(null), 00157 dot_prod_targ.ptr() 00158 ); 00159 return dot_prod_op(*dot_prod_targ); 00160 } 00161 00162 00163 template<class Scalar> 00164 Scalar Thyra::get_ele( const VectorBase<Scalar>& v, Ordinal i ) 00165 { 00166 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00167 #ifdef THYRA_DEBUG 00168 TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(i, 0, v.space()->dim()); 00169 #endif 00170 RTOpPack::ROpGetElement<Scalar> get_ele_op(i); 00171 Teuchos::RCP<RTOpPack::ReductTarget> get_ele_targ = get_ele_op.reduct_obj_create(); 00172 applyOp<Scalar>(get_ele_op, tuple(ptrInArg(v)), 00173 ArrayView<Ptr<VectorBase<Scalar> > >(null), 00174 get_ele_targ.ptr() ); 00175 return get_ele_op(*get_ele_targ); 00176 } 00177 00178 00179 // Transformation operations 00180 00181 00182 template<class Scalar> 00183 void Thyra::set_ele( Ordinal i, Scalar alpha, const Ptr<VectorBase<Scalar> > &v ) 00184 { 00185 using Teuchos::tuple; using Teuchos::null; 00186 #ifdef THYRA_DEBUG 00187 TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(i, 0, v->space()->dim()); 00188 #endif 00189 RTOpPack::TOpSetElement<Scalar> set_ele_op(i, alpha); 00190 applyOp<Scalar>(set_ele_op, 00191 ArrayView<Ptr<const VectorBase<Scalar> > >(null), 00192 tuple(v), 00193 null); 00194 } 00195 00196 00197 template<class Scalar> 00198 void Thyra::put_scalar( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &v_lhs ) 00199 { 00200 using Teuchos::tuple; using Teuchos::null; 00201 RTOpPack::TOpAssignScalar<Scalar> assign_scalar_op(alpha); 00202 applyOp<Scalar>(assign_scalar_op, 00203 ArrayView<Ptr<const VectorBase<Scalar> > >(null), 00204 tuple(v_lhs), null ); 00205 } 00206 00207 00208 template<class Scalar> 00209 void Thyra::copy( const VectorBase<Scalar>& v_rhs, 00210 const Ptr<VectorBase<Scalar> > &v_lhs ) 00211 { 00212 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00213 RTOpPack::TOpAssignVectors<Scalar> assign_vectors_op; 00214 applyOp<Scalar>( assign_vectors_op, tuple(ptrInArg(v_rhs)), tuple(v_lhs), null ); 00215 } 00216 00217 00218 template<class Scalar> 00219 void Thyra::add_scalar( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &v_lhs ) 00220 { 00221 using Teuchos::tuple; using Teuchos::null; 00222 RTOpPack::TOpAddScalar<Scalar> add_scalar_op(alpha); 00223 applyOp<Scalar>(add_scalar_op, 00224 ArrayView<Ptr<const VectorBase<Scalar> > >(null), 00225 tuple(v_lhs), null ); 00226 } 00227 00228 00229 template<class Scalar> 00230 void Thyra::scale( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &v_lhs ) 00231 { 00232 using Teuchos::tuple; using Teuchos::null; 00233 if( alpha == ScalarTraits<Scalar>::zero() ) { 00234 assign(v_lhs, ScalarTraits<Scalar>::zero()); 00235 } 00236 else if( alpha != ScalarTraits<Scalar>::one() ) { 00237 RTOpPack::TOpScaleVector<Scalar> scale_vector_op(alpha); 00238 applyOp<Scalar>(scale_vector_op, 00239 ArrayView<Ptr<const VectorBase<Scalar> > >(null), 00240 tuple(v_lhs), null ); 00241 } 00242 } 00243 00244 00245 template<class Scalar> 00246 void Thyra::abs( const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x ) 00247 { 00248 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00249 RTOpPack::TOpAbs<Scalar> abs_op; 00250 applyOp<Scalar>( abs_op, tuple(ptrInArg(x)), tuple(y), null ); 00251 } 00252 00253 00254 template<class Scalar> 00255 void Thyra::reciprocal( const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x ) 00256 { 00257 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00258 RTOpPack::TOpReciprocal<Scalar> recip_op; 00259 applyOp<Scalar>( recip_op, tuple(ptrInArg(x)), tuple(y), null ); 00260 } 00261 00262 00263 template<class Scalar> 00264 void Thyra::ele_wise_prod( 00265 const Scalar& alpha, const VectorBase<Scalar>& v_rhs1, 00266 const VectorBase<Scalar>& v_rhs2, const Ptr<VectorBase<Scalar> > &v_lhs 00267 ) 00268 { 00269 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00270 RTOpPack::TOpEleWiseProd<Scalar> ele_wise_prod_op(alpha); 00271 applyOp<Scalar>( ele_wise_prod_op, tuple(ptrInArg(v_rhs1),ptrInArg(v_rhs2)), 00272 tuple(v_lhs), null ); 00273 } 00274 00275 00276 template<class Scalar> 00277 void Thyra::ele_wise_conj_prod( 00278 const Scalar& alpha, const VectorBase<Scalar>& v_rhs1, 00279 const VectorBase<Scalar>& v_rhs2, const Ptr<VectorBase<Scalar> > &v_lhs 00280 ) 00281 { 00282 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00283 RTOpPack::TOpEleWiseConjProd<Scalar> ele_wise_conj_prod_op(alpha); 00284 applyOp<Scalar>( ele_wise_conj_prod_op, tuple(ptrInArg(v_rhs1),ptrInArg(v_rhs2)), 00285 tuple(v_lhs), null ); 00286 } 00287 00288 00289 template<class Scalar> 00290 void Thyra::Vp_StVtV( 00291 const Ptr<VectorBase<Scalar> > &v_lhs, 00292 const Scalar& alpha, const VectorBase<Scalar>& v_rhs1, 00293 const VectorBase<Scalar>& v_rhs2 00294 ) 00295 { 00296 ele_wise_prod(alpha,v_rhs1,v_rhs2,v_lhs); 00297 } 00298 00299 00300 template<class Scalar> 00301 void Thyra::ele_wise_prod_update( 00302 const Scalar& alpha, const VectorBase<Scalar>& v_rhs1, 00303 const Ptr<VectorBase<Scalar> > &v_lhs 00304 ) 00305 { 00306 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00307 RTOpPack::TOpEleWiseProdUpdate<Scalar> ele_wise_prod_update_op(alpha); 00308 applyOp<Scalar>( ele_wise_prod_update_op, tuple(ptrInArg(v_rhs1)), 00309 tuple(v_lhs), null ); 00310 } 00311 00312 00313 template<class Scalar> 00314 void Thyra::Vt_StV( 00315 const Ptr<VectorBase<Scalar> > &v_lhs, 00316 const Scalar& alpha, const VectorBase<Scalar>& x ) 00317 { 00318 ele_wise_prod_update(alpha,x,v_lhs); 00319 } 00320 00321 00322 template<class Scalar> 00323 void Thyra::ele_wise_divide( 00324 const Scalar& alpha, const VectorBase<Scalar>& v_rhs1, 00325 const VectorBase<Scalar>& v_rhs2, 00326 const Ptr<VectorBase<Scalar> > &v_lhs 00327 ) 00328 { 00329 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00330 RTOpPack::TOpEleWiseDivide<Scalar> ele_wise_divide_op(alpha); 00331 applyOp<Scalar>( ele_wise_divide_op, tuple(ptrInArg(v_rhs1),ptrInArg(v_rhs2)), 00332 tuple(v_lhs), null ); 00333 } 00334 00335 00336 template<class Scalar> 00337 void Thyra::linear_combination( 00338 const ArrayView<const Scalar> &alpha, 00339 const ArrayView<const Ptr<const VectorBase<Scalar> > > &x, 00340 const Scalar &beta, 00341 const Ptr<VectorBase<Scalar> > &y 00342 ) 00343 { 00344 using Teuchos::tuple; using Teuchos::ptr; using Teuchos::ptrInArg; 00345 using Teuchos::null; 00346 const int m = x.size(); 00347 if( beta == Teuchos::ScalarTraits<Scalar>::one() && m == 1 ) { 00348 Vp_StV( y, alpha[0], *x[0] ); 00349 return; 00350 } 00351 else if( m == 0 ) { 00352 Vt_S( y, beta ); 00353 return; 00354 } 00355 RTOpPack::TOpLinearCombination<Scalar> lin_comb_op(alpha,beta); 00356 applyOp<Scalar>( lin_comb_op, x, tuple(y), null ); 00357 } 00358 00359 00360 template<class Scalar> 00361 void Thyra::seed_randomize( unsigned int s ) 00362 { 00363 RTOpPack::TOpRandomize<Scalar>::set_static_seed(s); 00364 } 00365 00366 00367 template<class Scalar> 00368 void Thyra::randomize( Scalar l, Scalar u, const Ptr<VectorBase<Scalar> > &v ) 00369 { 00370 using Teuchos::tuple; using Teuchos::null; 00371 RTOpPack::TOpRandomize<Scalar> random_vector_op(l,u); 00372 applyOp<Scalar>( random_vector_op, 00373 ArrayView<Ptr<const VectorBase<Scalar> > >(null), 00374 tuple(v), 00375 null ); 00376 // Warning! If the RTOpPack::TOpRandomize<Scalar> object is ever made 00377 // static, the one must be careful to change the seed in between calls. 00378 // Right now the seed is being incremented by the constructor automatically. 00379 // It is important to generate different random vectors on each call 00380 // (i.e. to generate different columns in a multi-vector). 00381 } 00382 00383 00384 // Linear algebra names 00385 00386 00387 template<class Scalar> 00388 void Thyra::assign( const Ptr<VectorBase<Scalar> > &v_lhs, const Scalar& alpha ) 00389 { 00390 put_scalar(alpha,v_lhs); 00391 } 00392 00393 00394 template<class Scalar> 00395 void Thyra::assign( const Ptr<VectorBase<Scalar> > &v_lhs, const VectorBase<Scalar>& v_rhs ) 00396 { 00397 copy(v_rhs,v_lhs); 00398 } 00399 00400 00401 template<class Scalar> 00402 void Thyra::Vp_S( const Ptr<VectorBase<Scalar> > &v_lhs, const Scalar& alpha ) 00403 { 00404 add_scalar(alpha,v_lhs); 00405 } 00406 00407 00408 template<class Scalar> 00409 void Thyra::Vt_S( const Ptr<VectorBase<Scalar> > &v_lhs, const Scalar& alpha ) 00410 { 00411 scale(alpha,v_lhs); 00412 } 00413 00414 00415 template<class Scalar> 00416 void Thyra::V_StV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha, 00417 const VectorBase<Scalar> &x 00418 ) 00419 { 00420 using Teuchos::tuple; using Teuchos::ptrInArg; 00421 linear_combination<Scalar>( tuple<Scalar>(alpha), tuple(ptrInArg(x)), 00422 ScalarTraits<Scalar>::zero(), y ); 00423 } 00424 00425 00426 template<class Scalar> 00427 void Thyra::Vp_StV( const Ptr<VectorBase<Scalar> > &v_lhs, const Scalar& alpha, 00428 const VectorBase<Scalar>& v_rhs 00429 ) 00430 { 00431 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00432 RTOpPack::TOpAXPY<Scalar> axpy_op(alpha); 00433 applyOp<Scalar>( axpy_op, tuple(ptrInArg(v_rhs)), tuple(v_lhs), null ); 00434 } 00435 00436 00437 template<class Scalar> 00438 void Thyra::Vp_V( const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x, 00439 const Scalar& beta 00440 ) 00441 { 00442 using Teuchos::tuple; using Teuchos::ptrInArg; 00443 linear_combination<Scalar>( 00444 tuple<Scalar>(Teuchos::ScalarTraits<Scalar>::one()), 00445 tuple(ptrInArg(x)), 00446 beta, y ); 00447 } 00448 00449 00450 template<class Scalar> 00451 void Thyra::V_V( const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x ) 00452 { 00453 assign(y,x); 00454 } 00455 00456 00457 template<class Scalar> 00458 void Thyra::V_S( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha ) 00459 { 00460 assign(y,alpha); 00461 } 00462 00463 00464 template<class Scalar> 00465 void Thyra::V_VpV( const Ptr<VectorBase<Scalar> > &z, const VectorBase<Scalar>& x, 00466 const VectorBase<Scalar>& y 00467 ) 00468 { 00469 using Teuchos::tuple; using Teuchos::ptrInArg; 00470 typedef Teuchos::ScalarTraits<Scalar> ST; 00471 linear_combination<Scalar>( 00472 tuple(ST::one(),ST::one()), 00473 tuple(ptrInArg(x),ptrInArg(y)), 00474 ST::zero(), z 00475 ); 00476 } 00477 00478 00479 template<class Scalar> 00480 void Thyra::V_VmV( const Ptr<VectorBase<Scalar> > &z, const VectorBase<Scalar>& x, 00481 const VectorBase<Scalar>& y 00482 ) 00483 { 00484 using Teuchos::tuple; using Teuchos::ptrInArg; 00485 typedef Teuchos::ScalarTraits<Scalar> ST; 00486 linear_combination<Scalar>( 00487 tuple(ST::one(),Scalar(-ST::one())), 00488 tuple(ptrInArg(x),ptrInArg(y)), 00489 ST::zero(), z 00490 ); 00491 } 00492 00493 00494 template<class Scalar> 00495 void Thyra::V_StVpV( const Ptr<VectorBase<Scalar> > &z, const Scalar &alpha, 00496 const VectorBase<Scalar>& x, const VectorBase<Scalar>& y 00497 ) 00498 { 00499 using Teuchos::tuple; using Teuchos::ptrInArg; 00500 typedef Teuchos::ScalarTraits<Scalar> ST; 00501 linear_combination<Scalar>( 00502 tuple(alpha, ST::one()), tuple(ptrInArg(x),ptrInArg(y)), 00503 ST::zero(), z 00504 ); 00505 } 00506 00507 00508 template<class Scalar> 00509 void Thyra::V_VpStV( const Ptr<VectorBase<Scalar> > &z, 00510 const VectorBase<Scalar>& x, 00511 const Scalar &alpha, const VectorBase<Scalar>& y ) 00512 { 00513 using Teuchos::tuple; using Teuchos::ptrInArg; 00514 typedef Teuchos::ScalarTraits<Scalar> ST; 00515 linear_combination<Scalar>( 00516 tuple(ST::one(), alpha), tuple(ptrInArg(x),ptrInArg(y)), 00517 ST::zero(), z 00518 ); 00519 } 00520 00521 00522 template<class Scalar> 00523 void Thyra::V_StVpStV( const Ptr<VectorBase<Scalar> > &z, const Scalar &alpha, 00524 const VectorBase<Scalar>& x, const Scalar &beta, const VectorBase<Scalar>& y 00525 ) 00526 { 00527 using Teuchos::tuple; using Teuchos::ptrInArg; 00528 typedef Teuchos::ScalarTraits<Scalar> ST; 00529 linear_combination<Scalar>( 00530 tuple(alpha, beta), tuple(ptrInArg(x),ptrInArg(y)), 00531 ST::zero(), z 00532 ); 00533 } 00534 00535 00536 // 00537 // For real types only 00538 // 00539 00540 00541 template<class Scalar> 00542 Scalar Thyra::min( const VectorBase<Scalar>& x ) { 00543 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00544 RTOpPack::ROpMin<Scalar> min_op; 00545 Teuchos::RCP<RTOpPack::ReductTarget> min_targ = min_op.reduct_obj_create(); 00546 applyOp<Scalar>( min_op, tuple(ptrInArg(x)), 00547 ArrayView<const Ptr<VectorBase<Scalar> > >(null), 00548 min_targ.ptr() ); 00549 return min_op(*min_targ); 00550 } 00551 00552 00553 template<class Scalar> 00554 void Thyra::min( const VectorBase<Scalar>& x, 00555 const Ptr<Scalar> &minEle, const Ptr<Ordinal> &minIndex 00556 ) 00557 { 00558 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00559 RTOpPack::ROpMinIndex<Scalar> min_op; 00560 Teuchos::RCP<RTOpPack::ReductTarget> min_targ = min_op.reduct_obj_create(); 00561 applyOp<Scalar>( min_op, tuple(ptrInArg(x)), 00562 ArrayView<const Ptr<VectorBase<Scalar> > >(null), 00563 min_targ.ptr() ); 00564 RTOpPack::ScalarIndex<Scalar> scalarIndex = min_op(*min_targ); 00565 *minEle = scalarIndex.scalar; 00566 *minIndex = scalarIndex.index; 00567 } 00568 00569 00570 template<class Scalar> 00571 void Thyra::minGreaterThanBound( const VectorBase<Scalar>& x, 00572 const Scalar &bound, const Ptr<Scalar> &minEle, const Ptr<Ordinal> &minIndex 00573 ) 00574 { 00575 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00576 RTOpPack::ROpMinIndexGreaterThanBound<Scalar> min_op(bound); 00577 Teuchos::RCP<RTOpPack::ReductTarget> min_targ = min_op.reduct_obj_create(); 00578 applyOp<Scalar>( min_op, tuple(ptrInArg(x)), 00579 ArrayView<const Ptr<VectorBase<Scalar> > >(null), 00580 min_targ.ptr() ); 00581 RTOpPack::ScalarIndex<Scalar> scalarIndex = min_op(*min_targ); 00582 *minEle = scalarIndex.scalar; 00583 *minIndex = scalarIndex.index; 00584 } 00585 00586 00587 template<class Scalar> 00588 Scalar Thyra::max( const VectorBase<Scalar>& x ) 00589 { 00590 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00591 RTOpPack::ROpMax<Scalar> max_op; 00592 Teuchos::RCP<RTOpPack::ReductTarget> max_targ = max_op.reduct_obj_create(); 00593 applyOp<Scalar>( max_op, tuple(ptrInArg(x)), 00594 ArrayView<const Ptr<VectorBase<Scalar> > >(null), 00595 max_targ.ptr() ); 00596 return max_op(*max_targ); 00597 } 00598 00599 00600 template<class Scalar> 00601 void Thyra::max( const VectorBase<Scalar>& x, 00602 const Ptr<Scalar> &maxEle, const Ptr<Ordinal> &maxIndex 00603 ) 00604 { 00605 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00606 RTOpPack::ROpMaxIndex<Scalar> max_op; 00607 Teuchos::RCP<RTOpPack::ReductTarget> max_targ = max_op.reduct_obj_create(); 00608 applyOp<Scalar>( max_op, tuple(ptrInArg(x)), 00609 ArrayView<const Ptr<VectorBase<Scalar> > >(null), 00610 max_targ.ptr() ); 00611 RTOpPack::ScalarIndex<Scalar> scalarIndex = max_op(*max_targ); 00612 *maxEle = scalarIndex.scalar; 00613 *maxIndex = scalarIndex.index; 00614 } 00615 00616 00617 template<class Scalar> 00618 void Thyra::maxLessThanBound( const VectorBase<Scalar>& x, 00619 const Scalar &bound, const Ptr<Scalar> &maxEle, const Ptr<Ordinal> &maxIndex 00620 ) 00621 { 00622 using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null; 00623 RTOpPack::ROpMaxIndexLessThanBound<Scalar> max_op(bound); 00624 Teuchos::RCP<RTOpPack::ReductTarget> max_targ = max_op.reduct_obj_create(); 00625 applyOp<Scalar>( max_op, tuple(ptrInArg(x)), 00626 ArrayView<const Ptr<VectorBase<Scalar> > >(null), 00627 max_targ.ptr() ); 00628 RTOpPack::ScalarIndex<Scalar> scalarIndex = max_op(*max_targ); 00629 *maxEle = scalarIndex.scalar; 00630 *maxIndex = scalarIndex.index; 00631 } 00632 00633 00634 // 00635 // Explicit instantiation macro 00636 // 00637 00638 00639 #define THYRA_VECTOR_STD_OPS_INSTANT(SCALAR) \ 00640 \ 00641 template SCALAR sum( const VectorBase<SCALAR >& v_rhs ); \ 00642 \ 00643 template ScalarTraits<SCALAR >::magnitudeType \ 00644 norm_1( const VectorBase<SCALAR >& v_rhs ); \ 00645 \ 00646 template ScalarTraits<SCALAR >::magnitudeType \ 00647 norm_2( const VectorBase<SCALAR >& v_rhs ); \ 00648 \ 00649 template ScalarTraits<SCALAR >::magnitudeType \ 00650 norm_2( const VectorBase<SCALAR >& w, const VectorBase<SCALAR >& v ); \ 00651 \ 00652 template ScalarTraits<SCALAR >::magnitudeType \ 00653 norm_inf( const VectorBase<SCALAR >& v_rhs ); \ 00654 \ 00655 template SCALAR dot( const VectorBase<SCALAR >& v_rhs1, const VectorBase<SCALAR >& v_rhs2 ); \ 00656 \ 00657 template SCALAR get_ele( const VectorBase<SCALAR >& v, Ordinal i ); \ 00658 \ 00659 template void set_ele( Ordinal i, SCALAR alpha, const Ptr<VectorBase<SCALAR > > &v ); \ 00660 \ 00661 template void put_scalar( const SCALAR& alpha, const Ptr<VectorBase<SCALAR > > &v_lhs ); \ 00662 \ 00663 template void copy( const VectorBase<SCALAR >& v_rhs, \ 00664 const Ptr<VectorBase<SCALAR > > &v_lhs ); \ 00665 \ 00666 template void add_scalar( const SCALAR& alpha, const Ptr<VectorBase<SCALAR > > &v_lhs ); \ 00667 \ 00668 template void scale( const SCALAR& alpha, const Ptr<VectorBase<SCALAR > > &v_lhs ); \ 00669 \ 00670 template void abs( const Ptr<VectorBase<SCALAR > > &y, const VectorBase<SCALAR >& x ); \ 00671 \ 00672 template void reciprocal( const Ptr<VectorBase<SCALAR > > &y, const VectorBase<SCALAR >& x ); \ 00673 \ 00674 template void ele_wise_prod( \ 00675 const SCALAR& alpha, const VectorBase<SCALAR >& v_rhs1, \ 00676 const VectorBase<SCALAR >& v_rhs2, const Ptr<VectorBase<SCALAR > > &v_lhs \ 00677 ); \ 00678 \ 00679 template void ele_wise_conj_prod( \ 00680 const SCALAR& alpha, const VectorBase<SCALAR >& v_rhs1, \ 00681 const VectorBase<SCALAR >& v_rhs2, const Ptr<VectorBase<SCALAR > > &v_lhs \ 00682 ); \ 00683 \ 00684 template void Vp_StVtV( \ 00685 const Ptr<VectorBase<SCALAR > > &v_lhs, \ 00686 const SCALAR& alpha, const VectorBase<SCALAR >& v_rhs1, \ 00687 const VectorBase<SCALAR >& v_rhs2 \ 00688 ); \ 00689 \ 00690 template void ele_wise_prod_update( \ 00691 const SCALAR& alpha, const VectorBase<SCALAR >& v_rhs1, \ 00692 const Ptr<VectorBase<SCALAR > > &v_lhs \ 00693 ); \ 00694 \ 00695 template void Vt_StV( \ 00696 const Ptr<VectorBase<SCALAR > > &v_lhs, \ 00697 const SCALAR& alpha, const VectorBase<SCALAR >& x ); \ 00698 \ 00699 template void ele_wise_divide( \ 00700 const SCALAR& alpha, const VectorBase<SCALAR >& v_rhs1, \ 00701 const VectorBase<SCALAR >& v_rhs2, \ 00702 const Ptr<VectorBase<SCALAR > > &v_lhs \ 00703 ); \ 00704 \ 00705 template void linear_combination( \ 00706 const ArrayView<const SCALAR > &alpha, \ 00707 const ArrayView<const Ptr<const VectorBase<SCALAR > > > &x, \ 00708 const SCALAR &beta, \ 00709 const Ptr<VectorBase<SCALAR > > &y \ 00710 ); \ 00711 \ 00712 template void seed_randomize<SCALAR >( unsigned int s ); \ 00713 \ 00714 template void randomize( SCALAR l, SCALAR u, const Ptr<VectorBase<SCALAR > > &v ); \ 00715 \ 00716 template void assign( const Ptr<VectorBase<SCALAR > > &v_lhs, const SCALAR& alpha ); \ 00717 \ 00718 template void assign( const Ptr<VectorBase<SCALAR > > &v_lhs, const VectorBase<SCALAR >& v_rhs ); \ 00719 \ 00720 template void Vp_S( const Ptr<VectorBase<SCALAR > > &v_lhs, const SCALAR& alpha ); \ 00721 \ 00722 template void Vt_S( const Ptr<VectorBase<SCALAR > > &v_lhs, const SCALAR& alpha ); \ 00723 \ 00724 template void V_StV( const Ptr<VectorBase<SCALAR > > &y, const SCALAR& alpha, \ 00725 const VectorBase<SCALAR > &x \ 00726 ); \ 00727 \ 00728 template void Vp_StV( const Ptr<VectorBase<SCALAR > > &v_lhs, const SCALAR& alpha, \ 00729 const VectorBase<SCALAR >& v_rhs \ 00730 ); \ 00731 \ 00732 template void Vp_V( const Ptr<VectorBase<SCALAR > > &y, const VectorBase<SCALAR >& x, \ 00733 const SCALAR& beta \ 00734 ); \ 00735 \ 00736 template void V_V( const Ptr<VectorBase<SCALAR > > &y, const VectorBase<SCALAR >& x ); \ 00737 \ 00738 template void V_S( const Ptr<VectorBase<SCALAR > > &y, const SCALAR& alpha ); \ 00739 \ 00740 template void V_VpV( const Ptr<VectorBase<SCALAR > > &z, const VectorBase<SCALAR >& x, \ 00741 const VectorBase<SCALAR >& y \ 00742 ); \ 00743 \ 00744 template void V_VmV( const Ptr<VectorBase<SCALAR > > &z, const VectorBase<SCALAR >& x, \ 00745 const VectorBase<SCALAR >& y \ 00746 ); \ 00747 \ 00748 template void V_StVpV( const Ptr<VectorBase<SCALAR > > &z, const SCALAR &alpha, \ 00749 const VectorBase<SCALAR >& x, const VectorBase<SCALAR >& y \ 00750 ); \ 00751 \ 00752 template void V_VpStV( const Ptr<VectorBase<SCALAR > > &z, \ 00753 const VectorBase<SCALAR >& x, \ 00754 const SCALAR &alpha, const VectorBase<SCALAR >& y ); \ 00755 \ 00756 template void V_StVpStV( const Ptr<VectorBase<SCALAR > > &z, const SCALAR &alpha, \ 00757 const VectorBase<SCALAR >& x, const SCALAR &beta, const VectorBase<SCALAR >& y \ 00758 ); \ 00759 00760 00761 00762 #define THYRA_VECTOR_STD_OPS_REAL_INSTANT(SCALAR) \ 00763 \ 00764 template SCALAR min( const VectorBase<SCALAR >& x ); \ 00765 \ 00766 template void min( const VectorBase<SCALAR >& x, \ 00767 const Ptr<SCALAR > &minEle, const Ptr<Ordinal> &minIndex \ 00768 ); \ 00769 \ 00770 template void minGreaterThanBound( const VectorBase<SCALAR >& x, \ 00771 const SCALAR &bound, const Ptr<SCALAR > &minEle, const Ptr<Ordinal> &minIndex \ 00772 ); \ 00773 \ 00774 template SCALAR max( const VectorBase<SCALAR >& x ); \ 00775 \ 00776 template void max( const VectorBase<SCALAR >& x, \ 00777 const Ptr<SCALAR > &maxEle, const Ptr<Ordinal> &maxIndex \ 00778 ); \ 00779 \ 00780 template void maxLessThanBound( const VectorBase<SCALAR >& x, \ 00781 const SCALAR &bound, const Ptr<SCALAR > &maxEle, const Ptr<Ordinal> &maxIndex \ 00782 ); \ 00783 00784 00785 #endif // THYRA_VECTOR_STD_OPS_HPP
1.7.4