本文整理汇总了C++中nox::epetra::Vector::init方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector::init方法的具体用法?C++ Vector::init怎么用?C++ Vector::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nox::epetra::Vector
的用法示例。
在下文中一共展示了Vector::init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: solveMeasure
//***********************************************************************
bool NOX::Epetra::LinearSystemStratimikos::
applyJacobianInverse(Teuchos::ParameterList &p,
const NOX::Epetra::Vector& input,
NOX::Epetra::Vector& result)
{
using Teuchos::RCP;
using Teuchos::rcp;
NOX_FUNC_TIME_MONITOR("NOX: Total Linear Solve Time");
double startTime = timer.WallTime();
// Need non-const version of the input vector
// Epetra_LinearProblem requires non-const versions so we can perform
// scaling of the linear problem.
NOX::Epetra::Vector& nonConstInput = const_cast<NOX::Epetra::Vector&>(input);
// Zero out the delta X of the linear problem if requested by user.
if (zeroInitialGuess) result.init(0.0);
// Wrap Thyra objects around Epetra and NOX objects
Teuchos::RCP<const Thyra::LinearOpBase<double> > linearOp =
Thyra::epetraLinearOp(jacPtr);
// Set the linear Op and precomputed prec on this lows
if (precObj == Teuchos::null)
Thyra::initializeOp(*lowsFactory, linearOp, lows.ptr());
else
Thyra::initializePreconditionedOp<double>(
*lowsFactory, linearOp, precObj, lows.ptr());
Teuchos::RCP<Epetra_Vector> resultRCP =
Teuchos::rcp(&result.getEpetraVector(), false);
Teuchos::RCP<Epetra_Vector> inputRCP =
Teuchos::rcp(&nonConstInput.getEpetraVector(), false);
Teuchos::RCP<Thyra::VectorBase<double> >
x = Thyra::create_Vector(resultRCP , linearOp->domain() );
Teuchos::RCP<const Thyra::VectorBase<double> >
b = Thyra::create_Vector(inputRCP, linearOp->range() );
// Alter the convergence tolerance, if Inexact Newton
Teuchos::RCP<Thyra::SolveCriteria<double> > solveCriteria;
if (getLinearSolveToleranceFromNox) {
Thyra::SolveMeasureType solveMeasure(
Thyra::SOLVE_MEASURE_NORM_RESIDUAL,
Thyra::SOLVE_MEASURE_NORM_INIT_RESIDUAL );
solveCriteria = Teuchos::rcp(new Thyra::SolveCriteria<double>(
solveMeasure, p.get<double>("Tolerance") ) );
}
// Solve the linear system for x
Thyra::SolveStatus<double> status =
lows->solve(Thyra::NOTRANS, *b, x.ptr(), solveCriteria.ptr());
// MOVE TO FUNCTION: Update statistics: solves, iters, iters_total, achieved tol
++linearSolveCount;
if (status.extraParameters != Teuchos::null) {
if (status.extraParameters->isParameter("Belos/Iteration Count")) {
linearSolveIters_last = status.extraParameters->get<int>("Belos/Iteration Count");
linearSolveIters_total += linearSolveIters_last;
}
if (status.extraParameters->isParameter("Belos/Achieved Tolerance"))
linearSolveAchievedTol = status.extraParameters->get<double>("Belos/Achieved Tolerance");
if (status.extraParameters->isParameter("AztecOO/Iteration Count")) {
linearSolveIters_last = status.extraParameters->get<int>("AztecOO/Iteration Count");
linearSolveIters_total += linearSolveIters_last;
}
if (status.extraParameters->isParameter("AztecOO/Achieved Tolerance"))
linearSolveAchievedTol = status.extraParameters->get<double>("AztecOO/Achieved Tolerance");
}
// Dump solution of linear system
#ifdef HAVE_NOX_EPETRAEXT
if (p.get("Write Linear System", false)) {
std::ostringstream iterationNumber;
iterationNumber << linearSolveCount;
std::string prefixName = p.get("Write Linear System File Prefix",
"NOX_LinSys");
std::string postfixName = iterationNumber.str();
postfixName += ".mm";
std::string lhsFileName = prefixName + "_LHS_" + postfixName;
std::string rhsFileName = prefixName + "_RHS_" + postfixName;
std::string jacFileName = prefixName + "_Jacobian_" + postfixName;
EpetraExt::MultiVectorToMatrixMarketFile(lhsFileName.c_str(),
result.getEpetraVector());
EpetraExt::MultiVectorToMatrixMarketFile(rhsFileName.c_str(),
input.getEpetraVector());
Epetra_RowMatrix* printMatrix = NULL;
printMatrix = dynamic_cast<Epetra_RowMatrix*>(jacPtr.get());
if (printMatrix == NULL) {
std::cout << "Error: NOX::Epetra::LinearSystemAztecOO::applyJacobianInverse() - "
<< "Could not cast the Jacobian operator to an Epetra_RowMatrix!"
<< "Please set the \"Write Linear System\" parameter to false."
<< std::endl;
//.........这里部分代码省略.........