ML  Version of the Day
AdaptiveSA.cpp
/* ******************************************************************** */
/* See the file COPYRIGHT for a complete copyright notice, contact */
/* person and disclaimer. */
/* ******************************************************************** */
#include "ml_config.h"
#include "ml_common.h"
#ifdef HAVE_ML_MLAPI
#include "MLAPI_Space.h"
#include "MLAPI_Operator.h"
#include "MLAPI_Krylov.h"
using namespace Teuchos;
using namespace MLAPI;
// =========== //
// main driver //
// =========== //
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
#endif
try {
// Initialize the workspace and set the output level
Init();
int NX = 1000;
// define the space for fine level vectors and operators.
Space FineSpace(2*NX);
DistributedMatrix A(FineSpace, FineSpace);
// assemble the matrix on processor 0 only
if (GetMyPID() == 0)
{
for (int i = 0 ; i < NX ; ++i)
{
A(2*i, 2*i) = 2.0;
A(2*i+1, 2*i+1) = 2.0;
if (i)
{
A(2*i, 2*(i - 1)) = - 1.0;
A(2*i+1, 2*(i - 1)+1) = - 1.0;
}
if (i != NX - 1)
{
A(2*i, 2*(i + 1)) = - 1.0;
A(2*i+1, 2*(i + 1)+1) = - 1.0;
}
}
}
A.FillComplete();
int NumPDEEqns = 2;
int MaxLevels = 10;
Teuchos::ParameterList List;
List.set("additional candidates", 2);
List.set("use default null space", true);
List.set("krylov: type", "cg");
MultiLevelAdaptiveSA Prec(A, List, NumPDEEqns, MaxLevels);
// =============================================================== //
// setup the hierarchy: //
// - `UseDefaultNullSpace' toggles the use of default candidates. //
// - AdditionalCandidates = 2' means to compute two additionals. //
// - the final null space dimension is 3. //
// =============================================================== //
bool UseDefaultNullSpace = true;
int AdditionalCandidates = 1;
Prec.AdaptCompute(UseDefaultNullSpace, AdditionalCandidates);
LHS.Random();
RHS = 0.0;
Krylov(A, LHS, RHS, Prec, List);
}
catch (const int e) {
std::cerr << "Caught integer exception, code = " << e << std::endl;
}
catch (...) {
std::cerr << "Caught exception..." << std::endl;
}
#ifdef HAVE_MPI
MPI_Finalize() ;
#endif
return(0);
}
#else
#include "ml_include.h"
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
#endif
puts("This MLAPI example requires the following configuration options:");
puts("\t--enable-epetra");
puts("\t--enable-teuchos");
puts("\t--enable-ifpack");
puts("\t--enable-amesos");
puts("Please check your configure line.");
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return(0);
}
#endif // #if defined(HAVE_ML_MLAPI)
MLAPI::MultiLevelAdaptiveSA
Black-box multilevel adaptive smoothed aggregation preconditioner.
Definition: MLAPI_MultiLevelAdaptiveSA.h:91
MLAPI::Init
void Init()
Initialize the MLAPI workspace.
MLAPI::Operator::GetDomainSpace
const Space GetDomainSpace() const
Returns a reference to the internally stored domain space.
Definition: MLAPI_Operator.h:190
MLAPI::Operator::GetRangeSpace
const Space GetRangeSpace() const
Returns a reference to the internally stored range space.
Definition: MLAPI_Operator.h:195
MLAPI::Space
Specifies the number and distribution among processes of elements.
Definition: MLAPI_Space.h:40
MLAPI_Krylov.h
MLAPI interface to AztecOO's solvers.
MLAPI::GetMyPID
int GetMyPID()
Returns the ID of the calling process.
MLAPI_DistributedMatrix.h
MLAPI wrapper for Epetra_FECrsMatrix, which allows MATLAB-like syntax.
MLAPI::MultiVector::Random
void Random(int v=-1)
Populates the vector with random elements.
Definition: MLAPI_MultiVector.h:778
MLAPI::Finalize
void Finalize()
Destroys the MLAPI workspace.
MLAPI::DistributedMatrix
Definition: MLAPI_DistributedMatrix.h:29
MLAPI_Expressions.h
Overloaded operators for MultiVector's, Operator's, and InverseOpereator's.
MLAPI_MultiLevelAdaptiveSA.h
Adaptive smoothed aggregation preconditioner.
MLAPI_Operator.h
Basic class to define operators within MLAPI.
MLAPI_MultiVector.h
MLAPI wrapper for double vectors.
MLAPI::MultiVector
Basic class for distributed double-precision vectors.
Definition: MLAPI_MultiVector.h:103
MLAPI_Space.h
Class to specify the number and distribution among processes of elements.
MLAPI
MLAPI: Default namespace for all MLAPI objects and functions.
Definition: MLAPI_Aggregation.h:24