// ============================================================================ // == == // == AMDiS - Adaptive multidimensional simulations == // == == // ============================================================================ // == == // == crystal growth group == // == == // == Stiftung caesar == // == Ludwig-Erhard-Allee 2 == // == 53175 Bonn == // == germany == // == == // ============================================================================ // == == // == http://www.caesar.de/cg/AMDiS == // == == // ============================================================================ /** \file MeshStructure.h */ #ifndef AMDIS_MESHSTRUCTURE_H #define AMDIS_MESHSTRUCTURE_H #include #include "AMDiS_fwd.h" #include namespace AMDiS { class MeshStructure { public: MeshStructure() : currentIndex_(0), currentCode_(0), pos_(0), currentElement_(0), numElements_(0) {} void clear(); /** \brief * Creates a mesh structure code from a Mesh object by traversing it in preorder. */ void init(Mesh *mesh); void init(const std::vector& code, int numElements) { code_ = code; numElements_ = numElements; reset(); } void reset(); inline void commit() { if (pos_ > 0) { code_.push_back(currentCode_); } reset(); } bool skipBranch(MeshStructure *insert = NULL); ElInfo *skipBranch(ElInfo *elInfo, TraverseStack *stack); bool nextElement(MeshStructure *insert = NULL); inline bool isLeafElement() { return (currentCode_ & 1) == 0; } /** \brief * Merges a mesh structure code with its own mesh structure code. The * result overwrites the own mesh structure code. */ void merge(MeshStructure *structure) { MeshStructure temp(*this); merge(&temp, structure, this); } /** \brief * Fits a given mesh to the mesh structure code. * * \param debugMode In debugMode, the whole mesh is fitted to the mesh * structure code. Otherwise, the mesh is fitted only on the partition * of the current process. */ void fitMeshToStructure(Mesh *mesh, RefinementManager *manager, bool checkPartition = false, bool debugMode = false); /** \brief * Prints the mesh structure code. */ void print() { FUNCNAME("MeshStructure::print()"); reset(); bool cont = true; while (cont) { if (isLeafElement()) { MSG("0"); } else { MSG("1"); } cont = nextElement(); } MSG("\n"); } /** \brief * Returns the mesh structure code. */ inline const std::vector& getCode() { return code_; } inline int getNumElements() { return numElements_; } inline int getCurrentElement() { return currentElement_; } protected: /** \brief * Insert a new element to the structure code. Is used by the init * function. */ void insertElement(bool isLeaf); /** \brief * Merges two mesh structure codes to one structure code. */ void merge(MeshStructure *structure1, MeshStructure *structure2, MeshStructure *result); protected: std::vector code_; int currentIndex_; unsigned long int currentCode_; int pos_; int currentElement_; int numElements_; static const int unsignedLongSize_; }; } #endif