47 #ifndef BELOS_ICGS_ORTHOMANAGER_HPP 48 #define BELOS_ICGS_ORTHOMANAGER_HPP 64 #include "Teuchos_as.hpp" 65 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp" 66 #ifdef BELOS_TEUCHOS_TIME_MONITOR 67 #include "Teuchos_TimeMonitor.hpp" 68 #endif // BELOS_TEUCHOS_TIME_MONITOR 76 template<
class ScalarType>
77 Teuchos::RCP<const Teuchos::ParameterList> TEUCHOS_DEPRECATED
81 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType magnitude_type;
82 typedef Teuchos::ScalarTraits<magnitude_type> STM;
86 const int defaultMaxNumOrthogPasses = 2;
87 const magnitude_type eps = STM::eps();
88 const magnitude_type defaultBlkTol =
89 as<magnitude_type> (10) * STM::squareroot (eps);
90 const magnitude_type defaultSingTol = as<magnitude_type> (10) * eps;
92 Teuchos::RCP<Teuchos::ParameterList> params =
93 Teuchos::parameterList (
"ICGS");
94 params->set (
"maxNumOrthogPasses", defaultMaxNumOrthogPasses,
95 "Maximum number of orthogonalization passes " 96 "(includes the first). Default is 2, since " 97 "\"twice is enough\" for Krylov methods.");
98 params->set (
"blkTol", defaultBlkTol,
99 "Block reorthogonalization threshhold.");
100 params->set (
"singTol", defaultSingTol,
101 "Singular block detection threshold.");
109 template<
class ScalarType>
110 Teuchos::RCP<const Teuchos::ParameterList> TEUCHOS_DEPRECATED
113 using Teuchos::ParameterList;
116 using Teuchos::ScalarTraits;
117 typedef typename ScalarTraits<ScalarType>::magnitudeType magnitude_type;
118 typedef ScalarTraits<magnitude_type> STM;
120 RCP<const ParameterList> defaultParams = getDefaultIcgsParameters<ScalarType>();
122 RCP<ParameterList> params = rcp (
new ParameterList (*defaultParams));
124 const int maxBlkOrtho = 1;
125 const magnitude_type blkTol = STM::zero();
126 const magnitude_type singTol = STM::zero();
128 params->set (
"maxNumOrthogPasses", maxBlkOrtho);
129 params->set (
"blkTol", blkTol);
130 params->set (
"singTol", singTol);
144 template<
class ScalarType>
145 void TEUCHOS_DEPRECATED
147 int& maxNumOrthogPasses,
148 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType& blkTol,
149 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType& singTol)
151 using Teuchos::ParameterList;
153 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType magnitude_type;
154 const magnitude_type zero = Teuchos::ScalarTraits<magnitude_type>::zero();
155 RCP<const ParameterList> defaultParams = getDefaultIcgsParameters<ScalarType>();
162 int _maxNumOrthogPasses;
163 magnitude_type _blkTol, _singTol;
164 if (params.is_null()) {
165 _maxNumOrthogPasses = defaultParams->get<
int> (
"maxNumOrthogPasses");
166 _blkTol = defaultParams->get<magnitude_type> (
"blkTol");
167 _singTol = defaultParams->get<magnitude_type> (
"singTol");
170 _maxNumOrthogPasses = params->get<
int> (
"maxNumOrthogPasses");
171 if (_maxNumOrthogPasses < 1)
172 _maxNumOrthogPasses = defaultParams->get<
int> (
"maxNumOrthogPasses");
173 }
catch (Teuchos::Exceptions::InvalidParameter&) {
174 _maxNumOrthogPasses = defaultParams->get<
int> (
"maxNumOrthogPasses");
178 _blkTol = params->get<magnitude_type> (
"blkTol");
180 _blkTol = defaultParams->get<magnitude_type> (
"blkTol");
181 }
catch (Teuchos::Exceptions::InvalidParameter&) {
185 _blkTol = params->get<magnitude_type> (
"depTol");
186 }
catch (Teuchos::Exceptions::InvalidParameter&) {
187 _blkTol = defaultParams->get<magnitude_type> (
"blkTol");
192 _singTol = params->get<magnitude_type> (
"singTol");
194 _singTol = defaultParams->get<magnitude_type> (
"singTol");
195 }
catch (Teuchos::Exceptions::InvalidParameter&) {
196 _singTol = defaultParams->get<magnitude_type> (
"singTol");
199 maxNumOrthogPasses = _maxNumOrthogPasses;
205 template<
class ScalarType,
class MV,
class OP>
208 public Teuchos::ParameterListAcceptorDefaultBase
211 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
212 typedef typename Teuchos::ScalarTraits<MagnitudeType> MGT;
213 typedef Teuchos::ScalarTraits<ScalarType> SCT;
224 Teuchos::RCP<const OP> Op = Teuchos::null,
225 const int max_ortho_steps = 2,
226 const MagnitudeType blk_tol = 10*MGT::squareroot( MGT::eps() ),
227 const MagnitudeType sing_tol = 10*MGT::eps() )
229 max_ortho_steps_( max_ortho_steps ),
231 sing_tol_( sing_tol ),
234 #ifdef BELOS_TEUCHOS_TIME_MONITOR 235 std::string orthoLabel = label_ +
": Orthogonalization";
236 timerOrtho_ = Teuchos::TimeMonitor::getNewCounter(orthoLabel);
238 std::string updateLabel = label_ +
": Ortho (Update)";
239 timerUpdate_ = Teuchos::TimeMonitor::getNewCounter(updateLabel);
241 std::string normLabel = label_ +
": Ortho (Norm)";
242 timerNorm_ = Teuchos::TimeMonitor::getNewCounter(normLabel);
244 std::string ipLabel = label_ +
": Ortho (Inner Product)";
245 timerInnerProd_ = Teuchos::TimeMonitor::getNewCounter(ipLabel);
251 const std::string& label =
"Belos",
252 Teuchos::RCP<const OP> Op = Teuchos::null) :
254 max_ortho_steps_ (2),
255 blk_tol_ (10 * MGT::squareroot (MGT::eps())),
256 sing_tol_ (10 * MGT::eps()),
261 #ifdef BELOS_TEUCHOS_TIME_MONITOR 262 std::string orthoLabel = label_ +
": Orthogonalization";
263 timerOrtho_ = Teuchos::TimeMonitor::getNewCounter(orthoLabel);
265 std::string updateLabel = label_ +
": Ortho (Update)";
266 timerUpdate_ = Teuchos::TimeMonitor::getNewCounter(updateLabel);
268 std::string normLabel = label_ +
": Ortho (Norm)";
269 timerNorm_ = Teuchos::TimeMonitor::getNewCounter(normLabel);
271 std::string ipLabel = label_ +
": Ortho (Inner Product)";
272 timerInnerProd_ = Teuchos::TimeMonitor::getNewCounter(ipLabel);
286 using Teuchos::Exceptions::InvalidParameterName;
287 using Teuchos::ParameterList;
288 using Teuchos::parameterList;
292 RCP<ParameterList> params;
293 if (plist.is_null()) {
294 params = parameterList (*defaultParams);
309 int maxNumOrthogPasses;
310 MagnitudeType blkTol;
311 MagnitudeType singTol;
314 maxNumOrthogPasses = params->get<
int> (
"maxNumOrthogPasses");
315 }
catch (InvalidParameterName&) {
316 maxNumOrthogPasses = defaultParams->get<
int> (
"maxNumOrthogPasses");
317 params->set (
"maxNumOrthogPasses", maxNumOrthogPasses);
328 blkTol = params->get<MagnitudeType> (
"blkTol");
329 }
catch (InvalidParameterName&) {
331 blkTol = params->get<MagnitudeType> (
"depTol");
334 params->remove (
"depTol");
335 }
catch (InvalidParameterName&) {
336 blkTol = defaultParams->get<MagnitudeType> (
"blkTol");
338 params->set (
"blkTol", blkTol);
342 singTol = params->get<MagnitudeType> (
"singTol");
343 }
catch (InvalidParameterName&) {
344 singTol = defaultParams->get<MagnitudeType> (
"singTol");
345 params->set (
"singTol", singTol);
348 max_ortho_steps_ = maxNumOrthogPasses;
352 setMyParamList (params);
355 Teuchos::RCP<const Teuchos::ParameterList>
359 using Teuchos::ParameterList;
360 using Teuchos::parameterList;
363 if (defaultParams_.is_null()) {
364 RCP<ParameterList> params = parameterList (
"ICGS");
368 const int defaultMaxNumOrthogPasses = 2;
369 const MagnitudeType eps = MGT::eps();
370 const MagnitudeType defaultBlkTol =
371 as<MagnitudeType> (10) * MGT::squareroot (eps);
372 const MagnitudeType defaultSingTol = as<MagnitudeType> (10) * eps;
374 params->set (
"maxNumOrthogPasses", defaultMaxNumOrthogPasses,
375 "Maximum number of orthogonalization passes (includes the " 376 "first). Default is 2, since \"twice is enough\" for Krylov " 378 params->set (
"blkTol", defaultBlkTol,
"Block reorthogonalization " 380 params->set (
"singTol", defaultSingTol,
"Singular block detection " 382 defaultParams_ = params;
384 return defaultParams_;
392 Teuchos::RCP<const Teuchos::ParameterList>
396 using Teuchos::ParameterList;
397 using Teuchos::parameterList;
402 RCP<ParameterList> params = parameterList (*defaultParams);
404 const int maxBlkOrtho = 1;
405 const MagnitudeType blkTol = MGT::zero();
406 const MagnitudeType singTol = MGT::zero();
408 params->set (
"maxNumOrthogPasses", maxBlkOrtho);
409 params->set (
"blkTol", blkTol);
410 params->set (
"singTol", singTol);
421 Teuchos::RCP<Teuchos::ParameterList> params = getNonconstParameterList();
422 if (! params.is_null()) {
427 params->set (
"blkTol", blk_tol);
435 Teuchos::RCP<Teuchos::ParameterList> params = getNonconstParameterList();
436 if (! params.is_null()) {
441 params->set (
"singTol", sing_tol);
443 sing_tol_ = sing_tol;
485 void project ( MV &X, Teuchos::RCP<MV> MX,
486 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
487 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const;
493 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
494 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const {
524 int normalize ( MV &X, Teuchos::RCP<MV> MX,
525 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B)
const;
530 int normalize ( MV &X, Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B )
const {
577 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
578 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
579 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const;
584 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
585 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
586 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q )
const {
598 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
607 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
613 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
622 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
623 orthogError(
const MV &X1, Teuchos::RCP<const MV> MX1,
const MV &X2)
const;
632 void setLabel(
const std::string& label);
636 const std::string&
getLabel()
const {
return label_; }
642 int max_ortho_steps_;
644 MagnitudeType blk_tol_;
646 MagnitudeType sing_tol_;
650 #ifdef BELOS_TEUCHOS_TIME_MONITOR 651 Teuchos::RCP<Teuchos::Time> timerOrtho_, timerUpdate_,
652 timerNorm_, timerScale_, timerInnerProd_;
653 #endif // BELOS_TEUCHOS_TIME_MONITOR 656 mutable Teuchos::RCP<Teuchos::ParameterList> defaultParams_;
659 int findBasis(MV &X, Teuchos::RCP<MV> MX,
660 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > C,
661 bool completeBasis,
int howMany = -1 )
const;
664 bool blkOrtho1 ( MV &X, Teuchos::RCP<MV> MX,
665 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
666 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const;
669 bool blkOrtho ( MV &X, Teuchos::RCP<MV> MX,
670 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
671 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const;
686 int blkOrthoSing ( MV &X, Teuchos::RCP<MV> MX,
687 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
688 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
689 Teuchos::ArrayView<Teuchos::RCP<const MV> > QQ)
const;
694 template<
class ScalarType,
class MV,
class OP>
697 if (label != label_) {
699 std::string orthoLabel = label_ +
": Orthogonalization";
700 #ifdef BELOS_TEUCHOS_TIME_MONITOR 701 timerOrtho_ = Teuchos::TimeMonitor::getNewCounter(orthoLabel);
704 std::string updateLabel = label_ +
": Ortho (Update)";
705 #ifdef BELOS_TEUCHOS_TIME_MONITOR 706 timerUpdate_ = Teuchos::TimeMonitor::getNewCounter(updateLabel);
709 std::string normLabel = label_ +
": Ortho (Norm)";
710 #ifdef BELOS_TEUCHOS_TIME_MONITOR 711 timerNorm_ = Teuchos::TimeMonitor::getNewCounter(normLabel);
714 std::string ipLabel = label_ +
": Ortho (Inner Product)";
715 #ifdef BELOS_TEUCHOS_TIME_MONITOR 716 timerInnerProd_ = Teuchos::TimeMonitor::getNewCounter(ipLabel);
723 template<
class ScalarType,
class MV,
class OP>
724 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
726 const ScalarType ONE = SCT::one();
728 Teuchos::SerialDenseMatrix<int,ScalarType> xTx(rank,rank);
730 for (
int i=0; i<rank; i++) {
733 return xTx.normFrobenius();
738 template<
class ScalarType,
class MV,
class OP>
739 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
743 Teuchos::SerialDenseMatrix<int,ScalarType> xTx(r2,r1);
745 return xTx.normFrobenius();
750 template<
class ScalarType,
class MV,
class OP>
752 MV &X, Teuchos::RCP<MV> MX,
753 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
754 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
755 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q )
const 757 using Teuchos::Array;
759 using Teuchos::is_null;
762 using Teuchos::SerialDenseMatrix;
763 typedef SerialDenseMatrix< int, ScalarType > serial_dense_matrix_type;
764 typedef typename Array< RCP< const MV > >::size_type size_type;
766 #ifdef BELOS_TEUCHOS_TIME_MONITOR 767 Teuchos::TimeMonitor orthotimer(*timerOrtho_);
770 ScalarType ONE = SCT::one();
782 B = rcp (
new serial_dense_matrix_type (xc, xc));
792 for (size_type k = 0; k < nq; ++k)
795 const int numCols = xc;
798 C[k] = rcp (
new serial_dense_matrix_type (numRows, numCols));
799 else if (C[k]->numRows() != numRows || C[k]->numCols() != numCols)
801 int err = C[k]->reshape (numRows, numCols);
802 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error,
803 "IMGS orthogonalization: failed to reshape " 804 "C[" << k <<
"] (the array of block " 805 "coefficients resulting from projecting X " 806 "against Q[1:" << nq <<
"]).");
812 if (MX == Teuchos::null) {
820 MX = Teuchos::rcp( &X,
false );
827 TEUCHOS_TEST_FOR_EXCEPTION( xc == 0 || xr == 0, std::invalid_argument,
"Belos::ICGSOrthoManager::projectAndNormalize(): X must be non-empty" );
830 for (
int i=0; i<nq; i++) {
835 TEUCHOS_TEST_FOR_EXCEPTION( B->numRows() != xc || B->numCols() != xc, std::invalid_argument,
836 "Belos::ICGSOrthoManager::projectAndNormalize(): Size of X must be consistant with size of B" );
838 TEUCHOS_TEST_FOR_EXCEPTION( xc<0 || xr<0 || mxc<0 || mxr<0, std::invalid_argument,
839 "Belos::ICGSOrthoManager::projectAndNormalize(): MVT returned negative dimensions for X,MX" );
841 TEUCHOS_TEST_FOR_EXCEPTION( xc!=mxc || xr!=mxr, std::invalid_argument,
842 "Belos::ICGSOrthoManager::projectAndNormalize(): Size of X must be consistant with size of MX" );
848 bool dep_flg =
false;
851 Teuchos::RCP<MV> tmpX, tmpMX;
861 dep_flg = blkOrtho1( X, MX, C, Q );
865 #ifdef BELOS_TEUCHOS_TIME_MONITOR 866 Teuchos::TimeMonitor normTimer( *timerNorm_ );
868 if ( B == Teuchos::null ) {
869 B = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(xc,xc) );
871 std::vector<ScalarType> diag(xc);
873 (*B)(0,0) = SCT::squareroot(SCT::magnitude(diag[0]));
886 dep_flg = blkOrtho( X, MX, C, Q );
892 rank = blkOrthoSing( *tmpX, tmpMX, C, B, Q );
902 rank = findBasis( X, MX, B,
false );
907 rank = blkOrthoSing( *tmpX, tmpMX, C, B, Q );
919 TEUCHOS_TEST_FOR_EXCEPTION( rank > xc || rank < 0, std::logic_error,
920 "Belos::ICGSOrthoManager::projectAndNormalize(): Debug error in rank variable." );
930 template<
class ScalarType,
class MV,
class OP>
932 MV &X, Teuchos::RCP<MV> MX,
933 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B )
const {
935 #ifdef BELOS_TEUCHOS_TIME_MONITOR 936 Teuchos::TimeMonitor orthotimer(*timerOrtho_);
940 return findBasis(X, MX, B,
true);
946 template<
class ScalarType,
class MV,
class OP>
948 MV &X, Teuchos::RCP<MV> MX,
949 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
950 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const {
966 #ifdef BELOS_TEUCHOS_TIME_MONITOR 967 Teuchos::TimeMonitor orthotimer(*timerOrtho_);
973 std::vector<int> qcs(nq);
975 if (nq == 0 || xc == 0 || xr == 0) {
987 if (MX == Teuchos::null) {
995 MX = Teuchos::rcp( &X,
false );
1001 TEUCHOS_TEST_FOR_EXCEPTION( xc<0 || xr<0 || mxc<0 || mxr<0, std::invalid_argument,
1002 "Belos::ICGSOrthoManager::project(): MVT returned negative dimensions for X,MX" );
1004 TEUCHOS_TEST_FOR_EXCEPTION( xc!=mxc || xr!=mxr || xr!=qr, std::invalid_argument,
1005 "Belos::ICGSOrthoManager::project(): Size of X not consistant with MX,Q" );
1009 for (
int i=0; i<nq; i++) {
1011 "Belos::ICGSOrthoManager::project(): Q lengths not mutually consistant" );
1013 TEUCHOS_TEST_FOR_EXCEPTION( qr < qcs[i], std::invalid_argument,
1014 "Belos::ICGSOrthoManager::project(): Q has less rows than columns" );
1018 if ( C[i] == Teuchos::null ) {
1019 C[i] = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(qcs[i],xc) );
1022 TEUCHOS_TEST_FOR_EXCEPTION( C[i]->numRows() != qcs[i] || C[i]->numCols() != xc , std::invalid_argument,
1023 "Belos::ICGSOrthoManager::project(): Size of Q not consistant with size of C" );
1028 blkOrtho( X, MX, C, Q );
1035 template<
class ScalarType,
class MV,
class OP>
1039 Teuchos::RCP<MV> MX,
1040 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
1057 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1058 Teuchos::TimeMonitor normTimer (*timerNorm_);
1059 #endif // BELOS_TEUCHOS_TIME_MONITOR 1061 const ScalarType ONE = SCT::one ();
1062 const MagnitudeType ZERO = SCT::magnitude (SCT::zero ());
1067 if (howMany == -1) {
1078 if (MX == Teuchos::null) {
1088 if ( B == Teuchos::null ) {
1089 B = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(xc,xc) );
1096 TEUCHOS_TEST_FOR_EXCEPTION( xc == 0 || xr == 0, std::invalid_argument,
1097 "Belos::ICGSOrthoManager::findBasis(): X must be non-empty" );
1098 TEUCHOS_TEST_FOR_EXCEPTION( B->numRows() != xc || B->numCols() != xc, std::invalid_argument,
1099 "Belos::ICGSOrthoManager::findBasis(): Size of X not consistant with size of B" );
1100 TEUCHOS_TEST_FOR_EXCEPTION( xc != mxc || xr != mxr, std::invalid_argument,
1101 "Belos::ICGSOrthoManager::findBasis(): Size of X not consistant with size of MX" );
1102 TEUCHOS_TEST_FOR_EXCEPTION( as<ptrdiff_t> (xc) > xr, std::invalid_argument,
1103 "Belos::ICGSOrthoManager::findBasis(): Size of X not feasible for normalization" );
1104 TEUCHOS_TEST_FOR_EXCEPTION( howMany < 0 || howMany > xc, std::invalid_argument,
1105 "Belos::ICGSOrthoManager::findBasis(): Invalid howMany parameter" );
1110 int xstart = xc - howMany;
1112 for (
int j = xstart; j < xc; j++) {
1118 bool addVec =
false;
1121 std::vector<int> index(1);
1124 Teuchos::RCP<MV> MXj;
1135 std::vector<int> prev_idx( numX );
1136 Teuchos::RCP<const MV> prevX, prevMX;
1139 for (
int i=0; i<numX; i++) {
1149 Teuchos::SerialDenseMatrix<int,ScalarType> product(numX, 1);
1150 std::vector<ScalarType> oldDot( 1 ), newDot( 1 );
1157 TEUCHOS_TEST_FOR_EXCEPTION( SCT::real(oldDot[0]) < ZERO,
OrthoError,
1158 "Belos::ICGSOrthoManager::findBasis(): Negative definiteness discovered in inner product" );
1162 Teuchos::SerialDenseMatrix<int,ScalarType> P2(numX,1);
1164 for (
int i=0; i<max_ortho_steps_; ++i) {
1168 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1169 Teuchos::TimeMonitor innerProdTimer( *timerInnerProd_ );
1177 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1178 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1188 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1189 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1207 if (completeBasis) {
1211 if ( SCT::magnitude(newDot[0]) < SCT::magnitude(sing_tol_*oldDot[0]) ) {
1216 std::cout <<
"Belos::ICGSOrthoManager::findBasis() --> Random for column " << numX << std::endl;
1219 Teuchos::RCP<MV> tempXj =
MVT::Clone( X, 1 );
1220 Teuchos::RCP<MV> tempMXj;
1231 for (
int num_orth=0; num_orth<max_ortho_steps_; num_orth++){
1233 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1234 Teuchos::TimeMonitor innerProdTimer( *timerInnerProd_ );
1239 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1240 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1245 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1246 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1254 if ( SCT::magnitude(newDot[0]) >= SCT::magnitude(oldDot[0]*sing_tol_) ) {
1270 if ( SCT::magnitude(newDot[0]) < SCT::magnitude(oldDot[0]*blk_tol_) ) {
1278 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1297 for (
int i=0; i<numX; i++) {
1298 (*B)(i,j) = product(i,0);
1309 template<
class ScalarType,
class MV,
class OP>
1312 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
1313 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const 1317 const ScalarType ONE = SCT::one();
1319 std::vector<int> qcs( nq );
1320 for (
int i=0; i<nq; i++) {
1326 Teuchos::Array<Teuchos::RCP<MV> > MQ(nq);
1328 for (
int i=0; i<nq; i++) {
1331 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1332 Teuchos::TimeMonitor innerProdTimer( *timerInnerProd_ );
1338 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1339 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1359 for (
int j = 1; j < max_ortho_steps_; ++j) {
1361 for (
int i=0; i<nq; i++) {
1362 Teuchos::SerialDenseMatrix<int,ScalarType> C2(*C[i]);
1366 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1367 Teuchos::TimeMonitor innerProdTimer( *timerInnerProd_ );
1373 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1374 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1385 else if (xc <= qcs[i]) {
1398 template<
class ScalarType,
class MV,
class OP>
1401 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
1402 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const 1406 bool dep_flg =
false;
1407 const ScalarType ONE = SCT::one();
1409 std::vector<int> qcs( nq );
1410 for (
int i=0; i<nq; i++) {
1417 std::vector<ScalarType> oldDot( xc );
1420 Teuchos::Array<Teuchos::RCP<MV> > MQ(nq);
1422 for (
int i=0; i<nq; i++) {
1425 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1426 Teuchos::TimeMonitor innerProdTimer( *timerInnerProd_ );
1432 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1433 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1452 for (
int j = 1; j < max_ortho_steps_; ++j) {
1454 for (
int i=0; i<nq; i++) {
1455 Teuchos::SerialDenseMatrix<int,ScalarType> C2(*C[i]);
1459 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1460 Teuchos::TimeMonitor innerProdTimer( *timerInnerProd_ );
1466 #ifdef BELOS_TEUCHOS_TIME_MONITOR 1467 Teuchos::TimeMonitor updateTimer( *timerUpdate_ );
1478 else if (xc <= qcs[i]) {
1487 std::vector<ScalarType> newDot(xc);
1491 for (
int i=0; i<xc; i++){
1492 if (SCT::magnitude(newDot[i]) < SCT::magnitude(oldDot[i] * blk_tol_)) {
1501 template<
class ScalarType,
class MV,
class OP>
1504 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
1505 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
1506 Teuchos::ArrayView<Teuchos::RCP<const MV> > QQ)
const 1508 Teuchos::Array<Teuchos::RCP<const MV> > Q (QQ);
1510 const ScalarType ONE = SCT::one();
1511 const ScalarType ZERO = SCT::zero();
1515 std::vector<int> indX( 1 );
1516 std::vector<ScalarType> oldDot( 1 ), newDot( 1 );
1518 std::vector<int> qcs( nq );
1519 for (
int i=0; i<nq; i++) {
1524 Teuchos::RCP<const MV> lastQ;
1525 Teuchos::RCP<MV> Xj, MXj;
1526 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > lastC;
1529 for (
int j=0; j<xc; j++) {
1531 bool dep_flg =
false;
1535 std::vector<int> index( j );
1536 for (
int ind=0; ind<j; ind++) {
1542 Q.push_back( lastQ );
1560 Teuchos::Array<Teuchos::RCP<MV> > MQ(Q.size());
1562 for (
int i=0; i<Q.size(); i++) {
1565 Teuchos::SerialDenseMatrix<int,ScalarType> tempC( Teuchos::View, *C[i], qcs[i], 1, 0, j );
1587 for (
int num_ortho_steps=1; num_ortho_steps < max_ortho_steps_; ++num_ortho_steps) {
1589 for (
int i=0; i<Q.size(); i++) {
1590 Teuchos::SerialDenseMatrix<int,ScalarType> tempC( Teuchos::View, *C[i], qcs[i], 1, 0, j );
1591 Teuchos::SerialDenseMatrix<int,ScalarType> C2( qcs[i], 1 );
1604 else if (xc <= qcs[i]) {
1614 if (SCT::magnitude(newDot[0]) < SCT::magnitude(oldDot[0]*sing_tol_)) {
1620 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1633 Teuchos::RCP<MV> tempXj =
MVT::Clone( X, 1 );
1634 Teuchos::RCP<MV> tempMXj;
1645 for (
int num_orth=0; num_orth<max_ortho_steps_; num_orth++) {
1647 for (
int i=0; i<Q.size(); i++) {
1648 Teuchos::SerialDenseMatrix<int,ScalarType> product( qcs[i], 1 );
1660 else if (xc <= qcs[i]) {
1673 if ( SCT::magnitude(newDot[0]) >= SCT::magnitude(oldDot[0]*sing_tol_) ) {
1674 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1682 MVT::MvAddMv( ONE/diag, *tempMXj, ZERO, *tempMXj, *MXj );
1704 #endif // BELOS_ICGS_ORTHOMANAGER_HPP void setBlkTol(const MagnitudeType blk_tol)
Set parameter for block re-orthogonalization threshhold.
const std::string & getLabel() const
This method returns the label being used by the timers in the orthogonalization manager.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
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.
ICGSOrthoManager(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 getBlkTol() const
Return parameter for block re-orthogonalization threshhold.
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).
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...
Declaration of basic traits for the multivector type.
void setLabel(const std::string &label)
This method sets the label used by the timers in the orthogonalization manager.
Teuchos::RCP< const Teuchos::ParameterList > TEUCHOS_DEPRECATED getFastIcgsParameters()
"Fast" parameters for ICGSOrthoManager.
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...
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
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...
void TEUCHOS_DEPRECATED readIcgsParameters(const Teuchos::RCP< const Teuchos::ParameterList > ¶ms, int &maxNumOrthogPasses, typename Teuchos::ScalarTraits< ScalarType >::magnitudeType &blkTol, typename Teuchos::ScalarTraits< ScalarType >::magnitudeType &singTol)
Read ICGS options from the given parameter list.
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.
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
~ICGSOrthoManager()
Destructor.
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 ...
Exception thrown to signal error in an orthogonalization manager method.
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
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.
void setSingTol(const MagnitudeType sing_tol)
Set parameter for singular block detection.
MagnitudeType getSingTol() const
Return parameter for singular block detection.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using multiple steps ...
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 ...
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.
static ptrdiff_t GetGlobalLength(const MV &mv)
Obtain the vector length of mv.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters() const
"Fast" but possibly unsafe or less accurate parameters.
Class which defines basic traits for the operator type.
static void MvScale(MV &mv, const ScalarType alpha)
Scale each element of the vectors in mv with alpha.
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
Belos header file which uses auto-configuration information to include necessary C++ headers...
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 ...
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 ...
ICGSOrthoManager(const std::string &label="Belos", Teuchos::RCP< const OP > Op=Teuchos::null, const int max_ortho_steps=2, const MagnitudeType blk_tol=10 *MGT::squareroot(MGT::eps()), const MagnitudeType sing_tol=10 *MGT::eps())
Constructor specifying re-orthogonalization tolerance.
Teuchos::RCP< const Teuchos::ParameterList > TEUCHOS_DEPRECATED getDefaultIcgsParameters()
Default parameters for ICGSOrthoManager.
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const