47 #ifndef BELOS_IMGS_ORTHOMANAGER_HPP 48 #define BELOS_IMGS_ORTHOMANAGER_HPP 63 #include "Teuchos_SerialDenseMatrix.hpp" 64 #include "Teuchos_SerialDenseVector.hpp" 66 #include "Teuchos_as.hpp" 67 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp" 68 #ifdef BELOS_TEUCHOS_TIME_MONITOR 69 #include "Teuchos_TimeMonitor.hpp" 70 #endif // BELOS_TEUCHOS_TIME_MONITOR 78 template<
class ScalarType>
79 Teuchos::RCP<const Teuchos::ParameterList> TEUCHOS_DEPRECATED
83 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType magnitude_type;
84 typedef Teuchos::ScalarTraits<magnitude_type> STM;
88 const int defaultMaxNumOrthogPasses = 2;
89 const magnitude_type eps = STM::eps();
90 const magnitude_type defaultBlkTol =
91 as<magnitude_type> (10) * STM::squareroot (eps);
92 const magnitude_type defaultSingTol = as<magnitude_type> (10) * eps;
94 Teuchos::RCP<Teuchos::ParameterList> params =
95 Teuchos::parameterList (
"IMGS");
96 params->set (
"maxNumOrthogPasses", defaultMaxNumOrthogPasses,
97 "Maximum number of orthogonalization passes " 98 "(includes the first). Default is 2, since " 99 "\"twice is enough\" for Krylov methods.");
100 params->set (
"blkTol", defaultBlkTol,
101 "Block reorthogonalization threshhold.");
102 params->set (
"singTol", defaultSingTol,
103 "Singular block detection threshold.");
111 template<
class ScalarType>
112 Teuchos::RCP<const Teuchos::ParameterList> TEUCHOS_DEPRECATED
115 using Teuchos::ParameterList;
118 using Teuchos::ScalarTraits;
119 typedef typename ScalarTraits<ScalarType>::magnitudeType magnitude_type;
120 typedef ScalarTraits<magnitude_type> STM;
122 RCP<const ParameterList> defaultParams = getDefaultImgsParameters<ScalarType>();
124 RCP<ParameterList> params = rcp (
new ParameterList (*defaultParams));
126 const int maxBlkOrtho = 1;
127 const magnitude_type blkTol = STM::zero();
128 const magnitude_type singTol = STM::zero();
130 params->set (
"maxNumOrthogPasses", maxBlkOrtho);
131 params->set (
"blkTol", blkTol);
132 params->set (
"singTol", singTol);
146 template<
class ScalarType>
147 void TEUCHOS_DEPRECATED
149 int& maxNumOrthogPasses,
150 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType& blkTol,
151 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType& singTol)
153 using Teuchos::ParameterList;
155 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType magnitude_type;
156 const magnitude_type zero = Teuchos::ScalarTraits<magnitude_type>::zero();
157 RCP<const ParameterList> defaultParams = getDefaultImgsParameters<ScalarType>();
164 int _maxNumOrthogPasses;
165 magnitude_type _blkTol, _singTol;
166 if (params.is_null()) {
167 _maxNumOrthogPasses = defaultParams->get<
int> (
"maxNumOrthogPasses");
168 _blkTol = defaultParams->get<magnitude_type> (
"blkTol");
169 _singTol = defaultParams->get<magnitude_type> (
"singTol");
173 _maxNumOrthogPasses = params->get<
int> (
"maxNumOrthogPasses");
174 if (_maxNumOrthogPasses < 1)
175 _maxNumOrthogPasses = defaultParams->get<
int> (
"maxNumOrthogPasses");
176 }
catch (Teuchos::Exceptions::InvalidParameter&) {
177 _maxNumOrthogPasses = defaultParams->get<
int> (
"maxNumOrthogPasses");
181 _blkTol = params->get<magnitude_type> (
"blkTol");
183 _blkTol = defaultParams->get<magnitude_type> (
"blkTol");
184 }
catch (Teuchos::Exceptions::InvalidParameter&) {
188 _blkTol = params->get<magnitude_type> (
"depTol");
189 }
catch (Teuchos::Exceptions::InvalidParameter&) {
190 _blkTol = defaultParams->get<magnitude_type> (
"blkTol");
195 _singTol = params->get<magnitude_type> (
"singTol");
197 _singTol = defaultParams->get<magnitude_type> (
"singTol");
198 }
catch (Teuchos::Exceptions::InvalidParameter&) {
199 _singTol = defaultParams->get<magnitude_type> (
"singTol");
202 maxNumOrthogPasses = _maxNumOrthogPasses;
208 template<
class ScalarType,
class MV,
class OP>
211 public Teuchos::ParameterListAcceptorDefaultBase
214 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
215 typedef typename Teuchos::ScalarTraits<MagnitudeType> MGT;
216 typedef Teuchos::ScalarTraits<ScalarType> SCT;
227 Teuchos::RCP<const OP> Op = Teuchos::null,
228 const int max_ortho_steps = 1,
229 const MagnitudeType blk_tol = 10*MGT::squareroot( MGT::eps() ),
230 const MagnitudeType sing_tol = 10*MGT::eps() )
232 max_ortho_steps_( max_ortho_steps ),
234 sing_tol_( sing_tol ),
237 std::string orthoLabel = label_ +
": Orthogonalization";
238 #ifdef BELOS_TEUCHOS_TIME_MONITOR 239 timerOrtho_ = Teuchos::TimeMonitor::getNewCounter(orthoLabel);
242 std::string updateLabel = label_ +
": Ortho (Update)";
243 #ifdef BELOS_TEUCHOS_TIME_MONITOR 244 timerUpdate_ = Teuchos::TimeMonitor::getNewCounter(updateLabel);
247 std::string normLabel = label_ +
": Ortho (Norm)";
248 #ifdef BELOS_TEUCHOS_TIME_MONITOR 249 timerNorm_ = Teuchos::TimeMonitor::getNewCounter(normLabel);
252 std::string ipLabel = label_ +
": Ortho (Inner Product)";
253 #ifdef BELOS_TEUCHOS_TIME_MONITOR 254 timerInnerProd_ = Teuchos::TimeMonitor::getNewCounter(ipLabel);
260 const std::string& label =
"Belos",
261 Teuchos::RCP<const OP> Op = Teuchos::null) :
263 max_ortho_steps_ (2),
264 blk_tol_ (10 * MGT::squareroot (MGT::eps())),
265 sing_tol_ (10 * MGT::eps()),
270 std::string orthoLabel = label_ +
": Orthogonalization";
271 #ifdef BELOS_TEUCHOS_TIME_MONITOR 272 timerOrtho_ = Teuchos::TimeMonitor::getNewCounter(orthoLabel);
274 std::string updateLabel = label_ +
": Ortho (Update)";
275 #ifdef BELOS_TEUCHOS_TIME_MONITOR 276 timerUpdate_ = Teuchos::TimeMonitor::getNewCounter(updateLabel);
278 std::string normLabel = label_ +
": Ortho (Norm)";
279 #ifdef BELOS_TEUCHOS_TIME_MONITOR 280 timerNorm_ = Teuchos::TimeMonitor::getNewCounter(normLabel);
282 std::string ipLabel = label_ +
": Ortho (Inner Product)";
283 #ifdef BELOS_TEUCHOS_TIME_MONITOR 284 timerInnerProd_ = Teuchos::TimeMonitor::getNewCounter(ipLabel);
297 using Teuchos::Exceptions::InvalidParameterName;
298 using Teuchos::ParameterList;
299 using Teuchos::parameterList;
303 RCP<ParameterList> params;
304 if (plist.is_null()) {
305 params = parameterList (*defaultParams);
320 int maxNumOrthogPasses;
321 MagnitudeType blkTol;
322 MagnitudeType singTol;
325 maxNumOrthogPasses = params->get<
int> (
"maxNumOrthogPasses");
326 }
catch (InvalidParameterName&) {
327 maxNumOrthogPasses = defaultParams->get<
int> (
"maxNumOrthogPasses");
328 params->set (
"maxNumOrthogPasses", maxNumOrthogPasses);
339 blkTol = params->get<MagnitudeType> (
"blkTol");
340 }
catch (InvalidParameterName&) {
342 blkTol = params->get<MagnitudeType> (
"depTol");
345 params->remove (
"depTol");
346 }
catch (InvalidParameterName&) {
347 blkTol = defaultParams->get<MagnitudeType> (
"blkTol");
349 params->set (
"blkTol", blkTol);
353 singTol = params->get<MagnitudeType> (
"singTol");
354 }
catch (InvalidParameterName&) {
355 singTol = defaultParams->get<MagnitudeType> (
"singTol");
356 params->set (
"singTol", singTol);
359 max_ortho_steps_ = maxNumOrthogPasses;
363 setMyParamList (params);
366 Teuchos::RCP<const Teuchos::ParameterList>
370 using Teuchos::ParameterList;
371 using Teuchos::parameterList;
374 if (defaultParams_.is_null()) {
375 RCP<ParameterList> params = parameterList (
"IMGS");
379 const int defaultMaxNumOrthogPasses = 2;
380 const MagnitudeType eps = MGT::eps();
381 const MagnitudeType defaultBlkTol =
382 as<MagnitudeType> (10) * MGT::squareroot (eps);
383 const MagnitudeType defaultSingTol = as<MagnitudeType> (10) * eps;
385 params->set (
"maxNumOrthogPasses", defaultMaxNumOrthogPasses,
386 "Maximum number of orthogonalization passes (includes the " 387 "first). Default is 2, since \"twice is enough\" for Krylov " 389 params->set (
"blkTol", defaultBlkTol,
"Block reorthogonalization " 391 params->set (
"singTol", defaultSingTol,
"Singular block detection " 393 defaultParams_ = params;
395 return defaultParams_;
403 Teuchos::RCP<const Teuchos::ParameterList>
407 using Teuchos::ParameterList;
408 using Teuchos::parameterList;
413 RCP<ParameterList> params = parameterList (*defaultParams);
415 const int maxBlkOrtho = 1;
416 const MagnitudeType blkTol = MGT::zero();
417 const MagnitudeType singTol = MGT::zero();
419 params->set (
"maxNumOrthogPasses", maxBlkOrtho);
420 params->set (
"blkTol", blkTol);
421 params->set (
"singTol", singTol);
430 void setBlkTol(
const MagnitudeType blk_tol ) { blk_tol_ = blk_tol; }
433 void setSingTol(
const MagnitudeType sing_tol ) { sing_tol_ = sing_tol; }
474 void project ( MV &X, Teuchos::RCP<MV> MX,
475 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
476 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const;
482 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
483 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const {
513 int normalize ( MV &X, Teuchos::RCP<MV> MX,
514 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B)
const;
519 int normalize ( MV &X, Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B )
const {
566 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
567 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
568 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const;
573 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
574 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
575 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q )
const {
587 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
596 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
602 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
611 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
612 orthogError(
const MV &X1, Teuchos::RCP<const MV> MX1,
const MV &X2)
const;
621 void setLabel(
const std::string& label);
625 const std::string&
getLabel()
const {
return label_; }
631 int max_ortho_steps_;
633 MagnitudeType blk_tol_;
635 MagnitudeType sing_tol_;
639 #ifdef BELOS_TEUCHOS_TIME_MONITOR 640 Teuchos::RCP<Teuchos::Time> timerOrtho_, timerUpdate_,
641 timerNorm_, timerScale_, timerInnerProd_;
642 #endif // BELOS_TEUCHOS_TIME_MONITOR 645 mutable Teuchos::RCP<Teuchos::ParameterList> defaultParams_;
648 int findBasis(MV &X, Teuchos::RCP<MV> MX,
649 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > C,
650 bool completeBasis,
int howMany = -1 )
const;
653 bool blkOrtho1 ( MV &X, Teuchos::RCP<MV> MX,
654 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
655 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const;
658 bool blkOrtho ( MV &X, Teuchos::RCP<MV> MX,
659 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
660 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const;
675 int blkOrthoSing ( MV &X, Teuchos::RCP<MV> MX,
676 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
677 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
678 Teuchos::ArrayView<Teuchos::RCP<const MV> > QQ)
const;
683 template<
class ScalarType,
class MV,
class OP>
686 if (label != label_) {
688 std::string orthoLabel = label_ +
": Orthogonalization";
689 #ifdef BELOS_TEUCHOS_TIME_MONITOR 690 timerOrtho_ = Teuchos::TimeMonitor::getNewCounter(orthoLabel);
693 std::string updateLabel = label_ +
": Ortho (Update)";
694 #ifdef BELOS_TEUCHOS_TIME_MONITOR 695 timerUpdate_ = Teuchos::TimeMonitor::getNewCounter(updateLabel);
698 std::string normLabel = label_ +
": Ortho (Norm)";
699 #ifdef BELOS_TEUCHOS_TIME_MONITOR 700 timerNorm_ = Teuchos::TimeMonitor::getNewCounter(normLabel);
703 std::string ipLabel = label_ +
": Ortho (Inner Product)";
704 #ifdef BELOS_TEUCHOS_TIME_MONITOR 705 timerInnerProd_ = Teuchos::TimeMonitor::getNewCounter(ipLabel);
712 template<
class ScalarType,
class MV,
class OP>
713 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
715 const ScalarType ONE = SCT::one();
717 Teuchos::SerialDenseMatrix<int,ScalarType> xTx(rank,rank);
719 for (
int i=0; i<rank; i++) {
722 return xTx.normFrobenius();
727 template<
class ScalarType,
class MV,
class OP>
728 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
732 Teuchos::SerialDenseMatrix<int,ScalarType> xTx(r2,r1);
734 return xTx.normFrobenius();
739 template<
class ScalarType,
class MV,
class OP>
741 MV &X, Teuchos::RCP<MV> MX,
742 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
743 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
744 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q )
const 746 using Teuchos::Array;
748 using Teuchos::is_null;
751 using Teuchos::SerialDenseMatrix;
752 typedef SerialDenseMatrix< int, ScalarType > serial_dense_matrix_type;
753 typedef typename Array< RCP< const MV > >::size_type size_type;
755 #ifdef BELOS_TEUCHOS_TIME_MONITOR 756 Teuchos::TimeMonitor orthotimer(*timerOrtho_);
759 ScalarType ONE = SCT::one();
771 B = rcp (
new serial_dense_matrix_type (xc, xc));
781 for (size_type k = 0; k < nq; ++k)
784 const int numCols = xc;
787 C[k] = rcp (
new serial_dense_matrix_type (numRows, numCols));
788 else if (C[k]->numRows() != numRows || C[k]->numCols() != numCols)
790 int err = C[k]->reshape (numRows, numCols);
791 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error,
792 "IMGS orthogonalization: failed to reshape " 793 "C[" << k <<
"] (the array of block " 794 "coefficients resulting from projecting X " 795 "against Q[1:" << nq <<
"]).");
801 if (MX == Teuchos::null) {
809 MX = Teuchos::rcp( &X,
false );
816 TEUCHOS_TEST_FOR_EXCEPTION( xc == 0 || xr == 0, std::invalid_argument,
"Belos::IMGSOrthoManager::projectAndNormalize(): X must be non-empty" );
819 for (
int i=0; i<nq; i++) {
824 TEUCHOS_TEST_FOR_EXCEPTION( B->numRows() != xc || B->numCols() != xc, std::invalid_argument,
825 "Belos::IMGSOrthoManager::projectAndNormalize(): Size of X must be consistant with size of B" );
827 TEUCHOS_TEST_FOR_EXCEPTION( xc<0 || xr<0 || mxc<0 || mxr<0, std::invalid_argument,
828 "Belos::IMGSOrthoManager::projectAndNormalize(): MVT returned negative dimensions for X,MX" );
830 TEUCHOS_TEST_FOR_EXCEPTION( xc!=mxc || xr!=mxr, std::invalid_argument,
831 "Belos::IMGSOrthoManager::projectAndNormalize(): Size of X must be consistant with size of MX" );
837 bool dep_flg =
false;
840 Teuchos::RCP<MV> tmpX, tmpMX;
850 dep_flg = blkOrtho1( X, MX, C, Q );
854 #ifdef BELOS_TEUCHOS_TIME_MONITOR 855 Teuchos::TimeMonitor normTimer( *timerNorm_ );
857 if ( B == Teuchos::null ) {
858 B = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(xc,xc) );
860 std::vector<ScalarType> diag(xc);
862 (*B)(0,0) = SCT::squareroot(SCT::magnitude(diag[0]));
875 dep_flg = blkOrtho( X, MX, C, Q );
881 rank = blkOrthoSing( *tmpX, tmpMX, C, B, Q );
891 rank = findBasis( X, MX, B,
false );
896 rank = blkOrthoSing( *tmpX, tmpMX, C, B, Q );
908 TEUCHOS_TEST_FOR_EXCEPTION( rank > xc || rank < 0, std::logic_error,
909 "Belos::IMGSOrthoManager::projectAndNormalize(): Debug error in rank variable." );
919 template<
class ScalarType,
class MV,
class OP>
921 MV &X, Teuchos::RCP<MV> MX,
922 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B )
const {
924 #ifdef BELOS_TEUCHOS_TIME_MONITOR 925 Teuchos::TimeMonitor orthotimer(*timerOrtho_);
929 return findBasis(X, MX, B,
true);
935 template<
class ScalarType,
class MV,
class OP>
937 MV &X, Teuchos::RCP<MV> MX,
938 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
939 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const {
955 #ifdef BELOS_TEUCHOS_TIME_MONITOR 956 Teuchos::TimeMonitor orthotimer(*timerOrtho_);
962 std::vector<int> qcs(nq);
964 if (nq == 0 || xc == 0 || xr == 0) {
976 if (MX == Teuchos::null) {
984 MX = Teuchos::rcp( &X,
false );
990 TEUCHOS_TEST_FOR_EXCEPTION( xc<0 || xr<0 || mxc<0 || mxr<0, std::invalid_argument,
991 "Belos::IMGSOrthoManager::project(): MVT returned negative dimensions for X,MX" );
993 TEUCHOS_TEST_FOR_EXCEPTION( xc!=mxc || xr!=mxr || xr!=qr, std::invalid_argument,
994 "Belos::IMGSOrthoManager::project(): Size of X not consistant with MX,Q" );
998 for (
int i=0; i<nq; i++) {
1000 "Belos::IMGSOrthoManager::project(): Q lengths not mutually consistant" );
1002 TEUCHOS_TEST_FOR_EXCEPTION( qr < qcs[i], std::invalid_argument,
1003 "Belos::IMGSOrthoManager::project(): Q has less rows than columns" );
1007 if ( C[i] == Teuchos::null ) {
1008 C[i] = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(qcs[i],xc) );
1011 TEUCHOS_TEST_FOR_EXCEPTION( C[i]->numRows() != qcs[i] || C[i]->numCols() != xc , std::invalid_argument,
1012 "Belos::IMGSOrthoManager::project(): Size of Q not consistant with size of C" );
1017 blkOrtho( X, MX, C, Q );
1024 template<
class ScalarType,
class MV,
class OP>
1026 MV &X, Teuchos::RCP<MV> MX,
1027 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
1028 bool completeBasis,
int howMany )
const {
1045 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1046 Teuchos::TimeMonitor normTimer( *timerNorm_ );
1049 const ScalarType ONE = SCT::one();
1050 const MagnitudeType ZERO = SCT::magnitude(SCT::zero());
1055 if (howMany == -1) {
1066 if (MX == Teuchos::null) {
1076 if ( B == Teuchos::null ) {
1077 B = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(xc,xc) );
1084 TEUCHOS_TEST_FOR_EXCEPTION( xc == 0 || xr == 0, std::invalid_argument,
1085 "Belos::IMGSOrthoManager::findBasis(): X must be non-empty" );
1086 TEUCHOS_TEST_FOR_EXCEPTION( B->numRows() != xc || B->numCols() != xc, std::invalid_argument,
1087 "Belos::IMGSOrthoManager::findBasis(): Size of X not consistant with size of B" );
1088 TEUCHOS_TEST_FOR_EXCEPTION( xc != mxc || xr != mxr, std::invalid_argument,
1089 "Belos::IMGSOrthoManager::findBasis(): Size of X not consistant with size of MX" );
1090 TEUCHOS_TEST_FOR_EXCEPTION( xc > xr, std::invalid_argument,
1091 "Belos::IMGSOrthoManager::findBasis(): Size of X not feasible for normalization" );
1092 TEUCHOS_TEST_FOR_EXCEPTION( howMany < 0 || howMany > xc, std::invalid_argument,
1093 "Belos::IMGSOrthoManager::findBasis(): Invalid howMany parameter" );
1098 int xstart = xc - howMany;
1100 for (
int j = xstart; j < xc; j++) {
1106 bool addVec =
false;
1109 std::vector<int> index(1);
1112 Teuchos::RCP<MV> MXj;
1123 Teuchos::SerialDenseVector<int,ScalarType> product(numX);
1124 Teuchos::SerialDenseVector<int,ScalarType> P2(1);
1125 Teuchos::RCP<const MV> prevX, prevMX;
1127 std::vector<ScalarType> oldDot( 1 ), newDot( 1 );
1134 TEUCHOS_TEST_FOR_EXCEPTION( SCT::real(oldDot[0]) < ZERO,
OrthoError,
1135 "Belos::IMGSOrthoManager::findBasis(): Negative definiteness discovered in inner product" );
1138 for (
int ii=0; ii<numX; ii++) {
1146 for (
int i=0; i<max_ortho_steps_; ++i) {
1150 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1151 Teuchos::TimeMonitor innerProdTimer( *timerInnerProd_ );
1159 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1160 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1170 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1171 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1178 product[ii] = P2[0];
1180 product[ii] += P2[0];
1190 if (completeBasis) {
1194 if ( SCT::magnitude(newDot[0]) < SCT::magnitude(sing_tol_*oldDot[0]) ) {
1199 std::cout <<
"Belos::IMGSOrthoManager::findBasis() --> Random for column " << numX << std::endl;
1202 Teuchos::RCP<MV> tempXj =
MVT::Clone( X, 1 );
1203 Teuchos::RCP<MV> tempMXj;
1215 for (
int ii=0; ii<numX; ii++) {
1223 for (
int num_orth=0; num_orth<max_ortho_steps_; num_orth++){
1225 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1226 Teuchos::TimeMonitor innerProdTimer( *timerInnerProd_ );
1231 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1232 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1237 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1238 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1245 product[ii] = P2[0];
1247 product[ii] += P2[0];
1254 if ( SCT::magnitude(newDot[0]) >= SCT::magnitude(oldDot[0]*sing_tol_) ) {
1270 if ( SCT::magnitude(newDot[0]) < SCT::magnitude(oldDot[0]*blk_tol_) ) {
1279 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1298 for (
int i=0; i<numX; i++) {
1299 (*B)(i,j) = product(i);
1310 template<
class ScalarType,
class MV,
class OP>
1313 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
1314 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const 1318 const ScalarType ONE = SCT::one();
1320 std::vector<int> qcs( nq );
1321 for (
int i=0; i<nq; i++) {
1326 std::vector<int> index(1);
1327 Teuchos::RCP<const MV> tempQ;
1329 Teuchos::Array<Teuchos::RCP<MV> > MQ(nq);
1331 for (
int i=0; i<nq; i++) {
1334 for (
int ii=0; ii<qcs[i]; ii++) {
1338 Teuchos::SerialDenseMatrix<int,ScalarType> tempC( Teuchos::View, *C[i], 1, 1, ii, 0 );
1342 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1343 Teuchos::TimeMonitor innerProdTimer( *timerInnerProd_ );
1349 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1350 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1371 for (
int j = 1; j < max_ortho_steps_; ++j) {
1373 for (
int i=0; i<nq; i++) {
1375 Teuchos::SerialDenseMatrix<int,ScalarType> C2(qcs[i],1);
1378 for (
int ii=0; ii<qcs[i]; ii++) {
1382 Teuchos::SerialDenseMatrix<int,ScalarType> tempC( Teuchos::View, *C[i], 1, 1, ii, 0 );
1383 Teuchos::SerialDenseMatrix<int,ScalarType> tempC2( Teuchos::View, C2, 1, 1, ii, 0 );
1387 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1388 Teuchos::TimeMonitor innerProdTimer( *timerInnerProd_ );
1394 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1395 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1408 else if (xc <= qcs[i]) {
1421 template<
class ScalarType,
class MV,
class OP>
1424 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
1425 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const 1429 bool dep_flg =
false;
1430 const ScalarType ONE = SCT::one();
1432 std::vector<int> qcs( nq );
1433 for (
int i=0; i<nq; i++) {
1440 std::vector<ScalarType> oldDot( xc );
1443 std::vector<int> index(1);
1444 Teuchos::Array<Teuchos::RCP<MV> > MQ(nq);
1445 Teuchos::RCP<const MV> tempQ;
1448 for (
int i=0; i<nq; i++) {
1451 for (
int ii=0; ii<qcs[i]; ii++) {
1455 Teuchos::SerialDenseMatrix<int,ScalarType> tempC( Teuchos::View, *C[i], 1, xc, ii, 0 );
1459 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1460 Teuchos::TimeMonitor innerProdTimer( *timerInnerProd_ );
1466 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1467 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1488 for (
int j = 1; j < max_ortho_steps_; ++j) {
1490 for (
int i=0; i<nq; i++) {
1491 Teuchos::SerialDenseMatrix<int,ScalarType> C2(qcs[i],xc);
1494 for (
int ii=0; ii<qcs[i]; ii++) {
1498 Teuchos::SerialDenseMatrix<int,ScalarType> tempC( Teuchos::View, *C[i], 1, xc, ii, 0 );
1499 Teuchos::SerialDenseMatrix<int,ScalarType> tempC2( Teuchos::View, C2, 1, xc, ii, 0 );
1503 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1504 Teuchos::TimeMonitor innerProdTimer( *timerInnerProd_ );
1510 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1511 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1523 else if (xc <= qcs[i]) {
1532 std::vector<ScalarType> newDot(xc);
1536 for (
int i=0; i<xc; i++){
1537 if (SCT::magnitude(newDot[i]) < SCT::magnitude(oldDot[i] * blk_tol_)) {
1546 template<
class ScalarType,
class MV,
class OP>
1549 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
1550 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
1551 Teuchos::ArrayView<Teuchos::RCP<const MV> > QQ)
const 1553 Teuchos::Array<Teuchos::RCP<const MV> > Q (QQ);
1555 const ScalarType ONE = SCT::one();
1556 const ScalarType ZERO = SCT::zero();
1560 std::vector<int> indX( 1 );
1561 std::vector<ScalarType> oldDot( 1 ), newDot( 1 );
1563 std::vector<int> qcs( nq );
1564 for (
int i=0; i<nq; i++) {
1569 Teuchos::RCP<const MV> lastQ;
1570 Teuchos::RCP<MV> Xj, MXj;
1571 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > lastC;
1574 for (
int j=0; j<xc; j++) {
1576 bool dep_flg =
false;
1580 std::vector<int> index( j );
1581 for (
int ind=0; ind<j; ind++) {
1587 Q.push_back( lastQ );
1605 Teuchos::Array<Teuchos::RCP<MV> > MQ(Q.size());
1606 Teuchos::RCP<const MV> tempQ;
1609 for (
int i=0; i<Q.size(); i++) {
1612 for (
int ii=0; ii<qcs[i]; ii++) {
1617 Teuchos::SerialDenseMatrix<int,ScalarType> tempC( Teuchos::View, *C[i], 1, 1, ii, j );
1635 Teuchos::SerialDenseMatrix<int,ScalarType> tempC( Teuchos::View, *C[i], qcs[i], 1, 0, j );
1642 for (
int num_ortho_steps=1; num_ortho_steps < max_ortho_steps_; ++num_ortho_steps) {
1644 for (
int i=0; i<Q.size(); i++) {
1645 Teuchos::SerialDenseMatrix<int,ScalarType> C2( qcs[i], 1 );
1648 for (
int ii=0; ii<qcs[i]; ii++) {
1653 Teuchos::SerialDenseMatrix<int,ScalarType> tempC2( Teuchos::View, C2, 1, 1, ii );
1661 Teuchos::SerialDenseMatrix<int,ScalarType> tempC( Teuchos::View, *C[i], qcs[i], 1, 0, j );
1670 else if (xc <= qcs[i]) {
1680 if (SCT::magnitude(newDot[0]) < SCT::magnitude(oldDot[0]*sing_tol_)) {
1686 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1699 Teuchos::RCP<MV> tempXj =
MVT::Clone( X, 1 );
1700 Teuchos::RCP<MV> tempMXj;
1711 for (
int num_orth=0; num_orth<max_ortho_steps_; num_orth++) {
1713 for (
int i=0; i<Q.size(); i++) {
1714 Teuchos::SerialDenseMatrix<int,ScalarType> product( qcs[i], 1 );
1717 for (
int ii=0; ii<qcs[i]; ii++) {
1721 Teuchos::SerialDenseMatrix<int,ScalarType> tempC( Teuchos::View, product, 1, 1, ii );
1735 else if (xc <= qcs[i]) {
1747 if ( SCT::magnitude(newDot[0]) >= SCT::magnitude(oldDot[0]*sing_tol_) ) {
1748 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1756 MVT::MvAddMv( ONE/diag, *tempMXj, ZERO, *tempMXj, *MXj );
1778 #endif // BELOS_IMGS_ORTHOMANAGER_HPP void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
Teuchos::ScalarTraits< ScalarType >::magnitudeType orthogError(const MV &X1, const MV &X2) const
This method computes the error in orthogonality of two multivectors, measured as the Frobenius norm o...
static void MvDot(const MV &mv, const MV &A, std::vector< ScalarType > &b)
Compute a vector b where the components are the individual dot-products of the i-th columns of A and ...
static void MvRandom(MV &mv)
Replace the vectors in mv with random vectors.
void setBlkTol(const MagnitudeType blk_tol)
Set parameter for block re-orthogonalization threshhold.
void project(MV &X, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
This method calls project(X,Teuchos::null,C,Q); see documentation for that function.
Teuchos::ScalarTraits< ScalarType >::magnitudeType orthonormError(const MV &X) const
This method computes the error in orthonormality of a multivector, measured as the Frobenius norm of ...
static Teuchos::RCP< const MV > CloneView(const MV &mv, const std::vector< int > &index)
Creates a new const MV that shares the selected contents of mv (shallow copy).
Declaration of basic traits for the multivector type.
int projectAndNormalize(MV &X, Teuchos::RCP< MV > MX, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
Given a set of bases Q[i] and a multivector X, this method computes an orthonormal basis for ...
An extension of the MultiVecTraits class that adds a new vector length method.
Class which defines basic traits for the operator type.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
static void Assign(const MV &A, MV &mv)
mv := A
const std::string & getLabel() const
This method returns the label being used by the timers in the orthogonalization manager.
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
Replace mv with .
Traits class which defines basic operations on multivectors.
void innerProd(const MV &X, const MV &Y, Teuchos::SerialDenseMatrix< int, ScalarType > &Z) const
Provides the inner product defining the orthogonality concepts, using the provided operator...
int projectAndNormalize(MV &X, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
This method calls projectAndNormalize(X,Teuchos::null,C,B,Q); see documentation for that function...
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
Teuchos::RCP< const Teuchos::ParameterList > TEUCHOS_DEPRECATED getDefaultImgsParameters()
Default parameters for IMGSOrthoManager.
static void Apply(const OP &Op, const MV &x, MV &y, ETrans trans=NOTRANS)
Apply Op to x, putting the result into y.
Teuchos::RCP< const OP > _Op
int normalize(MV &X, Teuchos::RCP< MV > MX, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B) const
This method takes a multivector X and attempts to compute an orthonormal basis for ...
MagnitudeType getBlkTol() const
Return parameter for block re-orthogonalization threshhold.
IMGSOrthoManager(const std::string &label="Belos", Teuchos::RCP< const OP > Op=Teuchos::null, const int max_ortho_steps=1, const MagnitudeType blk_tol=10 *MGT::squareroot(MGT::eps()), const MagnitudeType sing_tol=10 *MGT::eps())
Constructor specifying re-orthogonalization tolerance.
Exception thrown to signal error in an orthogonalization manager method.
void TEUCHOS_DEPRECATED readImgsParameters(const Teuchos::RCP< const Teuchos::ParameterList > ¶ms, int &maxNumOrthogPasses, typename Teuchos::ScalarTraits< ScalarType >::magnitudeType &blkTol, typename Teuchos::ScalarTraits< ScalarType >::magnitudeType &singTol)
Read IMGS options from the given parameter list.
Teuchos::RCP< const Teuchos::ParameterList > TEUCHOS_DEPRECATED getFastImgsParameters()
"Fast" parameters for IMGSOrthoManager
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
void setLabel(const std::string &label)
This method sets the label used by the timers in the orthogonalization manager.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
void project(MV &X, Teuchos::RCP< MV > MX, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
Given a list of (mutually and internally) orthonormal bases Q, this method takes a multivector X and ...
static ptrdiff_t GetGlobalLength(const MV &mv)
Obtain the vector length of mv.
IMGSOrthoManager(const Teuchos::RCP< Teuchos::ParameterList > &plist, const std::string &label="Belos", Teuchos::RCP< const OP > Op=Teuchos::null)
Constructor that takes a list of parameters.
MagnitudeType getSingTol() const
Return parameter for singular block detection.
Class which defines basic traits for the operator type.
int normalize(MV &X, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B) const
This method calls normalize(X,Teuchos::null,B); see documentation for that function.
static void MvScale(MV &mv, const ScalarType alpha)
Scale each element of the vectors in mv with alpha.
~IMGSOrthoManager()
Destructor.
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
void setSingTol(const MagnitudeType sing_tol)
Set parameter for singular block detection.
Belos header file which uses auto-configuration information to include necessary C++ headers...
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters() const
"Fast" but possibly unsafe or less accurate parameters.
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...