00001
00002
00003
00004
00005
00006 #ifndef AMROC_COUPLED_GFMSOLVER_H
00007 #define AMROC_COUPLED_GFMSOLVER_H
00008
00016 #include "AMRGFMSolver.h"
00017
00024 template <class VectorType, class FixupType, class FlagType, int dim>
00025 class AMRCoupledGFMSolver : public AMRGFMSolver<VectorType,FixupType,FlagType,dim> {
00026 typedef typename VectorType::InternalDataType DataType;
00027 typedef AMRGFMSolver<VectorType,FixupType,FlagType,dim> base;
00028
00029 public:
00030 typedef typename base::integrator_type integrator_type;
00031 typedef typename base::initial_condition_type initial_condition_type;
00032 typedef typename base::boundary_conditions_type boundary_conditions_type;
00033 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00034
00035 AMRCoupledGFMSolver(integrator_type& integ,
00036 initial_condition_type& init,
00037 boundary_conditions_type& bc) : base(integ, init, bc),
00038 CouplingLevel(0), CouplingStrategy(0),
00039 _SubSteps(1) {}
00040 virtual ~AMRCoupledGFMSolver() {}
00041
00042
00043
00044
00045 virtual void SendBoundaryData() = 0;
00046 virtual void PostReceiveBoundaryData(bool FullDomain=false) = 0;
00047 virtual void WaitReceiveBoundaryData() = 0;
00048
00049
00050 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00051 base::register_at(Ctrl,prefix);
00052 RegisterAt(base::LocCtrl,"CouplingLevel",CouplingLevel);
00053 RegisterAt(base::LocCtrl,"CouplingStrategy",CouplingStrategy);
00054 }
00055 virtual void register_at(ControlDevice& Ctrl) {
00056 base::register_at(Ctrl);
00057 }
00058
00059 virtual bool setup() {
00060 bool ret = base::setup();
00061 if (CouplingLevel>base::MaxLev-1)
00062 CouplingLevel=base::MaxLev-1;
00063 _SubSteps = 1;
00064 for (register int n=0; n<CouplingLevel; n++)
00065 _SubSteps *= base::_RefineFactor[n];
00066 return ret;
00067 }
00068
00069 virtual void SetupData() {
00070 base::SetupData();
00071 #ifdef DEBUG_PRINT_AMRSOLVER
00072 ( comm_service::log() << "*** base::SetupData() finished.\n" ).flush();
00073 #endif
00074 }
00075
00076 virtual void Initialize(double& t, double &dt) {
00077 #ifdef DEBUG_PRINT_AMRSOLVER
00078 ( comm_service::log() << "*** AMRCoupledGFMSolver::Initialize().\n" ).flush();
00079 #endif
00080 if (CouplingLevel>=0) {
00081 PostReceiveBoundaryData(true);
00082 #ifdef DEBUG_PRINT_AMRSOLVER
00083 ( comm_service::log() << "*** PostReceiveBoundaryData() done.\n" ).flush();
00084 #endif
00085 WaitReceiveBoundaryData();
00086 #ifdef DEBUG_PRINT_AMRSOLVER
00087 ( comm_service::log() << "*** WaitReceiveBoundaryData() done.\n" ).flush();
00088 #endif
00089 }
00090 base::Initialize(t,dt);
00091 #ifdef DEBUG_PRINT_AMRSOLVER
00092 ( comm_service::log() << "*** base::Initialize() finished.\n" ).flush();
00093 #endif
00094 if (CouplingLevel>=0)
00095 SendBoundaryData();
00096 }
00097
00098 virtual void Restart(double& t, double& dt) {
00099 #ifdef DEBUG_PRINT_AMRSOLVER
00100 ( comm_service::log() << "*** AMRCoupledGFMSolver::Restart().\n" ).flush();
00101 #endif
00102 if (CouplingLevel>=0) {
00103 PostReceiveBoundaryData(true);
00104 #ifdef DEBUG_PRINT_AMRSOLVER
00105 ( comm_service::log() << "*** PostReceiveBoundaryData() done.\n" ).flush();
00106 #endif
00107 WaitReceiveBoundaryData();
00108 #ifdef DEBUG_PRINT_AMRSOLVER
00109 ( comm_service::log() << "*** WaitReceiveBoundaryData() done.\n" ).flush();
00110 #endif
00111 }
00112 base::Restart(t,dt);
00113 #ifdef DEBUG_PRINT_AMRSOLVER
00114 ( comm_service::log() << "*** base::Restart() finished.\n" ).flush();
00115 #endif
00116 if (CouplingLevel>=0)
00117 SendBoundaryData();
00118 }
00119
00120 virtual void Advance(double& t, double &dt) {
00121 #ifdef DEBUG_PRINT_AMRSOLVER
00122 ( comm_service::log() << "*** AMRCoupledGFMSolver::Advance().\n" ).flush();
00123 #endif
00124 if (CouplingLevel>=0) {
00125 PostReceiveBoundaryData(true);
00126 #ifdef DEBUG_PRINT_AMRSOLVER
00127 ( comm_service::log() << "*** PostReceiveBoundaryData() done.\n" ).flush();
00128 #endif
00129 WaitReceiveBoundaryData();
00130 #ifdef DEBUG_PRINT_AMRSOLVER
00131 ( comm_service::log() << "*** WaitReceiveBoundaryData() done.\n" ).flush();
00132 #endif
00133 }
00134 base::Advance(t,dt);
00135 #ifdef DEBUG_PRINT_AMRSOLVER
00136 ( comm_service::log() << "*** base::Advance() finished.\n" ).flush();
00137 #endif
00138 }
00139
00140 virtual void BeforeLevelStep(const int Level) {
00141 if (Level!=CouplingLevel) return;
00142 if (CouplingStrategy>0) {
00143 SendBoundaryData();
00144 if (CouplingLevel>0 && CurrentTime(base::GH(),Level)+TimeStep(base::U(),Level)<
00145 CurrentTime(base::GH(),0)+TimeStep(base::U(),0)) {
00146 if (base::RedistributeEvery>0)
00147 PostReceiveBoundaryData(false);
00148 else
00149 PostReceiveBoundaryData(true);
00150 #ifdef DEBUG_PRINT_AMRSOLVER
00151 ( comm_service::log() << "*** PostReceiveBoundaryData() on level "
00152 << Level << " done.\n" ).flush();
00153 #endif
00154 }
00155 }
00156 }
00157
00158 virtual void AfterLevelStep(const int Level) {
00159 if (Level!=CouplingLevel) return;
00160 if (CouplingStrategy<=0) SendBoundaryData();
00161 if (CouplingLevel>0 && CurrentTime(base::GH(),Level)<
00162 CurrentTime(base::GH(),0)+TimeStep(base::U(),0)) {
00163 if (CouplingStrategy<=0) {
00164 if (base::RedistributeEvery>0)
00165 PostReceiveBoundaryData(false);
00166 else
00167 PostReceiveBoundaryData(true);
00168 #ifdef DEBUG_PRINT_AMRSOLVER
00169 ( comm_service::log() << "*** PostReceiveBoundaryData() on level "
00170 << Level << " done.\n" ).flush();
00171 #endif
00172 }
00173 WaitReceiveBoundaryData();
00174 #ifdef DEBUG_PRINT_AMRSOLVER
00175 ( comm_service::log() << "*** WaitReceiveBoundaryData() on level "
00176 << Level << " done.\n" ).flush();
00177 #endif
00178 }
00179 }
00180
00181 const int& SubSteps() const { return _SubSteps; }
00182
00183 protected:
00184 int CouplingLevel, CouplingStrategy, _SubSteps;
00185 };
00186
00187
00188 #endif