本文整理汇总了C++中teuchos::RCP::Initialize方法的典型用法代码示例。如果您正苦于以下问题:C++ RCP::Initialize方法的具体用法?C++ RCP::Initialize怎么用?C++ RCP::Initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类teuchos::RCP
的用法示例。
在下文中一共展示了RCP::Initialize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main( int argc, char* argv[] )
{
#ifdef EPETRA_MPI
// Initialize MPI
MPI_Init(&argc,&argv);
Epetra_MpiComm Comm( MPI_COMM_WORLD );
#else
Epetra_SerialComm Comm;
#endif
// Create command line processor
Teuchos::CommandLineProcessor RBGen_CLP;
RBGen_CLP.recogniseAllOptions( false );
RBGen_CLP.throwExceptions( false );
// Generate list of acceptable command line options
bool verbose = false;
std::string xml_file = "";
RBGen_CLP.setOption("verbose", "quiet", &verbose, "Print messages and results.");
RBGen_CLP.setOption("xml-file", &xml_file, "XML Input File");
// Process command line.
Teuchos::CommandLineProcessor::EParseCommandLineReturn
parseReturn= RBGen_CLP.parse( argc, argv );
if( parseReturn == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED ) {
return 0;
}
if( parseReturn != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) {
#ifdef EPETRA_MPI
MPI_Finalize();
#endif
return -1; // Error!
}
// Check to make sure an XML input file was provided
TEUCHOS_TEST_FOR_EXCEPTION(xml_file == "", std::invalid_argument, "ERROR: An XML file was not provided; use --xml-file to provide an XML input file for this RBGen driver.");
Teuchos::Array<Teuchos::RCP<Teuchos::Time> > timersRBGen;
//
// ---------------------------------------------------------------
// CREATE THE INITIAL PARAMETER LIST FROM THE INPUT XML FILE
// ---------------------------------------------------------------
//
Teuchos::RCP<Teuchos::ParameterList> BasisParams = RBGen::createParams( xml_file );
if (verbose && Comm.MyPID() == 0)
{
std::cout<<"-------------------------------------------------------"<<std::endl;
std::cout<<"Input Parameter List: "<<std::endl;
std::cout<<"-------------------------------------------------------"<<std::endl;
BasisParams->print();
}
//
// ---------------------------------------------------------------
// CREATE THE FILE I/O HANDLER
// ---------------------------------------------------------------
//
// - First create the abstract factory for the file i/o handler.
//
RBGen::EpetraMVFileIOFactory fio_factory;
//
// - Then use the abstract factory to create the file i/o handler specified in the parameter list.
//
Teuchos::RCP<Teuchos::Time> timerFileIO = Teuchos::rcp( new Teuchos::Time("Create File I/O Handler") );
timersRBGen.push_back( timerFileIO );
//
Teuchos::RCP< RBGen::FileIOHandler<Epetra_MultiVector> > mvFileIO;
Teuchos::RCP< RBGen::FileIOHandler<Epetra_Operator> > opFileIO =
Teuchos::rcp( new RBGen::EpetraCrsMatrixFileIOHandler() );
{
Teuchos::TimeMonitor lcltimer( *timerFileIO );
mvFileIO = fio_factory.create( *BasisParams );
//
// Initialize file IO handlers
//
mvFileIO->Initialize( BasisParams );
opFileIO->Initialize( BasisParams );
}
if (verbose && Comm.MyPID() == 0)
{
std::cout<<"-------------------------------------------------------"<<std::endl;
std::cout<<"File I/O Handlers Generated"<<std::endl;
std::cout<<"-------------------------------------------------------"<<std::endl;
}
//
// ---------------------------------------------------------------
// READ IN THE DATA SET / SNAPSHOT SET & PREPROCESS
// ( this will be a separate abstract class type )
// ---------------------------------------------------------------
//
Teuchos::RCP<std::vector<std::string> > filenames = RBGen::genFileList( *BasisParams );
Teuchos::RCP<Teuchos::Time> timerSnapshotIn = Teuchos::rcp( new Teuchos::Time("Reading in Snapshot Set") );
timersRBGen.push_back( timerSnapshotIn );
//
Teuchos::RCP<Epetra_MultiVector> testMV;
{
Teuchos::TimeMonitor lcltimer( *timerSnapshotIn );
testMV = mvFileIO->Read( *filenames );
}
//.........这里部分代码省略.........
示例2: main
//.........这里部分代码省略.........
p.out() << "Creating Vectors and Matrices" << std::endl;
Teuchos::RCP<Epetra_Vector> solution_vec =
interface->getSolution();
Teuchos::RCP<Epetra_Vector> rhs_vec =
Teuchos::rcp(new Epetra_Vector(*solution_vec));
Teuchos::RCP<Epetra_Vector> lhs_vec =
Teuchos::rcp(new Epetra_Vector(*solution_vec));
Teuchos::RCP<Epetra_CrsMatrix> jacobian_matrix =
interface->getJacobian();
if (verbose)
p.out() << "Evaluating F and J" << std::endl;
solution_vec->PutScalar(1.0);
interface->computeF(*solution_vec, *rhs_vec);
rhs_vec->Scale(-1.0);
interface->computeJacobian(*solution_vec, *jacobian_matrix);
double norm =0.0;
rhs_vec->Norm2(&norm);
if (verbose)
p.out() << "Step 0, ||F|| = " << norm << std::endl;
if (verbose)
p.out() << "Creating Ifpack preconditioner" << std::endl;
Ifpack Factory;
Teuchos::RCP<Ifpack_Preconditioner> PreconditionerPtr;
PreconditionerPtr = Teuchos::rcp(Factory.Create("ILU",
jacobian_matrix.get(),0));
Teuchos::ParameterList teuchosParams;
PreconditionerPtr->SetParameters(teuchosParams);
PreconditionerPtr->Initialize();
PreconditionerPtr->Compute();
if (verbose)
p.out() << "Creating Aztec Solver" << std::endl;
Teuchos::RCP<AztecOO> aztecSolverPtr = Teuchos::rcp(new AztecOO());
if (verbose)
aztecSolverPtr->SetAztecOption(AZ_output, AZ_last);
else
aztecSolverPtr->SetAztecOption(AZ_output, AZ_none);
// *******************************
// Reuse Test
// *******************************
if (verbose) {
p.out() << "**********************************************" << std::endl;
p.out() << "Testing Newton solve with prec reuse" << std::endl;
p.out() << "**********************************************" << std::endl;
}
int step_number = 0;
int max_steps = 20;
bool converged = false;
int total_linear_iterations = 0;
while (norm > 1.0e-8 && step_number < max_steps) {
step_number++;
if (verbose)
p.out() << "Step " << step_number << ", ||F|| = " << norm << std::endl;
示例3: main
int main(int argc, char *argv[]) {
using std::cout;
using std::endl;
int i;
#ifdef EPETRA_MPI
// Initialize MPI
MPI_Init(&argc,&argv);
Epetra_MpiComm Comm(MPI_COMM_WORLD);
#else
Epetra_SerialComm Comm;
#endif
int MyPID = Comm.MyPID();
// Number of dimension of the domain
int space_dim = 2;
// Size of each of the dimensions of the domain
std::vector<double> brick_dim( space_dim );
brick_dim[0] = 1.0;
brick_dim[1] = 1.0;
// Number of elements in each of the dimensions of the domain
std::vector<int> elements( space_dim );
elements[0] = 10;
elements[1] = 10;
// Create problem
Teuchos::RCP<ModalProblem> testCase = Teuchos::rcp( new ModeLaplace2DQ2(Comm, brick_dim[0], elements[0], brick_dim[1], elements[1]) );
// Get the stiffness and mass matrices
Teuchos::RCP<Epetra_CrsMatrix> K = Teuchos::rcp( const_cast<Epetra_CrsMatrix *>(testCase->getStiffness()), false );
Teuchos::RCP<Epetra_CrsMatrix> M = Teuchos::rcp( const_cast<Epetra_CrsMatrix *>(testCase->getMass()), false );
//
// ************Construct preconditioner*************
//
Teuchos::ParameterList ifpackList;
// allocates an IFPACK factory. No data is associated
// to this object (only method Create()).
Ifpack Factory;
// create the preconditioner. For valid PrecType values,
// please check the documentation
std::string PrecType = "ICT"; // incomplete Cholesky
int OverlapLevel = 0; // must be >= 0. If Comm.NumProc() == 1,
// it is ignored.
Teuchos::RCP<Ifpack_Preconditioner> Prec = Teuchos::rcp( Factory.Create(PrecType, &*K, OverlapLevel) );
assert(Prec != Teuchos::null);
// specify parameters for ICT
ifpackList.set("fact: drop tolerance", 1e-4);
ifpackList.set("fact: ict level-of-fill", 0.);
// the combine mode is on the following:
// "Add", "Zero", "Insert", "InsertAdd", "Average", "AbsMax"
// Their meaning is as defined in file Epetra_CombineMode.h
ifpackList.set("schwarz: combine mode", "Add");
// sets the parameters
IFPACK_CHK_ERR(Prec->SetParameters(ifpackList));
// initialize the preconditioner. At this point the matrix must
// have been FillComplete()'d, but actual values are ignored.
IFPACK_CHK_ERR(Prec->Initialize());
// Builds the preconditioners, by looking for the values of
// the matrix.
IFPACK_CHK_ERR(Prec->Compute());
//
//*******************************************************/
// Set up Belos Block CG operator for inner iteration
//*******************************************************/
//
int blockSize = 3; // block size used by linear solver and eigensolver [ not required to be the same ]
int maxits = K->NumGlobalRows(); // maximum number of iterations to run
//
// Create the Belos::LinearProblem
//
Teuchos::RCP<Belos::LinearProblem<double,Epetra_MultiVector,Epetra_Operator> >
My_LP = Teuchos::rcp( new Belos::LinearProblem<double,Epetra_MultiVector,Epetra_Operator>() );
My_LP->setOperator( K );
// Create the Belos preconditioned operator from the Ifpack preconditioner.
// NOTE: This is necessary because Belos expects an operator to apply the
// preconditioner with Apply() NOT ApplyInverse().
Teuchos::RCP<Epetra_Operator> belosPrec = Teuchos::rcp( new Epetra_InvOperator( Prec.get() ) );
My_LP->setLeftPrec( belosPrec );
//
// Create the ParameterList for the Belos Operator
//
Teuchos::RCP<Teuchos::ParameterList> My_List = Teuchos::rcp( new Teuchos::ParameterList() );
My_List->set( "Solver", "BlockCG" );
My_List->set( "Maximum Iterations", maxits );
My_List->set( "Block Size", 1 );
My_List->set( "Convergence Tolerance", 1e-12 );
//
// Create the Belos::EpetraOperator
//.........这里部分代码省略.........