本文整理汇总了C++中LinearSolver::setUserPrec方法的典型用法代码示例。如果您正苦于以下问题:C++ LinearSolver::setUserPrec方法的具体用法?C++ LinearSolver::setUserPrec怎么用?C++ LinearSolver::setUserPrec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinearSolver
的用法示例。
在下文中一共展示了LinearSolver::setUserPrec方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
typedef Teuchos::ScalarTraits<double> ST;
try
{
GlobalMPISession session(&argc, &argv);
MPIComm::world().synchronize();
VectorType<double> type = new EpetraVectorType();
#ifdef HAVE_CONFIG_H
ParameterXMLFileReader reader(Sundance::searchForFile("SolverParameters/userPrecParams.xml"));
#else
ParameterXMLFileReader reader("userPrecParams.xml");
#endif
ParameterList solverParams = reader.getParameters();
ParameterList innerSolverParams = solverParams.sublist("Inner Solve");
ParameterList outerSolverParams = solverParams.sublist("Outer Solve");
/* create the range space */
int nLocalRows = solverParams.get<int>("nLocal");
MatrixLaplacian1D builder(nLocalRows, type);
LinearOperator<double> A = builder.getOp();
Vector<double> x = A.domain().createMember();
int myRank = MPIComm::world().getRank();
int nProcs = MPIComm::world().getNProc();
Thyra::randomize(-ST::one(),+ST::one(),x.ptr().ptr());
#ifdef TRILINOS_6
if (myRank==0) x[0] = 0.0;
if (myRank==nProcs-1) x[nProcs * nLocalRows - 1] = 0.0;
// need to fix operator[] routine
#else
if (myRank==0) x.setElement(0, 0);
if (myRank==nProcs-1) x.setElement(nProcs * nLocalRows - 1, 0.0);
#endif
cout << "x=" << std::endl;
x.print(cout);
Vector<double> y = A*x;
cout << "y=" << std::endl;
y.print(cout);
Vector<double> ans = A.range().createMember();
LinearSolver<double> innerSolver
= LinearSolverBuilder::createSolver(innerSolverParams);
LinearSolver<double> outerSolver
= LinearSolverBuilder::createSolver(outerSolverParams);
/* call the setUserPrec() function to set the operator and solver
* to be used for preconditioning */
outerSolver.setUserPrec(A, innerSolver);
LinearOperator<double> AInv = inverse(A, outerSolver);
ans = AInv * y;
// SolverState<double> state = solver.solve(A, y, ans);
// cout << state << std::endl;
cout << "answer is " << std::endl;
ans.print(cout);
double err = (x-ans).norm2();
cout << "error norm = " << err << std::endl;
double tol = 1.0e-8;
if (err > tol)
{
cout << "User-defined preconditioner test FAILED" << std::endl;
return 1;
}
else
{
cout << "User-defined preconditioner test PASSED" << std::endl;
return 0;
}
}
catch(std::exception& e)
{
cout << "Caught exception: " << e.what() << std::endl;
return -1;
}
}