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
00024
00028 template <class T>
00029 class MergeSolver : public BiCGStabSolver<LevelData<T> >
00030 {
00031 public:
00032
00033 MergeSolver();
00034
00035 virtual ~MergeSolver(){;}
00037
00040 virtual void setHomogeneous(bool a_homogeneous)
00041 {
00042 BiCGStabSolver<LevelData<T> >::setHomogeneous(a_homogeneous);
00043 }
00044
00045 virtual void define(LinearOp<LevelData<T> >* a_operator, bool a_homogeneous = false)
00046 {
00047 BiCGStabSolver<LevelData<T> >::define(a_operator, a_homogeneous);
00048 }
00049
00050 virtual void setConvergenceMetrics(Real a_metric, Real a_tolerance)
00051 {
00052 BiCGStabSolver<LevelData<T> >::setConvergenceMetrics(a_metric, a_tolerance);
00053 }
00054
00056 virtual void solve(LevelData<T>& a_phi, const LevelData<T>& a_rhs);
00057
00058 protected:
00059
00060 #ifdef CH_MPI
00061 MPI_Comm m_comm;
00062 #endif
00063 };
00064
00065
00066 template <class T>
00067 MergeSolver<T>::MergeSolver()
00068 {
00069 #ifdef CH_MPI
00070 MPI_Group proc0, cworld;
00071 int members[1] = {0};
00072 int err;
00073 err = MPI_Comm_group(Chombo_MPI::comm, &cworld);
00074 err = MPI_Group_incl(cworld , 1, members, &proc0);
00075 err = MPI_Comm_create(Chombo_MPI::comm, proc0, &m_comm);
00076 #endif
00077 }
00078
00079
00080 template <class T>
00081 void MergeSolver<T>::solve(LevelData<T>& a_phi, const LevelData<T>& a_rhs)
00082 {
00083 CH_TIME("MergeSolver::solve");
00084 DisjointBoxLayout dbl = a_phi.disjointBoxLayout();
00085 Box region;
00086 int numPts=0;
00087 for(LayoutIterator lit = dbl.layoutIterator(); lit.ok(); ++lit)
00088 {
00089 region.minBox(dbl[lit]);
00090 numPts+=dbl[lit].numPts();
00091 }
00092 if(region.numPts() == numPts)
00093 {
00094
00095 Vector<Box> newBoxes(1, region);
00096 Vector<int> newProc(1,0);
00097 DisjointBoxLayout newDBL(newBoxes, newProc, dbl.physDomain());
00098 LevelData<T> phi(newDBL, a_phi.nComp(), a_phi.ghostVect());
00099 LevelData<T> rhs(newDBL, a_rhs.nComp(), a_rhs.ghostVect());
00100 a_phi.copyTo(phi);
00101 a_rhs.copyTo(rhs);
00102 #ifdef CH_MPI
00103 MPI_Comm save=Chombo_MPI::comm;
00104 Chombo_MPI::comm = m_comm;
00105 #endif
00106 if(procID() == 0)
00107 BiCGStabSolver<LevelData<T> >::solve(phi, rhs);
00108 #ifdef CH_MPI
00109 Chombo_MPI::comm = save;
00110 #endif
00111 phi.copyTo(a_phi);
00112 }
00113 else{
00114 BiCGStabSolver<LevelData<T> >::solve(a_phi, a_rhs);
00115 }
00116 }
00117
00118
00119
00120 #include "NamespaceFooter.H"
00121 #endif