Skip to content
Snippets Groups Projects
Error.h 5.5 KiB
Newer Older
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file Error.h */

#ifndef AMDIS_ERROR_H
#define AMDIS_ERROR_H

#include "Global.h"
#include "Mesh.h"
#include "MemoryManager.h"

namespace AMDiS {

  class FastQuadrature;

  template<typename T> class DOFVector;

  // ============================================================================
  // ===== class Error ==========================================================
  // ============================================================================

  /** \ingroup Common
   * \brief
   * True error calculator
   */
  template<typename T>
  class Error
  {
  public:  
    MEMORY_MANAGED(Error<T>);

    static void setWriteLeafData() { 
      writeInLeafData = true; 
    };
    
    static void unsetWriteLeafData() { 
      writeInLeafData = false; 
    };
    
    static bool writeLeafData() { 
      return writeInLeafData; 
    };
  
    static double maxErrAtQp(const AbstractFunction<T, WorldVector<double> >& u,
			     const DOFVector<T>& uh,
			     const Quadrature* q);

    static double H1Err(const AbstractFunction<WorldVector<T>, WorldVector<double> >& grdU,
			const DOFVector<T>& uh,
			int relErr,
			double* max,
			bool writeLeafData = false,
			int comp = 0);

    static double L2Err(const AbstractFunction<T, WorldVector<double> >& u,
			const DOFVector<T>& uh,
			int relErr,
			double* max,
			bool writeLeafData = false,
			int comp = 0);

    // methods for traversal
    static int maxErrAtQpFct(ElInfo* elinfo);
    static int H1ErrFct(ElInfo* elinfo);
    static int L2ErrFct(ElInfo* elinfo);
    static int relFct(ElInfo* elinfo);
  
  public:
    static T errUFct(const DimVec<double>& lambda);
    static WorldVector<T> grdErrUFct(const DimVec<double>& lambda);

    /** \brief
     * 
     */
    class AbstrFctErrU  : public AbstractFunction<T, DimVec<double> >
    { 
    public:
      AbstrFctErrU() : AbstractFunction<T, DimVec<double> >(0) {};

      inline T operator()(const DimVec<double> & x) const { 
	return Error<T>::errUFct(x);
    static AbstrFctErrU errU;

    /** \brief
     * 
     */
    class AbstrFctGrdErrU  : public AbstractFunction<WorldVector<T>, DimVec<double> >
    { 
    public:
      AbstrFctGrdErrU() : AbstractFunction<WorldVector<T>, DimVec<double> >(0) {};

      inline WorldVector<T> operator()(const DimVec<double> & x) const { 
	return Error<T>::grdErrUFct(x);
      };
    };

    static AbstrFctGrdErrU   grdErrU;

  private:
    static ElInfo* elinfo;
    /*   static const Parametric* el_parametric; */
    static const FastQuadrature* quadFast;
    static const AbstractFunction<T, WorldVector<double> >* pU;
    static const AbstractFunction<WorldVector<T>, WorldVector<double> >* pGrdU;
    static const BasisFunction* basFct;
    static const DOFVector<T>* errUh;
    static double maxErr;
    static double l2Err2;
    static double l2Norm2;
    static int relative;
    static double relNorm2;
    static double h1Err2;
    static double h1Norm2;
    static bool writeInLeafData;
    static int component;
  };

  template<typename T> ElInfo* Error<T>::elinfo = NULL;
  template<typename T> const FastQuadrature* Error<T>::quadFast = NULL;
  template<typename T> const AbstractFunction<T, WorldVector<double> >* Error<T>::pU = NULL;
  template<typename T> const AbstractFunction<WorldVector<T>, WorldVector<double> >* Error<T>::pGrdU = NULL;
  template<typename T> const BasisFunction* Error<T>::basFct = NULL;
  template<typename T> const DOFVector<T>* Error<T>::errUh = NULL;
  template<typename T> double Error<T>::maxErr = 0.0;
  template<typename T> double Error<T>::l2Err2 = 0.0;
  template<typename T> double Error<T>::l2Norm2 = 0.0;
  template<typename T> int Error<T>::relative = 0;
  template<typename T> double Error<T>::relNorm2 = 0.0;
  template<typename T> double Error<T>::h1Err2 = 0.0;
  template<typename T> double Error<T>::h1Norm2 = 0.0;
  template<typename T> typename Error<T>::AbstrFctErrU Error<T>::errU;
  template<typename T> typename Error<T>::AbstrFctGrdErrU Error<T>::grdErrU;
  template<typename T> bool Error<T>::writeInLeafData = false;
  template<typename T> int Error<T>::component = 0;

}

#include "Error.hh"

#endif  // AMDIS_ERROR_H