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

/** \file Projection.h */

#ifndef AMDIS_PROJECTION_H
#define AMDIS_PROJECTION_H

#include "FixVec.h"
#include <map>

namespace AMDiS {

  /** \brief
   * Different possible types for a \ref Projection.
   */
  enum ProjectionType {
    BOUNDARY_PROJECTION = 0, /**< Projection of boundary parts of an element. */
    VOLUME_PROJECTION = 1    /**< Projection of whole elements. */
  };

  // ==============================================================================
  // ===== class Projection =======================================================
  // ==============================================================================

  /** \brief
   * A Projection is a mapping from world coordinates to world coordinates.
   * It must fullfill the condition \ref project(project(x)) == project(x).
   * Each projection object has its own unique \ref projectionID. This is
   * used to connect the projection indices used in the macro file with the
   * corresponding projection object. See \ref getProjection(int id).
   */
  class Projection
  {
  public:
    /** \brief
     * Constructs a prjection with given id and type.
     */
    Projection(int id, ProjectionType type) 
      : projectionID_(id),
	projectionType_(type)
    {
      TEST_EXIT(id != 0)
	("don't use 0 as projection id. is used as no projection\n");
      TEST_EXIT(projectionMap_[id] == NULL)
	("there is already a projection with this id\n");
      projectionMap_[id] = this;
    };

    virtual ~Projection() {};

    /** \brief
     * Projection method. Must be overriden in sub classes.
     */
    virtual void project(WorldVector<double>& x) = 0;

    /** \brief
     * Returns \ref projectionID.
     */
    inline int getID() { return projectionID_; };

    /** \brief
     * Returns \ref projectionType;
     */
    inline ProjectionType getType() { return projectionType_; };

    /** \brief
     * Returns the projection with the given id, if existing. 
     * Returns NULL otherwise.
     */
    static Projection* getProjection(int id) {
      return projectionMap_[id];
    };

  protected:
    /** \brief
     * Unique projection id.
     */
    int projectionID_;

    /** \brief
     * Type of this projection.
     */
    ProjectionType projectionType_;

    /** \brief
     * Static mapping from ids to projection objects. Used in \ref getProjection().
     */
    static std::map<int, Projection*> projectionMap_;
  };

}

#include "BallProject.h"
#include "CylinderProject.h"
#endif