本文整理汇总了C++中teuchos::RefCountPtr类的典型用法代码示例。如果您正苦于以下问题:C++ RefCountPtr类的具体用法?C++ RefCountPtr怎么用?C++ RefCountPtr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RefCountPtr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: InitValues
//==========================================================================
int Ifpack_CrsRiluk::InitValues(const Epetra_CrsMatrix & A) {
UserMatrixIsCrs_ = true;
if (!Allocated()) AllocateCrs();
Teuchos::RefCountPtr<Epetra_CrsMatrix> OverlapA = Teuchos::rcp( (Epetra_CrsMatrix *) &A, false );
if (IsOverlapped_) {
OverlapA = Teuchos::rcp( new Epetra_CrsMatrix(Copy, *Graph_.OverlapGraph()) );
EPETRA_CHK_ERR(OverlapA->Import(A, *Graph_.OverlapImporter(), Insert));
EPETRA_CHK_ERR(OverlapA->FillComplete());
}
// Get Maximun Row length
int MaxNumEntries = OverlapA->MaxNumEntries();
// Set L range map and U domain map
U_DomainMap_ = Teuchos::rcp( &(A.DomainMap()), false );
L_RangeMap_ = Teuchos::rcp( &(A.RangeMap()), false );
// Do the rest using generic Epetra_RowMatrix interface
EPETRA_CHK_ERR(InitAllValues(*OverlapA, MaxNumEntries));
return(0);
}
开发者ID:cakeisalie,项目名称:oomphlib_003,代码行数:28,代码来源:Ifpack_CrsRiluk.cpp
示例2: main
// Main driver
int main( int argc, char **argv )
{
// Initialise MPI
Teuchos::GlobalMPISession mpiSession(&argc,&argv);
try {
#ifdef HAVE_MPI
// Create a communicator
Teuchos::RefCountPtr <Epetra_MpiComm> comm =
Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD));
#else
// Create a communicator
Teuchos::RefCountPtr <Epetra_SerialComm> comm =
Teuchos::rcp(new Epetra_SerialComm);
#endif
std::string fileName = "task.xml";
if (argc>1)
fileName = argv[1];
// Instantiate the continuation manager
Teuchos::RefCountPtr <ContinuationManager> contManager =
Teuchos::rcp(new ContinuationManager(comm,fileName));
// Instantiate the problem
Teuchos::RefCountPtr <LinearSystem> problem =
Teuchos::rcp(new LinearSystem(comm));
// Set the problem in the continuation manager
contManager->SetLOCAProblem(problem);
// Prepare to run LOCA
contManager->BuildLOCAStepper();
// Run LOCA
bool status = contManager->RunLOCAStepper();
if (status)
std::cout << "\nAll tests passed" << std::endl;
}
catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
catch (const char *s) {
std::cout << s << std::endl;
}
catch (...) {
std::cout << "Caught unknown exception!" << std::endl;
}
return(EXIT_SUCCESS);
}
开发者ID:haripandey,项目名称:trilinos,代码行数:60,代码来源:main.C
示例3:
//==============================================================================
Ifpack_ReorderFilter::Ifpack_ReorderFilter(const Teuchos::RefCountPtr<Epetra_RowMatrix>& Matrix_in,
const Teuchos::RefCountPtr<Ifpack_Reordering>& Reordering_in) :
A_(Matrix_in),
Reordering_(Reordering_in),
NumMyRows_(Matrix_in->NumMyRows()),
MaxNumEntries_(Matrix_in->MaxNumEntries())
{
}
开发者ID:00liujj,项目名称:trilinos,代码行数:9,代码来源:Ifpack_ReorderFilter.cpp
示例4: BasicTest
// ======================================================================
bool BasicTest(string PrecType, const Teuchos::RefCountPtr<Epetra_RowMatrix>& A,bool backward, bool reorder=false)
{
Epetra_MultiVector LHS(A->RowMatrixRowMap(), NumVectors);
Epetra_MultiVector RHS(A->RowMatrixRowMap(), NumVectors);
LHS.PutScalar(0.0); RHS.Random();
double starting_residual = Galeri::ComputeNorm(&*A, &LHS, &RHS);
Epetra_LinearProblem Problem(&*A, &LHS, &RHS);
// Set up the list
Teuchos::ParameterList List;
List.set("relaxation: damping factor", 1.0);
List.set("relaxation: sweeps",2550);
List.set("relaxation: type", PrecType);
if(backward) List.set("relaxation: backward mode",backward);
// Reordering if needed
int NumRows=A->NumMyRows();
std::vector<int> RowList(NumRows);
if(reorder) {
for(int i=0; i<NumRows; i++)
RowList[i]=i;
List.set("relaxation: number of local smoothing indices",NumRows);
List.set("relaxation: local smoothing indices",RowList.size()>0? &RowList[0] : (int*)0);
}
Ifpack_PointRelaxation Point(&*A);
Point.SetParameters(List);
Point.Compute();
// use the preconditioner as solver, with 1550 iterations
Point.ApplyInverse(RHS,LHS);
// compute the real residual
double residual = Galeri::ComputeNorm(&*A, &LHS, &RHS);
if (A->Comm().MyPID() == 0 && verbose)
cout << "||A * x - b||_2 (scaled) = " << residual / starting_residual << endl;
// Jacobi is very slow to converge here
if (residual / starting_residual < 1e-2) {
if (verbose)
cout << "BasicTest Test passed" << endl;
return(true);
}
else {
if (verbose)
cout << "BasicTest Test failed!" << endl;
return(false);
}
}
开发者ID:bartlettroscoe,项目名称:trilinos_old_public,代码行数:53,代码来源:cxx_main.cpp
示例5: CompareBlockSizes
// ======================================================================
int CompareBlockSizes(string PrecType, const Teuchos::RefCountPtr<Epetra_RowMatrix>& A, int NumParts)
{
Epetra_MultiVector RHS(A->RowMatrixRowMap(), NumVectors);
Epetra_MultiVector LHS(A->RowMatrixRowMap(), NumVectors);
LHS.PutScalar(0.0); RHS.Random();
Epetra_LinearProblem Problem(&*A, &LHS, &RHS);
Teuchos::ParameterList List;
List.set("relaxation: damping factor", 1.0);
List.set("relaxation: type", PrecType);
List.set("relaxation: sweeps",1);
List.set("partitioner: type", "linear");
List.set("partitioner: local parts", NumParts);
RHS.PutScalar(1.0);
LHS.PutScalar(0.0);
Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_Amesos> > Prec(&*A);
Prec.SetParameters(List);
Prec.Compute();
// set AztecOO solver object
AztecOO AztecOOSolver(Problem);
AztecOOSolver.SetAztecOption(AZ_solver,Solver);
if (verbose)
AztecOOSolver.SetAztecOption(AZ_output,32);
else
AztecOOSolver.SetAztecOption(AZ_output,AZ_none);
AztecOOSolver.SetPrecOperator(&Prec);
AztecOOSolver.Iterate(2550,1e-5);
return(AztecOOSolver.NumIters());
}
开发者ID:bartlettroscoe,项目名称:trilinos_old_public,代码行数:36,代码来源:cxx_main.cpp
示例6: ConstructOverlapGraph
//==============================================================================
int Ifpack_IlukGraph::ConstructOverlapGraph() {
OverlapGraph_ = Teuchos::rcp( (Epetra_CrsGraph *) &Graph_, false );
OverlapRowMap_ = Teuchos::rcp( (Epetra_BlockMap *) &Graph_.RowMap(), false );
if (LevelOverlap_==0 || !Graph_.DomainMap().DistributedGlobal()) return(0); // Nothing to do
Teuchos::RefCountPtr<Epetra_CrsGraph> OldGraph;
Teuchos::RefCountPtr<Epetra_BlockMap> OldRowMap;
Epetra_BlockMap * DomainMap_tmp = (Epetra_BlockMap *) &Graph_.DomainMap();
Epetra_BlockMap * RangeMap_tmp = (Epetra_BlockMap *) &Graph_.RangeMap();
for (int level=1; level <= LevelOverlap_; level++) {
OldGraph = OverlapGraph_;
OldRowMap = OverlapRowMap_;
OverlapImporter_ = Teuchos::rcp( (Epetra_Import *) OldGraph->Importer(), false );
OverlapRowMap_ = Teuchos::rcp( new Epetra_BlockMap(OverlapImporter_->TargetMap()) );
if (level<LevelOverlap_)
OverlapGraph_ = Teuchos::rcp( new Epetra_CrsGraph(Copy, *OverlapRowMap_, 0) );
else
// On last iteration, we want to filter out all columns except those that correspond
// to rows in the graph. This assures that our matrix is square
OverlapGraph_ = Teuchos::rcp( new Epetra_CrsGraph(Copy, *OverlapRowMap_, *OverlapRowMap_, 0) );
EPETRA_CHK_ERR(OverlapGraph_->Import( Graph_, *OverlapImporter_, Insert));
if (level<LevelOverlap_) {
EPETRA_CHK_ERR(OverlapGraph_->FillComplete(*DomainMap_tmp, *RangeMap_tmp));
}
else {
// Copy last OverlapImporter because we will use it later
OverlapImporter_ = Teuchos::rcp( new Epetra_Import(*OverlapRowMap_, *DomainMap_tmp) );
EPETRA_CHK_ERR(OverlapGraph_->FillComplete(*DomainMap_tmp, *RangeMap_tmp));
}
}
NumMyBlockRows_ = OverlapGraph_->NumMyBlockRows();
NumMyBlockCols_ = OverlapGraph_->NumMyBlockCols();
NumMyRows_ = OverlapGraph_->NumMyRows();
NumMyCols_ = OverlapGraph_->NumMyCols();
return(0);
}
开发者ID:KineticTheory,项目名称:Trilinos,代码行数:45,代码来源:Ifpack_IlukGraph.cpp
示例7: Test
bool Test(const Teuchos::RefCountPtr<Epetra_RowMatrix>& Matrix, Teuchos::ParameterList& List)
{
int NumVectors = 1;
bool UseTranspose = false;
Epetra_MultiVector LHS(Matrix->OperatorDomainMap(),NumVectors);
Epetra_MultiVector RHS(Matrix->OperatorRangeMap(),NumVectors);
Epetra_MultiVector LHSexact(Matrix->OperatorDomainMap(),NumVectors);
LHS.PutScalar(0.0);
LHSexact.Random();
Matrix->Multiply(UseTranspose,LHSexact,RHS);
Epetra_LinearProblem Problem(&*Matrix,&LHS,&RHS);
Teuchos::RefCountPtr<T> Prec;
Prec = Teuchos::rcp( new T(&*Matrix) );
assert(Prec != Teuchos::null);
IFPACK_CHK_ERR(Prec->SetParameters(List));
IFPACK_CHK_ERR(Prec->Initialize());
IFPACK_CHK_ERR(Prec->Compute());
// create the AztecOO solver
AztecOO AztecOOSolver(Problem);
// specify solver
AztecOOSolver.SetAztecOption(AZ_solver,AZ_gmres);
AztecOOSolver.SetAztecOption(AZ_output,32);
AztecOOSolver.SetPrecOperator(&*Prec);
// solver. The solver should converge in one iteration,
// or maximum two (numerical errors)
AztecOOSolver.Iterate(1550,1e-8);
cout << *Prec;
vector<double> Norm(NumVectors);
LHS.Update(1.0,LHSexact,-1.0);
LHS.Norm2(&Norm[0]);
for (int i = 0 ; i < NumVectors ; ++i) {
cout << "Norm[" << i << "] = " << Norm[i] << endl;
if (Norm[i] > 1e-3)
return(false);
}
return(true);
}
开发者ID:cakeisalie,项目名称:oomphlib_003,代码行数:51,代码来源:cxx_main.cpp
示例8: AllSingle
// ======================================================================
int AllSingle(const Teuchos::RefCountPtr<Epetra_RowMatrix>& A, Teuchos::RCP<Epetra_MultiVector> coord)
{
Epetra_MultiVector LHS(A->RowMatrixRowMap(), NumVectors);
Epetra_MultiVector RHS(A->RowMatrixRowMap(), NumVectors);
LHS.PutScalar(0.0); RHS.Random();
Epetra_LinearProblem Problem(&*A, &LHS, &RHS);
Teuchos::ParameterList List;
List.set("relaxation: damping factor", 1.0);
List.set("relaxation: type", "symmetric Gauss-Seidel");
List.set("relaxation: sweeps",1);
List.set("partitioner: overlap",0);
List.set("partitioner: type", "line");
List.set("partitioner: line detection threshold",1.0);
List.set("partitioner: x-coordinates",&(*coord)[0][0]);
List.set("partitioner: y-coordinates",&(*coord)[1][0]);
List.set("partitioner: z-coordinates",(double*) 0);
RHS.PutScalar(1.0);
LHS.PutScalar(0.0);
Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_Amesos> > Prec(&*A);
Prec.SetParameters(List);
Prec.Compute();
// set AztecOO solver object
AztecOO AztecOOSolver(Problem);
AztecOOSolver.SetAztecOption(AZ_solver,Solver);
if (verbose)
AztecOOSolver.SetAztecOption(AZ_output,32);
else
AztecOOSolver.SetAztecOption(AZ_output,AZ_none);
AztecOOSolver.SetPrecOperator(&Prec);
AztecOOSolver.Iterate(2550,1e-5);
printf(" AllSingle iters %d \n",AztecOOSolver.NumIters());
return(AztecOOSolver.NumIters());
}
开发者ID:bartlettroscoe,项目名称:trilinos_old_public,代码行数:41,代码来源:cxx_main.cpp
示例9: CompareLineSmootherEntries
// ======================================================================
int CompareLineSmootherEntries(const Teuchos::RefCountPtr<Epetra_RowMatrix>& A)
{
Epetra_MultiVector LHS(A->RowMatrixRowMap(), NumVectors);
Epetra_MultiVector RHS(A->RowMatrixRowMap(), NumVectors);
LHS.PutScalar(0.0); RHS.Random();
Epetra_LinearProblem Problem(&*A, &LHS, &RHS);
Teuchos::ParameterList List;
List.set("relaxation: damping factor", 1.0);
List.set("relaxation: type", "symmetric Gauss-Seidel");
List.set("relaxation: sweeps",1);
List.set("partitioner: overlap",0);
List.set("partitioner: type", "line");
List.set("partitioner: line mode","matrix entries");
List.set("partitioner: line detection threshold",10.0);
RHS.PutScalar(1.0);
LHS.PutScalar(0.0);
Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_Amesos> > Prec(&*A);
Prec.SetParameters(List);
Prec.Compute();
// set AztecOO solver object
AztecOO AztecOOSolver(Problem);
AztecOOSolver.SetAztecOption(AZ_solver,Solver);
if (verbose)
AztecOOSolver.SetAztecOption(AZ_output,32);
else
AztecOOSolver.SetAztecOption(AZ_output,AZ_none);
AztecOOSolver.SetPrecOperator(&Prec);
AztecOOSolver.Iterate(2550,1e-5);
return(AztecOOSolver.NumIters());
}
开发者ID:KineticTheory,项目名称:Trilinos,代码行数:38,代码来源:cxx_main.cpp
示例10: V
//==============================================================================
int Ifpack_Chebyshev::
ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
{
if (!IsComputed())
IFPACK_CHK_ERR(-3);
if (PolyDegree_ == 0)
return 0;
int nVec = X.NumVectors();
int len = X.MyLength();
if (nVec != Y.NumVectors())
IFPACK_CHK_ERR(-2);
Time_->ResetStartTime();
// AztecOO gives X and Y pointing to the same memory location,
// need to create an auxiliary vector, Xcopy
Teuchos::RefCountPtr<const Epetra_MultiVector> Xcopy;
if (X.Pointers()[0] == Y.Pointers()[0])
Xcopy = Teuchos::rcp( new Epetra_MultiVector(X) );
else
Xcopy = Teuchos::rcp( &X, false );
double **xPtr = 0, **yPtr = 0;
Xcopy->ExtractView(&xPtr);
Y.ExtractView(&yPtr);
#ifdef HAVE_IFPACK_EPETRAEXT
EpetraExt_PointToBlockDiagPermute* IBD=0;
if (UseBlockMode_) IBD=&*InvBlockDiagonal_;
#endif
//--- Do a quick solve when the matrix is identity
double *invDiag=0;
if(!UseBlockMode_) invDiag=InvDiagonal_->Values();
if ((LambdaMin_ == 1.0) && (LambdaMax_ == LambdaMin_)) {
#ifdef HAVE_IFPACK_EPETRAEXT
if(UseBlockMode_) IBD->ApplyInverse(*Xcopy,Y);
else
#endif
if (nVec == 1) {
double *yPointer = yPtr[0], *xPointer = xPtr[0];
for (int i = 0; i < len; ++i)
yPointer[i] = xPointer[i]*invDiag[i];
}
else {
int i, k;
for (i = 0; i < len; ++i) {
double coeff = invDiag[i];
for (k = 0; k < nVec; ++k)
yPtr[k][i] = xPtr[k][i] * coeff;
}
} // if (nVec == 1)
return 0;
} // if ((LambdaMin_ == 1.0) && (LambdaMax_ == LambdaMin_))
//--- Initialize coefficients
// Note that delta stores the inverse of ML_Cheby::delta
double alpha = LambdaMax_ / EigRatio_;
double beta = 1.1 * LambdaMax_;
double delta = 2.0 / (beta - alpha);
double theta = 0.5 * (beta + alpha);
double s1 = theta * delta;
//--- Define vectors
// In ML_Cheby, V corresponds to pAux and W to dk
Epetra_MultiVector V(X);
Epetra_MultiVector W(X);
#ifdef HAVE_IFPACK_EPETRAEXT
Epetra_MultiVector Temp(X);
#endif
double *vPointer = V.Values(), *wPointer = W.Values();
double oneOverTheta = 1.0/theta;
int i, j, k;
//--- If solving normal equations, multiply RHS by A^T
if(SolveNormalEquations_){
Apply_Transpose(Operator_,Y,V);
Y=V;
}
// Do the smoothing when block scaling is turned OFF
// --- Treat the initial guess
if (ZeroStartingSolution_ == false) {
Operator_->Apply(Y, V);
// Compute W = invDiag * ( X - V )/ Theta
#ifdef HAVE_IFPACK_EPETRAEXT
if(UseBlockMode_) {
Temp.Update(oneOverTheta,X,-oneOverTheta,V,0.0);
IBD->ApplyInverse(Temp,W);
// Perform additional matvecs for normal equations
// CMS: Testing this only in block mode FOR NOW
//.........这里部分代码省略.........
开发者ID:gitter-badger,项目名称:quinoa,代码行数:101,代码来源:Ifpack_Chebyshev.cpp
示例11: KrylovTest
// ======================================================================
bool KrylovTest(string PrecType, const Teuchos::RefCountPtr<Epetra_RowMatrix>& A, bool backward, bool reorder=false)
{
Epetra_MultiVector LHS(A->RowMatrixRowMap(), NumVectors);
Epetra_MultiVector RHS(A->RowMatrixRowMap(), NumVectors);
LHS.PutScalar(0.0); RHS.Random();
Epetra_LinearProblem Problem(&*A, &LHS, &RHS);
// Set up the list
Teuchos::ParameterList List;
List.set("relaxation: damping factor", 1.0);
List.set("relaxation: type", PrecType);
if(backward) List.set("relaxation: backward mode",backward);
// Reordering if needed
int NumRows=A->NumMyRows();
std::vector<int> RowList(NumRows);
if(reorder) {
for(int i=0; i<NumRows; i++)
RowList[i]=i;
List.set("relaxation: number of local smoothing indices",NumRows);
List.set("relaxation: local smoothing indices",RowList.size()>0? &RowList[0] : (int*)0);
}
int Iters1, Iters10;
if (verbose) {
cout << "Krylov test: Using " << PrecType
<< " with AztecOO" << endl;
}
// ============================================== //
// get the number of iterations with 1 sweep only //
// ============================================== //
{
List.set("relaxation: sweeps",1);
Ifpack_PointRelaxation Point(&*A);
Point.SetParameters(List);
Point.Compute();
// set AztecOO solver object
AztecOO AztecOOSolver(Problem);
AztecOOSolver.SetAztecOption(AZ_solver,Solver);
AztecOOSolver.SetAztecOption(AZ_output,AZ_none);
AztecOOSolver.SetPrecOperator(&Point);
AztecOOSolver.Iterate(2550,1e-5);
double TrueResidual = AztecOOSolver.TrueResidual();
// some output
if (verbose && Problem.GetMatrix()->Comm().MyPID() == 0) {
cout << "Norm of the true residual = " << TrueResidual << endl;
}
Iters1 = AztecOOSolver.NumIters();
}
// ======================================================== //
// now re-run with 10 sweeps, solver should converge faster
// ======================================================== //
{
List.set("relaxation: sweeps",10);
Ifpack_PointRelaxation Point(&*A);
Point.SetParameters(List);
Point.Compute();
LHS.PutScalar(0.0);
// set AztecOO solver object
AztecOO AztecOOSolver(Problem);
AztecOOSolver.SetAztecOption(AZ_solver,Solver);
AztecOOSolver.SetAztecOption(AZ_output,AZ_none);
AztecOOSolver.SetPrecOperator(&Point);
AztecOOSolver.Iterate(2550,1e-5);
double TrueResidual = AztecOOSolver.TrueResidual();
// some output
if (verbose && Problem.GetMatrix()->Comm().MyPID() == 0) {
cout << "Norm of the true residual = " << TrueResidual << endl;
}
Iters10 = AztecOOSolver.NumIters();
}
if (verbose) {
cout << "Iters_1 = " << Iters1 << ", Iters_10 = " << Iters10 << endl;
cout << "(second number should be smaller than first one)" << endl;
}
if (Iters10 > Iters1) {
if (verbose)
cout << "KrylovTest TEST FAILED!" << endl;
return(false);
}
else {
if (verbose)
cout << "KrylovTest TEST PASSED" << endl;
return(true);
}
}
开发者ID:bartlettroscoe,项目名称:trilinos_old_public,代码行数:100,代码来源:cxx_main.cpp
示例12: ComparePointAndBlock
// ======================================================================
bool ComparePointAndBlock(string PrecType, const Teuchos::RefCountPtr<Epetra_RowMatrix>& A, int sweeps)
{
Epetra_MultiVector RHS(A->RowMatrixRowMap(), NumVectors);
Epetra_MultiVector LHS(A->RowMatrixRowMap(), NumVectors);
LHS.PutScalar(0.0); RHS.Random();
Epetra_LinearProblem Problem(&*A, &LHS, &RHS);
// Set up the list
Teuchos::ParameterList List;
List.set("relaxation: damping factor", 1.0);
List.set("relaxation: type", PrecType);
List.set("relaxation: sweeps",sweeps);
List.set("partitioner: type", "linear");
List.set("partitioner: local parts", A->NumMyRows());
int ItersPoint, ItersBlock;
// ================================================== //
// get the number of iterations with point relaxation //
// ================================================== //
{
RHS.PutScalar(1.0);
LHS.PutScalar(0.0);
Ifpack_PointRelaxation Point(&*A);
Point.SetParameters(List);
Point.Compute();
// set AztecOO solver object
AztecOO AztecOOSolver(Problem);
AztecOOSolver.SetAztecOption(AZ_solver,Solver);
if (verbose)
AztecOOSolver.SetAztecOption(AZ_output,32);
else
AztecOOSolver.SetAztecOption(AZ_output,AZ_none);
AztecOOSolver.SetPrecOperator(&Point);
AztecOOSolver.Iterate(2550,1e-2);
double TrueResidual = AztecOOSolver.TrueResidual();
ItersPoint = AztecOOSolver.NumIters();
// some output
if (verbose && Problem.GetMatrix()->Comm().MyPID() == 0) {
cout << "Iterations = " << ItersPoint << endl;
cout << "Norm of the true residual = " << TrueResidual << endl;
}
}
// ================================================== //
// get the number of iterations with block relaxation //
// ================================================== //
{
RHS.PutScalar(1.0);
LHS.PutScalar(0.0);
Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_Amesos> > Block(&*A);
Block.SetParameters(List);
Block.Compute();
// set AztecOO solver object
AztecOO AztecOOSolver(Problem);
AztecOOSolver.SetAztecOption(AZ_solver,Solver);
if (verbose)
AztecOOSolver.SetAztecOption(AZ_output,32);
else
AztecOOSolver.SetAztecOption(AZ_output,AZ_none);
AztecOOSolver.SetPrecOperator(&Block);
AztecOOSolver.Iterate(2550,1e-2);
double TrueResidual = AztecOOSolver.TrueResidual();
ItersBlock = AztecOOSolver.NumIters();
// some output
if (verbose && Problem.GetMatrix()->Comm().MyPID() == 0) {
cout << "Iterations " << ItersBlock << endl;
cout << "Norm of the true residual = " << TrueResidual << endl;
}
}
int diff = ItersPoint - ItersBlock;
if (diff < 0) diff = -diff;
if (diff > 10)
{
if (verbose)
cout << "ComparePointandBlock TEST FAILED!" << endl;
return(false);
}
else {
if (verbose)
cout << "ComparePointandBlock TEST PASSED" << endl;
return(true);
}
}
开发者ID:bartlettroscoe,项目名称:trilinos_old_public,代码行数:97,代码来源:cxx_main.cpp
示例13: TestContainer
// ======================================================================
bool TestContainer(std::string Type, const Teuchos::RefCountPtr<Epetra_RowMatrix>& A)
{
using std::cout;
using std::endl;
int NumVectors = 3;
int NumMyRows = A->NumMyRows();
Epetra_MultiVector LHS_exact(A->RowMatrixRowMap(), NumVectors);
Epetra_MultiVector LHS(A->RowMatrixRowMap(), NumVectors);
Epetra_MultiVector RHS(A->RowMatrixRowMap(), NumVectors);
LHS_exact.Random(); LHS.PutScalar(0.0);
A->Multiply(false, LHS_exact, RHS);
Epetra_LinearProblem Problem(&*A, &LHS, &RHS);
if (verbose) {
cout << "Container type = " << Type << endl;
cout << "NumMyRows = " << NumMyRows << ", NumVectors = " << NumVectors << endl;
}
LHS.PutScalar(0.0);
Teuchos::RefCountPtr<Ifpack_Container> Container;
if (Type == "dense")
Container = Teuchos::rcp( new Ifpack_DenseContainer(A->NumMyRows(), NumVectors) );
else
Container = Teuchos::rcp( new Ifpack_SparseContainer<Ifpack_Amesos>(A->NumMyRows(), NumVectors) );
assert (Container != Teuchos::null);
IFPACK_CHK_ERR(Container->Initialize());
// set as ID all the local rows of A
for (int i = 0 ; i < A->NumMyRows() ; ++i)
Container->ID(i) = i;
// extract submatrix (in this case, the entire matrix)
// and complete setup
IFPACK_CHK_ERR(Container->Compute(*A));
// set the RHS and LHS
for (int i = 0 ; i < A->NumMyRows() ; ++i)
for (int j = 0 ; j < NumVectors ; ++j) {
Container->RHS(i,j) = RHS[j][i];
Container->LHS(i,j) = LHS[j][i];
}
// set parameters (empty for dense containers)
Teuchos::ParameterList List;
List.set("amesos: solver type", Type);
IFPACK_CHK_ERR(Container->SetParameters(List));
// solve the linear system
IFPACK_CHK_ERR(Container->ApplyInverse());
// get the computed solution, store it in LHS
for (int i = 0 ; i < A->NumMyRows() ; ++i)
for (int j = 0 ; j < NumVectors ; ++j) {
LHS[j][i] = Container->LHS(i,j);
}
double residual = Galeri::ComputeNorm(&LHS, &LHS_exact);
if (A->Comm().MyPID() == 0 && verbose) {
cout << "||x_exact - x||_2 = " << residual << endl;
cout << *Container;
}
bool passed = false;
if (residual < 1e-5)
passed = true;
return(passed);
}
开发者ID:KineticTheory,项目名称:Trilinos,代码行数:75,代码来源:cxx_main.cpp
示例14: 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
// 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();
// ========================================= //
// Compare IC preconditioners to no precond. //
// ----------------------------------------- //
const double tol = 1e-5;
const int maxIter = 500;
// Baseline: No preconditioning
// Compute number of iterations, to compare to IC later.
// Here we create an AztecOO object
LHS->PutScalar(0.0);
AztecOO solver;
solver.SetUserMatrix(&*A);
solver.SetLHS(&*LHS);
solver.SetRHS(&*RHS);
solver.SetAztecOption(AZ_solver,AZ_cg);
//solver.SetPrecOperator(&*PrecDiag);
solver.SetAztecOption(AZ_output, 16);
solver.Iterate(maxIter, tol);
int Iters = solver.NumIters();
//cout << "No preconditioner iterations: " << Iters << endl;
#if 0
// Not sure how to use Ifpack_CrsRick - leave out for now.
//
// 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_CrsRick> IC;
Ifpack_IlukGraph mygraph (A->Graph(), 0, 0);
IC = Teuchos::rcp( new Ifpack_CrsRick(*A, mygraph) );
IC->SetAbsoluteThreshold(0.00123);
IC->SetRelativeThreshold(0.9876);
// Init values from A
IC->InitValues(*A);
// compute the factors
IC->Factor();
// and now estimate the condition number
IC->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
std::string label = "Ifpack_CrsRick Preconditioner: LevelFill = " + toString(LevelFill) +
" Overlap = 0";
IC->SetLabel(label.c_str());
// Here we create an AztecOO object
LHS->PutScalar(0.0);
AztecOO solver;
solver.SetUserMatrix(&*A);
solver.SetLHS(&*LHS);
solver.SetRHS(&*RHS);
solver.SetAztecOption(AZ_solver,AZ_cg);
solver.SetPrecOperator(&*IC);
solver.SetAztecOption(AZ_output, 16);
solver.Iterate(maxIter, tol);
int RickIters = solver.NumIters();
//cout << "Ifpack_Rick iterations: " << RickIters << endl;
// Compare to no preconditioning
if (RickIters > Iters/2)
IFPACK_CHK_ERR(-1);
#endif
//////////////////////////////////////////////////////
//.........这里部分代码省略.........
开发者ID:KineticTheory,项目名称:Trilinos,代码行数:101,代码来源:cxx_main.cpp
示例15: InitValues
//==========================================================================
int Ifpack_CrsIct::InitValues(const Epetra_CrsMatrix & A) {
int ierr = 0;
int i, j;
int NumIn, NumL, NumU;
bool DiagFound;
int NumNonzeroDiags = 0;
Teuchos::RefCountPtr<Epetra_CrsMatrix> OverlapA = Teuchos::rcp( (Epetra_CrsMatrix *) &A_ , false );
if (LevelOverlap_>0) {
EPETRA_CHK_ERR(-1); // Not implemented yet
//OverlapA = new Epetra_CrsMatrix(Copy, *Graph_.OverlapGraph());
//EPETRA_CHK_ERR(OverlapA->Import(A, *Graph_.OverlapImporter(), Insert));
//EPETRA_CHK_ERR(OverlapA->FillComplete());
}
// Get Maximun Row length
int MaxNumEntries = OverlapA->MaxNumEntries();
vector<int> InI(MaxNumEntries); // Allocate temp space
vector<int> UI(MaxNumEntries);
vector<double> InV(MaxNumEntries);
vector<double> UV(MaxNumEntries);
double *DV;
ierr = D_->ExtractView(&DV); // Get view of diagonal
// First we copy the user's matrix into diagonal vector and U, regardless of fill level
int NumRows = OverlapA->NumMyRows();
for (i=0; i< NumRows; i++) {
OverlapA->ExtractMyRowCopy(i, MaxNumEntries, NumIn, &InV[0], &InI[0]); // Get Values and Indices
// Split into L and U (we don't assume that indices are ordered).
NumL = 0;
NumU = 0;
DiagFound = false;
for (j=0; j< NumIn; j++) {
int k = InI[j];
if (k==i) {
DiagFound = true;
DV[i] += Rthresh_ * InV[j] + EPETRA_SGN(InV[j]) * Athresh_; // Store perturbed diagonal in Epetra_Vector D_
}
else if (k < 0) return(-1); // Out of range
else if (i<k && k<NumRows) {
UI[NumU] = k;
UV[NumU] = InV[j];
NumU++;
}
}
// Check in things for this row of L and U
if (DiagFound) NumNonzeroDiags++;
if (NumU) U_->InsertMyValues(i, NumU, &UV[0], &UI[0]);
}
U_->FillComplete(A_.OperatorDomainMap(), A_.OperatorRangeMap());
SetValuesInitialized(true);
SetFactored(false);
int ierr1 = 0;
if (NumNonzeroDiags<U_->NumMyRows()) ierr1 = 1;
A_.Comm().MaxAll(&ierr1, &ierr, 1);
EPETRA_CHK_ERR(ierr);
return(0);
}
开发者ID:haripandey,项目名称:trilinos,代码行数:76,代码来源:Ifpack_CrsIct.cpp
示例16: rcp
Teuchos::RefCountPtr<StdVector<Scalar> > Create() const {
return Teuchos::rcp( new StdVector<Scalar>(
Teuchos::rcp(new std::vector<Scalar>(std_vec_->size(),0))));
}
开发者ID:jdbooth,项目名称:Trilinos,代码行数:4,代码来源:test_20.cpp
示例17: main
int main(int argc, char *argv[])
{
// initialize MPI and Epetra communicator
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
Epetra_MpiComm Comm( MPI_COMM_WORLD );
#else
Epetra_SerialComm Comm;
#endif
Teuchos::ParameterList GaleriList;
// The problem is defined on a 2D grid, global size is nx * nx.
int nx = 30;
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_RowMatrix> A = Teuchos::rcp( Galeri::CreateCrsMatrix("Laplace2D", &*Map, GaleriList) );
// =============================================================== //
// B E G I N N I N G O F I F P A C K C O N S T R U C T I O N //
// =============================================================== //
Teuchos::ParameterList List;
// 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 = "Amesos";
int OverlapLevel = 2; // must be >= 0. If Comm.NumProc() == 1,
// it is ignored.
Teuchos::RefCountPtr<Ifpack_Preconditioner> Prec = Teuchos::rcp( Factory.Create(PrecType, &*A, OverlapLevel) );
assert(Prec != Teuchos::null);
// specify the Amesos solver to be used.
// If the selected solver is not available,
// IFPACK will try to use Amesos' KLU (which is usually always
// compiled). Amesos' serial solvers are:
// "Amesos_Klu", "Amesos_Umfpack", "Amesos_Superlu"
List.set("amesos: solver type", "Amesos_Klu");
// sets the parameters
IFPACK_CHK_ERR(Prec->SetParameters(List));
// initialize the preconditioner. At this point the matrix must
// have been FillComplete()'d, but actual values are ignored.
// At this call, Amesos will perform the symbolic factorization.
IFPACK_CHK_ERR(Prec->Initialize());
// Builds the preconditioners, by looking for the values of
// the matrix. At this call, Amesos will perform the
// numeric factorization.
IFPACK_CHK_ERR(Prec->Compute());
// =================================================== //
// E N D O F I F P A C K C O N S T R U C T I O N //
// =================================================== //
// At this point, we need some additional objects
// to define and solve the linear system.
// defines LHS and RHS
Epetra_Vector LHS(A->OperatorDomainMap());
Epetra_Vector RHS(A->OperatorDomainMap());
// solution is constant
LHS.PutScalar(1.0);
// now build corresponding RHS
A->Apply(LHS,RHS);
// now randomize the solution
RHS.Random();
// need an Epetra_LinearProblem to define AztecOO solver
Epetra_LinearProblem Problem(&*A,&LHS,&RHS);
// now we can allocate the AztecOO solver
AztecOO Solver(Problem);
// specify solver
Solver.SetAztecOption(AZ_solver,AZ_gmres);
Solver.SetAztecOption(AZ_output,32);
// HERE WE SET THE IFPACK PRECONDITIONER
Solver.SetPrecOperator(&*Prec);
// .. and here we solve
// NOTE: with one process, the solver must converge in
// one iteration.
Solver.Iterate(1550,1e-8);
#ifdef HAVE_MPI
MPI_Finalize() ;
//.........这里部分代码省略.........
开发者ID:KineticTheory,项目名称:Trilinos,代码行数:101,代码来源:Ifpack_ex_Amesos.cpp
示例18: 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);
//.........这里部分代码省略.........
开发者ID:cakeisalie,项目名称:oomphlib_003,代码行数:101,代码来源:cxx_main.cpp
示例19: main
// ======================================================================
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
Epetra_MpiComm Comm( MPI_COMM_WORLD );
#else
E
|
请发表评论