00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011
00012
00013 #ifndef _MERGESOLVER_H_
00014 #define _MERGESOLVER_H_
00015
00016 #include "LinearSolver.H"
00017 #include "parstream.H"
00018 #include "BiCGStabSolver.H"
00019 #include "LevelData.H"
00020 #include "SPMD.H"
00021 #include "NamespaceHeader.H"
00022
00023
00024
00025
00026
00027
00028 template <class T>
00029 class MergeSolver : public BiCGStabSolver<LevelData<T> >
00030 {
00031 public:
00032
00033 MergeSolver();
00034
00035 virtual ~MergeSolver()
00036 {
00037 }
00038
00039
00040
00041
00042
00043 virtual void setHomogeneous(bool a_homogeneous)
00044 {
00045 BiCGStabSolver<LevelData<T> >::setHomogeneous(a_homogeneous);
00046 }
00047
00048 virtual void define(LinearOp<LevelData<T> >* a_operator, bool a_homogeneous = false)
00049 {
00050 BiCGStabSolver<LevelData<T> >::define(a_operator, a_homogeneous);
00051 }
00052
00053 virtual void setConvergenceMetrics(Real a_metric, Real a_tolerance)
00054 {
00055 BiCGStabSolver<LevelData<T> >::setConvergenceMetrics(a_metric, a_tolerance);
00056 }
00057
00058
00059 virtual void solve(LevelData<T>& a_phi, const LevelData<T>& a_rhs);
00060
00061 protected:
00062
00063 #ifdef CH_MPI
00064 MPI_Comm m_comm;
00065 #endif
00066 };
00067
00068 template <class T>
00069 MergeSolver<T>::MergeSolver()
00070 {
00071 #ifdef CH_MPI
00072 MPI_Group proc0, cworld;
00073 int members[1] =
00074 {
00075 0
00076 };
00077 int err;
00078 err = MPI_Comm_group(Chombo_MPI::comm, &cworld);
00079 err = MPI_Group_incl(cworld , 1, members, &proc0);
00080 err = MPI_Comm_create(Chombo_MPI::comm, proc0, &m_comm);
00081 #endif
00082 }
00083
00084 template <class T>
00085 void MergeSolver<T>::solve(LevelData<T>& a_phi, const LevelData<T>& a_rhs)
00086 {
00087 CH_TIME("MergeSolver::solve");
00088 DisjointBoxLayout dbl = a_phi.disjointBoxLayout();
00089 Box region;
00090 int numPts=0;
00091 for (LayoutIterator lit = dbl.layoutIterator(); lit.ok(); ++lit)
00092 {
00093 region.minBox(dbl[lit]);
00094 numPts+=dbl[lit].numPts();
00095 }
00096 if (region.numPts() == numPts)
00097 {
00098
00099 Vector<Box> newBoxes(1, region);
00100 Vector<int> newProc(1,0);
00101 DisjointBoxLayout newDBL(newBoxes, newProc, dbl.physDomain());
00102 LevelData<T> phi(newDBL, a_phi.nComp(), a_phi.ghostVect());
00103 LevelData<T> rhs(newDBL, a_rhs.nComp(), a_rhs.ghostVect());
00104 a_phi.copyTo(phi);
00105 a_rhs.copyTo(rhs);
00106 #ifdef CH_MPI
00107 MPI_Comm save=Chombo_MPI::comm;
00108 Chombo_MPI::comm = m_comm;
00109 #endif
00110 if (procID() == 0)
00111 BiCGStabSolver<LevelData<T> >::solve(phi, rhs);
00112 #ifdef CH_MPI
00113 Chombo_MPI::comm = save;
00114 #endif
00115 phi.copyTo(a_phi);
00116 }
00117 else
00118 {
00119 BiCGStabSolver<LevelData<T> >::solve(a_phi, a_rhs);
00120 }
00121 }
00122
00123 #include "NamespaceFooter.H"
00124
00125 #endif