本文整理汇总了C++中teuchos::Array::back方法的典型用法代码示例。如果您正苦于以下问题:C++ Array::back方法的具体用法?C++ Array::back怎么用?C++ Array::back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类teuchos::Array
的用法示例。
在下文中一共展示了Array::back方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
std::string xmlfilename;
if(argc > 1){
if(!strcmp(argv[1],"--help")){
printf("albany [inputfile.xml]\n");
exit(1);
}
else
xmlfilename = argv[1];
}
else
xmlfilename = "input.xml";
try {
RCP<Teuchos::Time> totalTime =
Teuchos::TimeMonitor::getNewTimer("Albany: ***Total Time***");
RCP<Teuchos::Time> setupTime =
Teuchos::TimeMonitor::getNewTimer("Albany: Setup Time");
Teuchos::TimeMonitor totalTimer(*totalTime); //start timer
Teuchos::TimeMonitor setupTimer(*setupTime); //start timer
Albany::SolverFactory slvrfctry(xmlfilename, Albany_MPI_COMM_WORLD);
RCP<Epetra_Comm> appComm = Albany::createEpetraCommFromMpiComm(Albany_MPI_COMM_WORLD);
RCP<Albany::Application> app;
const RCP<Thyra::ModelEvaluator<double> > solver =
slvrfctry.createThyraSolverAndGetAlbanyApp(app, appComm, appComm);
setupTimer.~TimeMonitor();
Teuchos::ParameterList &solveParams =
slvrfctry.getAnalysisParameters().sublist("Solve", /*mustAlreadyExist =*/ false);
// By default, request the sensitivities if not explicitly disabled
solveParams.get("Compute Sensitivities", true);
Teuchos::Array<Teuchos::RCP<const Thyra::VectorBase<double> > > thyraResponses;
Teuchos::Array<Teuchos::Array<Teuchos::RCP<const Thyra::MultiVectorBase<double> > > > thyraSensitivities;
// The PoissonSchrodinger_SchroPo and PoissonSchroMosCap1D tests seg fault as albanyApp is null -
// For now, do not resize the response vectors. FIXME sort out this issue.
if(Teuchos::nonnull(app))
Piro::PerformSolveBase(*solver, solveParams, thyraResponses, thyraSensitivities, app->getAdaptSolMgr()->getSolObserver());
else
Piro::PerformSolveBase(*solver, solveParams, thyraResponses, thyraSensitivities);
*out << "After main solve" << std::endl;
Teuchos::Array<Teuchos::RCP<const Epetra_Vector> > responses;
Teuchos::Array<Teuchos::Array<Teuchos::RCP<const Epetra_MultiVector> > > sensitivities;
epetraFromThyra(appComm, thyraResponses, thyraSensitivities, responses, sensitivities);
const int num_p = solver->Np(); // Number of *vectors* of parameters
const int num_g = solver->Ng(); // Number of *vectors* of responses
*out << "Finished eval of first model: Params, Responses "
<< std::setprecision(12) << std::endl;
const Thyra::ModelEvaluatorBase::InArgs<double> nominal = solver->getNominalValues();
for (int i=0; i<num_p; i++) {
const Teuchos::RCP<const Epetra_Vector> p_init = epetraVectorFromThyra(appComm, nominal.get_p(i));
p_init->Print(*out << "\nParameter vector " << i << ":\n");
}
for (int i=0; i<num_g-1; i++) {
const RCP<const Epetra_Vector> g = responses[i];
bool is_scalar = true;
if (app != Teuchos::null)
is_scalar = app->getResponse(i)->isScalarResponse();
if (is_scalar) {
g->Print(*out << "\nResponse vector " << i << ":\n");
if (num_p == 0) {
// Just calculate regression data
status += slvrfctry.checkSolveTestResults(i, 0, g.get(), NULL);
} else {
for (int j=0; j<num_p; j++) {
const RCP<const Epetra_MultiVector> dgdp = sensitivities[i][j];
if (Teuchos::nonnull(dgdp)) {
dgdp->Print(*out << "\nSensitivities (" << i << "," << j << "):!\n");
}
status += slvrfctry.checkSolveTestResults(i, j, g.get(), dgdp.get());
}
}
}
}
const RCP<const Epetra_Vector> xfinal = responses.back();
double mnv; xfinal->MeanValue(&mnv);
*out << "Main_Solve: MeanValue of final solution " << mnv << std::endl;
*out << "\nNumber of Failed Comparisons: " << status << std::endl;
}
TEUCHOS_STANDARD_CATCH_STATEMENTS(true, std::cerr, success);
if (!success) status+=10000;
Teuchos::TimeMonitor::summarize(*out,false,true,false/*zero timers*/);
return status;
}
示例2: main
//.........这里部分代码省略.........
for (int i=0; i<num_g-1; i++) {
const RCP<const Epetra_Vector> g = responses[i];
bool is_scalar = true;
if (app != Teuchos::null)
is_scalar = app->getResponse(i)->isScalarResponse();
if (is_scalar) {
g->Print(*out << "\nResponse vector " << i << ":\n");
if (num_p == 0) {
// Just calculate regression data
status += slvrfctry.checkSolveTestResults(i, 0, g.get(), NULL);
} else {
for (int j=0; j<num_p; j++) {
const RCP<const Epetra_MultiVector> dgdp = sensitivities[i][j];
if (Teuchos::nonnull(dgdp)) {
if(j < num_param_vecs) {
dgdp->Print(*out << "\nSensitivities (" << i << "," << j << "): \n");
status += slvrfctry.checkSolveTestResults(i, j, g.get(), dgdp.get());
}
else {
const Epetra_Map serial_map(-1, 1, 0, dgdp.get()->Comm());
Epetra_MultiVector norms(serial_map,dgdp->NumVectors());
// RCP<Albany::ScalarResponseFunction> response = rcp_dynamic_cast<Albany::ScalarResponseFunction>(app->getResponse(i));
// int numResponses = response->numResponses();
*out << "\nSensitivities (" << i << "," << j << ") for Distributed Parameters: (two-norm)\n";
*out << " ";
for(int ir=0; ir<dgdp->NumVectors(); ++ir) {
(*dgdp)(ir)->Norm2(&norm2);
(*norms(ir))[0] = norm2;
*out << " " << norm2;
}
*out << "\n" << std::endl;
status += slvrfctry.checkSolveTestResults(i, j, g.get(), &norms);
}
}
}
}
}
}
// Create debug output object
Teuchos::ParameterList &debugParams =
slvrfctry.getParameters().sublist("Debug Output", true);
bool writeToMatrixMarketSoln = debugParams.get("Write Solution to MatrixMarket", false);
bool writeToMatrixMarketDistrSolnMap = debugParams.get("Write Distributed Solution and Map to MatrixMarket", false);
bool writeToCoutSoln = debugParams.get("Write Solution to Standard Output", false);
const RCP<const Epetra_Vector> xfinal = responses.back();
double mnv; xfinal->MeanValue(&mnv);
*out << "Main_Solve: MeanValue of final solution " << mnv << std::endl;
*out << "\nNumber of Failed Comparisons: " << status << std::endl;
if (writeToCoutSoln == true)
std::cout << "xfinal: " << *xfinal << std::endl;
#ifdef ALBANY_PERIDIGM
#if defined(ALBANY_EPETRA)
if (Teuchos::nonnull(LCM::PeridigmManager::self())) {
*out << setprecision(12) << "\nPERIDIGM-ALBANY OPTIMIZATION-BASED COUPLING FINAL FUNCTIONAL VALUE = "
<< LCM::PeridigmManager::self()->obcEvaluateFunctional() << "\n" << std::endl;
}
#endif
#endif
if (debugParams.get<bool>("Analyze Memory", false))
Albany::printMemoryAnalysis(std::cout, comm);
if (writeToMatrixMarketSoln == true) {
//create serial map that puts the whole solution on processor 0
int numMyElements = (xfinal->Comm().MyPID() == 0) ? app->getDiscretization()->getMap()->NumGlobalElements() : 0;
const Epetra_Map serial_map(-1, numMyElements, 0, xfinal->Comm());
//create importer from parallel map to serial map and populate serial solution xfinal_serial
Epetra_Import importOperator(serial_map, *app->getDiscretization()->getMap());
Epetra_Vector xfinal_serial(serial_map);
xfinal_serial.Import(*app->getDiscretization()->getSolutionField(), importOperator, Insert);
//writing to MatrixMarket file
EpetraExt::MultiVectorToMatrixMarketFile("xfinal.mm", xfinal_serial);
}
if (writeToMatrixMarketDistrSolnMap == true) {
//writing to MatrixMarket file
EpetraExt::MultiVectorToMatrixMarketFile("xfinal_distributed.mm", *xfinal);
EpetraExt::BlockMapToMatrixMarketFile("xfinal_distributed_map.mm", *app->getDiscretization()->getMap());
}
}
TEUCHOS_STANDARD_CATCH_STATEMENTS(true, std::cerr, success);
if (!success) status+=10000;
Teuchos::TimeMonitor::summarize(*out,false,true,false/*zero timers*/);
Kokkos::finalize_all();
return status;
}