47 #ifndef BELOS_DGKS_ORTHOMANAGER_HPP 48 #define BELOS_DGKS_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 one = STM::one();
88 const magnitude_type eps = STM::eps();
89 const magnitude_type squareRootTwo =
90 STM::squareroot (as<magnitude_type> (2));
91 const magnitude_type defaultBlkTol =
92 as<magnitude_type> (10) * STM::squareroot (eps);
93 const magnitude_type defaultDepTol = one / squareRootTwo;
94 const magnitude_type defaultSingTol = as<magnitude_type> (10) * eps;
96 Teuchos::RCP<Teuchos::ParameterList> params =
97 Teuchos::parameterList (
"DGKS");
98 params->set (
"maxNumOrthogPasses", defaultMaxNumOrthogPasses,
99 "Maximum number of orthogonalization passes " 100 "(includes the first). Default is 2, since " 101 "\"twice is enough\" for Krylov methods.");
102 params->set (
"blkTol", defaultBlkTol,
103 "Block reorthogonalization threshhold.");
104 params->set (
"depTol", defaultDepTol,
105 "(Non-block) reorthogonalization threshold.");
106 params->set (
"singTol", defaultSingTol,
107 "Singular block detection threshold.");
116 template<
class ScalarType>
117 Teuchos::RCP<const Teuchos::ParameterList> TEUCHOS_DEPRECATED
120 using Teuchos::ParameterList;
123 using Teuchos::ScalarTraits;
124 typedef typename ScalarTraits<ScalarType>::magnitudeType magnitude_type;
125 typedef ScalarTraits<magnitude_type> STM;
127 RCP<const ParameterList> defaultParams = getDefaultDgksParameters<ScalarType> ();
129 RCP<ParameterList> params = rcp (
new ParameterList (*defaultParams));
131 const int maxBlkOrtho = 1;
132 const magnitude_type blkTol = STM::zero();
133 const magnitude_type depTol = STM::zero();
134 const magnitude_type singTol = STM::zero();
136 params->set (
"maxNumOrthogPasses", maxBlkOrtho);
137 params->set (
"blkTol", blkTol);
138 params->set (
"depTol", depTol);
139 params->set (
"singTol", singTol);
153 template<
class ScalarType>
154 void TEUCHOS_DEPRECATED
156 int& maxNumOrthogPasses,
157 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType& blkTol,
158 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType& depTol,
159 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType& singTol)
161 using Teuchos::ParameterList;
163 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType magnitude_type;
164 const magnitude_type zero = Teuchos::ScalarTraits<magnitude_type>::zero();
165 RCP<const ParameterList> defaultParams = getDefaultDgksParameters<ScalarType>();
172 int _maxNumOrthogPasses;
173 magnitude_type _blkTol, _depTol, _singTol;
174 if (params.is_null())
176 _maxNumOrthogPasses = defaultParams->get<
int> (
"maxNumOrthogPasses");
177 _blkTol = defaultParams->get<magnitude_type> (
"blkTol");
178 _depTol = defaultParams->get<magnitude_type> (
"depTol");
179 _singTol = defaultParams->get<magnitude_type> (
"singTol");
184 _maxNumOrthogPasses = params->get<
int> (
"maxNumOrthogPasses");
185 if (_maxNumOrthogPasses < 1)
186 _maxNumOrthogPasses = defaultParams->get<
int> (
"maxNumOrthogPasses");
187 }
catch (Teuchos::Exceptions::InvalidParameter&) {
188 _maxNumOrthogPasses = defaultParams->get<
int> (
"maxNumOrthogPasses");
192 _blkTol = params->get<magnitude_type> (
"blkTol");
194 _blkTol = defaultParams->get<magnitude_type> (
"blkTol");
195 }
catch (Teuchos::Exceptions::InvalidParameter&) {
196 _blkTol = defaultParams->get<magnitude_type> (
"blkTol");
200 _depTol = params->get<magnitude_type> (
"depTol");
202 _depTol = defaultParams->get<magnitude_type> (
"depTol");
203 }
catch (Teuchos::Exceptions::InvalidParameter&) {
204 _depTol = defaultParams->get<magnitude_type> (
"depTol");
208 _singTol = params->get<magnitude_type> (
"singTol");
210 _singTol = defaultParams->get<magnitude_type> (
"singTol");
211 }
catch (Teuchos::Exceptions::InvalidParameter&) {
212 _singTol = defaultParams->get<magnitude_type> (
"singTol");
215 maxNumOrthogPasses = _maxNumOrthogPasses;
221 template<
class ScalarType,
class MV,
class OP>
224 public Teuchos::ParameterListAcceptorDefaultBase
227 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
228 typedef typename Teuchos::ScalarTraits<MagnitudeType> MGT;
229 typedef Teuchos::ScalarTraits<ScalarType> SCT;
240 Teuchos::RCP<const OP> Op = Teuchos::null,
241 const int max_blk_ortho = 2,
242 const MagnitudeType blk_tol = 10*MGT::squareroot( MGT::eps() ),
243 const MagnitudeType dep_tol = MGT::one()/MGT::squareroot( 2*MGT::one() ),
244 const MagnitudeType sing_tol = 10*MGT::eps() )
246 max_blk_ortho_( max_blk_ortho ),
249 sing_tol_( sing_tol ),
252 #ifdef BELOS_TEUCHOS_TIME_MONITOR 253 std::string orthoLabel = label_ +
": Orthogonalization";
254 timerOrtho_ = Teuchos::TimeMonitor::getNewCounter( orthoLabel );
260 const std::string& label =
"Belos",
261 Teuchos::RCP<const OP> Op = Teuchos::null)
264 blk_tol_ (Teuchos::as<MagnitudeType>(10) * MGT::squareroot(MGT::eps())),
265 dep_tol_ (MGT::one() / MGT::squareroot (Teuchos::as<MagnitudeType>(2))),
266 sing_tol_ (Teuchos::as<MagnitudeType>(10) * MGT::eps()),
271 #ifdef BELOS_TEUCHOS_TIME_MONITOR 272 std::string orthoLabel = label_ +
": Orthogonalization";
273 timerOrtho_ = Teuchos::TimeMonitor::getNewCounter( orthoLabel );
287 using Teuchos::ParameterList;
288 using Teuchos::parameterList;
292 RCP<ParameterList> params;
293 if (plist.is_null()) {
295 params = parameterList (*defaultParams);
298 params->validateParametersAndSetDefaults (*defaultParams);
306 const int maxNumOrthogPasses = params->get<
int> (
"maxNumOrthogPasses");
307 const MagnitudeType blkTol = params->get<MagnitudeType> (
"blkTol");
308 const MagnitudeType depTol = params->get<MagnitudeType> (
"depTol");
309 const MagnitudeType singTol = params->get<MagnitudeType> (
"singTol");
311 max_blk_ortho_ = maxNumOrthogPasses;
316 setMyParamList (params);
319 Teuchos::RCP<const Teuchos::ParameterList>
323 using Teuchos::ParameterList;
324 using Teuchos::parameterList;
327 if (defaultParams_.is_null()) {
328 RCP<ParameterList> params = parameterList (
"DGKS");
329 const MagnitudeType eps = MGT::eps ();
333 const int defaultMaxNumOrthogPasses = 2;
334 const MagnitudeType defaultBlkTol =
335 as<MagnitudeType> (10) * MGT::squareroot (eps);
336 const MagnitudeType defaultDepTol =
337 MGT::one() / MGT::squareroot (as<MagnitudeType> (2));
339 const MagnitudeType defaultSingTol = as<MagnitudeType> (10) * eps;
341 params->set (
"maxNumOrthogPasses", defaultMaxNumOrthogPasses,
342 "Maximum number of orthogonalization passes (includes the " 343 "first). Default is 2, since \"twice is enough\" for Krylov " 345 params->set (
"blkTol", defaultBlkTol,
"Block reorthogonalization " 347 params->set (
"depTol", defaultDepTol,
348 "(Non-block) reorthogonalization threshold.");
349 params->set (
"singTol", defaultSingTol,
"Singular block detection " 351 defaultParams_ = params;
353 return defaultParams_;
358 Teuchos::RCP<const Teuchos::ParameterList>
361 using Teuchos::ParameterList;
367 RCP<ParameterList> params = rcp (
new ParameterList (*defaultParams));
369 const int maxBlkOrtho = 1;
370 const MagnitudeType blkTol = MGT::zero();
371 const MagnitudeType depTol = MGT::zero();
372 const MagnitudeType singTol = MGT::zero();
374 params->set (
"maxNumOrthogPasses", maxBlkOrtho);
375 params->set (
"blkTol", blkTol);
376 params->set (
"depTol", depTol);
377 params->set (
"singTol", singTol);
388 Teuchos::RCP<Teuchos::ParameterList> params = getNonconstParameterList();
389 if (! params.is_null()) {
394 params->set (
"blkTol", blk_tol);
402 Teuchos::RCP<Teuchos::ParameterList> params = getNonconstParameterList();
403 if (! params.is_null()) {
404 params->set (
"depTol", dep_tol);
412 Teuchos::RCP<Teuchos::ParameterList> params = getNonconstParameterList();
413 if (! params.is_null()) {
414 params->set (
"singTol", sing_tol);
416 sing_tol_ = sing_tol;
461 void project ( MV &X, Teuchos::RCP<MV> MX,
462 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
463 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const;
469 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
470 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const {
500 int normalize ( MV &X, Teuchos::RCP<MV> MX,
501 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B)
const;
506 int normalize ( MV &X, Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B )
const {
567 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
568 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
569 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const;
574 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
575 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
576 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q )
const {
590 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
601 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
607 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
616 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
617 orthogError(
const MV &X1, Teuchos::RCP<const MV> MX1,
const MV &X2)
const;
626 void setLabel(
const std::string& label);
630 const std::string&
getLabel()
const {
return label_; }
639 MagnitudeType blk_tol_;
641 MagnitudeType dep_tol_;
643 MagnitudeType sing_tol_;
647 #ifdef BELOS_TEUCHOS_TIME_MONITOR 648 Teuchos::RCP<Teuchos::Time> timerOrtho_;
649 #endif // BELOS_TEUCHOS_TIME_MONITOR 652 mutable Teuchos::RCP<Teuchos::ParameterList> defaultParams_;
655 int findBasis(MV &X, Teuchos::RCP<MV> MX,
656 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > C,
657 bool completeBasis,
int howMany = -1 )
const;
660 bool blkOrtho ( MV &X, Teuchos::RCP<MV> MX,
661 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
662 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const;
677 int blkOrthoSing ( MV &X, Teuchos::RCP<MV> MX,
678 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
679 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
680 Teuchos::ArrayView<Teuchos::RCP<const MV> > QQ)
const;
685 template<
class ScalarType,
class MV,
class OP>
688 if (label != label_) {
690 std::string orthoLabel = label_ +
": Orthogonalization";
691 #ifdef BELOS_TEUCHOS_TIME_MONITOR 692 timerOrtho_ = Teuchos::TimeMonitor::getNewCounter(orthoLabel);
699 template<
class ScalarType,
class MV,
class OP>
700 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
702 const ScalarType ONE = SCT::one();
704 Teuchos::SerialDenseMatrix<int,ScalarType> xTx(rank,rank);
706 for (
int i=0; i<rank; i++) {
709 return xTx.normFrobenius();
714 template<
class ScalarType,
class MV,
class OP>
715 typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
719 Teuchos::SerialDenseMatrix<int,ScalarType> xTx(r2,r1);
721 return xTx.normFrobenius();
726 template<
class ScalarType,
class MV,
class OP>
728 MV &X, Teuchos::RCP<MV> MX,
729 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
730 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
731 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q )
const 733 using Teuchos::Array;
735 using Teuchos::is_null;
738 using Teuchos::SerialDenseMatrix;
739 typedef SerialDenseMatrix< int, ScalarType > serial_dense_matrix_type;
740 typedef typename Array< RCP< const MV > >::size_type size_type;
742 #ifdef BELOS_TEUCHOS_TIME_MONITOR 743 Teuchos::TimeMonitor orthotimer(*timerOrtho_);
746 ScalarType ONE = SCT::one();
747 ScalarType ZERO = SCT::zero();
758 B = rcp (
new serial_dense_matrix_type (xc, xc));
768 for (size_type k = 0; k < nq; ++k)
771 const int numCols = xc;
774 C[k] = rcp (
new serial_dense_matrix_type (numRows, numCols));
775 else if (C[k]->numRows() != numRows || C[k]->numCols() != numCols)
777 int err = C[k]->reshape (numRows, numCols);
778 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error,
779 "DGKS orthogonalization: failed to reshape " 780 "C[" << k <<
"] (the array of block " 781 "coefficients resulting from projecting X " 782 "against Q[1:" << nq <<
"]).");
788 if (MX == Teuchos::null) {
796 MX = Teuchos::rcp( &X,
false );
803 TEUCHOS_TEST_FOR_EXCEPTION( xc == 0 || xr == 0, std::invalid_argument,
"Belos::DGKSOrthoManager::projectAndNormalize(): X must be non-empty" );
806 for (
int i=0; i<nq; i++) {
811 TEUCHOS_TEST_FOR_EXCEPTION( B->numRows() != xc || B->numCols() != xc, std::invalid_argument,
812 "Belos::DGKSOrthoManager::projectAndNormalize(): Size of X must be consistant with size of B" );
814 TEUCHOS_TEST_FOR_EXCEPTION( xc<0 || xr<0 || mxc<0 || mxr<0, std::invalid_argument,
815 "Belos::DGKSOrthoManager::projectAndNormalize(): MVT returned negative dimensions for X,MX" );
817 TEUCHOS_TEST_FOR_EXCEPTION( xc!=mxc || xr!=mxr, std::invalid_argument,
818 "Belos::DGKSOrthoManager::projectAndNormalize(): Size of X must be consistant with size of MX" );
824 bool dep_flg =
false;
827 Teuchos::RCP<MV> tmpX, tmpMX;
834 dep_flg = blkOrtho( X, MX, C, Q );
839 rank = blkOrthoSing( *tmpX, tmpMX, C, B, Q );
849 rank = findBasis( X, MX, B,
false );
853 rank = blkOrthoSing( *tmpX, tmpMX, C, B, Q );
864 TEUCHOS_TEST_FOR_EXCEPTION( rank > xc || rank < 0, std::logic_error,
865 "Belos::DGKSOrthoManager::projectAndNormalize(): Debug error in rank variable." );
875 template<
class ScalarType,
class MV,
class OP>
877 MV &X, Teuchos::RCP<MV> MX,
878 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B )
const {
880 #ifdef BELOS_TEUCHOS_TIME_MONITOR 881 Teuchos::TimeMonitor orthotimer(*timerOrtho_);
885 return findBasis(X, MX, B,
true);
891 template<
class ScalarType,
class MV,
class OP>
893 MV &X, Teuchos::RCP<MV> MX,
894 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
895 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const {
911 #ifdef BELOS_TEUCHOS_TIME_MONITOR 912 Teuchos::TimeMonitor orthotimer(*timerOrtho_);
918 std::vector<int> qcs(nq);
920 if (nq == 0 || xc == 0 || xr == 0) {
932 if (MX == Teuchos::null) {
940 MX = Teuchos::rcp( &X,
false );
946 TEUCHOS_TEST_FOR_EXCEPTION( xc<0 || xr<0 || mxc<0 || mxr<0, std::invalid_argument,
947 "Belos::DGKSOrthoManager::project(): MVT returned negative dimensions for X,MX" );
949 TEUCHOS_TEST_FOR_EXCEPTION( xc!=mxc || xr!=mxr || xr!=qr, std::invalid_argument,
950 "Belos::DGKSOrthoManager::project(): Size of X not consistant with MX,Q" );
954 for (
int i=0; i<nq; i++) {
956 "Belos::DGKSOrthoManager::project(): Q lengths not mutually consistant" );
958 TEUCHOS_TEST_FOR_EXCEPTION( qr < qcs[i], std::invalid_argument,
959 "Belos::DGKSOrthoManager::project(): Q has less rows than columns" );
963 if ( C[i] == Teuchos::null ) {
964 C[i] = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(qcs[i],xc) );
967 TEUCHOS_TEST_FOR_EXCEPTION( C[i]->numRows() != qcs[i] || C[i]->numCols() != xc , std::invalid_argument,
968 "Belos::DGKSOrthoManager::project(): Size of Q not consistant with size of C" );
973 blkOrtho( X, MX, C, Q );
980 template<
class ScalarType,
class MV,
class OP>
982 MV &X, Teuchos::RCP<MV> MX,
983 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
984 bool completeBasis,
int howMany )
const {
1001 const ScalarType ONE = SCT::one();
1002 const MagnitudeType ZERO = SCT::magnitude(SCT::zero());
1007 if (howMany == -1) {
1018 if (MX == Teuchos::null) {
1028 if ( B == Teuchos::null ) {
1029 B = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(xc,xc) );
1036 TEUCHOS_TEST_FOR_EXCEPTION( xc == 0 || xr == 0, std::invalid_argument,
1037 "Belos::DGKSOrthoManager::findBasis(): X must be non-empty" );
1038 TEUCHOS_TEST_FOR_EXCEPTION( B->numRows() != xc || B->numCols() != xc, std::invalid_argument,
1039 "Belos::DGKSOrthoManager::findBasis(): Size of X not consistant with size of B" );
1040 TEUCHOS_TEST_FOR_EXCEPTION( xc != mxc || xr != mxr, std::invalid_argument,
1041 "Belos::DGKSOrthoManager::findBasis(): Size of X not consistant with size of MX" );
1042 TEUCHOS_TEST_FOR_EXCEPTION( static_cast<ptrdiff_t>(xc) > xr, std::invalid_argument,
1043 "Belos::DGKSOrthoManager::findBasis(): Size of X not feasible for normalization" );
1044 TEUCHOS_TEST_FOR_EXCEPTION( howMany < 0 || howMany > xc, std::invalid_argument,
1045 "Belos::DGKSOrthoManager::findBasis(): Invalid howMany parameter" );
1050 int xstart = xc - howMany;
1052 for (
int j = xstart; j < xc; j++) {
1058 bool addVec =
false;
1061 std::vector<int> index(1);
1064 Teuchos::RCP<MV> MXj;
1075 std::vector<int> prev_idx( numX );
1076 Teuchos::RCP<const MV> prevX, prevMX;
1079 for (
int i=0; i<numX; i++) {
1089 Teuchos::SerialDenseMatrix<int,ScalarType> product(numX, 1);
1090 std::vector<ScalarType> oldDot( 1 ), newDot( 1 );
1097 TEUCHOS_TEST_FOR_EXCEPTION( SCT::real(oldDot[0]) < ZERO,
OrthoError,
1098 "Belos::DGKSOrthoManager::findBasis(): Negative definiteness discovered in inner product" );
1122 if ( SCT::magnitude(newDot[0]) < SCT::magnitude(dep_tol_*oldDot[0]) ) {
1125 Teuchos::SerialDenseMatrix<int,ScalarType> P2(numX,1);
1141 if (completeBasis) {
1145 if ( SCT::magnitude(newDot[0]) < SCT::magnitude(sing_tol_*oldDot[0]) ) {
1150 std::cout <<
"Belos::DGKSOrthoManager::findBasis() --> Random for column " << numX << std::endl;
1153 Teuchos::RCP<MV> tempXj =
MVT::Clone( X, 1 );
1154 Teuchos::RCP<MV> tempMXj;
1165 for (
int num_orth=0; num_orth<max_blk_ortho_; num_orth++){
1175 if ( SCT::magnitude(newDot[0]) >= SCT::magnitude(oldDot[0]*sing_tol_) ) {
1191 if ( SCT::magnitude(newDot[0]) < SCT::magnitude(oldDot[0]*blk_tol_) ) {
1199 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1201 if (SCT::magnitude(diag) > ZERO) {
1219 for (
int i=0; i<numX; i++) {
1220 (*B)(i,j) = product(i,0);
1231 template<
class ScalarType,
class MV,
class OP>
1234 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
1235 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q)
const 1239 bool dep_flg =
false;
1240 const ScalarType ONE = SCT::one();
1242 std::vector<int> qcs( nq );
1243 for (
int i=0; i<nq; i++) {
1250 std::vector<ScalarType> oldDot( xc );
1253 Teuchos::Array<Teuchos::RCP<MV> > MQ(nq);
1255 for (
int i=0; i<nq; i++) {
1276 for (
int j = 1; j < max_blk_ortho_; ++j) {
1278 for (
int i=0; i<nq; i++) {
1279 Teuchos::SerialDenseMatrix<int,ScalarType> C2(*C[i]);
1292 else if (xc <= qcs[i]) {
1301 std::vector<ScalarType> newDot(xc);
1305 for (
int i=0; i<xc; i++){
1306 if (SCT::magnitude(newDot[i]) < SCT::magnitude(oldDot[i] * blk_tol_)) {
1316 template<
class ScalarType,
class MV,
class OP>
1319 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
1320 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
1321 Teuchos::ArrayView<Teuchos::RCP<const MV> > QQ)
const 1323 Teuchos::Array<Teuchos::RCP<const MV> > Q (QQ);
1325 const ScalarType ONE = SCT::one();
1326 const ScalarType ZERO = SCT::zero();
1330 std::vector<int> indX( 1 );
1331 std::vector<ScalarType> oldDot( 1 ), newDot( 1 );
1333 std::vector<int> qcs( nq );
1334 for (
int i=0; i<nq; i++) {
1339 Teuchos::RCP<const MV> lastQ;
1340 Teuchos::RCP<MV> Xj, MXj;
1341 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > lastC;
1344 for (
int j=0; j<xc; j++) {
1346 bool dep_flg =
false;
1350 std::vector<int> index( j );
1351 for (
int ind=0; ind<j; ind++) {
1357 Q.push_back( lastQ );
1375 Teuchos::Array<Teuchos::RCP<MV> > MQ(Q.size());
1377 for (
int i=0; i<Q.size(); i++) {
1380 Teuchos::SerialDenseMatrix<int,ScalarType> tempC( Teuchos::View, *C[i], qcs[i], 1, 0, j );
1407 if ( SCT::magnitude(newDot[0]) < SCT::magnitude(oldDot[0]*dep_tol_) ) {
1409 for (
int i=0; i<Q.size(); i++) {
1410 Teuchos::SerialDenseMatrix<int,ScalarType> tempC( Teuchos::View, *C[i], qcs[i], 1, 0, j );
1411 Teuchos::SerialDenseMatrix<int,ScalarType> C2( qcs[i], 1 );
1424 else if (xc <= qcs[i]) {
1437 if (SCT::magnitude(newDot[0]) < SCT::magnitude(oldDot[0]*sing_tol_)) {
1443 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1456 Teuchos::RCP<MV> tempXj =
MVT::Clone( X, 1 );
1457 Teuchos::RCP<MV> tempMXj;
1468 for (
int num_orth=0; num_orth<max_blk_ortho_; num_orth++) {
1470 for (
int i=0; i<Q.size(); i++) {
1471 Teuchos::SerialDenseMatrix<int,ScalarType> product( qcs[i], 1 );
1483 else if (xc <= qcs[i]) {
1496 if ( SCT::magnitude(newDot[0]) >= SCT::magnitude(oldDot[0]*sing_tol_) ) {
1497 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1505 MVT::MvAddMv( ONE/diag, *tempMXj, ZERO, *tempMXj, *MXj );
1527 #endif // BELOS_DGKS_ORTHOMANAGER_HPP void setSingTol(const MagnitudeType sing_tol)
Set parameter for singular block detection.
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 ...
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 ...
const std::string & getLabel() const
This method returns the label being used by the timers in the orthogonalization manager.
~DGKSOrthoManager()
Destructor.
void setBlkTol(const MagnitudeType blk_tol)
Set parameter for block re-orthogonalization threshhold.
static void MvRandom(MV &mv)
Replace the vectors in mv with random vectors.
void setDepTol(const MagnitudeType dep_tol)
Set parameter for 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).
Declaration of basic traits for the multivector type.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
DGKSOrthoManager(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.
An extension of the MultiVecTraits class that adds a new vector length method.
Class which defines basic traits for the operator type.
void setLabel(const std::string &label)
This method sets the label used by the timers in the orthogonalization manager.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
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.
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...
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...
MagnitudeType getDepTol() const
Return parameter for re-orthogonalization threshhold.
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
Teuchos::RCP< const Teuchos::ParameterList > TEUCHOS_DEPRECATED getDefaultDgksParameters()
Default parameters for DGKSOrthoManager.
Exception thrown to signal error in an orthogonalization manager method.
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 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 .
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...
DGKSOrthoManager(const std::string &label="Belos", Teuchos::RCP< const OP > Op=Teuchos::null, const int max_blk_ortho=2, const MagnitudeType blk_tol=10 *MGT::squareroot(MGT::eps()), const MagnitudeType dep_tol=MGT::one()/MGT::squareroot(2 *MGT::one()), const MagnitudeType sing_tol=10 *MGT::eps())
Constructor specifying re-orthogonalization tolerance.
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 ...
Teuchos::ScalarTraits< ScalarType >::magnitudeType orthonormError(const MV &X) const
This method computes the error in orthonormality of a multivector.
Teuchos::RCP< const Teuchos::ParameterList > TEUCHOS_DEPRECATED getFastDgksParameters()
"Fast" parameters for DGKSOrthoManager
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
static ptrdiff_t GetGlobalLength(const MV &mv)
Obtain the vector length of mv.
An implementation of the Belos::MatOrthoManager that performs orthogonalization using (potentially) m...
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.
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
MagnitudeType getBlkTol() const
Return parameter for block re-orthogonalization threshhold.
Belos header file which uses auto-configuration information to include necessary C++ headers...
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 ...
MagnitudeType getSingTol() const
Return parameter for singular block detection.
void TEUCHOS_DEPRECATED readDgksParameters(const Teuchos::RCP< const Teuchos::ParameterList > ¶ms, int &maxNumOrthogPasses, typename Teuchos::ScalarTraits< ScalarType >::magnitudeType &blkTol, typename Teuchos::ScalarTraits< ScalarType >::magnitudeType &depTol, typename Teuchos::ScalarTraits< ScalarType >::magnitudeType &singTol)
Read DGKS options from the given parameter list.
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters() const