// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file parareal/AdaptInfo.h */

#ifndef AMDIS_PARAREAL_ADAPTINFO_H
#define AMDIS_PARAREAL_ADAPTINFO_H

#include "AdaptInstationary.h"
#include "parareal/ProblemBase.h"

namespace AMDiS {

  class AdaptParaReal : public AdaptInstationary
  {
  public:
    AdaptParaReal(const char *name, 
		  ProblemIterationInterface *problemStat,
		  AdaptInfo *info,
		  ProblemTimeInterface *problemInstat,
		  ParaRealProblemBase< DOFVector<double> > *paraProb,
		  AdaptInfo *initialInfo,
		  time_t initialTimestamp = 0)
      : AdaptInstationary(name, problemStat, info, problemInstat, initialInfo, initialTimestamp),
	coarseTimestep(0.0),
	fineTimestep(0.0),
	pararealIter(1),
	pararealProb(paraProb)
    {
      GET_PARAMETER(0, static_cast<std::string>(name) + "->coarse timestep", "%f", &coarseTimestep);
      GET_PARAMETER(0, static_cast<std::string>(name) + "->timestep", "%f", &fineTimestep);
      GET_PARAMETER(0, static_cast<std::string>(name) + "->parareal iteration", "%d", &pararealIter);
      
      TEST_EXIT(fineTimestep > 0.0)("fineTimestep must be greater than zero!\n");
      TEST_EXIT(coarseTimestep > 0.0)("coarseTimestep must be greater than zero!\n");
      TEST_EXIT(fineTimestep < coarseTimestep)("fineTimestep must be smaller than coarseTimestep!\n");
      TEST_EXIT(pararealIter >= 0)("ParaReal Iterations must be >= 0!\n");
    }

    /** \brief
     * Here, the parareal algorithm is executed.
     */
    virtual int adapt();

  protected:
    /** \brief
     * Timestep for the coarse time grid.
     */
    double coarseTimestep;
    
    /** \brief
     * Timestep for the fine time grid.
     */
    double fineTimestep;
    
    /** \brief
     * Number of parareal iterations.
     */
    int pararealIter;
    
    /** \brief
     * Pointer to the parareal problem.
     */
    ParaRealProblemBase< DOFVector<double> > *pararealProb;
  };

}

#endif // AMDIS_PARAREAL_ADAPTINFO