本文整理汇总了C++中teuchos::LAPACK::LATRS方法的典型用法代码示例。如果您正苦于以下问题:C++ LAPACK::LATRS方法的具体用法?C++ LAPACK::LATRS怎么用?C++ LAPACK::LATRS使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类teuchos::LAPACK
的用法示例。
在下文中一共展示了LAPACK::LATRS方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
//.........这里部分代码省略.........
std::vector<RCP<Vector<Real > > > V;
std::vector<RCP<Vector<Real > > > Z;
(*res_)[0] = r_->norm();
Real rtol = std::min(absTol_,relTol_*(*res_)[0]);
V.push_back(b.clone());
(V[0])->set(*r_);
(V[0])->scale(one/(*res_)[0]);
(*s_)(0) = (*res_)[0];
for( iter=0; iter<maxit_; ++iter ) {
// std::cout << (*res_)[iter] << std::endl;
if( useInexact_ ) {
itol = rtol/(maxit_*(*res_)[iter]);
}
Z.push_back(x.clone());
// Apply right preconditioner
M.applyInverse(*(Z[iter]),*(V[iter]),itol);
// Apply operator
A.apply(*w_,*(Z[iter]),itol);
// Evaluate coefficients and orthogonalize using Gram-Schmidt
for( int k=0; k<=iter; ++k ) {
(*H_)(k,iter) = w_->dot(*(V[k]));
w_->axpy( -(*H_)(k,iter), *(V[k]) );
}
(*H_)(iter+1,iter) = w_->norm();
V.push_back( b.clone() );
(V[iter+1])->set(*w_);
(V[iter+1])->scale(one/((*H_)(iter+1,iter)));
// Apply Givens rotations
for( int k=0; k<=iter-1; ++k ) {
temp = (*cs_)(k)*(*H_)(k,iter) + (*sn_)(k)*(*H_)(k+1,iter);
(*H_)(k+1,iter) = -(*sn_)(k)*(*H_)(k,iter) + (*cs_)(k)*(*H_)(k+1,iter);
(*H_)(k,iter) = temp;
}
// Form i-th rotation matrix
if( (*H_)(iter+1,iter) == zero ) {
(*cs_)(iter) = one;
(*sn_)(iter) = zero;
}
else if ( std::abs((*H_)(iter+1,iter)) > std::abs((*H_)(iter,iter)) ) {
temp = (*H_)(iter,iter) / (*H_)(iter+1,iter);
(*sn_)(iter) = one / std::sqrt( one + temp*temp );
(*cs_)(iter) = temp*(*sn_)(iter);
}
else {
temp = (*H_)(iter+1,iter) / (*H_)(iter,iter);
(*cs_)(iter) = one / std::sqrt( one + temp*temp );
(*sn_)(iter) = temp*(*cs_)(iter);
}
// Approximate residual norm
temp = (*cs_)(iter)*(*s_)(iter);
(*s_)(iter+1) = -(*sn_)(iter)*(*s_)(iter);
(*s_)(iter) = temp;
(*H_)(iter,iter) = (*cs_)(iter)*(*H_)(iter,iter) + (*sn_)(iter)*(*H_)(iter+1,iter);
(*H_)(iter+1,iter) = zero;
(*res_)[iter+1] = std::abs((*s_)(iter+1));
// Update solution approximation.
const char uplo = 'U';
const char trans = 'N';
const char diag = 'N';
const char normin = 'N';
Real scaling = zero;
int info = 0;
*y_ = *s_;
lapack_.LATRS(uplo, trans, diag, normin, iter+1, H_->values(), maxit_+1, y_->values(), &scaling, cnorm_->values(), &info);
z_->zero();
for( int k=0; k<=iter;++k ) {
z_->axpy((*y_)(k),*(Z[k]));
}
if( (*res_)[iter+1] <= rtol ) {
// Update solution vector
x.plus(*z_);
break;
}
if(iter == maxit_) {
flag = 1;
}
} // loop over iter
}