Skip to content
Snippets Groups Projects
MacroReader.h 5.37 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 MacroReader.h */

#ifndef AMDIS_MACROREADER_H
#define AMDIS_MACROREADER_H

#include <deque>
#include "Global.h"
#include "FixVec.h"
#include "Boundary.h"

namespace AMDiS {

  class Mesh;
  class MacroElement;
  class ElInfo;
  class MacroInfo;

  /** \defgroup Input Input module */

  // ===========================================================================
  // ===== class MacroReader ===================================================
  // ===========================================================================

  /** \ingroup Input
   *  
   * \brief
   * Static class which reads a macro triangulation file and creates
   * the corresponding macro mesh.
   */
  class MacroReader
  {
  public:
    /** \brief
     * Creates a Mesh by reading the macro file with the given filename
     */
    static MacroInfo* readMacro(const char *filename, 
				Mesh* mesh,
				const char *periodicFile,
				int check);

  protected:
    static void computeNeighbours(Mesh *mesh);
    static void boundaryDOFs(Mesh *mesh);

    static void umb(int *ele, Mesh *mesh,
		    void (*umbvk)(Mesh *mesh, MacroElement*,int k, int *el));

    static int macrotest(Mesh *mesh);

    static void macroTest(Mesh *mesh, const char *nameneu);

    static bool newEdge(Mesh *mesh, MacroElement *mel,
			int mel_edge_no, int *n_neigh);

    static void fillMelBoundary(Mesh *, MacroElement *mel,
				FixVec<BoundaryType ,NEIGH>);

    static void fillMelNeigh(MacroElement *mel,
			     std::deque<MacroElement*>& macro_elements,
			     FixVec<int,NEIGH> ind);

    static void umbVkantMacro(Mesh *mesh,
			      MacroElement *,
			      int ka,
			      int *ele);

    static void recumb(Mesh *mesh, 
		       MacroElement *mel, MacroElement *macroalt,
		       int *test, double lg, int ka, int *ele, 
		       void (*umbvk)(Mesh *mesh, MacroElement*,int k, int *el));

    static void laengstekante(FixVec<WorldVector<double>,VERTEX> coord, 
			      double *l, int *v);

    static void checkMesh(Mesh *mesh);

    static int basicCheckFct(ElInfo* e);

    static int basicDOFCheckFct(ElInfo* e);

    static int basicNodeFct(ElInfo* e);

    friend class MacroInfo;
  };

  // ==========================================================================
  // ===== class MacroInfo ====================================================
  // ==========================================================================

  /** \ingroup Input
   * \brief
   * Used for reading a macro triangulation
   */
  class MacroInfo
  {
  public:
    MEMORY_MANAGED(MacroInfo);

    /** \brief
     * Pointer to the Mesh
     */
    Mesh *mesh;

    /** \brief
     * list of macro elements
     */
    std::deque<MacroElement*> mel;

    /** \brief
     * vector of all vertex dofs
     */
    DegreeOfFreedom **dof;

    /** \brief
     * coords[j][k]: kth coordinate of global vertex j
     */
    WorldVector<double> *coords;

    /** \brief
     * mel_vertex[i][k]: global index of kth vertex of element i
     */
    int **mel_vertex;

    /** \brief
     * true, if neighbour information is in macro file
     */
    bool neigh_set;

    /** \brief
     * true, if boundary information is in macro file
     */
    bool bound_set;

  public:
    /** \brief
     * Fills MacroInfo structure and some pointers in mesh 
     */
    void fill(Mesh *mesh, int ne, int nv);  

    /** \brief
     * Reads macro triangulation from ascii file in AMDiS format.
     * Fills MacroInfo structure.
     * Called by Mesh::readMacro(), fills missing information  
     */
    void readAMDiSMacro(const char *filename, Mesh* mesh);

    /** \brief
     * Frees memory of MacroInfo
     */
    void clear(int ne, int nv);

    /** \brief
     * Sets the boundary of all edges/faces with no neigbour to a straight  
     * line/face with dirichlet boundary type
     */
    void dirichletBoundary();

    void fillBoundaryInfo(Mesh *mesh);

  protected:
    /** \brief
     * Reads indices from macro file
     */
    int  read_indices(FILE *file, DimVec<int> &id);
  };
}

#endif