// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ==  http://www.amdis-fem.org                                              ==
// ==                                                                        ==
// ============================================================================
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.



/** \file AdaptBase.h */

#ifndef AMDIS_ADAPTBASE_H
#define AMDIS_ADAPTBASE_H

#include <string>
#include "AMDiS_fwd.h"

namespace AMDiS {

  /// Interface for adaption loops.
  class AdaptBase
  {
  public:
    /// Constructor
    AdaptBase(std::string sname,
	      ProblemIterationInterface *problemIteration_,
	      AdaptInfo *adapt,
	      ProblemTimeInterface *problemTime_ = NULL,
	      AdaptInfo *initialAdaptInfo_ = NULL)
      : name(sname),
	problemIteration(problemIteration_),
	adaptInfo(adapt),
	problemTime(problemTime_),
	initialAdaptInfo(initialAdaptInfo_)
    {}

    /// Destructor
    virtual ~AdaptBase() {}

    /** \brief
     * Pure virtual method. Must be overloaded by sub classes to perform
     * a concrete adaption loop. 
     */
    virtual int adapt() = 0;

    /// Returns \ref name
    inline std::string getName() const 
    { 
      return name; 
    }

    /// Returns \ref problemIteration_
    inline ProblemIterationInterface *getProblemIteration() 
    {
      return problemIteration;
    }

    ///
    inline void setProblemIteration(ProblemIterationInterface *pii) 
    {
      problemIteration = pii;
    }

    /// Returns \ref adaptInfo
    inline AdaptInfo *getAdaptInfo() 
    { 
      return adaptInfo; 
    }

    /// Returns \ref problemTime_
    inline ProblemTimeInterface *getProblemTime() 
    {
      return problemTime;
    }

    ///
    inline void setProblemTime(ProblemTimeInterface *pti) 
    {
      problemTime = pti;
    }

    /// Returns \ref initialAdaptInfo_
    inline AdaptInfo *getInitialAdaptInfo() 
    { 
      return initialAdaptInfo; 
    }

  protected:
    /// Name of the adaption loop
    std::string name;

    /// Problem iteration interface
    ProblemIterationInterface *problemIteration;

    /// Main adapt info
    AdaptInfo *adaptInfo;

    /// problem time interface
    ProblemTimeInterface *problemTime;

    /** \brief
     * Adapt info for initial adapt. Will be given to 
     * problemTime_->solveInitialProblem().
     */
    AdaptInfo *initialAdaptInfo;

    /// Info level
    static int info;
  };

}

#endif