本文整理汇总了C++中Teuchos::describe方法的典型用法代码示例。如果您正苦于以下问题:C++ Teuchos::describe方法的具体用法?C++ Teuchos::describe怎么用?C++ Teuchos::describe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Teuchos
的用法示例。
在下文中一共展示了Teuchos::describe方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: describe
void AmesosLinearOpWithSolve::describe(
Teuchos::FancyOStream &out,
const Teuchos::EVerbosityLevel verbLevel
) const
{
using Teuchos::OSTab;
using Teuchos::typeName;
using Teuchos::describe;
switch(verbLevel) {
case Teuchos::VERB_DEFAULT:
case Teuchos::VERB_LOW:
out << this->description() << std::endl;
break;
case Teuchos::VERB_MEDIUM:
case Teuchos::VERB_HIGH:
case Teuchos::VERB_EXTREME:
{
out
<< Teuchos::Describable::description() << "{"
<< "rangeDim=" << this->range()->dim()
<< ",domainDim="<< this->domain()->dim() << "}\n";
OSTab tab(out);
if(!is_null(fwdOp_)) {
out << "fwdOp = " << describe(*fwdOp_,verbLevel);
}
if(!is_null(amesosSolver_)) {
out << "amesosSolver=" << typeName(*amesosSolver_) << "\n";
}
break;
}
default:
TEST_FOR_EXCEPT(true); // Should never get here!
}
}
示例2: tab
void BelosLinearOpWithSolve<Scalar>::describe(
Teuchos::FancyOStream &out_arg,
const Teuchos::EVerbosityLevel verbLevel
) const
{
typedef Teuchos::ScalarTraits<Scalar> ST;
using Teuchos::FancyOStream;
using Teuchos::OSTab;
using Teuchos::describe;
RCP<FancyOStream> out = rcp(&out_arg,false);
OSTab tab(out);
switch (verbLevel) {
case Teuchos::VERB_DEFAULT:
case Teuchos::VERB_LOW:
*out << this->description() << std::endl;
break;
case Teuchos::VERB_MEDIUM:
case Teuchos::VERB_HIGH:
case Teuchos::VERB_EXTREME:
{
*out
<< Teuchos::Describable::description()<< "{"
<< "rangeDim=" << this->range()->dim()
<< ",domainDim=" << this->domain()->dim() << "}\n";
if (lp_->getOperator().get()) {
OSTab tab(out);
*out
<< "iterativeSolver = "<<describe(*iterativeSolver_,verbLevel)
<< "fwdOp = " << describe(*lp_->getOperator(),verbLevel);
if (lp_->getLeftPrec().get())
*out << "leftPrecOp = "<<describe(*lp_->getLeftPrec(),verbLevel);
if (lp_->getRightPrec().get())
*out << "rightPrecOp = "<<describe(*lp_->getRightPrec(),verbLevel);
}
break;
}
default:
TEST_FOR_EXCEPT(true); // Should never get here!
}
}
示例3: tab
void DefaultProductVector<Scalar>::describe(
Teuchos::FancyOStream &out_arg,
const Teuchos::EVerbosityLevel verbLevel
) const
{
typedef Teuchos::ScalarTraits<Scalar> ST;
using Teuchos::FancyOStream;
using Teuchos::OSTab;
using Teuchos::describe;
RCP<FancyOStream> out = rcp(&out_arg,false);
OSTab tab(out);
switch(verbLevel) {
case Teuchos::VERB_NONE:
break;
case Teuchos::VERB_DEFAULT:
case Teuchos::VERB_LOW:
*out << this->description() << std::endl;
break;
case Teuchos::VERB_MEDIUM:
case Teuchos::VERB_HIGH:
case Teuchos::VERB_EXTREME:
{
*out
<< Teuchos::Describable::description() << "{"
<< "dim=" << this->space()->dim()
<< "}\n";
OSTab tab2(out);
*out
<< "numBlocks="<< numBlocks_ << std::endl
<< "Constituent vector objects v[0], v[1], ... v[numBlocks-1]:\n";
OSTab tab3(out);
for( int k = 0; k < numBlocks_; ++k ) {
*out << "v["<<k<<"] = " << describe(*vecs_[k].getConstObj(),verbLevel);
}
break;
}
default:
TEST_FOR_EXCEPT(true); // Should never get here!
}
}
示例4: TEUCHOS_FUNC_TIME_MONITOR
SolveStatus<Scalar>
BelosLinearOpWithSolve<Scalar>::solveImpl(
const EOpTransp M_trans,
const MultiVectorBase<Scalar> &B,
const Ptr<MultiVectorBase<Scalar> > &X,
const Ptr<const SolveCriteria<Scalar> > solveCriteria
) const
{
TEUCHOS_FUNC_TIME_MONITOR("BelosLOWS");
using Teuchos::rcp;
using Teuchos::rcpFromRef;
using Teuchos::rcpFromPtr;
using Teuchos::FancyOStream;
using Teuchos::OSTab;
using Teuchos::describe;
typedef Teuchos::ScalarTraits<Scalar> ST;
typedef typename ST::magnitudeType ScalarMag;
Teuchos::Time totalTimer(""), timer("");
totalTimer.start(true);
assertSolveSupports(*this, M_trans, solveCriteria);
// 2010/08/22: rabartl: Bug 4915 ToDo: Move the above into the NIV function
// solve(...).
const int numRhs = B.domain()->dim();
const int numEquations = B.range()->dim();
const RCP<FancyOStream> out = this->getOStream();
const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
OSTab tab = this->getOSTab();
if (out.get() && static_cast<int>(verbLevel) > static_cast<int>(Teuchos::VERB_LOW)) {
*out << "\nStarting iterations with Belos:\n";
OSTab tab2(out);
*out << "Using forward operator = " << describe(*fwdOpSrc_->getOp(),verbLevel);
*out << "Using iterative solver = " << describe(*iterativeSolver_,verbLevel);
*out << "With #Eqns="<<numEquations<<", #RHSs="<<numRhs<<" ...\n";
}
//
// Set RHS and LHS
//
bool ret = lp_->setProblem( rcpFromPtr(X), rcpFromRef(B) );
TEST_FOR_EXCEPTION(
ret == false, CatastrophicSolveFailure
,"Error, the Belos::LinearProblem could not be set for the current solve!"
);
//
// Set the solution criteria
//
const RCP<Teuchos::ParameterList> tmpPL = Teuchos::parameterList();
SolveMeasureType solveMeasureType;
RCP<GeneralSolveCriteriaBelosStatusTest<Scalar> > generalSolveCriteriaBelosStatusTest;
if (nonnull(solveCriteria)) {
solveMeasureType = solveCriteria->solveMeasureType;
const ScalarMag requestedTol = solveCriteria->requestedTol;
if (solveMeasureType.useDefault()) {
tmpPL->set("Convergence Tolerance", defaultTol_);
}
else if (solveMeasureType(SOLVE_MEASURE_NORM_RESIDUAL, SOLVE_MEASURE_NORM_RHS)) {
if (requestedTol != SolveCriteria<Scalar>::unspecifiedTolerance()) {
tmpPL->set("Convergence Tolerance", requestedTol);
}
else {
tmpPL->set("Convergence Tolerance", defaultTol_);
}
tmpPL->set("Explicit Residual Scaling", "Norm of RHS");
}
else if (solveMeasureType(SOLVE_MEASURE_NORM_RESIDUAL, SOLVE_MEASURE_NORM_INIT_RESIDUAL)) {
if (requestedTol != SolveCriteria<Scalar>::unspecifiedTolerance()) {
tmpPL->set("Convergence Tolerance", requestedTol);
}
else {
tmpPL->set("Convergence Tolerance", defaultTol_);
}
tmpPL->set("Explicit Residual Scaling", "Norm of Initial Residual");
}
else {
// Set the most generic (and inefficient) solve criteria
generalSolveCriteriaBelosStatusTest = createGeneralSolveCriteriaBelosStatusTest(
*solveCriteria, convergenceTestFrequency_);
// Set the verbosity level (one level down)
generalSolveCriteriaBelosStatusTest->setOStream(out);
generalSolveCriteriaBelosStatusTest->setVerbLevel(incrVerbLevel(verbLevel, -1));
// Set the default convergence tolerance to always converged to allow
// the above status test to control things.
tmpPL->set("Convergence Tolerance", 1.0);
}
}
else {
// No solveCriteria was even passed in!
tmpPL->set("Convergence Tolerance", defaultTol_);
}
//
//.........这里部分代码省略.........
示例5: tab
bool VectorTester<Scalar>::check(
const VectorBase<Scalar> &v
,Teuchos::FancyOStream *out_arg
) const
{
using std::endl;
using Teuchos::describe;
using Teuchos::FancyOStream;
using Teuchos::OSTab;
typedef Teuchos::ScalarTraits<Scalar> ST;
//typedef typename ST::magnitudeType ScalarMag;
Teuchos::RCP<FancyOStream> out = Teuchos::rcp(out_arg,false);
const Teuchos::EVerbosityLevel verbLevel = (dump_all()?Teuchos::VERB_EXTREME:Teuchos::VERB_MEDIUM);
OSTab tab(out,1,"THYRA");
bool result, success = true;
if(out.get()) *out <<endl<< "*** Entering Thyra::VectorTester<"<<ST::name()<<">::check(v,...) ...\n";
if(out.get()) *out <<endl<< "Testing a VectorBase object described as:\n" << describe(v,verbLevel);
if(out.get()) *out <<endl<< "A) Creating temporary vector t1, t2, t3, and t4 from v.space() ...\n";
Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
vs = v.space();
Teuchos::RCP<Thyra::VectorBase<Scalar> >
t1 = createMember(vs), t2 = createMember(vs), t3 = createMember(vs), t4 = createMember(vs);
if(out.get()) *out <<endl<< "B) Testing VectorBase::applyOp(...) by calling a few standard RTOp operations ... ";
const Scalar
one = ST::one(),
two = Scalar(2)*one,
three = Scalar(3)*one;
{
using Teuchos::inoutArg;
TestResultsPrinter testResultsPrinter(out, show_all_tests());
const RCP<FancyOStream> testOut = testResultsPrinter.getTestOStream();
bool these_results = true;
*testOut <<endl<< "assign(t1.ptr(),2.0) ...\n";
Thyra::assign( t1.ptr(), two );
if(dump_all()) *testOut <<endl<< "\nt1 =\n" << describe(*t1,verbLevel);
result = Teuchos::testRelErr<Scalar>(
"sum(t1)", sum(*t1), "2*vs->dim()", two*Scalar(vs->dim()),
"error_tol()", error_tol(), "warning_tol()", warning_tol(),
inoutArg(*testOut)
);
if(!result) these_results = false;
*testOut <<endl<< "assign(t2.ptr(),3.0) ...\n";
Thyra::assign( t2.ptr(), three );
if(dump_all()) *testOut <<endl<< "t2 =\n" << *t1;
result = Teuchos::testRelErr<Scalar>(
"sum(t2)",sum(*t2),"3*vs->dim()",three*Scalar(vs->dim()),
"error_tol()",error_tol(),"warning_tol()",warning_tol(),
inoutArg(*testOut)
);
if(!result) these_results = false;
result = Teuchos::testRelErr<Scalar>(
"vs->scalarProd(*t1,*t2)",vs->scalarProd(*t1,*t2),"2*3*vs->dim()",two*three*Scalar(vs->dim()),
"error_tol()",error_tol(),"warning_tol()",warning_tol(),
inoutArg(*testOut)
);
if(!result) these_results = false;
testResultsPrinter.printTestResults(these_results, inoutArg(success));
}
// ToDo: Test the rest of the specific VectorBase interface on v1
if(out.get()) *out <<endl<< "C) Checking the MultiVectorBase interface of v ...\n";
result = multiVectorTester_.check(v, out.ptr());
if(!result) success = false;
if(out.get()) *out <<endl<< "*** Leaving Thyra::VectorTester<"<<ST::name()<<">::check(v,...) ...\n";
return success;
}
示例6: THYRA_FUNC_TIME_MONITOR
SolveStatus<Scalar>
BelosLinearOpWithSolve<Scalar>::solveImpl(
const EOpTransp M_trans,
const MultiVectorBase<Scalar> &B,
const Ptr<MultiVectorBase<Scalar> > &X,
const Ptr<const SolveCriteria<Scalar> > solveCriteria
) const
{
THYRA_FUNC_TIME_MONITOR("Stratimikos: BelosLOWS");
using Teuchos::rcp;
using Teuchos::rcpFromRef;
using Teuchos::rcpFromPtr;
using Teuchos::FancyOStream;
using Teuchos::OSTab;
using Teuchos::ParameterList;
using Teuchos::parameterList;
using Teuchos::describe;
typedef Teuchos::ScalarTraits<Scalar> ST;
typedef typename ST::magnitudeType ScalarMag;
Teuchos::Time totalTimer(""), timer("");
totalTimer.start(true);
assertSolveSupports(*this, M_trans, solveCriteria);
// 2010/08/22: rabartl: Bug 4915 ToDo: Move the above into the NIV function
// solve(...).
const RCP<FancyOStream> out = this->getOStream();
const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
OSTab tab = this->getOSTab();
if (out.get() && static_cast<int>(verbLevel) > static_cast<int>(Teuchos::VERB_LOW)) {
*out << "\nStarting iterations with Belos:\n";
OSTab tab2(out);
*out << "Using forward operator = " << describe(*fwdOpSrc_->getOp(),verbLevel);
*out << "Using iterative solver = " << describe(*iterativeSolver_,verbLevel);
*out << "With #Eqns="<<B.range()->dim()<<", #RHSs="<<B.domain()->dim()<<" ...\n";
}
//
// Set RHS and LHS
//
bool ret = lp_->setProblem( rcpFromPtr(X), rcpFromRef(B) );
TEUCHOS_TEST_FOR_EXCEPTION(
ret == false, CatastrophicSolveFailure
,"Error, the Belos::LinearProblem could not be set for the current solve!"
);
//
// Set the solution criteria
//
// Parameter list for the current solve.
const RCP<ParameterList> tmpPL = Teuchos::parameterList();
// The solver's valid parameter list.
RCP<const ParameterList> validPL = iterativeSolver_->getValidParameters();
SolveMeasureType solveMeasureType;
RCP<GeneralSolveCriteriaBelosStatusTest<Scalar> > generalSolveCriteriaBelosStatusTest;
if (nonnull(solveCriteria)) {
solveMeasureType = solveCriteria->solveMeasureType;
const ScalarMag requestedTol = solveCriteria->requestedTol;
if (solveMeasureType.useDefault()) {
tmpPL->set("Convergence Tolerance", defaultTol_);
}
else if (solveMeasureType(SOLVE_MEASURE_NORM_RESIDUAL, SOLVE_MEASURE_NORM_RHS)) {
if (requestedTol != SolveCriteria<Scalar>::unspecifiedTolerance()) {
tmpPL->set("Convergence Tolerance", requestedTol);
}
else {
tmpPL->set("Convergence Tolerance", defaultTol_);
}
setResidualScalingType (tmpPL, validPL, "Norm of RHS");
}
else if (solveMeasureType(SOLVE_MEASURE_NORM_RESIDUAL, SOLVE_MEASURE_NORM_INIT_RESIDUAL)) {
if (requestedTol != SolveCriteria<Scalar>::unspecifiedTolerance()) {
tmpPL->set("Convergence Tolerance", requestedTol);
}
else {
tmpPL->set("Convergence Tolerance", defaultTol_);
}
setResidualScalingType (tmpPL, validPL, "Norm of Initial Residual");
}
else {
// Set the most generic (and inefficient) solve criteria
generalSolveCriteriaBelosStatusTest = createGeneralSolveCriteriaBelosStatusTest(
*solveCriteria, convergenceTestFrequency_);
// Set the verbosity level (one level down)
generalSolveCriteriaBelosStatusTest->setOStream(out);
generalSolveCriteriaBelosStatusTest->setVerbLevel(incrVerbLevel(verbLevel, -1));
// Set the default convergence tolerance to always converged to allow
// the above status test to control things.
tmpPL->set("Convergence Tolerance", 1.0);
}
// maximum iterations
if (nonnull(solveCriteria->extraParameters)) {
if (Teuchos::isParameterType<int>(*solveCriteria->extraParameters,"Maximum Iterations")) {
tmpPL->set("Maximum Iterations", Teuchos::get<int>(*solveCriteria->extraParameters,"Maximum Iterations"));
//.........这里部分代码省略.........
示例7: TEUCHOS_UNIT_TEST
TEUCHOS_UNIT_TEST( BasicDiscreteAdjointStepperTester, rawNonlinearAdjoint )
{
using Teuchos::outArg;
using Teuchos::describe;
using Teuchos::getParametersFromXmlString;
typedef Thyra::ModelEvaluatorBase MEB;
//
out << "\nA) Create the nonlinear ME ...\n";
//
RCP<VanderPolModel> stateModel = vanderPolModel(
getParametersFromXmlString(
"<ParameterList>"
" <Parameter name=\"Implicit model formulation\" type=\"bool\" value=\"1\"/>"
"</ParameterList>"
)
);
//
out << "\nB) Create the nonlinear solver ...\n";
//
RCP<TimeStepNonlinearSolver<double> > nlSolver = timeStepNonlinearSolver<double>(
getParametersFromXmlString(
"<ParameterList>"
" <Parameter name=\"Default Tol\" type=\"double\" value=\"1.0e-10\"/>"
" <Parameter name=\"Default Max Iters\" type=\"int\" value=\"20\"/>"
"</ParameterList>"
)
);
//
out << "\nC) Create the integrator for the forward state problem ...\n";
//
RCP<IntegratorBuilder<double> > ib = integratorBuilder<double>(
Teuchos::getParametersFromXmlString(
"<ParameterList>"
" <ParameterList name=\"Stepper Settings\">"
" <ParameterList name=\"Stepper Selection\">"
" <Parameter name=\"Stepper Type\" type=\"string\" value=\"Backward Euler\"/>"
" </ParameterList>"
" </ParameterList>"
" <ParameterList name=\"Integration Control Strategy Selection\">"
" <Parameter name=\"Integration Control Strategy Type\" type=\"string\""
" value=\"Simple Integration Control Strategy\"/>"
" <ParameterList name=\"Simple Integration Control Strategy\">"
" <Parameter name=\"Take Variable Steps\" type=\"bool\" value=\"false\"/>"
" <Parameter name=\"Fixed dt\" type=\"double\" value=\"0.5\"/>" // Gives 2 time steps!
" </ParameterList>"
" </ParameterList>"
" <ParameterList name=\"Interpolation Buffer Settings\">"
" <ParameterList name=\"Trailing Interpolation Buffer Selection\">"
" <Parameter name=\"Interpolation Buffer Type\" type=\"string\" value=\"Interpolation Buffer\"/>"
" </ParameterList>"
" </ParameterList>"
"</ParameterList>"
)
);
MEB::InArgs<double> ic = stateModel->getNominalValues();
RCP<IntegratorBase<double> > integrator = ib->create(stateModel, ic, nlSolver);
//integrator->setVerbLevel(Teuchos::VERB_EXTREME);
// ToDo: Set the trailing IB to pick up the entire state solution!
//
out << "\nD) Solve the basic forward problem ...\n";
//
const TimeRange<double> fwdTimeRange = integrator->getFwdTimeRange();
const double t_final = fwdTimeRange.upper();
RCP<const Thyra::VectorBase<double> > x_final, x_dot_final;
get_fwd_x_and_x_dot( *integrator, t_final, outArg(x_final), outArg(x_dot_final) );
out << "\nt_final = " << t_final << "\n";
out << "\nx_final: " << *x_final;
out << "\nx_dot_final: " << *x_dot_final;
//
out << "\nE) Create the basic adjoint model (no distributed response) ...\n";
//
RCP<AdjointModelEvaluator<double> > adjModel =
adjointModelEvaluator<double>(
stateModel, fwdTimeRange
);
adjModel->setFwdStateSolutionBuffer(integrator);
//
out << "\nF) Create a stepper and integrator for the adjoint ...\n";
//
RCP<Thyra::LinearNonlinearSolver<double> > adjTimeStepSolver =
Thyra::linearNonlinearSolver<double>();
RCP<Rythmos::StepperBase<double> > adjStepper =
integrator->getStepper()->cloneStepperAlgorithm();
//.........这里部分代码省略.........
示例8: main
int main(int argc, char *argv[])
{
using std::endl;
typedef double Scalar;
// typedef double ScalarMag; // unused
typedef Teuchos::ScalarTraits<Scalar> ST;
using Teuchos::describe;
using Teuchos::Array;
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::outArg;
using Teuchos::rcp_implicit_cast;
using Teuchos::rcp_dynamic_cast;
using Teuchos::as;
using Teuchos::ParameterList;
using Teuchos::CommandLineProcessor;
typedef Teuchos::ParameterList::PrintOptions PLPrintOptions;
typedef Thyra::ModelEvaluatorBase MEB;
bool result, success = true;
Teuchos::GlobalMPISession mpiSession(&argc,&argv);
RCP<Epetra_Comm> epetra_comm;
#ifdef HAVE_MPI
epetra_comm = rcp( new Epetra_MpiComm(MPI_COMM_WORLD) );
#else
epetra_comm = rcp( new Epetra_SerialComm );
#endif // HAVE_MPI
RCP<Teuchos::FancyOStream>
out = Teuchos::VerboseObjectBase::getDefaultOStream();
try {
//
// Read commandline options
//
CommandLineProcessor clp;
clp.throwExceptions(false);
clp.addOutputSetupOptions(true);
std::string paramsFileName = "";
clp.setOption( "params-file", ¶msFileName,
"File name for XML parameters" );
double t_final = 1e-3;
clp.setOption( "final-time", &t_final,
"Final integration time (initial time is 0.0)" );
int numTimeSteps = 10;
clp.setOption( "num-time-steps", &numTimeSteps,
"Number of (fixed) time steps. If <= 0.0, then variable time steps are taken" );
double maxStateError = 1e-14;
clp.setOption( "max-state-error", &maxStateError,
"Maximum relative error in the integrated state allowed" );
Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_DEFAULT;
setVerbosityLevelOption( "verb-level", &verbLevel,
"Top-level verbosity level. By default, this gets deincremented as you go deeper into numerical objects.",
&clp );
Teuchos::EVerbosityLevel solnVerbLevel = Teuchos::VERB_DEFAULT;
setVerbosityLevelOption( "soln-verb-level", &solnVerbLevel,
"Solution verbosity level",
&clp );
CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
//
*out << "\nA) Get the base parameter list ...\n";
//
RCP<ParameterList>
paramList = Teuchos::parameterList();
if (paramsFileName.length())
updateParametersFromXmlFile( paramsFileName, paramList.ptr() );
paramList->validateParameters(*getValidParameters());
const Scalar t_init = 0.0;
const Rythmos::TimeRange<Scalar> fwdTimeRange(t_init, t_final);
const Scalar delta_t = t_final / numTimeSteps;
*out << "\ndelta_t = " << delta_t;
//
*out << "\nB) Create the Stratimikos linear solver factory ...\n";
//
// This is the linear solve strategy that will be used to solve for the
// linear system with the W.
//
Stratimikos::DefaultLinearSolverBuilder linearSolverBuilder;
linearSolverBuilder.setParameterList(sublist(paramList,Stratimikos_name));
RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> >
//.........这里部分代码省略.........
示例9: tab
bool VectorSpaceTester<Scalar>::check(
const VectorSpaceBase<Scalar> &vs
,Teuchos::FancyOStream *out_arg
) const
{
using std::endl;
using Teuchos::describe;
using Teuchos::FancyOStream;
using Teuchos::OSTab;
typedef Teuchos::ScalarTraits<Scalar> ST;
//typedef typename ST::magnitudeType ScalarMag;
Teuchos::RCP<FancyOStream> out = Teuchos::rcp(out_arg,false);
const Teuchos::EVerbosityLevel verbLevel = (dump_all()?Teuchos::VERB_EXTREME:Teuchos::VERB_MEDIUM);
OSTab tab(out,1,"THYRA");
bool result, success = true;
if(out.get()) *out <<endl<< "*** Entering Thyra::VectorSpaceTester<"<<ST::name()<<">::check(vs,...) ...\n";
if(out.get()) *out <<endl<< "Testing a vector space vs described as:\n" << describe(vs,verbLevel);
if(out.get())
*out
<<endl<< "A) Calling basic query functions ...\n"
<<endl<< "vs.dim() = " << vs.dim()
<<endl<< "vs.hasInCoreView() = " << vs.hasInCoreView() << std::endl;
if(out.get()) *out <<endl<< "B) Checking that vs is compatible with itself ...\n";
if(out.get()) *out <<endl<< "vs.isCompatible(vs)=";
result = vs.isCompatible(vs);
if(!result) success = false;
if(out.get()) *out << result << " == true : " << passfail(result) << std::endl;
if(out.get()) *out <<endl<< "C) Creating a randomized vector member v ...\n";
Teuchos::RCP<Thyra::VectorBase<Scalar> >
v = createMember(vs);
randomize(Scalar(-ST::one()),Scalar(+ST::one()),v.ptr());
if(out.get()) *out <<endl<< "D) Testing the VectorBase interface of v ...\n";
result = vectorTester_.check(*v,out.get());
if(!result) success = false;
if(out.get()) *out <<endl<< "C) Creating a randomized MultiVector member mv ...\n";
Teuchos::RCP<Thyra::MultiVectorBase<Scalar> >
mv = createMembers(vs,num_mv_cols());
randomize(Scalar(-ST::one()),Scalar(+ST::one()),mv.ptr());
if(out.get()) *out <<endl<< "D) Testing the MultiVectorBase interface of mv ...\n";
result = vectorTester_.multiVectorTester().check(*mv, out.ptr());
if(!result) success = false;
if(out.get()) {
if(success)
*out << endl <<"Congratulations, this VectorSpaceBase object seems to check out!\n";
else
*out << endl <<"Oh no, at least one of the tests performed with this VectorSpaceBase object failed (see above failures)!\n";
*out << endl << "*** Leaving VectorSpaceTester<"<<ST::name()<<">::check(vs,...)\n";
}
return success;
}
示例10: main
int main(int argc, char *argv[])
{
using std::endl;
typedef double Scalar;
typedef double ScalarMag;
using Teuchos::describe;
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::rcp_implicit_cast;
using Teuchos::rcp_dynamic_cast;
using Teuchos::as;
using Teuchos::ParameterList;
using Teuchos::CommandLineProcessor;
typedef Teuchos::ParameterList::PrintOptions PLPrintOptions;
typedef Thyra::ModelEvaluatorBase MEB;
typedef Thyra::DefaultMultiVectorProductVectorSpace<Scalar> DMVPVS;
using Thyra::productVectorBase;
bool result, success = true;
Teuchos::GlobalMPISession mpiSession(&argc,&argv);
RCP<Epetra_Comm> epetra_comm;
#ifdef HAVE_MPI
epetra_comm = rcp( new Epetra_MpiComm(MPI_COMM_WORLD) );
#else
epetra_comm = rcp( new Epetra_SerialComm );
#endif // HAVE_MPI
RCP<Teuchos::FancyOStream>
out = Teuchos::VerboseObjectBase::getDefaultOStream();
try {
//
// Read commandline options
//
CommandLineProcessor clp;
clp.throwExceptions(false);
clp.addOutputSetupOptions(true);
std::string paramsFileName = "";
clp.setOption( "params-file", ¶msFileName,
"File name for XML parameters" );
std::string extraParamsString = "";
clp.setOption( "extra-params", &extraParamsString,
"Extra XML parameters" );
std::string extraParamsFile = "";
clp.setOption( "extra-params-file", &extraParamsFile, "File containing extra parameters in XML format.");
double maxStateError = 1e-6;
clp.setOption( "max-state-error", &maxStateError,
"The maximum allowed error in the integrated state in relation to the exact state solution" );
double finalTime = 1e-3;
clp.setOption( "final-time", &finalTime,
"Final integration time (initial time is 0.0)" );
int numTimeSteps = 10;
clp.setOption( "num-time-steps", &numTimeSteps,
"Number of (fixed) time steps. If <= 0.0, then variable time steps are taken" );
bool useBDF = false;
clp.setOption( "use-BDF", "use-BE", &useBDF,
"Use BDF or Backward Euler (BE)" );
bool useIRK = false;
clp.setOption( "use-IRK", "use-other", &useIRK,
"Use IRK or something" );
bool doFwdSensSolve = false;
clp.setOption( "fwd-sens-solve", "state-solve", &doFwdSensSolve,
"Do the forward sensitivity solve or just the state solve" );
bool doFwdSensErrorControl = false;
clp.setOption( "fwd-sens-err-cntrl", "no-fwd-sens-err-cntrl", &doFwdSensErrorControl,
"Do error control on the forward sensitivity solve or not" );
double maxRestateError = 0.0;
clp.setOption( "max-restate-error", &maxRestateError,
"The maximum allowed error between the state integrated by itself verses integrated along with DxDp" );
double maxSensError = 1e-4;
clp.setOption( "max-sens-error", &maxSensError,
"The maximum allowed error in the integrated sensitivity in relation to"
" the finite-difference sensitivity" );
Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_DEFAULT;
setVerbosityLevelOption( "verb-level", &verbLevel,
"Top-level verbosity level. By default, this gets deincremented as you go deeper into numerical objects.",
&clp );
bool testExactSensitivity = false;
clp.setOption( "test-exact-sens", "no-test-exact-sens", &testExactSensitivity,
"Test the exact sensitivity with finite differences or not." );
//.........这里部分代码省略.........
示例11: describe
void AztecOOLinearOpWithSolve::describe(
Teuchos::FancyOStream &out,
const Teuchos::EVerbosityLevel verbLevel
) const
{
using Teuchos::OSTab;
using Teuchos::typeName;
using Teuchos::describe;
switch(verbLevel) {
case Teuchos::VERB_DEFAULT:
case Teuchos::VERB_LOW:
out << this->description() << std::endl;
break;
case Teuchos::VERB_MEDIUM:
case Teuchos::VERB_HIGH:
case Teuchos::VERB_EXTREME:
{
out
<< Teuchos::Describable::description() << "{"
<< "rangeDim=" << this->range()->dim()
<< ",domainDim="<< this->domain()->dim() << "}\n";
OSTab tab(out);
if (!is_null(fwdOp_)) {
out << "fwdOp = " << describe(*fwdOp_,verbLevel);
}
if (!is_null(prec_)) {
out << "prec = " << describe(*prec_,verbLevel);
}
if (!is_null(aztecFwdSolver_)) {
if (aztecFwdSolver_->GetUserOperator())
out
<< "Aztec Fwd Op = "
<< typeName(*aztecFwdSolver_->GetUserOperator()) << "\n";
if (aztecFwdSolver_->GetUserMatrix())
out
<< "Aztec Fwd Mat = "
<< typeName(*aztecFwdSolver_->GetUserMatrix()) << "\n";
if (aztecFwdSolver_->GetPrecOperator())
out
<< "Aztec Fwd Prec Op = "
<< typeName(*aztecFwdSolver_->GetPrecOperator()) << "\n";
if (aztecFwdSolver_->GetPrecMatrix())
out
<< "Aztec Fwd Prec Mat = "
<< typeName(*aztecFwdSolver_->GetPrecMatrix()) << "\n";
}
if (!is_null(aztecAdjSolver_)) {
if (aztecAdjSolver_->GetUserOperator())
out
<< "Aztec Adj Op = "
<< typeName(*aztecAdjSolver_->GetUserOperator()) << "\n";
if (aztecAdjSolver_->GetUserMatrix())
out
<< "Aztec Adj Mat = "
<< typeName(*aztecAdjSolver_->GetUserMatrix()) << "\n";
if (aztecAdjSolver_->GetPrecOperator())
out
<< "Aztec Adj Prec Op = "
<< typeName(*aztecAdjSolver_->GetPrecOperator()) << "\n";
if (aztecAdjSolver_->GetPrecMatrix())
out
<< "Aztec Adj Prec Mat = "
<< typeName(*aztecAdjSolver_->GetPrecMatrix()) << "\n";
}
break;
}
default:
TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
}
}
示例12: main
int main(int argc, char* argv[])
{
using Teuchos::describe;
using Teuchos::rcp;
using Teuchos::rcp_dynamic_cast;
using Teuchos::rcp_const_cast;
using Teuchos::RCP;
using Teuchos::CommandLineProcessor;
using Teuchos::ParameterList;
using Teuchos::sublist;
using Teuchos::getParametersFromXmlFile;
typedef ParameterList::PrintOptions PLPrintOptions;
using Thyra::inverse;
using Thyra::initializePreconditionedOp;
using Thyra::initializeOp;
using Thyra::unspecifiedPrec;
using Thyra::solve;
typedef RCP<const Thyra::LinearOpBase<double> > LinearOpPtr;
typedef RCP<Thyra::VectorBase<double> > VectorPtr;
bool success = true;
bool verbose = true;
Teuchos::GlobalMPISession mpiSession(&argc,&argv);
Teuchos::RCP<Teuchos::FancyOStream>
out = Teuchos::VerboseObjectBase::getDefaultOStream();
try {
//
// Read in options from the command line
//
CommandLineProcessor clp(false); // Don't throw exceptions
const int numVerbLevels = 6;
Teuchos::EVerbosityLevel
verbLevelValues[] =
{
Teuchos::VERB_DEFAULT, Teuchos::VERB_NONE,
Teuchos::VERB_LOW, Teuchos::VERB_MEDIUM,
Teuchos::VERB_HIGH, Teuchos::VERB_EXTREME
};
const char*
verbLevelNames[] =
{ "default", "none", "low", "medium", "high", "extreme" };
Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_MEDIUM;
clp.setOption( "verb-level", &verbLevel,
numVerbLevels, verbLevelValues, verbLevelNames,
"Verbosity level used for all objects."
);
std::string matrixFile = ".";
clp.setOption( "matrix-file", &matrixFile,
"Matrix file."
);
std::string paramListFile = "";
clp.setOption( "param-list-file", ¶mListFile,
"Parameter list for preconditioner and solver blocks."
);
bool showParams = false;
clp.setOption( "show-params", "no-show-params", &showParams,
"Show the parameter list or not."
);
bool testPrecIsLinearOp = true;
clp.setOption( "test-prec-is-linear-op", "test-prec-is-linear-op", &testPrecIsLinearOp,
"Test if the preconditioner is a linear operator or not."
);
double solveTol = 1e-8;
clp.setOption( "solve-tol", &solveTol,
"Tolerance for the solution to determine success or failure!"
);
clp.setDocString(
"This example program shows how to use one linear solver (e.g. AztecOO)\n"
"as a preconditioner for another iterative solver (e.g. Belos).\n"
);
// Note: Use --help on the command line to see the above documentation
CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
//
*out << "\nA) Reading in the matrix ...\n";
//
#ifdef HAVE_MPI
Epetra_MpiComm comm(MPI_COMM_WORLD);
#else
Epetra_SerialComm comm;
#endif
//.........这里部分代码省略.........
示例13: main
int main(int argc, char *argv[])
{
using std::endl;
typedef double Scalar;
typedef double ScalarMag;
using Teuchos::describe;
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::rcp_implicit_cast;
using Teuchos::rcp_dynamic_cast;
using Teuchos::as;
using Teuchos::ParameterList;
using Teuchos::CommandLineProcessor;
typedef Teuchos::ParameterList::PrintOptions PLPrintOptions;
typedef Thyra::ModelEvaluatorBase MEB;
using Thyra::createMember;
using Thyra::createMembers;
bool success = true;
Teuchos::GlobalMPISession mpiSession(&argc,&argv);
RCP<Epetra_Comm> epetra_comm;
#ifdef HAVE_MPI
epetra_comm = rcp( new Epetra_MpiComm(MPI_COMM_WORLD) );
#else
epetra_comm = rcp( new Epetra_SerialComm );
#endif // HAVE_MPI
RCP<Teuchos::FancyOStream>
out = Teuchos::VerboseObjectBase::getDefaultOStream();
try {
//
// A) Read commandline options
//
CommandLineProcessor clp;
clp.throwExceptions(false);
clp.addOutputSetupOptions(true);
std::string paramsFileName = "";
clp.setOption( "params-file", ¶msFileName,
"File name for XML parameters" );
std::string extraParamsString = "";
clp.setOption( "extra-params", &extraParamsString,
"Extra XML parameter string" );
Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_DEFAULT;
setVerbosityLevelOption( "verb-level", &verbLevel,
"Top-level verbosity level. By default, this gets deincremented as you go deeper into numerical objects.",
&clp );
double finalTime = 1.0;
clp.setOption( "final-time", &finalTime, "Final time (the inital time)" );
int numTimeSteps = 2;
clp.setOption( "num-time-steps", &numTimeSteps, "Number of time steps" );
bool dumpFinalSolutions = false;
clp.setOption(
"dump-final-solutions", "no-dump-final-solutions", &dumpFinalSolutions,
"Determine if the final solutions are dumpped or not." );
double maxStateError = 1e-6;
clp.setOption( "max-state-error", &maxStateError,
"The maximum allowed error in the integrated state in relation to the exact state solution" );
// ToDo: Read in more parameters
CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
if ( Teuchos::VERB_DEFAULT == verbLevel )
verbLevel = Teuchos::VERB_LOW;
const Teuchos::EVerbosityLevel
solnVerbLevel = ( dumpFinalSolutions ? Teuchos::VERB_EXTREME : verbLevel );
//
// B) Get the base parameter list that all other parameter lists will be
// read from.
//
RCP<ParameterList> paramList = Teuchos::parameterList();
if (paramsFileName.length())
updateParametersFromXmlFile( paramsFileName, &*paramList );
if (extraParamsString.length())
updateParametersFromXmlString( extraParamsString, &*paramList );
paramList->validateParameters(*getValidParameters());
//
// C) Create the Stratimikos linear solver factories.
//
// Get the linear solve strategy that will be used to solve for the linear
//.........这里部分代码省略.........
示例14: TEUCHOS_UNIT_TEST
TEUCHOS_UNIT_TEST( EpetraLinearOp, blocked_op )
{
if (Teuchos::GlobalMPISession::getNProc() > 2) {
out << "Skipping test if numProc > 2 since it fails for some reason\n";
return;
}
using Teuchos::describe;
// build sub operators
RCP<const LinearOpBase<double> > A00 =
epetraLinearOp(getEpetraMatrix(4,4,0));
RCP<const LinearOpBase<double> > A01 =
epetraLinearOp(getEpetraMatrix(4,3,1));
RCP<const LinearOpBase<double> > A02 =
epetraLinearOp(getEpetraMatrix(4,2,2));
RCP<const LinearOpBase<double> > A10 =
epetraLinearOp(getEpetraMatrix(3,4,3));
RCP<const LinearOpBase<double> > A11 =
epetraLinearOp(getEpetraMatrix(3,3,4));
RCP<const LinearOpBase<double> > A12 =
epetraLinearOp(getEpetraMatrix(3,2,5));
RCP<const LinearOpBase<double> > A20 =
epetraLinearOp(getEpetraMatrix(2,4,6));
RCP<const LinearOpBase<double> > A21 =
epetraLinearOp(getEpetraMatrix(2,3,8));
RCP<const LinearOpBase<double> > A22 =
epetraLinearOp(getEpetraMatrix(2,2,8));
const Teuchos::EVerbosityLevel verbLevel =
(g_dumpAll ? Teuchos::VERB_HIGH : Teuchos::VERB_MEDIUM);
out << "Sub operators built" << std::endl;
{
// build composite operator
RCP<const LinearOpBase<double> > A =
block2x2<double>(
block2x2<double>(A00, A01, A10, A11), block2x1<double>(A02,A12),
block1x2<double>(A20, A21), A22
);
out << "First composite operator built" << std::endl;
// build vectors for use in apply
RCP<MultiVectorBase<double> > x = createMembers<double>(A->domain(), 3);
RCP<MultiVectorBase<double> > y = createMembers<double>(A->range(), 3);
randomize(-1.0, 1.0, x.ptr());
out << "A = \n" << describe(*A, verbLevel) << std::endl;
out << "x = \n" << describe(*x, verbLevel) << std::endl;
out << "y = \n" << describe(*y, verbLevel) << std::endl;
// perform a matrix vector multiply
apply(*A, NOTRANS, *x, y.ptr());
out << "First composite operator completed" << std::endl;
}
{
RCP<const LinearOpBase<double> > A = block2x2<double>(
A11, block1x2<double>(A10, A12),
block2x1<double>(A01, A21), block2x2<double>(A00, A02, A20, A22)
);
out << "Second composite operator built" << std::endl;
// build vectors for use in apply
RCP<MultiVectorBase<double> > x = createMembers<double>(A->domain(), 3);
RCP<MultiVectorBase<double> > y = createMembers<double>(A->range(), 3);
randomize(-1.0, 1.0, x.ptr());
out << "A = \n" << describe(*A, verbLevel) << std::endl;
out << "x = \n" << describe(*x, verbLevel) << std::endl;
out << "y = \n" << describe(*y, verbLevel) << std::endl;
// perform a matrix vector multiply
apply(*A, NOTRANS, *x, y.ptr());
out << "Second composite operator completed" << std::endl;
}
out << "Test complete" << std::endl;
}