本文整理汇总了C++中Thyra::zero方法的典型用法代码示例。如果您正苦于以下问题:C++ Thyra::zero方法的具体用法?C++ Thyra::zero怎么用?C++ Thyra::zero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thyra
的用法示例。
在下文中一共展示了Thyra::zero方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_initializePrec
bool tBlockJacobiPreconditionerFactory::test_initializePrec(int verbosity,std::ostream & os)
{
using Thyra::zero;
bool status = false;
bool allPassed = true;
std::string constrType[3] = {
std::string("Static"),
std::string("2x2 Static Strategy"),
std::string("3x3 Static Strategy") };
// three by three bloock diagonal
std::vector<RCP<const Thyra::LinearOpBase<double> > > invD;
invD.push_back(invF_); invD.push_back(invC_); invD.push_back(invF_);
// allocate new linear operator
const RCP<Thyra::PhysicallyBlockedLinearOpBase<double> > blkOp
= Thyra::defaultBlockedLinearOp<double>();
blkOp->beginBlockFill(3,3);
blkOp->setBlock(0,0,F_); blkOp->setBlock(0,1,Bt_);
blkOp->setBlock(1,0,B_); blkOp->setBlock(1,1,C_); blkOp->setBlock(1,2,B_);
blkOp->setBlock(2,1,Bt_); blkOp->setBlock(2,2,F_);
blkOp->endBlockFill();
const RCP<Thyra::PhysicallyBlockedLinearOpBase<double> > invBlkOp
= Thyra::defaultBlockedLinearOp<double>();
invBlkOp->beginBlockFill(3,3);
invBlkOp->setBlock(0,0,invF_);
invBlkOp->setBlock(1,1,invC_);
invBlkOp->setBlock(2,2,invF_);
invBlkOp->endBlockFill();
// build factory array
RCP<JacobiPreconditionerFactory> fact_array[3]
= { rcp(new JacobiPreconditionerFactory(invF_,invC_)),
rcp(new JacobiPreconditionerFactory(rcp(new StaticInvDiagStrategy(invF_,invC_)))),
rcp(new JacobiPreconditionerFactory(rcp(new StaticInvDiagStrategy(invD)))) };
RCP<const Thyra::LinearOpBase<double> > A[3] = {
block2x2(F_,Bt_,B_,C_),
block2x2(F_,Bt_,B_,C_),
blkOp };
// this is what the factory should build
RCP<const Thyra::LinearOpBase<double> > invA[3] = {
block2x2(invF_,zero(Bt_->range(),Bt_->domain()),zero(B_->range(),B_->domain()),invC_),
block2x2(invF_,zero(Bt_->range(),Bt_->domain()),zero(B_->range(),B_->domain()),invC_),
invBlkOp };
// test both constructors
for(int i=0;i<3;i++) {
RCP<const Thyra::LinearOpBase<double> > op;
RCP<Thyra::PreconditionerFactoryBase<double> > fact = fact_array[i];
RCP<Thyra::PreconditionerBase<double> > prec = fact->createPrec();
// initialize the preconditioner
fact->initializePrec(Thyra::defaultLinearOpSource(A[i]), &*prec);
op = prec->getRightPrecOp();
TEST_EQUALITY(op,Teuchos::null,
std::endl << " tBlockJacobiPreconditionerFactory::test_initializePrec "
<< "using \"" << constrType[i] << "\" constructor " << toString(status)
<< ": Preconditioner \"getRightPrecOp\" is not null (it should be!)");
op = prec->getLeftPrecOp();
TEST_EQUALITY(op,Teuchos::null,
std::endl << " tBlockJacobiPreconditionerFactory::test_initializePrec "
<< "using \"" << constrType[i] << "\" constructor " << toString(status)
<< ": Preconditioner \"getLeftPrecOp\" is not null (it should be!)");
op = prec->getUnspecifiedPrecOp();
TEST_NOT_EQUAL(op,Teuchos::null,
std::endl << " tBlockJacobiPreconditionerFactory::test_initializePrec "
<< "using \"" << constrType[i] << "\" constructor " << toString(status)
<< ": Preconditioner \"getUnspecifiedPrecOp\" is null (it should not be!)");
LinearOpTester<double> tester;
tester.show_all_tests(true);
std::stringstream ss;
Teuchos::FancyOStream fos(rcpFromRef(ss)," |||");
const bool result = tester.compare( *invA[i], *op, &fos );
TEST_ASSERT(result,
std::endl << " tBlockJacobiPreconditionerFactory::test_initializePrec "
<< ": Comparing factory generated operator to correct operator");
if(not result || verbosity>=10)
os << ss.str();
}
return allPassed;
}