InteriorBoundary.h 4.29 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
33
34

namespace AMDiS {

35
36
  using namespace std;

37
38
39
40
41
  /** \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
42
  public:
43
    typedef map<int, vector<AtomicBoundary> > RankToBoundMap;
Thomas Witkowski's avatar
Thomas Witkowski committed
44

Thomas Witkowski's avatar
Thomas Witkowski committed
45
46
47
48
    /// Iterator for the interior boundary object.
    class iterator {      
    public:
      iterator(InteriorBoundary &b)
49
50
51
52
53
54
55
56
57
58
59
	: bound(b),
	  levelData(NULL),
	  level(0)
      {
	reset();
      }

      iterator(InteriorBoundary &b, MeshLevelData &levelData, int level)
	: bound(b),
	  levelData(&levelData),
	  level(level)
Thomas Witkowski's avatar
Thomas Witkowski committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
      {
	reset();
      }

      /// Set the iterator to the first position.
      void reset()
      {
	mapIt = bound.boundary.begin();
	nextNonempty();

	if (mapIt != bound.boundary.end())
	  vecIt = mapIt->second.begin();	
      }

      /// Test if iterator is at the final position.
      bool end() const
      {
	return (mapIt == bound.boundary.end());
      }

      /// Move iterator to the next position.
      void operator++()
      {
	++vecIt;
	if (vecIt == mapIt->second.end()) {
	  ++mapIt;
	  nextNonempty();

	  if (mapIt != bound.boundary.end())
	    vecIt = mapIt->second.begin();	  
	}	
      }

93
94
95
96
97
98
99
100
101
102
      inline AtomicBoundary& operator*()
      {
	return *vecIt;
      }

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

Thomas Witkowski's avatar
Thomas Witkowski committed
103
104
105
106
107
108
109
110
111
      void nextRank()
      {
	++mapIt;
	nextNonempty();

	if (mapIt != bound.boundary.end())
	  vecIt = mapIt->second.begin();	
      }

112
      inline int getRank() 
Thomas Witkowski's avatar
Thomas Witkowski committed
113
      {
114
115
	if (level > 0) {
	  int r = levelData->mapRank(mapIt->first, level - 1, level);
116

117
118
119
	  TEST_EXIT_DBG(r >= 0)
	    ("Mapping rank %d from level % to level %d does not work!\n",
	     mapIt->first, level - 1, level);
120
121

	  return r;
122
123
	}

Thomas Witkowski's avatar
Thomas Witkowski committed
124
125
126
127
128
129
130
	return mapIt->first;
      }

    protected:

      inline void nextNonempty()
      {
Thomas Witkowski's avatar
Thomas Witkowski committed
131
132
133
	if (mapIt == bound.boundary.end())
	  return;

134
135
136
137
	if (level > 0) {
	  TEST_EXIT_DBG(levelData)("No mesh level data object defined!\n");
	  TEST_EXIT_DBG(level == 1)("Only 2-level method supported!\n");

138
	  while (!levelData->rankInSubdomain(mapIt->first, level) ||
139
140
141
142
143
144
145
146
147
148
149
		 mapIt->second.size() == 0) {
	    ++mapIt;
	    if (mapIt == bound.boundary.end())
	      return;	  
	  }
	} else {
	  while (mapIt->second.size() == 0) {
	    ++mapIt;
	    if (mapIt == bound.boundary.end())
	      return;
	  }
Thomas Witkowski's avatar
Thomas Witkowski committed
150
151
152
153
154
155
	}
      }

    protected:
      RankToBoundMap::iterator mapIt;

156
      vector<AtomicBoundary>::iterator vecIt;
Thomas Witkowski's avatar
Thomas Witkowski committed
157
158

      InteriorBoundary &bound;
159
160
161
162

      MeshLevelData *levelData;

      int level;
Thomas Witkowski's avatar
Thomas Witkowski committed
163
164
    };

165
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
166
167
    InteriorBoundary() {}

Thomas Witkowski's avatar
Thomas Witkowski committed
168
169
170
171
172
    void clear()
    {
      boundary.clear();
    }

173
    AtomicBoundary& getNewAtomic(int rank);
Thomas Witkowski's avatar
Thomas Witkowski committed
174

175
    /// Writes this object to a file.
176
    void serialize(ostream &out);
177

178
    /// Reads the state of an interior boundary from a file.
179
    void deserialize(istream &in, map<int, Element*> &elIndexMap);
180

181
182
183
184
    /// 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;

185
  protected:
186
    void serializeExcludeList(ostream &out, ExcludeList &list);
187

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

Thomas Witkowski's avatar
Thomas Witkowski committed
190
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
191
    RankToBoundMap boundary;
192
193
194
195
  };
}

#endif // AMDIS_INTERIORBOUNDARY_H