// ============================================================================ // == == // == AMDiS - Adaptive multidimensional simulations == // == == // == http://www.amdis-fem.org == // == == // ============================================================================ // // Software License for AMDiS // // Copyright (c) 2010 Dresden University of Technology // All rights reserved. // Authors: Simon Vey, Thomas Witkowski et al. // // This file is part of AMDiS // // See also license.opensource.txt in the distribution. /** \file InteriorBoundary.h */ #ifndef AMDIS_INTERIORBOUNDARY_H #define AMDIS_INTERIORBOUNDARY_H #include #include #include "AMDiS_fwd.h" #include "BoundaryObject.h" #include "parallel/MeshLevelData.h" namespace AMDiS { using namespace std; /** \brief * Defines the interior boundary, i.e. a bound within the domain. It is used for * the classical domain decomposition parallelization. */ class InteriorBoundary { public: typedef map > RankToBoundMap; /// Iterator for the interior boundary object. class iterator { public: iterator(InteriorBoundary &b) : bound(b), level(0) { reset(); } iterator(InteriorBoundary &b, int level) : bound(b), level(level) { TEST_EXIT_DBG(level < bound.boundary.size()) ("Should not happen!\n"); reset(); } /// Set the iterator to the first position. void reset() { mapIt = bound.boundary[level].begin(); nextNonempty(); if (mapIt != bound.boundary[level].end()) vecIt = mapIt->second.begin(); } /// Test if iterator is at the final position. bool end() const { return (mapIt == bound.boundary[level].end()); } /// Move iterator to the next position. void operator++() { ++vecIt; if (vecIt == mapIt->second.end()) { ++mapIt; nextNonempty(); if (mapIt != bound.boundary[level].end()) vecIt = mapIt->second.begin(); } } inline AtomicBoundary& operator*() { return *vecIt; } inline AtomicBoundary* operator->() { return &(*vecIt); } void nextRank() { ++mapIt; nextNonempty(); if (mapIt != bound.boundary[level].end()) vecIt = mapIt->second.begin(); } inline int getRank() { return mapIt->first; } protected: inline void nextNonempty() { if (mapIt == bound.boundary[level].end()) return; while (mapIt->second.size() == 0) { ++mapIt; if (mapIt == bound.boundary[level].end()) return; } } protected: RankToBoundMap::iterator mapIt; vector::iterator vecIt; InteriorBoundary &bound; int level; }; public: InteriorBoundary(int l = 1) : nLevel(l) { boundary.resize(nLevel); } void reset(int nLevel); AtomicBoundary& getNewAtomic(int level, int rank); /// Writes this object to a file. void serialize(ostream &out); /// Reads the state of an interior boundary from a file. void deserialize(istream &in, map &elIndexMap); /// Compares this interior boundaries with some other. The order of the /// boundary elements within the object does not play a role. bool operator==(const InteriorBoundary& other) const; protected: void serializeExcludeList(ostream &out, ExcludeList &list); void deserializeExcludeList(istream &in, ExcludeList &list); public: vector boundary; protected: int nLevel; }; } #endif // AMDIS_INTERIORBOUNDARY_H