InteriorBoundary.cc 5.56 KB
Newer Older
1
#include "InteriorBoundary.h"
2
3
#include "FiniteElemSpace.h"
#include "BasisFunction.h"
4
#include "Serializer.h"
5
6

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

8
9
10
11
12
13
14
15
16
  void BoundaryObject::setReverseMode(BoundaryObject &otherBound, 
				      FiniteElemSpace *feSpace)
  {
    FUNCNAME("BoundaryObject::setReverseMode()");

    bool otherMode = false;

    switch (feSpace->getMesh()->getDim()) {
    case 2:
17
      otherMode = true;
18
      break;
19

20
    case 3:
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
      if (subObj == EDGE) {	
	int el0_v0 = el->getVertexOfEdge(ithObj, 0);
	int el0_v1 = el->getVertexOfEdge(ithObj, 1);
	int el1_v0 = el->getVertexOfEdge(otherBound.ithObj, 0);
	int el1_v1 = el->getVertexOfEdge(otherBound.ithObj, 1);

	const BasisFunction *basFcts = feSpace->getBasisFcts();
	int nBasFcts = basFcts->getNumber();
	std::vector<DegreeOfFreedom> localDofs0(nBasFcts), localDofs1(nBasFcts);
	basFcts->getLocalIndices(el, feSpace->getAdmin(), localDofs0);
	basFcts->getLocalIndices(otherBound.el, feSpace->getAdmin(), localDofs1);

	TEST_EXIT_DBG(localDofs0[el0_v0] == localDofs1[el1_v0] ||
		      localDofs0[el0_v0] == localDofs1[el1_v1])
	  ("This should not happen!\n");
	TEST_EXIT_DBG(localDofs0[el0_v1] == localDofs1[el1_v0] ||
		      localDofs0[el0_v1] == localDofs1[el1_v1])
	  ("This should not happen!\n");
	
 	if (localDofs0[el0_v0] != localDofs1[el1_v0])
	  otherMode = true; 	
      }

      if (subObj == FACE && ithObj != 1) {
45
46
47
	const BasisFunction *basFcts = feSpace->getBasisFcts();
	int nBasFcts = basFcts->getNumber();
	std::vector<DegreeOfFreedom> localDofs0(nBasFcts), localDofs1(nBasFcts);
48
	basFcts->getLocalIndices(el, feSpace->getAdmin(), localDofs0);
49
	basFcts->getLocalIndices(otherBound.el, feSpace->getAdmin(), localDofs1);
50
51
52
53
54
55
	
	if (ithObj == 2 || ithObj == 3)
	  otherMode = (localDofs0[0] != localDofs1[0]);
	  
	if (ithObj == 0)
	  otherMode = localDofs0[1] != localDofs1[1];	
56
57
      }
      break;
58

59
60
61
62
63
64
65
66
    default:
      ERROR_EXIT("This should not happen!\n");
    }

    otherBound.reverseMode = otherMode;
  }


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  bool BoundaryObject::operator==(const BoundaryObject& other) const
  {
    return (other.elIndex == elIndex && 
	    other.subObj == subObj && 
	    other.ithObj == ithObj);
  }


  bool BoundaryObject::operator!=(const BoundaryObject& other) const
  {
    return (other.elIndex != elIndex || 
	    other.subObj != subObj || 
	    other.ithObj != ithObj);
  }


83
  AtomicBoundary& InteriorBoundary::getNewAtomic(int rank)
Thomas Witkowski's avatar
Thomas Witkowski committed
84
85
86
87
88
  {
    boundary[rank].resize(boundary[rank].size() + 1);
    return boundary[rank][boundary[rank].size() - 1];
  }

89

90
91
  void InteriorBoundary::serialize(std::ostream &out)
  {
92
    int mSize = boundary.size();
93
    SerUtil::serialize(out, mSize);
94
95
96
    for (RankToBoundMap::iterator it = boundary.begin(); it != boundary.end(); ++it) {
      int rank = it->first;
      int boundSize = it->second.size();
97
98
      SerUtil::serialize(out, rank);
      SerUtil::serialize(out, boundSize);
99
100
101
      for (int i = 0; i < boundSize; i++) {
	AtomicBoundary &bound = (it->second)[i];

102
	SerUtil::serialize(out, bound.rankObj.elIndex);
103
	SerUtil::serialize(out, bound.rankObj.elType);
104
105
	SerUtil::serialize(out, bound.rankObj.subObj);
	SerUtil::serialize(out, bound.rankObj.ithObj);
106
	SerUtil::serialize(out, bound.rankObj.reverseMode);
107
	serializeExcludeList(out, bound.rankObj.excludedSubstructures);
108

109
	SerUtil::serialize(out, bound.neighObj.elIndex);
110
	SerUtil::serialize(out, bound.neighObj.elType);
111
112
	SerUtil::serialize(out, bound.neighObj.subObj);
	SerUtil::serialize(out, bound.neighObj.ithObj);
113
	SerUtil::serialize(out, bound.neighObj.reverseMode);
114
	serializeExcludeList(out, bound.neighObj.excludedSubstructures);
115
116
      }
    }
117
118
  }

119

120
121
  void InteriorBoundary::deserialize(std::istream &in, 
				     std::map<int, Element*> &elIndexMap)
122
  {
123
124
    FUNCNAME("InteriorBoundary::deserialize()");

125
    int mSize = 0;
126
    SerUtil::deserialize(in, mSize);
127
128
129
    for (int i = 0; i < mSize; i++) {
      int rank = 0;
      int boundSize = 0;
130
131
      SerUtil::deserialize(in, rank);
      SerUtil::deserialize(in, boundSize);
132
133
134
135
136

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

137
	SerUtil::deserialize(in, bound.rankObj.elIndex);
138
	SerUtil::deserialize(in, bound.rankObj.elType);
139
140
	SerUtil::deserialize(in, bound.rankObj.subObj);
	SerUtil::deserialize(in, bound.rankObj.ithObj);
141
	SerUtil::deserialize(in, bound.rankObj.reverseMode);
142
	deserializeExcludeList(in, bound.rankObj.excludedSubstructures);
143

144
	SerUtil::deserialize(in, bound.neighObj.elIndex);
145
	SerUtil::deserialize(in, bound.neighObj.elType);
146
147
	SerUtil::deserialize(in, bound.neighObj.subObj);
	SerUtil::deserialize(in, bound.neighObj.ithObj);
148
	SerUtil::deserialize(in, bound.neighObj.reverseMode);
149
	deserializeExcludeList(in, bound.neighObj.excludedSubstructures);
150

151
152
153
154
	TEST_EXIT_DBG(elIndexMap.count(bound.rankObj.elIndex) == 1)
	  ("Cannot find element with index %d for deserialization!\n", 
	   bound.rankObj.elIndex);

155
156
	bound.rankObj.el = elIndexMap[bound.rankObj.elIndex];
	bound.neighObj.el = NULL;
157
158
      }
    }
159
  }
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189


  void InteriorBoundary::serializeExcludeList(std::ostream &out, ExcludeList &list)
  {
    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);
    }
  }


  void InteriorBoundary::deserializeExcludeList(std::istream &in, ExcludeList &list)
  {
    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));
    }
  }

190
}