/* $Id: adapt.h,v 1.2 1996/10/04 15:06:20 roitzsch Exp $ */

#ifndef ADAPT_H
#define ADAPT_H

#include "general.h"
#include "kvector.h"

class PATCH;
class MESH;
class Problem;
class Element;
class Interface;
class ErrorEstimator;

//-------------------------------------------------------------------------


class ErrorEstimator
{

  public:

    ErrorEstimator();
    virtual ~ErrorEstimator();

    virtual void adapt(Problem& problem, Real* error, Real reqGlobalPrecision, 
		       Real* linENorm=0);

  protected:

    Vector<Real>*  elementError;

    Real 	EnergyError;
    Real 	L2Error;
    Real	LinENorm;
    int 	infoErrorEstimator, timeErrorEstimator, accTime;

    Real	minRefinementRatio;

    enum refStrategyType   { maxValue, extrapolation, uniform, random };
    refStrategyType 	   refStrategy;


    virtual Bool estimateError(Problem& problem); 
    virtual void setRefinementFlags(MESH& mesh, Real reqGlobalPrec, 
				    int* markedElems); 
    virtual Bool DoRefine(int /*node*/) { return False; }  // dummy, used in adaptnl


    // --		refinement strategies:

    virtual void MaxValue	   (MESH& mesh, Real reqGlobalPrec, 
				    int* markedElems);
    virtual void ExtrapolRefinement(MESH& mesh, Real reqGlobalPrec, 
				    int* markedElems);
    virtual void UniformRefinement (MESH& mesh, Real reqGlobalPrec, 
				    int* markedElems);
    virtual void RandomRefinement  (MESH& mesh, Real reqGlobalPrec, 
				    int* markedElems);
};
//-------------------------------------------------------------------------


class DLY : public ErrorEstimator
{
  public:

    DLY(Element* elementDLY, Interface* interfaceDLY);
    ~DLY();
    virtual Bool estimateError(Problem& problem);

  protected:

    Element* 	elementDLY;
    Interface*	interfaceDLY;

    Bool solveQuadDefectProblem(Problem& problem, Vector<Num>& b);
    void distributeEdgeErrors(Problem& problem, Vector<Num>& error);
};
//-------------------------------------------------------------------------

class EFDLY : public DLY
{
  public:

    EFDLY(Element* elementDLY, Interface* interfaceDLY);
    virtual Bool estimateError(Problem& problem);
};
//-------------------------------------------------------------------------

class ResidualError : public ErrorEstimator
{
  public:
    
    ResidualError();
    virtual Bool estimateError(Problem& problem);
};
//-------------------------------------------------------------------------

class QuadStdTriangleError : public ErrorEstimator
{
  public:
    
    QuadStdTriangleError();
    virtual Bool estimateError(Problem& problem);
};

#endif
