Skip to content
Snippets Groups Projects
AdaptInstationary.h 5.92 KiB
Newer Older
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ==                                                                        ==
// ============================================================================
//
// 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 AdaptInstationary.h */

#ifndef AMDIS_ADAPTINSTATIONARY_H
#define AMDIS_ADAPTINSTATIONARY_H

#include <string>
#include <ctime>
#include <queue>
#include "Flag.h"
#include "AdaptInfo.h"
#include "AdaptBase.h"
  /** \ingroup Adaption  
   * \brief
   * AdaptInstationary implements the adaptive procdure for time dependent 
   * problems (see ProblemInstat). It contains a pointer to a ProblemInstat
   * object.
   */
  class AdaptInstationary : public AdaptBase
  {
  public:
    /** \brief
     * Creates a AdaptInstationary object with the given name for the time 
     * dependent problem problemInstat. TODO: Make obsolete!
    AdaptInstationary(string name, 
		      ProblemIterationInterface *problemStat,
		      AdaptInfo *info,
		      ProblemTimeInterface *problemInstat,
		      AdaptInfo *initialInfo,
    /** \brief
     * Creates a AdaptInstationary object with the given name for the time 
     * dependent problem problemInstat.
     */
    AdaptInstationary(string name, 
		      ProblemIterationInterface &problemStat,
		      AdaptInfo &info,
		      ProblemTimeInterface &problemInstat,
		      AdaptInfo &initialInfo,

    /** \brief
     * This funciton is used only to avoid double code in both constructors. If the
     * obsolte constructure, which uses pointers instead of references, will be
     * removed, remove also this function.
     * TODO: Remove if obsolete constructor will be removed.
     */
    void initConstructor(ProblemIterationInterface *problemStat,  
			 AdaptInfo *info,
			 AdaptInfo *initialInfo,
Thomas Witkowski's avatar
Thomas Witkowski committed
    /// Destructor
    virtual ~AdaptInstationary() {}
Thomas Witkowski's avatar
Thomas Witkowski committed
    /// Sets \ref strategy to aStrategy
Thomas Witkowski's avatar
Thomas Witkowski committed
    inline void setStrategy(int aStrategy) 
    { 
      strategy = aStrategy; 
Thomas Witkowski's avatar
Thomas Witkowski committed
    /// Returns \ref strategy
Thomas Witkowski's avatar
Thomas Witkowski committed
    const int getStrategy() const 
    {
      return strategy;
Thomas Witkowski's avatar
Thomas Witkowski committed
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
    /// Implementation of AdaptBase::adapt()
    virtual int adapt();

Thomas Witkowski's avatar
Thomas Witkowski committed
    /// Serialization
    virtual void serialize(ostream &out);
Thomas Witkowski's avatar
Thomas Witkowski committed
    /// deserialization
    virtual void deserialize(istream &in);


  protected:
    /** \brief
     * Implements one (maybe adaptive) timestep. Both the explicit and the 
     * implicit time strategy are implemented. The semi-implicit strategy 
     * is only a special case of the implicit strategy with a limited number of 
     * iterations (exactly one).
     * The routine uses the parameter \ref strategy to select the strategy:
     * strategy 0: Explicit strategy, 
     * strategy 1: Implicit strategy.
     */
    virtual void oneTimestep();

Thomas Witkowski's avatar
Thomas Witkowski committed
    /// Initialisation of this AdaptInstationary object
    void initialize(string aName);
Thomas Witkowski's avatar
Thomas Witkowski committed
    /// Implements the explit time strategy. Used by \ref oneTimestep().
    virtual void explicitTimeStrategy();

Thomas Witkowski's avatar
Thomas Witkowski committed
    /// Implements the implicit time strategy. Used by \ref oneTimestep().
    virtual void implicitTimeStrategy();

Thomas Witkowski's avatar
Thomas Witkowski committed
    /** \brief
     * This iteration strategy allows the timestep and the mesh to be adapted 
     * after each timestep solution. There are no inner loops for mesh adaption and
     * no refused timesteps.
     */
    void simpleAdaptiveTimeStrategy();

    /** \brief
     * Checks whether the runtime of the queue (of the servers batch system) requires
     * to stop the calculation and to reschedule the problem to the batch system.
     *
     * The function return true, if there will be a timeout in the near future, and
     * therefore the problem should be rescheduled. Otherwise, the return value is
     * false.
     */
    bool checkQueueRuntime();

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
    /// Strategy for choosing one timestep
Thomas Witkowski's avatar
Thomas Witkowski committed
    /// Parameter \f$ \delta_1 \f$ used in time step reduction
Thomas Witkowski's avatar
Thomas Witkowski committed
    double timeDelta1;
Thomas Witkowski's avatar
Thomas Witkowski committed
    /// Parameter \f$ \delta_2 \f$ used in time step enlargement
Thomas Witkowski's avatar
Thomas Witkowski committed
    double timeDelta2;

    /** \brief
     * If this parameter is 1 and the instationary problem is stable, hence the number
     * of solver iterations to solve the problem is zero, the adaption loop will stop.
     */
    int breakWhenStable;
Thomas Witkowski's avatar
Thomas Witkowski committed
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
    bool fixedTimestep;

    /** \brief
     * Runtime of the queue (of the servers batch system) in seconds. If the problem
     * runs on a computer/server without a time limited queue, the value is -1.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
    int queueRuntime;
Thomas Witkowski's avatar
Thomas Witkowski committed
    /// Name of the file used to automatically serialize the problem.
    string queueSerializationFilename;
Thomas Witkowski's avatar
Thomas Witkowski committed
     * Timestamp at the beginning of all calculations. It is used to calculate the 
     * overall runtime of the problem.
Thomas Witkowski's avatar
Thomas Witkowski committed
    time_t initialTimestamp;
Thomas Witkowski's avatar
Thomas Witkowski committed
     * Timestamp at the beginning of the last timestep iteration. Is is used to 
     * calculate the runtime of the last timestep.
Thomas Witkowski's avatar
Thomas Witkowski committed
    time_t iterationTimestamp;
Thomas Witkowski's avatar
Thomas Witkowski committed
    /// Stores the runtime (in seconds) of some last timestep iterations.
    queue<int> lastIterationsDuration;
Thomas Witkowski's avatar
Thomas Witkowski committed
     * In debug mode, the adapt loop will print information about timestep decreasing 
     * and increasing.
  };

}

#endif // AMDIS_ADAPTINSTATIONARY_H