Chombo + EB + MF  3.2
MergeSolver.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 // BVS, June 18, 2003
12 
13 #ifndef _MERGESOLVER_H_
14 #define _MERGESOLVER_H_
15 
16 #include "LinearSolver.H"
17 #include "parstream.H"
18 #include "BiCGStabSolver.H"
19 #include "LevelData.H"
20 #include "SPMD.H"
21 #include "NamespaceHeader.H"
22 
23 ///
24 /**
25  Elliptic solver using the BiCGStab algorithm that turns the bottom solve into a single grid and solves on one processor if it can.
26  */
27 
28 template <class T>
29 class MergeSolver : public BiCGStabSolver<LevelData<T> >
30 {
31 public:
32 
33  MergeSolver();
34 
35  virtual ~MergeSolver()
36  {
37  }
38 
39  ///
40  /**
41  reset whether the solver is homogeneous.
42  */
43  virtual void setHomogeneous(bool a_homogeneous)
44  {
46  }
47 
48  virtual void define(LinearOp<LevelData<T> >* a_operator, bool a_homogeneous = false)
49  {
50  BiCGStabSolver<LevelData<T> >::define(a_operator, a_homogeneous);
51  }
52 
53  virtual void setConvergenceMetrics(Real a_metric, Real a_tolerance)
54  {
56  }
57 
58  /// only overridden virtual function
59  virtual void solve(LevelData<T>& a_phi, const LevelData<T>& a_rhs);
60 
61 protected:
62 
63 #ifdef CH_MPI
64  MPI_Comm m_comm;
65 #endif
66 };
67 
68 template <class T>
70 {
71 #ifdef CH_MPI
72  MPI_Group proc0, cworld;
73  int members[1] =
74  {
75  0
76  };
77  int err;
78  err = MPI_Comm_group(Chombo_MPI::comm, &cworld);
79  err = MPI_Group_incl(cworld , 1, members, &proc0);
80  err = MPI_Comm_create(Chombo_MPI::comm, proc0, &m_comm);
81 #endif
82 }
83 
84 template <class T>
86 {
87  CH_TIME("MergeSolver::solve");
89  Box region;
90  int numPts=0;
91  for (LayoutIterator lit = dbl.layoutIterator(); lit.ok(); ++lit)
92  {
93  region.minBox(dbl[lit]);
94  numPts+=dbl[lit].numPts();
95  }
96  if (region.numPts() == numPts)
97  {
98  // bottomsolve can be done in just one box without any exchanges.
99  Vector<Box> newBoxes(1, region);
100  Vector<int> newProc(1,0);
101  DisjointBoxLayout newDBL(newBoxes, newProc, dbl.physDomain());
102  LevelData<T> phi(newDBL, a_phi.nComp(), a_phi.ghostVect());
103  LevelData<T> rhs(newDBL, a_rhs.nComp(), a_rhs.ghostVect());
104  a_phi.copyTo(phi);
105  a_rhs.copyTo(rhs);
106 #ifdef CH_MPI
107  MPI_Comm save=Chombo_MPI::comm;
108  Chombo_MPI::comm = m_comm;
109 #endif
110  if (procID() == 0)
111  BiCGStabSolver<LevelData<T> >::solve(phi, rhs);
112 #ifdef CH_MPI
113  Chombo_MPI::comm = save;
114 #endif
115  phi.copyTo(a_phi);
116  }
117  else
118  {
119  BiCGStabSolver<LevelData<T> >::solve(a_phi, a_rhs);
120  }
121 }
122 
123 #include "NamespaceFooter.H"
124 
125 #endif /*_MERGESOLVER_H_*/
Definition: LinearSolver.H:28
virtual void setHomogeneous(bool a_homogeneous)
Definition: MergeSolver.H:43
int nComp() const
Definition: BoxLayoutData.H:306
Definition: MergeSolver.H:29
LayoutIterator layoutIterator() const
Iterator that processes through ALL the boxes in a BoxLayout.
const ProblemDomain & physDomain() const
An Iterator based on a BoxLayout object.
Definition: LayoutIterator.H:35
virtual void define(LinearOp< LevelData< T > > *a_operator, bool a_homogeneous=false)
Definition: MergeSolver.H:48
MergeSolver()
Definition: MergeSolver.H:69
virtual void copyTo(const Interval &srcComps, BoxLayoutData< T > &dest, const Interval &destComps) const
Definition: LevelDataI.H:198
#define CH_TIME(name)
Definition: CH_Timer.H:82
new code
Definition: BoxLayoutData.H:170
double Real
Definition: REAL.H:33
virtual void solve(LevelData< T > &a_phi, const LevelData< T > &a_rhs)
only overridden virtual function
Definition: MergeSolver.H:85
const DisjointBoxLayout & disjointBoxLayout() const
Definition: LevelData.H:209
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:30
virtual void setConvergenceMetrics(Real a_metric, Real a_tolerance)
Set a convergence metric, along with solver tolerance, if desired.
Definition: MergeSolver.H:53
Box & minBox(const Box &b)
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
size_t numPts() const
virtual ~MergeSolver()
Definition: MergeSolver.H:35
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:117
int procID()
local process ID
Definition: BiCGStabSolver.H:26
const IntVect & ghostVect() const
Definition: LevelData.H:170