InteriorBoundary.cc 4.95 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
26
  {
    boundary[rank].resize(boundary[rank].size() + 1);
    return boundary[rank][boundary[rank].size() - 1];
  }

27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  bool InteriorBoundary::operator==(const InteriorBoundary& other) const
  {
    InteriorBoundary& other2 = const_cast<InteriorBoundary&>(other);

    for (RankToBoundMap::const_iterator it = boundary.begin(); 
	 it != boundary.end(); ++it) {
      if (other2.boundary.count(it->first) == 0)
	return false;     

      if (other2.boundary[it->first].size() != it->second.size())
	return false;
            
      for (unsigned int i = 0; i < it->second.size(); i++) {
	std::vector<AtomicBoundary>::iterator bIt = 
	  find(other2.boundary[it->first].begin(),
	       other2.boundary[it->first].end(), it->second[i]);
	
	if (bIt == other2.boundary[it->first].end())
	  return false;	
      }      
    }

    return true;
  }


54
55
  void InteriorBoundary::serialize(std::ostream &out)
  {
56
57
    FUNCNAME("InteriorBoundary::serialize()");

58
    int mSize = boundary.size();
59
    SerUtil::serialize(out, mSize);
60
61
    for (RankToBoundMap::iterator it = boundary.begin(); 
	 it != boundary.end(); ++it) {
62
63
      int rank = it->first;
      int boundSize = it->second.size();
64
65
      SerUtil::serialize(out, rank);
      SerUtil::serialize(out, boundSize);
66
67
68
      for (int i = 0; i < boundSize; i++) {
	AtomicBoundary &bound = (it->second)[i];

69
	SerUtil::serialize(out, bound.rankObj.elIndex);
70
	SerUtil::serialize(out, bound.rankObj.elType);
71
72
	SerUtil::serialize(out, bound.rankObj.subObj);
	SerUtil::serialize(out, bound.rankObj.ithObj);
73
	SerUtil::serialize(out, bound.rankObj.reverseMode);
74
	serializeExcludeList(out, bound.rankObj.excludedSubstructures);
75

76
	SerUtil::serialize(out, bound.neighObj.elIndex);
77
	SerUtil::serialize(out, bound.neighObj.elType);
78
79
	SerUtil::serialize(out, bound.neighObj.subObj);
	SerUtil::serialize(out, bound.neighObj.ithObj);
80
	SerUtil::serialize(out, bound.neighObj.reverseMode);
81
	serializeExcludeList(out, bound.neighObj.excludedSubstructures);
82
83

	SerUtil::serialize(out, bound.type);
84
85
      }
    }
86
87
  }

88

89
90
  void InteriorBoundary::deserialize(std::istream &in, 
				     std::map<int, Element*> &elIndexMap)
91
  {
92
93
    FUNCNAME("InteriorBoundary::deserialize()");

94
    int mSize = 0;
95
    SerUtil::deserialize(in, mSize);
96
97
98
    for (int i = 0; i < mSize; i++) {
      int rank = 0;
      int boundSize = 0;
99
100
      SerUtil::deserialize(in, rank);
      SerUtil::deserialize(in, boundSize);
101
102
103
104
105

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

106
	SerUtil::deserialize(in, bound.rankObj.elIndex);
107
	SerUtil::deserialize(in, bound.rankObj.elType);
108
109
	SerUtil::deserialize(in, bound.rankObj.subObj);
	SerUtil::deserialize(in, bound.rankObj.ithObj);
110
	SerUtil::deserialize(in, bound.rankObj.reverseMode);
111
	deserializeExcludeList(in, bound.rankObj.excludedSubstructures);
112

113
	SerUtil::deserialize(in, bound.neighObj.elIndex);
114
	SerUtil::deserialize(in, bound.neighObj.elType);
115
116
	SerUtil::deserialize(in, bound.neighObj.subObj);
	SerUtil::deserialize(in, bound.neighObj.ithObj);
117
	SerUtil::deserialize(in, bound.neighObj.reverseMode);
118
	deserializeExcludeList(in, bound.neighObj.excludedSubstructures);
119

120
121
	SerUtil::deserialize(in, bound.type);

122
123
124
125
	TEST_EXIT_DBG(elIndexMap.count(bound.rankObj.elIndex) == 1)
	  ("Cannot find element with index %d for deserialization!\n", 
	   bound.rankObj.elIndex);

126
127
128
	TEST_EXIT_DBG(elIndexMap[bound.rankObj.elIndex]->getIndex() == 
		      bound.rankObj.elIndex)("Should not happen!\n");

129
	bound.rankObj.el = elIndexMap[bound.rankObj.elIndex];
130

131
132
133
	// 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.
134
135
136
137
	if (elIndexMap.count(bound.neighObj.elIndex))
	  bound.neighObj.el = elIndexMap[bound.neighObj.elIndex];
	else
	  bound.neighObj.el = NULL;
138
139
      }
    }
140
  }
141
142


143
144
  void InteriorBoundary::serializeExcludeList(std::ostream &out, 
					      ExcludeList &list)
145
146
147
148
149
150
151
152
153
154
  {
    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);
    }
  }


155
156
  void InteriorBoundary::deserializeExcludeList(std::istream &in, 
						ExcludeList &list)
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
  {
    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));
    }
  }

173
}