Memosa-FVM  0.2
JacobiSolver.cpp
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 #ifdef FVM_PARALLEL
6 #include <mpi.h>
7 #endif
8 
9 #include "JacobiSolver.h"
10 #include "LinearSystemMerger.h"
11 #include "CRConnectivity.h"
12 #include <set>
13 
14 
16 {
17  logCtor();
18 
19 }
20 
22 {
23  logDtor();
24 }
25 
26 void
27 JacobiSolver::doSweeps(LinearSystem& ls, const int nSweeps)
28 {
29  const MultiFieldMatrix& m = ls.getMatrix();
30  MultiField& delta = ls.getDelta();
31  const MultiField& b = ls.getB();
32  MultiField& r = ls.getResidual();
33 
34  for(int i=0; i<nSweeps; i++)
35  {
36  m.Jacobi(delta,b,r);
37  }
38 }
39 
40 
41 void
43 {
44 }
45 
46 MFRPtr
48 {
50  ls.getB(),
51  ls.getResidual());
52  MFRPtr rNorm0(ls.getResidual().getOneNorm());
53 
54 #ifdef FVM_PARALLEL
55  if (verbosity >0 && MPI::COMM_WORLD.Get_rank() == 0 )
56  cout << "0: " << *rNorm0 << endl;
57 #endif
58 
59 #ifndef FVM_PARALLEL
60  if ( verbosity > 0 )
61  cout << "0: " << *rNorm0 << endl;
62 #endif
63 
64  if (*rNorm0 < absoluteTolerance )
65  return rNorm0;
66 
67  for(int i=1; i<nMaxIterations; i++)
68  {
69  doSweeps(ls,1);
70 
72  ls.getB(),
73  ls.getResidual());
74  MFRPtr rNorm(ls.getResidual().getOneNorm());
75  MFRPtr normRatio((*rNorm)/(*rNorm0));
76 
77 #ifndef FVM_PARALLEL
78  if (verbosity >0 )
79  cout << i << ": " << *rNorm << endl;
80 #endif
81 
82 
83 #ifdef FVM_PARALLEL
84  if (*rNorm < absoluteTolerance || *normRatio < relativeTolerance || i == nMaxIterations-1)
85  if (verbosity >0 && MPI::COMM_WORLD.Get_rank() == 0 )
86  cout <<i << ": " << *rNorm << endl;
87 #endif
88 
89  if (*rNorm < absoluteTolerance || *normRatio < relativeTolerance)
90  break;
91 
92  }
93  return rNorm0;
94 }
95 
96 
97 void
99 {
100  doSweeps(ls,2);
101 }
void doSweeps(LinearSystem &ls, const int nSweeps)
MultiField & getResidual()
Definition: LinearSystem.h:35
#define logCtor()
Definition: RLogInterface.h:26
MultiField & getDelta()
Definition: LinearSystem.h:34
virtual void cleanup()
int nMaxIterations
Definition: LinearSolver.h:31
shared_ptr< MultiFieldReduction > getOneNorm() const
Definition: MultiField.cpp:216
double relativeTolerance
Definition: LinearSolver.h:33
virtual void computeResidual(const IContainer &xB, const IContainer &bB, IContainer &rB) const
virtual void Jacobi(IContainer &xB, const IContainer &bB, IContainer &tempB) const
#define logDtor()
Definition: RLogInterface.h:33
virtual void smooth(LinearSystem &ls)
double absoluteTolerance
Definition: LinearSolver.h:34
MultiField & getB()
Definition: LinearSystem.h:33
shared_ptr< MultiFieldReduction > MFRPtr
virtual ~JacobiSolver()
virtual MFRPtr solve(LinearSystem &ls)
MultiFieldMatrix & getMatrix()
Definition: LinearSystem.h:37