~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to dolfin/la/EpetraKrylovSolver.cpp

  • Committer: Kent-Andre Mardal
  • Date: 2008-05-17 07:35:53 UTC
  • mto: (2668.7.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 2670.
  • Revision ID: kent-and@simula.no-20080517073553-etp0lk7zfd1a1jjt
more clean up

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#include "Epetra_FEVector.h"
15
15
#include "Epetra_FECrsMatrix.h"
16
16
#include "Epetra_LinearProblem.h"
 
17
 
 
18
#ifdef HAVE_ML_AZTECOO 
17
19
#include "AztecOO.h"
18
20
#include "ml_include.h"
19
21
#include "ml_MultiLevelOperator.h"
20
22
#include "ml_epetra_utils.h"
 
23
#endif 
21
24
 
22
25
 
23
26
 
39
42
//-----------------------------------------------------------------------------
40
43
dolfin::uint EpetraKrylovSolver::solve(const EpetraMatrix& A, EpetraVector& x, const EpetraVector& b) {
41
44
//FIXME need the ifdef AztecOO 
42
 
 
 
45
//
 
46
 
 
47
  if (pc_type == amg) 
 
48
  {  
 
49
 
 
50
#ifdef HAVE_ML_AZTECOO
43
51
    // create linear system 
44
 
  Epetra_LinearProblem linear_system(&(A.mat()),&(x.vec()),&(b.vec()));
45
 
  // create AztecOO instance
46
 
  AztecOO linear_solver(linear_system);
47
 
 
48
 
  linear_solver.SetAztecOption( AZ_solver, AZ_gmres);
49
 
 
50
 
  //FIXME ifdef ML 
51
 
  //FIXME if amg 
52
 
  // Code from trilinos-8.0.3/packages/didasko/examples/ml/ex1.cpp 
53
 
  
54
 
  // Create and set an ML multilevel preconditioner
55
 
  ML *ml_handle;
56
 
 
57
 
  // Maximum number of levels
58
 
  int N_levels = 10;
59
 
 
60
 
  // output level
61
 
//  ML_Set_PrintLevel(3);
62
 
 
63
 
  ML_Create(&ml_handle,N_levels);
64
 
 
65
 
  // wrap Epetra Matrix into ML matrix (data is NOT copied)
66
 
  EpetraMatrix2MLMatrix(ml_handle, 0, &(A.mat()));
67
 
 
68
 
  // create a ML_Aggregate object to store the aggregates
69
 
  ML_Aggregate *agg_object;
70
 
  ML_Aggregate_Create(&agg_object);
71
 
 
72
 
  // specify max coarse size 
73
 
  ML_Aggregate_Set_MaxCoarseSize(agg_object,1);
74
 
 
75
 
  // generate the hierady
76
 
  N_levels = ML_Gen_MGHierarchy_UsingAggregation(ml_handle, 0, ML_INCREASING, agg_object);
77
 
 
78
 
  // Set a symmetric Gauss-Seidel smoother for the MG method 
79
 
  ML_Gen_Smoother_SymGaussSeidel(ml_handle, ML_ALL_LEVELS, ML_BOTH, 1, ML_DEFAULT);
80
 
 
81
 
  // generate solver
82
 
  ML_Gen_Solver(ml_handle, ML_MGV, 0, N_levels-1);
83
 
 
84
 
  // wrap ML_Operator into Epetra_Operator
85
 
  ML_Epetra::MultiLevelOperator  MLop(ml_handle,A.mat().Comm(),A.mat().DomainMap(),A.mat().RangeMap());
86
 
 
87
 
  // set this operator as preconditioner for AztecOO
88
 
  linear_solver.SetPrecOperator(&MLop);
89
 
 
90
 
  linear_solver.Iterate(1000,1E-9);
91
 
 
 
52
    Epetra_LinearProblem linear_system(&(A.mat()),&(x.vec()),&(b.vec()));
 
53
    // create AztecOO instance
 
54
    AztecOO linear_solver(linear_system);
 
55
 
 
56
    linear_solver.SetAztecOption( AZ_solver, AZ_gmres);
 
57
 
 
58
    //FIXME ifdef ML 
 
59
    //FIXME if amg 
 
60
    // Code from trilinos-8.0.3/packages/didasko/examples/ml/ex1.cpp 
 
61
 
 
62
    // Create and set an ML multilevel preconditioner
 
63
    ML *ml_handle;
 
64
 
 
65
    // Maximum number of levels
 
66
    int N_levels = 10;
 
67
 
 
68
    // output level
 
69
    //  ML_Set_PrintLevel(3);
 
70
 
 
71
    ML_Create(&ml_handle,N_levels);
 
72
 
 
73
    // wrap Epetra Matrix into ML matrix (data is NOT copied)
 
74
    EpetraMatrix2MLMatrix(ml_handle, 0, &(A.mat()));
 
75
 
 
76
    // create a ML_Aggregate object to store the aggregates
 
77
    ML_Aggregate *agg_object;
 
78
    ML_Aggregate_Create(&agg_object);
 
79
 
 
80
    // specify max coarse size 
 
81
    ML_Aggregate_Set_MaxCoarseSize(agg_object,1);
 
82
 
 
83
    // generate the hierady
 
84
    N_levels = ML_Gen_MGHierarchy_UsingAggregation(ml_handle, 0, ML_INCREASING, agg_object);
 
85
 
 
86
    // Set a symmetric Gauss-Seidel smoother for the MG method 
 
87
    ML_Gen_Smoother_SymGaussSeidel(ml_handle, ML_ALL_LEVELS, ML_BOTH, 1, ML_DEFAULT);
 
88
 
 
89
    // generate solver
 
90
    ML_Gen_Solver(ml_handle, ML_MGV, 0, N_levels-1);
 
91
 
 
92
    // wrap ML_Operator into Epetra_Operator
 
93
    ML_Epetra::MultiLevelOperator  MLop(ml_handle,A.mat().Comm(),A.mat().DomainMap(),A.mat().RangeMap());
 
94
 
 
95
    // set this operator as preconditioner for AztecOO
 
96
    linear_solver.SetPrecOperator(&MLop);
 
97
 
 
98
    linear_solver.Iterate(1000,1E-9);
 
99
#else 
 
100
    error("EpetraKrylovSolver::solve not compiled with ML support."); 
 
101
#endif 
 
102
  } else { 
 
103
    error("EpetraKrylovSolver::solve only AMG preconditioner implemented."); 
 
104
  }
92
105
  return 0; 
93
106
}
94
107
//-----------------------------------------------------------------------------