InteriorBoundary.cc 5.32 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// 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.


13
#include "parallel/InteriorBoundary.h"
14
15
#include "FiniteElemSpace.h"
#include "BasisFunction.h"
16
#include "Serializer.h"
17
#include "VertexVector.h"
18
19

namespace AMDiS {
Thomas Witkowski's avatar
Thomas Witkowski committed
20

21
  AtomicBoundary& InteriorBoundary::getNewAtomic(int rank)
Thomas Witkowski's avatar
Thomas Witkowski committed
22
  {
23
24
25
    int size = boundary[rank].size();
    boundary[rank].resize(size + 1);
    return boundary[rank][size];
Thomas Witkowski's avatar
Thomas Witkowski committed
26
27
  }

28

29
30
31
32
  bool InteriorBoundary::operator==(const InteriorBoundary& other) const
  {
    InteriorBoundary& other2 = const_cast<InteriorBoundary&>(other);

33
34
35
36
    if (boundary.size() != other2.boundary.size())
      return false;

    for (unsigned int level = 0; level < boundary.size(); level++) {
37
38
39
      for (RankToBoundMap::const_iterator it = boundary.begin(); 
	   it != boundary.end(); ++it) {
	if (other2.boundary.count(it->first) == 0)
40
41
	  return false;     
	
42
	if (other2.boundary[it->first].size() != it->second.size())
43
	  return false;
44
	
45
46
	for (unsigned int i = 0; i < it->second.size(); i++) {
	  std::vector<AtomicBoundary>::iterator bIt = 
47
48
	    find(other2.boundary[it->first].begin(),
		 other2.boundary[it->first].end(), it->second[i]);
49
	  
50
	  if (bIt == other2.boundary[it->first].end())
51
52
53
	    return false;	
	}      
      }
54
55
56
57
58
59
    }

    return true;
  }


60
  void InteriorBoundary::clear()
61
  { 
62
    FUNCNAME("InteriorBoundary::clear()");
63
64
65
66
67

    boundary.clear();
  }


68
69
  void InteriorBoundary::serialize(std::ostream &out)
  {
70
71
    FUNCNAME("InteriorBoundary::serialize()");

72
73
74
    ERROR_EXIT("REWRITE TO MULTILEVEL STRUCTURE!\n");

#if 0
75
    int mSize = boundary.size();
76
    SerUtil::serialize(out, mSize);
77
78
    for (RankToBoundMap::iterator it = boundary.begin(); 
	 it != boundary.end(); ++it) {
79
80
      int rank = it->first;
      int boundSize = it->second.size();
81
82
      SerUtil::serialize(out, rank);
      SerUtil::serialize(out, boundSize);
83
84
85
      for (int i = 0; i < boundSize; i++) {
	AtomicBoundary &bound = (it->second)[i];

86
	SerUtil::serialize(out, bound.rankObj.elIndex);
87
	SerUtil::serialize(out, bound.rankObj.elType);
88
89
	SerUtil::serialize(out, bound.rankObj.subObj);
	SerUtil::serialize(out, bound.rankObj.ithObj);
90
	SerUtil::serialize(out, bound.rankObj.reverseMode);
91
	serializeExcludeList(out, bound.rankObj.excludedSubstructures);
92

93
	SerUtil::serialize(out, bound.neighObj.elIndex);
94
	SerUtil::serialize(out, bound.neighObj.elType);
95
96
	SerUtil::serialize(out, bound.neighObj.subObj);
	SerUtil::serialize(out, bound.neighObj.ithObj);
97
	SerUtil::serialize(out, bound.neighObj.reverseMode);
98
	serializeExcludeList(out, bound.neighObj.excludedSubstructures);
99
100

	SerUtil::serialize(out, bound.type);
101
102
      }
    }
103
#endif
104
105
  }

106

107
108
  void InteriorBoundary::deserialize(std::istream &in, 
				     std::map<int, Element*> &elIndexMap)
109
  {
110
111
    FUNCNAME("InteriorBoundary::deserialize()");

112
113
114
    ERROR_EXIT("REWRITE TO MULTILEVEL STRUCTURE!\n");

#if 0
115
    int mSize = 0;
116
    SerUtil::deserialize(in, mSize);
117
118
119
    for (int i = 0; i < mSize; i++) {
      int rank = 0;
      int boundSize = 0;
120
121
      SerUtil::deserialize(in, rank);
      SerUtil::deserialize(in, boundSize);
122
123
124
125
126

      boundary[rank].resize(boundSize);
      for (int i = 0; i < boundSize; i++) {
	AtomicBoundary &bound = boundary[rank][i];

127
	SerUtil::deserialize(in, bound.rankObj.elIndex);
128
	SerUtil::deserialize(in, bound.rankObj.elType);
129
130
	SerUtil::deserialize(in, bound.rankObj.subObj);
	SerUtil::deserialize(in, bound.rankObj.ithObj);
131
	SerUtil::deserialize(in, bound.rankObj.reverseMode);
132
	deserializeExcludeList(in, bound.rankObj.excludedSubstructures);
133

134
	SerUtil::deserialize(in, bound.neighObj.elIndex);
135
	SerUtil::deserialize(in, bound.neighObj.elType);
136
137
	SerUtil::deserialize(in, bound.neighObj.subObj);
	SerUtil::deserialize(in, bound.neighObj.ithObj);
138
	SerUtil::deserialize(in, bound.neighObj.reverseMode);
139
	deserializeExcludeList(in, bound.neighObj.excludedSubstructures);
140

141
142
	SerUtil::deserialize(in, bound.type);

143
144
145
146
	TEST_EXIT_DBG(elIndexMap.count(bound.rankObj.elIndex) == 1)
	  ("Cannot find element with index %d for deserialization!\n", 
	   bound.rankObj.elIndex);

147
148
149
	TEST_EXIT_DBG(elIndexMap[bound.rankObj.elIndex]->getIndex() == 
		      bound.rankObj.elIndex)("Should not happen!\n");

150
	bound.rankObj.el = elIndexMap[bound.rankObj.elIndex];
151

152
153
154
	// For the case of periodic interior boundaries, a rank may have an
	// boundary with itself. In this case, also the pointer to the neighbour
	//  object must be set correctly.
155
156
157
158
	if (elIndexMap.count(bound.neighObj.elIndex))
	  bound.neighObj.el = elIndexMap[bound.neighObj.elIndex];
	else
	  bound.neighObj.el = NULL;
159
160
      }
    }
161
#endif
162
  }
163
164


165
166
  void InteriorBoundary::serializeExcludeList(std::ostream &out, 
					      ExcludeList &list)
167
168
169
170
171
172
173
174
175
176
  {
    int size = list.size();
    SerUtil::serialize(out, size);
    for (int i = 0; i < size; i++) {
      SerUtil::serialize(out, list[i].first);
      SerUtil::serialize(out, list[i].second);
    }
  }


177
178
  void InteriorBoundary::deserializeExcludeList(std::istream &in, 
						ExcludeList &list)
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
  {
    int size = 0;
    SerUtil::deserialize(in, size);
    list.resize(0);
    list.reserve(size);

    for (int i = 0; i < size; i++) {
      GeoIndex a;
      int b;

      SerUtil::deserialize(in, a);
      SerUtil::deserialize(in, b);
      list.push_back(std::make_pair(a, b));
    }
  }

195
}