InteriorBoundary.cc 8.07 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 "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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  BoundaryObject::BoundaryObject()
    : elType(0),
      reverseMode(false),
      excludedSubstructures(0)
  {}


  BoundaryObject::BoundaryObject(Element *e, 
				 int eType, 
				 GeoIndex sObj, 
				 int iObj, 
				 bool rMode)
  : el(e),
    elIndex(e->getIndex()),
    elType(eType),
    subObj(sObj),
    ithObj(iObj),
    reverseMode(rMode),
    excludedSubstructures(0)
  {}

42
43
44

  bool BoundaryObject::computeReverseMode(BoundaryObject &obj0, 
					  BoundaryObject &obj1,
45
					  const FiniteElemSpace *feSpace,
46
					  BoundaryType boundary)
47
  {
48
    FUNCNAME("BoundaryObject::computeReverseMode()");
49

50
    bool reverseMode = false;
51
52
53

    switch (feSpace->getMesh()->getDim()) {
    case 2:
54
      reverseMode = true;
55
      break;
56

57
    case 3:
58
59
60
      TEST_EXIT_DBG(obj1.elType == 0)
	("Only 3D macro elements with level 0 are supported. This element has level %d!\n", 
	 obj1.elType);
61

62

63
64
65
66
67
      if (obj0.subObj == EDGE) {	
	int el0_v0 = obj0.el->getVertexOfEdge(obj0.ithObj, 0);
	int el0_v1 = obj0.el->getVertexOfEdge(obj0.ithObj, 1);
	int el1_v0 = obj0.el->getVertexOfEdge(obj1.ithObj, 0);
	int el1_v1 = obj0.el->getVertexOfEdge(obj1.ithObj, 1);
68
69
70
71

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

75
76
77
78
79
80
81
82
83
	Mesh *mesh = feSpace->getMesh();

	if (mesh->isPeriodicAssociation(boundary) == false) {
	  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");
84

85
	  if (localDofs0[el0_v0] != localDofs1[el1_v0])
86
	    reverseMode = true; 	
87
88
	} else {
	  if (mesh->associated(localDofs0[el0_v0], localDofs1[el1_v0]) == false)
89
	    reverseMode = true;
90
	}
91
92
      }

93
      if (obj0.subObj == FACE && obj0.ithObj != 1) {
94
95
96
	const BasisFunction *basFcts = feSpace->getBasisFcts();
	int nBasFcts = basFcts->getNumber();
	std::vector<DegreeOfFreedom> localDofs0(nBasFcts), localDofs1(nBasFcts);
97
98
	basFcts->getLocalIndices(obj0.el, feSpace->getAdmin(), localDofs0);
	basFcts->getLocalIndices(obj1.el, feSpace->getAdmin(), localDofs1);
99
	
100
101
	if (obj0.ithObj == 2 || obj0.ithObj == 3)
	  reverseMode = (localDofs0[0] != localDofs1[0]);
102
	  
103
104
	if (obj0.ithObj == 0)
	  reverseMode = (localDofs0[1] != localDofs1[1]);
105
106
      }
      break;
107

108
109
110
111
    default:
      ERROR_EXIT("This should not happen!\n");
    }

112
113
114
115
    return reverseMode;
  }


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
  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);
  }


132
133
134
135
136
137
138
139
  bool AtomicBoundary::operator==(const AtomicBoundary& other) const
  {
    return (rankObj == other.rankObj && 
	    neighObj == other.neighObj && 
	    type == other.type);
  }


140
  AtomicBoundary& InteriorBoundary::getNewAtomic(int rank)
Thomas Witkowski's avatar
Thomas Witkowski committed
141
142
143
144
145
  {
    boundary[rank].resize(boundary[rank].size() + 1);
    return boundary[rank][boundary[rank].size() - 1];
  }

146

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
  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;
  }


173
174
  void InteriorBoundary::serialize(std::ostream &out)
  {
175
176
    FUNCNAME("InteriorBoundary::serialize()");

177
    int mSize = boundary.size();
178
    SerUtil::serialize(out, mSize);
179
180
181
    for (RankToBoundMap::iterator it = boundary.begin(); it != boundary.end(); ++it) {
      int rank = it->first;
      int boundSize = it->second.size();
182
183
      SerUtil::serialize(out, rank);
      SerUtil::serialize(out, boundSize);
184
185
186
      for (int i = 0; i < boundSize; i++) {
	AtomicBoundary &bound = (it->second)[i];

187
	SerUtil::serialize(out, bound.rankObj.elIndex);
188
	SerUtil::serialize(out, bound.rankObj.elType);
189
190
	SerUtil::serialize(out, bound.rankObj.subObj);
	SerUtil::serialize(out, bound.rankObj.ithObj);
191
	SerUtil::serialize(out, bound.rankObj.reverseMode);
192
	serializeExcludeList(out, bound.rankObj.excludedSubstructures);
193

194
	SerUtil::serialize(out, bound.neighObj.elIndex);
195
	SerUtil::serialize(out, bound.neighObj.elType);
196
197
	SerUtil::serialize(out, bound.neighObj.subObj);
	SerUtil::serialize(out, bound.neighObj.ithObj);
198
	SerUtil::serialize(out, bound.neighObj.reverseMode);
199
	serializeExcludeList(out, bound.neighObj.excludedSubstructures);
200
201

	SerUtil::serialize(out, bound.type);
202
203
      }
    }
204
205
  }

206

207
208
  void InteriorBoundary::deserialize(std::istream &in, 
				     std::map<int, Element*> &elIndexMap)
209
  {
210
211
    FUNCNAME("InteriorBoundary::deserialize()");

212
    int mSize = 0;
213
    SerUtil::deserialize(in, mSize);
214
215
216
    for (int i = 0; i < mSize; i++) {
      int rank = 0;
      int boundSize = 0;
217
218
      SerUtil::deserialize(in, rank);
      SerUtil::deserialize(in, boundSize);
219
220
221
222
223

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

224
	SerUtil::deserialize(in, bound.rankObj.elIndex);
225
	SerUtil::deserialize(in, bound.rankObj.elType);
226
227
	SerUtil::deserialize(in, bound.rankObj.subObj);
	SerUtil::deserialize(in, bound.rankObj.ithObj);
228
	SerUtil::deserialize(in, bound.rankObj.reverseMode);
229
	deserializeExcludeList(in, bound.rankObj.excludedSubstructures);
230

231
	SerUtil::deserialize(in, bound.neighObj.elIndex);
232
	SerUtil::deserialize(in, bound.neighObj.elType);
233
234
	SerUtil::deserialize(in, bound.neighObj.subObj);
	SerUtil::deserialize(in, bound.neighObj.ithObj);
235
	SerUtil::deserialize(in, bound.neighObj.reverseMode);
236
	deserializeExcludeList(in, bound.neighObj.excludedSubstructures);
237

238
239
	SerUtil::deserialize(in, bound.type);

240
241
242
243
	TEST_EXIT_DBG(elIndexMap.count(bound.rankObj.elIndex) == 1)
	  ("Cannot find element with index %d for deserialization!\n", 
	   bound.rankObj.elIndex);

244
245
246
	TEST_EXIT_DBG(elIndexMap[bound.rankObj.elIndex]->getIndex() == 
		      bound.rankObj.elIndex)("Should not happen!\n");

247
	bound.rankObj.el = elIndexMap[bound.rankObj.elIndex];
248
249
250
251
252
253
254
255

	// 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.
	if (elIndexMap.count(bound.neighObj.elIndex))
	  bound.neighObj.el = elIndexMap[bound.neighObj.elIndex];
	else
	  bound.neighObj.el = NULL;
256
257
      }
    }
258
  }
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288


  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));
    }
  }

289
}