本文整理汇总了C++中thyra::LinearOpTester::check_linear_properties方法的典型用法代码示例。如果您正苦于以下问题:C++ LinearOpTester::check_linear_properties方法的具体用法?C++ LinearOpTester::check_linear_properties怎么用?C++ LinearOpTester::check_linear_properties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thyra::LinearOpTester
的用法示例。
在下文中一共展示了LinearOpTester::check_linear_properties方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runCgSolveExample
bool runCgSolveExample(
const int dim,
const Scalar diagScale,
const bool symOp,
const bool showAllTests,
const typename Teuchos::ScalarTraits<Scalar>::magnitudeType tolerance,
const int maxNumIters
)
{
using Teuchos::as;
using Teuchos::null;
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::OSTab;
typedef Teuchos::ScalarTraits<Scalar> ST;
using Thyra::multiply;
using Thyra::scale;
typedef typename ST::magnitudeType ScalarMag;
bool success = true;
bool result;
Teuchos::RCP<Teuchos::FancyOStream> out =
Teuchos::VerboseObjectBase::getDefaultOStream();
*out << "\n***\n*** Running silly CG solver using scalar type = \'"
<< ST::name() << "\' ...\n***\n";
Teuchos::Time timer("");
timer.start(true);
//
// (A) Setup a simple linear system with tridiagonal operator:
//
// [ a*2 -1 ]
// [ -r(1) a*2 -1 ]
// A = [ . . . ]
// [ -r(n-2) a*2 -1 ]
// [ -r(n-1) a*2 ]
//
// (A.1) Create the tridiagonal matrix operator
*out << "\nConstructing tridiagonal matrix A of dimension = " << dim
<< " and diagonal multiplier = " << diagScale << " ...\n";
Teuchos::Array<Scalar> lower(dim-1), diag(dim), upper(dim-1);
const Scalar
up = -ST::one(),
diagTerm = as<Scalar>(2.0) * diagScale * ST::one(),
low = -(symOp ? ST::one() : ST::random());
int k = 0;
// First row
diag[k] = diagTerm; upper[k] = up;
// Middle rows
for( k = 1; k < dim - 1; ++k ) {
lower[k-1] = low; diag[k] = diagTerm; upper[k] = up;
}
// Last row
lower[k-1] = low; diag[k] = diagTerm;
RCP<const Thyra::LinearOpBase<Scalar> > A =
rcp(new ExampleTridiagSerialLinearOp<Scalar>(dim, lower, diag, upper));
// (A.2) Testing the linear operator constructed linear operator
*out << "\nTesting the constructed linear operator A ...\n";
Thyra::LinearOpTester<Scalar> linearOpTester;
linearOpTester.enable_all_tests(false);
linearOpTester.check_linear_properties(true);
linearOpTester.set_all_error_tol(tolerance);
linearOpTester.set_all_warning_tol(1e-2*tolerance);
linearOpTester.show_all_tests(showAllTests);
result = linearOpTester.check(*A, out.ptr());
if(!result) success = false;
// (A.3) Create RHS vector b and set to a random value
RCP<Thyra::VectorBase<Scalar> > b = createMember(A->range());
Thyra::seed_randomize<Scalar>(0);
Thyra::randomize( -ST::one(), +ST::one(), b.ptr() );
// (A.4) Create LHS vector x and set to zero
RCP<Thyra::VectorBase<Scalar> > x = createMember(A->domain());
Thyra::V_S( x.ptr(), ST::zero() );
// (A.5) Create the final linear system
if(!symOp) {
*out << "\nSetting up normal equations for unsymmetric system A^H*(A*x-b) => new A*x = b ...\n";
// A^H*A
RCP<const Thyra::LinearOpBase<Scalar> > AtA = multiply(adjoint(A), A);
// A^H*b
RCP<Thyra::VectorBase<Scalar> > nb = createMember(AtA->range());
Thyra::apply<Scalar>(*A, Thyra::CONJTRANS, *b, nb.ptr());
A = AtA;
b = nb;
}
// (A.6) Testing the linear operator used with the solve
*out << "\nTesting the linear operator used with the solve ...\n";
linearOpTester.check_for_symmetry(true);
result = linearOpTester.check(*A, out.ptr());
if(!result) success = false;
//
// (B) Solve the linear system with the silly CG solver
//
*out << "\nSolving the linear system with sillyCgSolve(...) ...\n";
//.........这里部分代码省略.........