DualTraverse.cc 4.54 KB
Newer Older
1
2
3
4
5
6
#include "DualTraverse.h"
#include "Mesh.h"
#include "ElInfo.h"

namespace AMDiS {

7
8
9
10
11
12
  bool DualTraverse::traverseFirst(Mesh *mesh1, 
				   Mesh *mesh2, 
				   int level1, 
				   int level2, 
				   Flag flag1,
				   Flag flag2,
13
14
15
16
17
18
				   ElInfo **elInfo1,
				   ElInfo **elInfo2,
				   ElInfo **elInfoSmall,
				   ElInfo **elInfoLarge)
  {
    // replace CALL_EL_LEVEL by CALL_MG_LEVEL (covers whole domain)
19
    if (flag1.isSet(Mesh::CALL_EL_LEVEL)) {
20
21
22
23
24
25
26
      flag1 &= ~Mesh::CALL_EL_LEVEL;
      flag1 |= Mesh::CALL_MG_LEVEL;
      level1_ = level1;
    } else {
      level1_ = -1;
    }

27
    if (flag2.isSet(Mesh::CALL_EL_LEVEL)) {
28
29
30
31
32
33
34
35
      flag2 &= ~Mesh::CALL_EL_LEVEL;
      flag2 |= Mesh::CALL_MG_LEVEL;
      level2_ = level2;
    } else {
      level2_ = -1;
    }

    // replace CALL_LEAF_EL_LEVEL by CALL_MG_LEVEL (covers whole domain)
36
    if (flag1.isSet(Mesh::CALL_LEAF_EL_LEVEL)) {
37
38
39
40
41
42
43
44
45
      flag1 &= ~Mesh::CALL_LEAF_EL_LEVEL;
      flag1 |= Mesh::CALL_MG_LEVEL;
      level1_ = level1;
      callLeafElLevel1_ = true;
    } else {
      level1_ = -1;
      callLeafElLevel1_ = false;
    }

46
    if (flag2.isSet(Mesh::CALL_LEAF_EL_LEVEL)) {
47
48
49
50
51
52
53
54
55
56
57
58
      flag2 &= ~Mesh::CALL_LEAF_EL_LEVEL;
      flag2 |= Mesh::CALL_MG_LEVEL;
      level2_ = level2;
      callLeafElLevel2_ = true;
    } else {
      level2_ = -1;
      callLeafElLevel2_ = false;
    }

    // call standard traverse
    *elInfo1 = stack1.traverseFirst(mesh1, level1, flag1);
    *elInfo2 = stack2.traverseFirst(mesh2, level2, flag2);
59
 
60
    // finished ?
61
    if (*elInfo1 == NULL || *elInfo2 == NULL) {
62
      TEST_EXIT(*elInfo1 == *elInfo2)("invalid dual traverse\n");
63
64
65
      return false;
    }

66
    rest = 1.0;
67

68
    bool accepted = check(elInfo1, elInfo2, elInfoSmall, elInfoLarge);
69
70

    // check for non domain covering level traverse
71
72
73
74
75
76
77
    if (!accepted ||
	(level1_ != -1 && (*elInfo1)->getLevel() != level1_) ||
	(callLeafElLevel1_ && !(*elInfo1)->getElement()->isLeaf()) ||
	(level2_ != -1 && (*elInfo2)->getLevel() != level2_) ||
	(callLeafElLevel2_ && !(*elInfo2)->getElement()->isLeaf())) {
      return traverseNext(elInfo1, elInfo2, elInfoSmall, elInfoLarge);
    }
78

79
80
    fillSubElInfo(*elInfo1, *elInfo2, *elInfoSmall, *elInfoLarge);

81
82
83
84
85
86
87
88
89
    return true;
  }

  bool DualTraverse::traverseNext(ElInfo **elInfo1,
				  ElInfo **elInfo2,
				  ElInfo **elInfoSmall,
				  ElInfo **elInfoLarge)
  {
    // call standard traverse
90
    if (inc1) {
91
      *elInfo1 = stack1.traverseNext(*elInfo1);
92
    }
93
    if (inc2) {
94
      *elInfo2 = stack2.traverseNext(*elInfo2);
95
96
97
    }

    // finished ?
98
    if (*elInfo1 == NULL || *elInfo2 == NULL) {
99
      TEST_EXIT(*elInfo1 == *elInfo2)("invalid dual traverse\n");
100
101
102
      return false;
    }

103
    bool accepted = check(elInfo1, elInfo2, elInfoSmall, elInfoLarge);
104
105

    // check for non domain covering level traverse
106
107
108
109
110
111
112
    if (!accepted ||
	(level1_ != -1 && (*elInfo1)->getLevel() != level1_) ||
	(callLeafElLevel1_ && !(*elInfo1)->getElement()->isLeaf()) ||
	(level2_ != -1 && (*elInfo2)->getLevel() != level2_) ||
	(callLeafElLevel2_ && !(*elInfo2)->getElement()->isLeaf())) {
      return traverseNext(elInfo1, elInfo2, elInfoSmall, elInfoLarge);
    }
113
114
115

    fillSubElInfo(*elInfo1, *elInfo2, *elInfoSmall, *elInfoLarge);

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
    return true;
  }

  void DualTraverse::prepareNextStep(ElInfo **elInfo1,
				     ElInfo **elInfo2,
				     ElInfo **elInfoSmall,
				     ElInfo **elInfoLarge)
  {
    // which is the smaller element ?
    *elInfoSmall = 
      (*elInfo1)->getLevel() > (*elInfo2)->getLevel() ?
      *elInfo1 :
      *elInfo2;
    *elInfoLarge = 
      (*elInfo1)->getLevel() <= (*elInfo2)->getLevel() ?
      *elInfo1 :
      *elInfo2;

    // update rest
135
    rest -= 1.0 / (1 << ((*elInfoSmall)->getLevel() - (*elInfoLarge)->getLevel()));
136

137
    if (rest < 1e-32) {
138
      // large element finished -> increment both elements
139
140
141
      rest = 1.0; 
      inc1 = true;
      inc2 = true;
142
143
    } else {
      // increment only small element
144
145
      inc1 = (*elInfo1 == *elInfoSmall) ? true : false;
      inc2 = (*elInfo2 == *elInfoSmall) ? true : false;
146
147
148
    }
  }

149
150
151
152
153
  void DualTraverse::fillSubElInfo(ElInfo *elInfo1, 
				   ElInfo *elInfo2,
				   ElInfo *elInfoSmall,
				   ElInfo *elInfoLarge)
  {
154
    if (!fillSubElemMat)
155
156
      return;

157
158
159
    DimMat<double> *subCoordsMat = elInfoSmall->getSubElemCoordsMat();
    if (!subCoordsMat) {
      subCoordsMat = NEW DimMat<double>(elInfo1->getMesh()->getDim());
160
161
162
    }

    if (elInfo1 == elInfoSmall) {
163
      stack1.getCoordsInElem(elInfo2, subCoordsMat);
164
    } else {
165
      stack2.getCoordsInElem(elInfo1, subCoordsMat);
166
    }
167
168

    elInfoSmall->setSubElemCoordsMat(subCoordsMat);
169
  }
170
}