InteriorBoundary.h 3.8 KB
Newer Older
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// 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.


20
21
22
23
24
25
26

/** \file InteriorBoundary.h */

#ifndef AMDIS_INTERIORBOUNDARY_H
#define AMDIS_INTERIORBOUNDARY_H

#include <vector>
Thomas Witkowski's avatar
Thomas Witkowski committed
27
#include <map>
28

29
#include "AMDiS_fwd.h"
30
#include "BoundaryObject.h"
31
#include "parallel/MeshLevelData.h"
32
#include "parallel/ParallelTypes.h"
33
34
35

namespace AMDiS {

36
37
  using namespace std;

38
39
40
41
42
  /** \brief
   * Defines the interior boundary, i.e. a bound within the domain. It is used for
   * the classical domain decomposition parallelization.
   */
  class InteriorBoundary {
Thomas Witkowski's avatar
Thomas Witkowski committed
43
  public:
44
45
    void create(MPI::Intracomm &mpiComm,
		ElementObjectDatabase &elObjDb);
Thomas Witkowski's avatar
Thomas Witkowski committed
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    AtomicBoundary& getNewAtomicOwn(int rank);

    AtomicBoundary& getNewAtomicOther(int rank);

    AtomicBoundary& getNewAtomicPer(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<int, Element*> &elIndexMap);

  private:
    void serializeExcludeList(ostream &out, ExcludeList &list);

    void deserializeExcludeList(istream &in, ExcludeList &list);    

  public:
    RankToBoundMap own, other, periodic;


  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
69
70
71
    /// Iterator for the interior boundary object.
    class iterator {      
    public:
72
      iterator(RankToBoundMap &b, int traverseLevel = 0)
73
	: bound(b),
74
	  level(traverseLevel)
75
76
77
78
      {
	reset();
      }

Thomas Witkowski's avatar
Thomas Witkowski committed
79
80
81
      /// Set the iterator to the first position.
      void reset()
      {
82
	mapIt = bound.begin();
Thomas Witkowski's avatar
Thomas Witkowski committed
83
84
85
86
87
88
	nextNonempty();
      }

      /// Test if iterator is at the final position.
      bool end() const
      {
89
	return (mapIt == bound.end());
Thomas Witkowski's avatar
Thomas Witkowski committed
90
91
92
93
94
      }

      /// Move iterator to the next position.
      void operator++()
      {
95
96
97
98
	do {
	  ++vecIt;
	} while (vecIt->maxLevel < level && vecIt != mapIt->second.end());

Thomas Witkowski's avatar
Thomas Witkowski committed
99
100
101
102
103
104
	if (vecIt == mapIt->second.end()) {
	  ++mapIt;
	  nextNonempty();
	}	
      }

105
106
107
108
109
110
111
112
113
114
      inline AtomicBoundary& operator*()
      {
	return *vecIt;
      }

      inline AtomicBoundary* operator->()
      {
	return &(*vecIt);
      }

Thomas Witkowski's avatar
Thomas Witkowski committed
115
116
117
118
119
120
      void nextRank()
      {
	++mapIt;
	nextNonempty();
      }

121
      inline int getRank() 
Thomas Witkowski's avatar
Thomas Witkowski committed
122
123
124
125
126
127
128
129
      {
	return mapIt->first;
      }

    protected:

      inline void nextNonempty()
      {
130
131
	do {
	  // Return, we are at the end.
132
	  if (mapIt == bound.end())
133
134
135
136
137
	    return;
	  
	  // Search for the next non empty boundary map.
	  while (mapIt->second.size() == 0) {
	    ++mapIt;
138
	    if (mapIt == bound.end())
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
	      return;	  
	  }
	  
	  vecIt = mapIt->second.begin();
	  
	  // Search for the next atomic boundary on the mesh level
	  while (vecIt->maxLevel < level && vecIt != mapIt->second.end())
	    ++vecIt;
	  
	  // If vector iterator is not at the end, we have found one and
	  // can return.
	  if (vecIt != mapIt->second.end())
	    return;
	  
	  // In this case, no boundary on the given level is found, continue
	  // with next rank.
155
	  ++mapIt;
156
	} while (true);
Thomas Witkowski's avatar
Thomas Witkowski committed
157
158
159
160
161
      }

    protected:
      RankToBoundMap::iterator mapIt;

162
      vector<AtomicBoundary>::iterator vecIt;
Thomas Witkowski's avatar
Thomas Witkowski committed
163

164
      RankToBoundMap &bound;
165
166

      int level;
Thomas Witkowski's avatar
Thomas Witkowski committed
167
    };
168
169
170
171
  };
}

#endif // AMDIS_INTERIORBOUNDARY_H