本文整理汇总了C++中AztecOO::SetLHS方法的典型用法代码示例。如果您正苦于以下问题:C++ AztecOO::SetLHS方法的具体用法?C++ AztecOO::SetLHS怎么用?C++ AztecOO::SetLHS使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AztecOO
的用法示例。
在下文中一共展示了AztecOO::SetLHS方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: JustTryIt
int Ifpack_ShyLU::JustTryIt()
{
// Dummy function, To show the error in AztecOO, This works
//cout << "Entering JustTryIt" << endl;
AztecOO *solver;
solver = slu_data_.innersolver;
//cout << solver_ << endl;
Epetra_Map BsMap(-1, slu_data_.Snr, slu_data_.SRowElems, 0, A_->Comm());
Epetra_MultiVector Xs(BsMap, 1);
Epetra_MultiVector Bs(BsMap, 1);
Xs.PutScalar(0.0);
solver->SetLHS(&Xs);
solver->SetRHS(&Bs);
solver->Iterate(30, 1e-10);
return 0;
}
示例2: main
int main(int argc, char *argv[]) {
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
Epetra_MpiComm Comm (MPI_COMM_WORLD);
#else
Epetra_SerialComm Comm;
#endif
int MyPID = Comm.MyPID();
bool verbose = false;
if (MyPID==0) verbose = true;
// matrix downloaded from MatrixMarket
char FileName[] = "../HBMatrices/fidap005.rua";
Epetra_Map * readMap; // Pointers because of Trilinos_Util_ReadHb2Epetra
Epetra_CrsMatrix * readA;
Epetra_Vector * readx;
Epetra_Vector * readb;
Epetra_Vector * readxexact;
// Call routine to read in HB problem
Trilinos_Util_ReadHb2Epetra(FileName, Comm, readMap, readA, readx,
readb, readxexact);
int NumGlobalElements = readMap->NumGlobalElements();
// Create uniform distributed map
Epetra_Map map(NumGlobalElements, 0, Comm);
// Create Exporter to distribute read-in matrix and vectors
Epetra_Export exporter(*readMap, map);
Epetra_CrsMatrix A(Copy, map, 0);
Epetra_Vector x(map);
Epetra_Vector b(map);
Epetra_Vector xexact(map);
Epetra_Time FillTimer(Comm);
A.Export(*readA, exporter, Add);
x.Export(*readx, exporter, Add);
b.Export(*readb, exporter, Add);
xexact.Export(*readxexact, exporter, Add);
A.FillComplete();
delete readA;
delete readx;
delete readb;
delete readxexact;
delete readMap;
// ============================ //
// Construct ILU preconditioner //
// ---------------------------- //
// modify those parameters
int LevelFill = 1;
double DropTol = 0.0;
double Condest;
Ifpack_CrsIct * ICT = NULL;
ICT = new Ifpack_CrsIct(A,DropTol,LevelFill);
// Init values from A
ICT->InitValues(A);
// compute the factors
ICT->Factor();
// and now estimate the condition number
ICT->Condest(false,Condest);
cout << Condest << endl;
if( Comm.MyPID() == 0 ) {
cout << "Condition number estimate (level-of-fill = "
<< LevelFill << ") = " << Condest << endl;
}
// Define label for printing out during the solve phase
string label = "Ifpack_CrsIct Preconditioner: LevelFill = " + toString(LevelFill) +
" Overlap = 0";
ICT->SetLabel(label.c_str());
// Here we create an AztecOO object
AztecOO solver;
solver.SetUserMatrix(&A);
solver.SetLHS(&x);
solver.SetRHS(&b);
solver.SetAztecOption(AZ_solver,AZ_cg);
// Here we set the IFPACK preconditioner and specify few parameters
solver.SetPrecOperator(ICT);
int Niters = 1200;
solver.SetAztecOption(AZ_kspace, Niters);
solver.SetAztecOption(AZ_output, 20);
solver.Iterate(Niters, 5.0e-5);
if (ICT!=0) delete ICT;
//.........这里部分代码省略.........
示例3: main
int main(int argc, char *argv[]) {
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
Epetra_MpiComm Comm (MPI_COMM_WORLD);
#else
Epetra_SerialComm Comm;
#endif
int MyPID = Comm.MyPID();
bool verbose = false;
if (MyPID==0) verbose = true;
// The problem is defined on a 2D grid, global size is nx * nx.
int nx = 30;
Teuchos::ParameterList GaleriList;
GaleriList.set("nx", nx);
GaleriList.set("ny", nx * Comm.NumProc());
GaleriList.set("mx", 1);
GaleriList.set("my", Comm.NumProc());
Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap("Cartesian2D", Comm, GaleriList) );
Teuchos::RefCountPtr<Epetra_CrsMatrix> A = Teuchos::rcp( Galeri::CreateCrsMatrix("Laplace2D", &*Map, GaleriList) );
Teuchos::RefCountPtr<Epetra_MultiVector> LHS = Teuchos::rcp( new Epetra_MultiVector(*Map, 1) );
Teuchos::RefCountPtr<Epetra_MultiVector> RHS = Teuchos::rcp( new Epetra_MultiVector(*Map, 1) );
LHS->PutScalar(0.0); RHS->Random();
// ============================ //
// Construct ILU preconditioner //
// ---------------------------- //
// I wanna test funky values to be sure that they have the same
// influence on the algorithms, both old and new
int LevelFill = 2;
double DropTol = 0.3333;
double Condest;
Teuchos::RefCountPtr<Ifpack_CrsIct> ICT;
ICT = Teuchos::rcp( new Ifpack_CrsIct(*A,DropTol,LevelFill) );
ICT->SetAbsoluteThreshold(0.00123);
ICT->SetRelativeThreshold(0.9876);
// Init values from A
ICT->InitValues(*A);
// compute the factors
ICT->Factor();
// and now estimate the condition number
ICT->Condest(false,Condest);
if( Comm.MyPID() == 0 ) {
cout << "Condition number estimate (level-of-fill = "
<< LevelFill << ") = " << Condest << endl;
}
// Define label for printing out during the solve phase
string label = "Ifpack_CrsIct Preconditioner: LevelFill = " + toString(LevelFill) +
" Overlap = 0";
ICT->SetLabel(label.c_str());
// Here we create an AztecOO object
LHS->PutScalar(0.0);
int Niters = 1200;
AztecOO solver;
solver.SetUserMatrix(&*A);
solver.SetLHS(&*LHS);
solver.SetRHS(&*RHS);
solver.SetAztecOption(AZ_solver,AZ_cg);
solver.SetPrecOperator(&*ICT);
solver.SetAztecOption(AZ_output, 16);
solver.Iterate(Niters, 5.0e-5);
int OldIters = solver.NumIters();
// now rebuild the same preconditioner using ICT, we expect the same
// number of iterations
Ifpack Factory;
Teuchos::RefCountPtr<Ifpack_Preconditioner> Prec = Teuchos::rcp( Factory.Create("IC", &*A) );
Teuchos::ParameterList List;
List.get("fact: level-of-fill", 2);
List.get("fact: drop tolerance", 0.3333);
List.get("fact: absolute threshold", 0.00123);
List.get("fact: relative threshold", 0.9876);
List.get("fact: relaxation value", 0.0);
IFPACK_CHK_ERR(Prec->SetParameters(List));
IFPACK_CHK_ERR(Prec->Compute());
// Here we create an AztecOO object
LHS->PutScalar(0.0);
solver.SetUserMatrix(&*A);
solver.SetLHS(&*LHS);
solver.SetRHS(&*RHS);
solver.SetAztecOption(AZ_solver,AZ_cg);
solver.SetPrecOperator(&*Prec);
solver.SetAztecOption(AZ_output, 16);
solver.Iterate(Niters, 5.0e-5);
//.........这里部分代码省略.........
示例4: main
//.........这里部分代码省略.........
Teuchos::rcp(new ML_Epetra::MultiLevelPreconditioner(*sg_J, precParams,
false));
// Setup InArgs and OutArgs
EpetraExt::ModelEvaluator::InArgs sg_inArgs = sg_model->createInArgs();
EpetraExt::ModelEvaluator::OutArgs sg_outArgs = sg_model->createOutArgs();
sg_inArgs.set_p(1, sg_p);
sg_inArgs.set_x(sg_x);
sg_outArgs.set_f(sg_f);
sg_outArgs.set_W(sg_J);
// Evaluate model
sg_model->evalModel(sg_inArgs, sg_outArgs);
sg_M->ComputePreconditioner();
// Print initial residual norm
double norm_f;
sg_f->Norm2(&norm_f);
if (MyPID == 0)
std::cout << "\nInitial residual norm = " << norm_f << std::endl;
// Setup AztecOO solver
AztecOO aztec;
if (symmetric)
aztec.SetAztecOption(AZ_solver, AZ_cg);
else
aztec.SetAztecOption(AZ_solver, AZ_gmres);
aztec.SetAztecOption(AZ_precond, AZ_none);
aztec.SetAztecOption(AZ_kspace, 20);
aztec.SetAztecOption(AZ_conv, AZ_r0);
aztec.SetAztecOption(AZ_output, 1);
aztec.SetUserOperator(sg_J.get());
aztec.SetPrecOperator(sg_M.get());
aztec.SetLHS(sg_dx.get());
aztec.SetRHS(sg_f.get());
// Solve linear system
aztec.Iterate(1000, 1e-12);
// Update x
sg_x->Update(-1.0, *sg_dx, 1.0);
// Save solution to file
EpetraExt::VectorToMatrixMarketFile("stochastic_solution_interlaced.mm",
*sg_x);
// Save RHS to file
EpetraExt::VectorToMatrixMarketFile("stochastic_RHS_interlaced.mm",
*sg_f);
// Save operator to file
EpetraExt::RowMatrixToMatrixMarketFile("stochastic_operator_interlaced.mm",
*sg_J);
// Save mean and variance to file
Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly> sg_x_poly =
sg_model->create_x_sg(View, sg_x.get());
Epetra_Vector mean(*(model->get_x_map()));
Epetra_Vector std_dev(*(model->get_x_map()));
sg_x_poly->computeMean(mean);
sg_x_poly->computeStandardDeviation(std_dev);
EpetraExt::VectorToMatrixMarketFile("mean_gal_interlaced.mm", mean);
EpetraExt::VectorToMatrixMarketFile("std_dev_gal_interlaced.mm", std_dev);
// Compute new residual & response function
EpetraExt::ModelEvaluator::OutArgs sg_outArgs2 = sg_model->createOutArgs();
示例5: main
int main(int argc, char *argv[]) {
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
Epetra_MpiComm Comm (MPI_COMM_WORLD);
#else
Epetra_SerialComm Comm;
#endif
int ierr=HIPS_Initialize(1);
HIPS_ExitOnError(ierr);
int MyPID = Comm.MyPID();
bool verbose = false;
if (MyPID==0) verbose = true;
Teuchos::ParameterList GaleriList;
int nx = 100;
GaleriList.set("nx", nx);
GaleriList.set("ny", nx * Comm.NumProc());
// GaleriList.set("ny", nx);
GaleriList.set("mx", 1);
GaleriList.set("my", Comm.NumProc());
Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap("Cartesian2D", Comm, GaleriList) );
Teuchos::RefCountPtr<Epetra_CrsMatrix> A = Teuchos::rcp( Galeri::CreateCrsMatrix("Laplace2D", &*Map, GaleriList) );
Teuchos::RefCountPtr<Epetra_MultiVector> LHS = Teuchos::rcp( new Epetra_MultiVector(*Map, 1) );
Teuchos::RefCountPtr<Epetra_MultiVector> RHS = Teuchos::rcp( new Epetra_MultiVector(*Map, 1) );
LHS->PutScalar(0.0); RHS->Random();
// ============================ //
// Construct ILU preconditioner //
// ---------------------------- //
Teuchos::RefCountPtr<Ifpack_HIPS> RILU;
RILU = Teuchos::rcp( new Ifpack_HIPS(&*A) );
Teuchos::ParameterList List;
List.set("hips: id",0);
List.set("hips: setup output",2);
List.set("hips: iteration output",0);
List.set("hips: drop tolerance",5e-3);
List.set("hips: graph symmetric",1);
RILU->SetParameters(List);
RILU->Initialize();
RILU->Compute();
// Here we create an AztecOO object
LHS->PutScalar(0.0);
int Niters = 50;
AztecOO solver;
solver.SetUserMatrix(&*A);
solver.SetLHS(&*LHS);
solver.SetRHS(&*RHS);
solver.SetAztecOption(AZ_solver,AZ_gmres);
solver.SetPrecOperator(&*RILU);
solver.SetAztecOption(AZ_output, 1);
solver.Iterate(Niters, 1.0e-8);
int OldIters = solver.NumIters();
HIPS_Finalize();
#ifdef HAVE_MPI
MPI_Finalize() ;
#endif
return(EXIT_SUCCESS);
}
示例6: Problem
int shylu_local_solve<Epetra_CrsMatrix, Epetra_MultiVector>
(
shylu_symbolic<Epetra_CrsMatrix,Epetra_MultiVector> *ssym,
shylu_data<Epetra_CrsMatrix,Epetra_MultiVector> *data,
shylu_config<Epetra_CrsMatrix,Epetra_MultiVector> *config,
const Epetra_MultiVector& X,
Epetra_MultiVector& Y
)
{
int err;
#ifndef NDEBUG
int nvectors = X.NumVectors();
assert (nvectors == data->localrhs->NumVectors());
#endif // NDEBUG
// Initialize the X vector for iterative solver
data->Xs->PutScalar(0.0);
// Get local portion of X
data->localrhs->Import(X, *(data->BdImporter), Insert);
data->localrhs->Print(std::cout);
std::cout << " " << std::endl;
data->locallhs->Print(std::cout);
// locallhs is z in paper
if (config->amesosForDiagonal) {
std::cout << "calling amesos for diagon" << endl;
ssym->OrigLP->SetRHS((data->localrhs).getRawPtr());
ssym->OrigLP->SetLHS((data->locallhs).getRawPtr());
std::cout << "set RHS and LHS " << std::endl;
ssym->ReIdx_LP->fwd();
ssym->Solver->Solve();
}
else {
ssym->ifSolver->ApplyInverse(*(data->localrhs), *(data->locallhs));
}
err = ssym->R->Multiply(false, *(data->locallhs), *(data->temp1));
assert (err == 0);
// Export temp1 to a dist vector - temp2
data->temp2->Import(*(data->temp1), *(data->DistImporter), Insert);
//Epetra_MultiVector Bs(SMap, nvectors); // b_2 - R * z in ShyLU paper
data->Bs->Import(X, *(data->BsImporter), Insert);
data->Bs->Update(-1.0, *(data->temp2), 1.0);
AztecOO *solver = 0;
Epetra_LinearProblem Problem(data->Sbar.get(),
(data->Xs).getRawPtr(), (data->Bs).getRawPtr());
if ((config->schurSolver == "G") || (config->schurSolver == "IQR"))
{
IFPACK_CHK_ERR(data->iqrSolver->Solve(*(data->schur_op),
*(data->Bs), *(data->Xs)));
}
else if (config->schurSolver == "Amesos")
{
Amesos_BaseSolver *solver2 = data->dsolver;
data->OrigLP2->SetLHS((data->Xs).getRawPtr());
data->OrigLP2->SetRHS((data->Bs).getRawPtr());
data->ReIdx_LP2->fwd();
//cout << "Calling solve *****************************" << endl;
solver2->Solve();
//cout << "Out of solve *****************************" << endl;
}
else
{
if (config->libName == "Belos")
{
solver = data->innersolver;
solver->SetLHS((data->Xs).getRawPtr());
solver->SetRHS((data->Bs).getRawPtr());
}
else
{
// See the comment above on why we are not able to reuse the solver
// when outer solve is AztecOO as well.
solver = new AztecOO();
//solver.SetPrecOperator(precop_);
solver->SetAztecOption(AZ_solver, AZ_gmres);
// Do not use AZ_none
solver->SetAztecOption(AZ_precond, AZ_dom_decomp);
//solver->SetAztecOption(AZ_precond, AZ_none);
//solver->SetAztecOption(AZ_precond, AZ_Jacobi);
////solver->SetAztecOption(AZ_precond, AZ_Neumann);
//solver->SetAztecOption(AZ_overlap, 3);
//solver->SetAztecOption(AZ_subdomain_solve, AZ_ilu);
//solver->SetAztecOption(AZ_output, AZ_all);
//solver->SetAztecOption(AZ_diagnostics, AZ_all);
solver->SetProblem(Problem);
}
// What should be a good inner_tolerance :-) ?
solver->Iterate(config->inner_maxiters, config->inner_tolerance);
}
// Import Xs locally
data->LocalXs->Import(*(data->Xs), *(data->XsImporter), Insert);
//.........这里部分代码省略.........
示例7: BsMap
int shylu_dist_solve<Epetra_CrsMatrix,Epetra_MultiVector>(
shylu_symbolic<Epetra_CrsMatrix,Epetra_MultiVector> *ssym,
shylu_data<Epetra_CrsMatrix,Epetra_MultiVector> *data,
shylu_config<Epetra_CrsMatrix,Epetra_MultiVector> *config,
const Epetra_MultiVector& X,
Epetra_MultiVector& Y
)
{
int err;
AztecOO *solver = 0;
assert(X.Map().SameAs(Y.Map()));
//assert(X.Map().SameAs(A_->RowMap()));
const Epetra_MultiVector *newX;
newX = &X;
//rd_->redistribute(X, newX);
int nvectors = newX->NumVectors();
// May have to use importer/exporter
Epetra_Map BsMap(-1, data->Snr, data->SRowElems, 0, X.Comm());
Epetra_Map BdMap(-1, data->Dnr, data->DRowElems, 0, X.Comm());
Epetra_MultiVector Bs(BsMap, nvectors);
Epetra_Import BsImporter(BsMap, newX->Map());
assert(BsImporter.SourceMap().SameAs(newX->Map()));
assert((newX->Map()).SameAs(BsImporter.SourceMap()));
Bs.Import(*newX, BsImporter, Insert);
Epetra_MultiVector Xs(BsMap, nvectors);
Epetra_SerialComm LComm; // Use Serial Comm for the local vectors.
Epetra_Map LocalBdMap(-1, data->Dnr, data->DRowElems, 0, LComm);
Epetra_MultiVector localrhs(LocalBdMap, nvectors);
Epetra_MultiVector locallhs(LocalBdMap, nvectors);
Epetra_MultiVector Z(BdMap, nvectors);
Epetra_MultiVector Bd(BdMap, nvectors);
Epetra_Import BdImporter(BdMap, newX->Map());
assert(BdImporter.SourceMap().SameAs(newX->Map()));
assert((newX->Map()).SameAs(BdImporter.SourceMap()));
Bd.Import(*newX, BdImporter, Insert);
int lda;
double *values;
err = Bd.ExtractView(&values, &lda);
assert (err == 0);
int nrows = ssym->C->RowMap().NumMyElements();
// copy to local vector //TODO: OMP ?
assert(lda == nrows);
for (int v = 0; v < nvectors; v++)
{
for (int i = 0; i < nrows; i++)
{
err = localrhs.ReplaceMyValue(i, v, values[i+v*lda]);
assert (err == 0);
}
}
// TODO : Do we need to reset the lhs and rhs here ?
if (config->amesosForDiagonal)
{
ssym->LP->SetRHS(&localrhs);
ssym->LP->SetLHS(&locallhs);
ssym->Solver->Solve();
}
else
{
ssym->ifSolver->ApplyInverse(localrhs, locallhs);
}
err = locallhs.ExtractView(&values, &lda);
assert (err == 0);
// copy to distributed vector //TODO: OMP ?
assert(lda == nrows);
for (int v = 0; v < nvectors; v++)
{
for (int i = 0; i < nrows; i++)
{
err = Z.ReplaceMyValue(i, v, values[i+v*lda]);
assert (err == 0);
}
}
Epetra_MultiVector temp1(BsMap, nvectors);
ssym->R->Multiply(false, Z, temp1);
Bs.Update(-1.0, temp1, 1.0);
Xs.PutScalar(0.0);
Epetra_LinearProblem Problem(data->Sbar.get(), &Xs, &Bs);
if (config->schurSolver == "Amesos")
{
Amesos_BaseSolver *solver2 = data->dsolver;
data->LP2->SetLHS(&Xs);
data->LP2->SetRHS(&Bs);
//cout << "Calling solve *****************************" << endl;
//.........这里部分代码省略.........