Chombo + EB  3.0
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 
69 template <class T>
71 {
72 #ifdef CH_MPI
73  MPI_Group proc0, cworld;
74  int members[1] =
75  {
76  0
77  };
78  int err;
79  err = MPI_Comm_group(Chombo_MPI::comm, &cworld);
80  err = MPI_Group_incl(cworld , 1, members, &proc0);
81  err = MPI_Comm_create(Chombo_MPI::comm, proc0, &m_comm);
82 #endif
83 }
84 
85 
86 template <class T>
88 {
89  CH_TIME("MergeSolver::solve");
91  Box region;
92  int numPts=0;
93  for (LayoutIterator lit = dbl.layoutIterator(); lit.ok(); ++lit)
94  {
95  region.minBox(dbl[lit]);
96  numPts+=dbl[lit].numPts();
97  }
98  if (region.numPts() == numPts)
99  {
100  // bottomsolve can be done in just one box without any exchanges.
101  Vector<Box> newBoxes(1, region);
102  Vector<int> newProc(1,0);
103  DisjointBoxLayout newDBL(newBoxes, newProc, dbl.physDomain());
104  LevelData<T> phi(newDBL, a_phi.nComp(), a_phi.ghostVect());
105  LevelData<T> rhs(newDBL, a_rhs.nComp(), a_rhs.ghostVect());
106  a_phi.copyTo(phi);
107  a_rhs.copyTo(rhs);
108 #ifdef CH_MPI
109  MPI_Comm save=Chombo_MPI::comm;
110  Chombo_MPI::comm = m_comm;
111 #endif
112  if (procID() == 0)
113  BiCGStabSolver<LevelData<T> >::solve(phi, rhs);
114 #ifdef CH_MPI
115  Chombo_MPI::comm = save;
116 #endif
117  phi.copyTo(a_phi);
118  }
119  else
120  {
121  BiCGStabSolver<LevelData<T> >::solve(a_phi, a_rhs);
122  }
123 }
124 
125 
126 
127 #include "NamespaceFooter.H"
128 #endif /*_MERGESOLVER_H_*/
Definition: LinearSolver.H:28
virtual void setHomogeneous(bool a_homogeneous)
Definition: MergeSolver.H:43
int nComp() const
Definition: BoxLayoutData.H:258
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:38
virtual void define(LinearOp< LevelData< T > > *a_operator, bool a_homogeneous=false)
Definition: MergeSolver.H:48
MergeSolver()
Definition: MergeSolver.H:70
virtual void copyTo(const Interval &srcComps, BoxLayoutData< T > &dest, const Interval &destComps) const
Definition: LevelDataI.H:164
#define CH_TIME(name)
Definition: CH_Timer.H:59
Definition: BoxLayoutData.H:136
double Real
Definition: REAL.H:33
long numPts() const
virtual void solve(LevelData< T > &a_phi, const LevelData< T > &a_rhs)
only overridden virtual function
Definition: MergeSolver.H:87
const DisjointBoxLayout & disjointBoxLayout() const
Definition: LevelData.H:196
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:31
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:465
virtual ~MergeSolver()
Definition: MergeSolver.H:35
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:110
int procID()
local process ID
Definition: BiCGStabSolver.H:26
const IntVect & ghostVect() const
Definition: LevelData.H:157