47 #ifndef BELOS_IMGS_ORTHOMANAGER_HPP
48 #define BELOS_IMGS_ORTHOMANAGER_HPP
67 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
68 #ifdef BELOS_TEUCHOS_TIME_MONITOR
70 #endif // BELOS_TEUCHOS_TIME_MONITOR
78 template<
class ScalarType>
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;
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>
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,
157 RCP<const ParameterList> defaultParams = getDefaultImgsParameters<ScalarType>();
164 int _maxNumOrthogPasses;
165 magnitude_type _blkTol, _singTol;
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");
177 _maxNumOrthogPasses = defaultParams->get<
int> (
"maxNumOrthogPasses");
181 _blkTol = params->
get<magnitude_type> (
"blkTol");
183 _blkTol = defaultParams->get<magnitude_type> (
"blkTol");
188 _blkTol = params->
get<magnitude_type> (
"depTol");
190 _blkTol = defaultParams->get<magnitude_type> (
"blkTol");
195 _singTol = params->
get<magnitude_type> (
"singTol");
197 _singTol = defaultParams->get<magnitude_type> (
"singTol");
199 _singTol = defaultParams->get<magnitude_type> (
"singTol");
202 maxNumOrthogPasses = _maxNumOrthogPasses;
208 template<
class ScalarType,
class MV,
class OP>
228 const int max_ortho_steps = 1,
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
242 std::string updateLabel = label_ +
": Ortho (Update)";
243 #ifdef BELOS_TEUCHOS_TIME_MONITOR
247 std::string normLabel = label_ +
": Ortho (Norm)";
248 #ifdef BELOS_TEUCHOS_TIME_MONITOR
252 std::string ipLabel = label_ +
": Ortho (Inner Product)";
253 #ifdef BELOS_TEUCHOS_TIME_MONITOR
260 const std::string& label =
"Belos",
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
274 std::string updateLabel = label_ +
": Ortho (Update)";
275 #ifdef BELOS_TEUCHOS_TIME_MONITOR
278 std::string normLabel = label_ +
": Ortho (Norm)";
279 #ifdef BELOS_TEUCHOS_TIME_MONITOR
282 std::string ipLabel = label_ +
": Ortho (Inner Product)";
283 #ifdef BELOS_TEUCHOS_TIME_MONITOR
299 using Teuchos::parameterList;
303 RCP<ParameterList> params;
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;
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 =
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_;
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; }
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
641 timerNorm_, timerScale_, timerInnerProd_;
642 #endif // BELOS_TEUCHOS_TIME_MONITOR
650 bool completeBasis,
int howMany = -1 )
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
693 std::string updateLabel = label_ +
": Ortho (Update)";
694 #ifdef BELOS_TEUCHOS_TIME_MONITOR
698 std::string normLabel = label_ +
": Ortho (Norm)";
699 #ifdef BELOS_TEUCHOS_TIME_MONITOR
703 std::string ipLabel = label_ +
": Ortho (Inner Product)";
704 #ifdef BELOS_TEUCHOS_TIME_MONITOR
712 template<
class ScalarType,
class MV,
class OP>
715 const ScalarType ONE = SCT::one();
716 int rank = MVT::GetNumberVecs(X);
719 for (
int i=0; i<rank; i++) {
727 template<
class ScalarType,
class MV,
class OP>
730 int r1 = MVT::GetNumberVecs(X1);
731 int r2 = MVT::GetNumberVecs(X2);
739 template<
class ScalarType,
class MV,
class OP>
753 typedef typename Array< RCP< const MV > >::size_type size_type;
755 #ifdef BELOS_TEUCHOS_TIME_MONITOR
759 ScalarType ONE = SCT::one();
763 int xc = MVT::GetNumberVecs( X );
764 ptrdiff_t xr = MVText::GetGlobalLength( X );
771 B =
rcp (
new serial_dense_matrix_type (xc, xc));
781 for (size_type k = 0; k < nq; ++k)
783 const int numRows = MVT::GetNumberVecs (*Q[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);
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) {
803 MX = MVT::Clone(X,MVT::GetNumberVecs(X));
804 OPT::Apply(*(this->_Op),X,*MX);
812 int mxc = MVT::GetNumberVecs( *MX );
813 ptrdiff_t mxr = MVText::GetGlobalLength( *MX );
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++) {
820 numbas += MVT::GetNumberVecs( *Q[i] );
825 "Belos::IMGSOrthoManager::projectAndNormalize(): Size of X must be consistant with size of B" );
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;
841 tmpX = MVT::CloneCopy(X);
843 tmpMX = MVT::CloneCopy(*MX);
850 dep_flg = blkOrtho1( X, MX, C, Q );
854 #ifdef BELOS_TEUCHOS_TIME_MONITOR
857 if ( B == Teuchos::null ) {
860 std::vector<ScalarType> diag(xc);
861 MVT::MvDot( X, *MX, diag );
862 (*B)(0,0) = SCT::squareroot(SCT::magnitude(diag[0]));
864 MVT::MvScale( X, ONE/(*B)(0,0) );
867 MVT::MvScale( *MX, ONE/(*B)(0,0) );
875 dep_flg = blkOrtho( X, MX, C, Q );
881 rank = blkOrthoSing( *tmpX, tmpMX, C, B, Q );
884 MVT::Assign( *tmpX, X );
886 MVT::Assign( *tmpMX, *MX );
891 rank = findBasis( X, MX, B,
false );
896 rank = blkOrthoSing( *tmpX, tmpMX, C, B, Q );
899 MVT::Assign( *tmpX, X );
901 MVT::Assign( *tmpMX, *MX );
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>
924 #ifdef BELOS_TEUCHOS_TIME_MONITOR
929 return findBasis(X, MX, B,
true);
935 template<
class ScalarType,
class MV,
class OP>
955 #ifdef BELOS_TEUCHOS_TIME_MONITOR
959 int xc = MVT::GetNumberVecs( X );
960 ptrdiff_t xr = MVText::GetGlobalLength( X );
962 std::vector<int> qcs(nq);
964 if (nq == 0 || xc == 0 || xr == 0) {
967 ptrdiff_t qr = MVText::GetGlobalLength ( *Q[0] );
976 if (MX == Teuchos::null) {
978 MX = MVT::Clone(X,MVT::GetNumberVecs(X));
979 OPT::Apply(*(this->_Op),X,*MX);
986 int mxc = MVT::GetNumberVecs( *MX );
987 ptrdiff_t mxr = MVText::GetGlobalLength( *MX );
991 "Belos::IMGSOrthoManager::project(): MVT returned negative dimensions for X,MX" );
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" );
1001 qcs[i] = MVT::GetNumberVecs( *Q[i] );
1003 "Belos::IMGSOrthoManager::project(): Q has less rows than columns" );
1007 if ( C[i] == Teuchos::null ) {
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>
1028 bool completeBasis,
int howMany )
const {
1045 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1049 const ScalarType ONE = SCT::one();
1050 const MagnitudeType ZERO = SCT::magnitude(SCT::zero());
1052 int xc = MVT::GetNumberVecs( X );
1053 ptrdiff_t xr = MVText::GetGlobalLength( X );
1055 if (howMany == -1) {
1066 if (MX == Teuchos::null) {
1068 MX = MVT::Clone(X,xc);
1069 OPT::Apply(*(this->_Op),X,*MX);
1076 if ( B == Teuchos::null ) {
1080 int mxc = (this->_hasOp) ? MVT::GetNumberVecs( *MX ) : xc;
1081 ptrdiff_t mxr = (this->_hasOp) ? MVText::GetGlobalLength( *MX ) : xr;
1085 "Belos::IMGSOrthoManager::findBasis(): X must be non-empty" );
1087 "Belos::IMGSOrthoManager::findBasis(): Size of X not consistant with size of B" );
1089 "Belos::IMGSOrthoManager::findBasis(): Size of X not consistant with size of MX" );
1091 "Belos::IMGSOrthoManager::findBasis(): Size of X not feasible for normalization" );
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);
1113 if ((this->_hasOp)) {
1115 MXj = MVT::CloneViewNonConst( *MX, index );
1127 std::vector<ScalarType> oldDot( 1 ), newDot( 1 );
1132 MVT::MvDot( *Xj, *MXj, oldDot );
1135 "Belos::IMGSOrthoManager::findBasis(): Negative definiteness discovered in inner product" );
1138 for (
int ii=0; ii<numX; ii++) {
1141 prevX = MVT::CloneView( X, index );
1143 prevMX = MVT::CloneView( *MX, index );
1146 for (
int i=0; i<max_ortho_steps_; ++i) {
1150 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1159 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1162 MVT::MvTimesMatAddMv( -ONE, *prevX, P2, ONE, *Xj );
1170 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1173 MVT::MvTimesMatAddMv( -ONE, *prevMX, P2, ONE, *MXj );
1178 product[ii] = P2[0];
1180 product[ii] += P2[0];
1187 MVT::MvDot( *Xj, *oldMXj, newDot );
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;
1204 MVT::MvRandom( *tempXj );
1206 tempMXj = MVT::Clone( X, 1 );
1207 OPT::Apply( *(this->_Op), *tempXj, *tempMXj );
1212 MVT::MvDot( *tempXj, *tempMXj, oldDot );
1215 for (
int ii=0; ii<numX; ii++) {
1218 prevX = MVT::CloneView( X, index );
1220 prevMX = MVT::CloneView( *MX, index );
1223 for (
int num_orth=0; num_orth<max_ortho_steps_; num_orth++){
1225 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1231 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1234 MVT::MvTimesMatAddMv( -ONE, *prevX, P2, ONE, *tempXj );
1237 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1240 MVT::MvTimesMatAddMv( -ONE, *prevMX, P2, ONE, *tempMXj );
1245 product[ii] = P2[0];
1247 product[ii] += P2[0];
1252 MVT::MvDot( *tempXj, *tempMXj, newDot );
1254 if ( SCT::magnitude(newDot[0]) >= SCT::magnitude(oldDot[0]*sing_tol_) ) {
1256 MVT::Assign( *tempXj, *Xj );
1258 MVT::Assign( *tempMXj, *MXj );
1270 if ( SCT::magnitude(newDot[0]) < SCT::magnitude(oldDot[0]*blk_tol_) ) {
1279 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1281 MVT::MvScale( *Xj, ONE/diag );
1284 MVT::MvScale( *MXj, ONE/diag );
1298 for (
int i=0; i<numX; i++) {
1299 (*B)(i,j) = product(i);
1310 template<
class ScalarType,
class MV,
class OP>
1312 IMGSOrthoManager<ScalarType, MV, OP>::blkOrtho1 ( MV &X,
Teuchos::RCP<MV> MX,
1317 int xc = MVT::GetNumberVecs( X );
1318 const ScalarType ONE = SCT::one();
1320 std::vector<int> qcs( nq );
1321 for (
int i=0; i<nq; i++) {
1322 qcs[i] = MVT::GetNumberVecs( *Q[i] );
1326 std::vector<int> index(1);
1331 for (
int i=0; i<nq; i++) {
1334 for (
int ii=0; ii<qcs[i]; ii++) {
1337 tempQ = MVT::CloneView( *Q[i], index );
1342 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1349 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1352 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC, ONE, X );
1359 OPT::Apply( *(this->_Op), X, *MX);
1363 MQ[i] = MVT::Clone( *Q[i], qcs[i] );
1364 OPT::Apply( *(this->_Op), *Q[i], *MQ[i] );
1365 MVT::MvTimesMatAddMv( -ONE, *MQ[i], *C[i], ONE, *MX );
1371 for (
int j = 1; j < max_ortho_steps_; ++j) {
1373 for (
int i=0; i<nq; i++) {
1378 for (
int ii=0; ii<qcs[i]; ii++) {
1381 tempQ = MVT::CloneView( *Q[i], index );
1387 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1394 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1397 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC2, ONE, X );
1406 MVT::MvTimesMatAddMv( -ONE, *MQ[i], C2, ONE, *MX );
1408 else if (xc <= qcs[i]) {
1410 OPT::Apply( *(this->_Op), X, *MX);
1421 template<
class ScalarType,
class MV,
class OP>
1423 IMGSOrthoManager<ScalarType, MV, OP>::blkOrtho ( MV &X,
Teuchos::RCP<MV> MX,
1428 int xc = MVT::GetNumberVecs( X );
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++) {
1434 qcs[i] = MVT::GetNumberVecs( *Q[i] );
1440 std::vector<ScalarType> oldDot( xc );
1441 MVT::MvDot( X, *MX, oldDot );
1443 std::vector<int> index(1);
1448 for (
int i=0; i<nq; i++) {
1451 for (
int ii=0; ii<qcs[i]; ii++) {
1454 tempQ = MVT::CloneView( *Q[i], index );
1459 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1466 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1469 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC, ONE, X );
1476 OPT::Apply( *(this->_Op), X, *MX);
1480 MQ[i] = MVT::Clone( *Q[i], qcs[i] );
1481 OPT::Apply( *(this->_Op), *Q[i], *MQ[i] );
1482 MVT::MvTimesMatAddMv( -ONE, *MQ[i], *C[i], ONE, *MX );
1488 for (
int j = 1; j < max_ortho_steps_; ++j) {
1490 for (
int i=0; i<nq; i++) {
1494 for (
int ii=0; ii<qcs[i]; ii++) {
1497 tempQ = MVT::CloneView( *Q[i], index );
1503 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1510 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1513 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC2, ONE, X );
1521 MVT::MvTimesMatAddMv( -ONE, *MQ[i], C2, ONE, *MX );
1523 else if (xc <= qcs[i]) {
1525 OPT::Apply( *(this->_Op), X, *MX);
1532 std::vector<ScalarType> newDot(xc);
1533 MVT::MvDot( X, *MX, newDot );
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>
1548 IMGSOrthoManager<ScalarType, MV, OP>::blkOrthoSing ( MV &X,
Teuchos::RCP<MV> MX,
1555 const ScalarType ONE = SCT::one();
1556 const ScalarType ZERO = SCT::zero();
1559 int xc = MVT::GetNumberVecs( X );
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++) {
1565 qcs[i] = MVT::GetNumberVecs( *Q[i] );
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++) {
1584 lastQ = MVT::CloneView( X, index );
1587 Q.push_back( lastQ );
1589 qcs.push_back( MVT::GetNumberVecs( *lastQ ) );
1594 Xj = MVT::CloneViewNonConst( X, indX );
1596 MXj = MVT::CloneViewNonConst( *MX, indX );
1603 MVT::MvDot( *Xj, *MXj, oldDot );
1609 for (
int i=0; i<Q.size(); i++) {
1612 for (
int ii=0; ii<qcs[i]; ii++) {
1615 tempQ = MVT::CloneView( *Q[i], indX );
1623 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC, ONE, *Xj );
1629 OPT::Apply( *(this->_Op), *Xj, *MXj);
1633 MQ[i] = MVT::Clone( *Q[i], qcs[i] );
1634 OPT::Apply( *(this->_Op), *Q[i], *MQ[i] );
1636 MVT::MvTimesMatAddMv( -ONE, *MQ[i], tempC, ONE, *MXj );
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++) {
1648 for (
int ii=0; ii<qcs[i]; ii++) {
1651 tempQ = MVT::CloneView( *Q[i], indX );
1657 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC2, ONE, *Xj );
1668 MVT::MvTimesMatAddMv( -ONE, *MQ[i], C2, ONE, *MXj );
1670 else if (xc <= qcs[i]) {
1672 OPT::Apply( *(this->_Op), *Xj, *MXj);
1680 if (SCT::magnitude(newDot[0]) < SCT::magnitude(oldDot[0]*sing_tol_)) {
1686 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1688 MVT::MvScale( *Xj, ONE/diag );
1691 MVT::MvScale( *MXj, ONE/diag );
1701 MVT::MvRandom( *tempXj );
1703 tempMXj = MVT::Clone( X, 1 );
1704 OPT::Apply( *(this->_Op), *tempXj, *tempMXj );
1709 MVT::MvDot( *tempXj, *tempMXj, oldDot );
1711 for (
int num_orth=0; num_orth<max_ortho_steps_; num_orth++) {
1713 for (
int i=0; i<Q.size(); i++) {
1717 for (
int ii=0; ii<qcs[i]; ii++) {
1720 tempQ = MVT::CloneView( *Q[i], indX );
1725 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC, ONE, *tempXj );
1733 MVT::MvTimesMatAddMv( -ONE, *MQ[i], product, ONE, *tempMXj );
1735 else if (xc <= qcs[i]) {
1737 OPT::Apply( *(this->_Op), *tempXj, *tempMXj);
1744 MVT::MvDot( *tempXj, *tempMXj, newDot );
1747 if ( SCT::magnitude(newDot[0]) >= SCT::magnitude(oldDot[0]*sing_tol_) ) {
1748 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1754 MVT::MvAddMv( ONE/diag, *tempXj, ZERO, *tempXj, *Xj );
1756 MVT::MvAddMv( ONE/diag, *tempMXj, ZERO, *tempMXj, *MXj );
1778 #endif // BELOS_IMGS_ORTHOMANAGER_HPP
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
bool is_null(const boost::shared_ptr< T > &p)
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 magnitudeType eps()
void setBlkTol(const MagnitudeType blk_tol)
Set parameter for block re-orthogonalization threshhold.
T & get(const std::string &name, T def_value)
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 ...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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.
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
const std::string & getLabel() const
This method returns the label being used by the timers in the orthogonalization manager.
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...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Teuchos::ParameterList > TEUCHOS_DEPRECATED getDefaultImgsParameters()
Default parameters for IMGSOrthoManager.
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.
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.
void setMyParamList(const RCP< ParameterList > ¶mList)
Teuchos::RCP< const Teuchos::ParameterList > TEUCHOS_DEPRECATED getFastImgsParameters()
"Fast" parameters for IMGSOrthoManager
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
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 ...
TypeTo as(const TypeFrom &t)
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.
~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 ...