InteriorBoundary.cc 4.4 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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  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:
      ERROR_EXIT("Not yet implemented!\n");
      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;
  }


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


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

61

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

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

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

91

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

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

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

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

121
122
	bound.rankObj.el = elIndexMap[bound.rankObj.elIndex];
	bound.neighObj.el = NULL;
123
124
      }
    }
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


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

156
}