InteriorBoundary.cc 4.43 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
17
18
19
20
  void BoundaryObject::setReverseMode(BoundaryObject &otherBound, 
				      FiniteElemSpace *feSpace)
  {
    FUNCNAME("BoundaryObject::setReverseMode()");

    bool otherMode = false;

    const BasisFunction *basFcts = feSpace->getBasisFcts();
    int nBasFcts = basFcts->getNumber();
    std::vector<DegreeOfFreedom> localDofs0(nBasFcts), localDofs1(nBasFcts);
    
    switch (feSpace->getMesh()->getDim()) {
    case 2:
Thomas Witkowski's avatar
Thomas Witkowski committed
21
22
23
      if (ithObj == 2 || ithObj != otherBound.ithObj)
	otherMode = true;

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
      break;
    case 3:
      if (ithObj == 2 || ithObj == 3) {
	basFcts->getLocalIndices(el, feSpace->getAdmin(), localDofs0);
	basFcts->getLocalIndices(otherBound.el, feSpace->getAdmin(), localDofs1);
	otherMode = (localDofs0[0] != localDofs1[0]);
      }

      break;
    default:
      ERROR_EXIT("This should not happen!\n");
    }

    otherBound.reverseMode = otherMode;
  }


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  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);
  }


57
  AtomicBoundary& InteriorBoundary::getNewAtomic(int rank)
Thomas Witkowski's avatar
Thomas Witkowski committed
58
59
60
61
62
  {
    boundary[rank].resize(boundary[rank].size() + 1);
    return boundary[rank][boundary[rank].size() - 1];
  }

63

64
65
  void InteriorBoundary::serialize(std::ostream &out)
  {
66
    int mSize = boundary.size();
67
    SerUtil::serialize(out, mSize);
68
69
70
    for (RankToBoundMap::iterator it = boundary.begin(); it != boundary.end(); ++it) {
      int rank = it->first;
      int boundSize = it->second.size();
71
72
      SerUtil::serialize(out, rank);
      SerUtil::serialize(out, boundSize);
73
74
75
      for (int i = 0; i < boundSize; i++) {
	AtomicBoundary &bound = (it->second)[i];

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

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

93

94
95
  void InteriorBoundary::deserialize(std::istream &in, 
				     std::map<int, Element*> &elIndexMap)
96
  {
97
    int mSize = 0;
98
    SerUtil::deserialize(in, mSize);
99
100
101
    for (int i = 0; i < mSize; i++) {
      int rank = 0;
      int boundSize = 0;
102
103
      SerUtil::deserialize(in, rank);
      SerUtil::deserialize(in, boundSize);
104
105
106
107
108

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

109
	SerUtil::deserialize(in, bound.rankObj.elIndex);
110
	SerUtil::deserialize(in, bound.rankObj.elType);
111
112
	SerUtil::deserialize(in, bound.rankObj.subObj);
	SerUtil::deserialize(in, bound.rankObj.ithObj);
113
	SerUtil::deserialize(in, bound.rankObj.reverseMode);
114
	deserializeExcludeList(in, bound.rankObj.excludedSubstructures);
115

116
	SerUtil::deserialize(in, bound.neighObj.elIndex);
117
	SerUtil::deserialize(in, bound.neighObj.elType);
118
119
	SerUtil::deserialize(in, bound.neighObj.subObj);
	SerUtil::deserialize(in, bound.neighObj.ithObj);
120
	SerUtil::deserialize(in, bound.neighObj.reverseMode);
121
	deserializeExcludeList(in, bound.neighObj.excludedSubstructures);
122

123
124
	bound.rankObj.el = elIndexMap[bound.rankObj.elIndex];
	bound.neighObj.el = NULL;
125
126
      }
    }
127
  }
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157


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

158
}