本文整理汇总了C++中teuchos::RefCountPtr::OperatorDomainMap方法的典型用法代码示例。如果您正苦于以下问题:C++ RefCountPtr::OperatorDomainMap方法的具体用法?C++ RefCountPtr::OperatorDomainMap怎么用?C++ RefCountPtr::OperatorDomainMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类teuchos::RefCountPtr
的用法示例。
在下文中一共展示了RefCountPtr::OperatorDomainMap方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例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
Teuchos::ParameterList GaleriList;
// The problem is defined on a 2D grid, global size is nx * nx.
int nx = 30;
GaleriList.set("n", nx * nx);
GaleriList.set("nx", nx);
GaleriList.set("ny", nx);
Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap64("Linear", 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
string PrecType = "ILU"; // incomplete LU
int OverlapLevel = 1; // 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 parameters for ILU
List.set("fact: drop tolerance", 1e-9);
List.set("fact: level-of-fill", 1);
// the combine mode is on the following:
// "Add", "Zero", "Insert", "InsertAdd", "Average", "AbsMax"
// Their meaning is as defined in file Epetra_CombineMode.h
List.set("schwarz: combine mode", "Add");
// 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.
IFPACK_CHK_ERR(Prec->Initialize());
// Builds the preconditioners, by looking for the values of
// the matrix.
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
Solver.Iterate(1550,1e-8);
cout << *Prec;
#ifdef HAVE_MPI
MPI_Finalize() ;
#endif
return(EXIT_SUCCESS);
}
示例3: 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() ;
//.........这里部分代码省略.........
示例4: 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::CreateMap64("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;
// builds an Ifpack_AdditiveSchwarz. This is templated with
// the local solvers, in this case Ifpack_ICT. Note that any
// other Ifpack_Preconditioner-derived class can be used
// instead of Ifpack_ICT.
// In this example the overlap is zero. Use
// Prec(A,OverlapLevel) for the general case.
Ifpack_AdditiveSchwarz<Ifpack_ICT> Prec(&*A);
// `1.0' means that the factorization should approximatively
// keep the same number of nonzeros per row of the original matrix.
List.set("fact: ict level-of-fill", 1.0);
// no modifications on the diagonal
List.set("fact: absolute threshold", 0.0);
List.set("fact: relative threshold", 1.0);
List.set("fact: relaxation value", 0.0);
// matrix `laplace_2d_bc' is not symmetric because of the way
// boundary conditions are imposed. We can filter the singletons,
// (that is, Dirichlet nodes) and end up with a symmetric
// matrix (as ICT requires).
List.set("schwarz: filter singletons", true);
// 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.
IFPACK_CHK_ERR(Prec.Initialize());
// Builds the preconditioners, by looking for the values of
// the matrix.
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());
LHS.PutScalar(0.0);
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_cg_condnum);
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-5);
// Prints out some information about the preconditioner
cout << Prec;
#ifdef HAVE_MPI
MPI_Finalize();
#endif
//.........这里部分代码省略.........
示例5: 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::CreateMap64("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;
// builds an Ifpack_AdditiveSchwarz. This is templated with
// the local solvers, in this case Ifpack_BlockRelaxation.
// Ifpack_BlockRelaxation requires as a templated a container
// class. A container defines
// how to store the diagonal blocks. Two choices are available:
// Ifpack_DenseContainer (to store them as dense block,
// than use LAPACK' factorization to apply the inverse of
// each block), of Ifpack_SparseContainer (to store
// the diagonal block as Epetra_CrsMatrix's).
//
// Here, we use Ifpack_SparseContainer, which in turn is
// templated with the class to use to apply the inverse
// of each block. For example, we can use Ifpack_Amesos.
// We still have to decide the overlap among the processes,
// and the overlap among the blocks. The two values
// can be different. The overlap among the blocks is
// considered only if block Jacobi is used.
int OverlapProcs = 2;
int OverlapBlocks = 0;
// define the block below to use dense containers
#if 0
Ifpack_AdditiveSchwarz<Ifpack_BlockRelaxation<Ifpack_DenseContainer> > Prec(A, OverlapProcs);
#else
Ifpack_AdditiveSchwarz<Ifpack_BlockRelaxation<Ifpack_SparseContainer<Ifpack_Amesos> > > Prec(&*A, OverlapProcs);
#endif
List.set("relaxation: type", "symmetric Gauss-Seidel");
List.set("partitioner: overlap", OverlapBlocks);
#ifdef HAVE_IFPACK_METIS
// use METIS to create the blocks. This requires --enable-ifpack-metis.
// If METIS is not installed, the user may select "linear".
List.set("partitioner: type", "metis");
#else
// or a simple greedy algorithm is METIS is not enabled
List.set("partitioner: type", "greedy");
#endif
// defines here the number of local blocks. If 1,
// and only one process is used in the computation, then
// the preconditioner must converge in one iteration.
List.set("partitioner: local parts", 4);
// sets the parameters
IFPACK_CHK_ERR(Prec.SetParameters(List));
// initialize the preconditioner.
IFPACK_CHK_ERR(Prec.Initialize());
// Builds the preconditioners.
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());
LHS.PutScalar(0.0);
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
//.........这里部分代码省略.........