Memosa-FVM  0.2
AMG.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifndef _AMG_H_
6 #define _AMG_H_
7 
8 #include <vector>
9 #include <cmath>
10 #include "LinearSystem.h"
11 #include "LinearSolver.h"
12 
13 #include "MultiFieldReduction.h"
14 #include "LinearSystemMerger.h"
15 #include <iostream>
16 #include <fstream>
17 
18 class LinearSystemMerger;
19 
20 using namespace std;
21 
27 class AMG : public LinearSolver
28 {
29 public:
30 
31  enum CycleType
32  {
35  F_CYCLE
36  };
37 
39  {
41  JACOBI
42  };
43 
44  AMG();
45  virtual ~AMG();
46 
47  DEFINE_TYPENAME("AMG");
48 
49  virtual MFRPtr solve(LinearSystem & ls);
50  virtual void smooth(LinearSystem & ls);
51 
52 
53  virtual void setMergeLevelSize(int ls_size){
54 #ifdef FVM_PARALLEL
55  //_mergeLevelSize = ceil( double(ls_size) / double(MPI::COMM_WORLD.Get_size()) );
56  _mergeLevelSize = ls_size;
57  _isMerge = true;
58 #endif
59 
60 #ifndef FVM_PARALLEL
61  _mergeLevelSize = ls_size;
62  cout << " you can not set mergeLevelSize in serial version !!!!!!!!!!! " << endl;
63  abort();
64 #endif
65 }
66 
67  void redirectPrintToFile( const string& fname );
68  void redirectPrintToScreen( );
69  int getTotalIterations() const { return _totalIterations;}
70 
71  virtual void cleanup();
72 
73  // these parameters can be tuned.
82 private:
83 
84  AMG(const AMG&);
85 
87  vector<shared_ptr<LinearSystem> > _coarseLinearSystems;
88  shared_ptr<LinearSystemMerger> _mergeLS;
89 
90  void createCoarseLevels( );
91  void doSweeps( const int nSweeps, const int level );
92  void cycle( CycleType cycleType, const int level );
93  void flipComm();
94 
95  static int amg_indx;
96 
97  int _mergeLevelSize; //where
99  bool _isMerge;
101 
102 #ifdef FVM_PARALLEL
103  MPI::Intracomm _commTarget;
104 #endif
105 
106  streambuf *m_psbuf;
107  streambuf *m_backup;
108  ofstream m_filestr;
110 };
111 
112 #endif
int getTotalIterations() const
Definition: AMG.h:69
SmootherType
Definition: AMG.h:38
int _mergeLevelSize
Definition: AMG.h:97
CycleType
Definition: AMG.h:31
int nPostSweeps
Definition: AMG.h:76
int nPreSweeps
Definition: AMG.h:75
virtual void setMergeLevelSize(int ls_size)
Definition: AMG.h:53
streambuf * m_backup
Definition: AMG.h:107
vector< shared_ptr< LinearSystem > > _coarseLinearSystems
Definition: AMG.h:87
SmootherType smootherType
Definition: AMG.h:80
bool scaleCorrections
Definition: AMG.h:81
streambuf * m_psbuf
Definition: AMG.h:106
Definition: AMG.h:27
int _mergeLevel
Definition: AMG.h:98
ofstream m_filestr
Definition: AMG.h:108
int maxCoarseLevels
Definition: AMG.h:74
bool _isMerge
Definition: AMG.h:99
int _totalIterations
Definition: AMG.h:100
shared_ptr< LinearSystemMerger > _mergeLS
Definition: AMG.h:88
#define DEFINE_TYPENAME(T)
Definition: RLogInterface.h:46
bool _isCOMMWORLD
Definition: AMG.h:109
LinearSystem * _finestLinearSystem
Definition: AMG.h:86
static int amg_indx
Definition: AMG.h:95
shared_ptr< MultiFieldReduction > MFRPtr
CycleType cycleType
Definition: AMG.h:79
double weightRatioThreshold
Definition: AMG.h:78
int coarseGroupSize
Definition: AMG.h:77