Marker.cc 5.97 KB
Newer Older
1
2
3
4
#include "Marker.h"

namespace AMDiS {

5
  Marker *Marker::createMarker(std::string name, int row) {
6
7
8
9
10
11
12
13
14
    int strategy = 0;
    GET_PARAMETER(0, name + "->strategy", "%d", &strategy);
  
    Marker *marker = NULL;

    switch(strategy) {
    case 0: 
      break;
    case 1:
Thomas Witkowski's avatar
Thomas Witkowski committed
15
      marker = new GRMarker(name, row);
16
17
      break;
    case 2:
Thomas Witkowski's avatar
Thomas Witkowski committed
18
      marker = new MSMarker(name, row);
19
20
      break;
    case 3:
Thomas Witkowski's avatar
Thomas Witkowski committed
21
      marker = new ESMarker(name, row);
22
23
      break;
    case 4:
Thomas Witkowski's avatar
Thomas Witkowski committed
24
      marker = new GERSMarker(name, row);
25
26
27
28
29
30
      break;
    default: ERROR_EXIT("invalid strategy\n");
    }
    
    return marker;
  }
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  
  void Marker::initMarking(AdaptInfo *adaptInfo, Mesh *mesh)
  {
    elMarkRefine = 0;
    elMarkCoarsen = 0;
    estSum = pow(adaptInfo->getEstSum(row == -1 ? 0 : row), p);
    estMax = adaptInfo->getEstMax(row == -1 ? 0 : row);
  }

  void Marker::finishMarking(AdaptInfo *adaptInfo) {
    FUNCNAME("Marker::finishMarking()");
    
    INFO(info, 4)("%d elements marked for refinement\n", elMarkRefine);
    INFO(info, 4)("%d elements marked for coarsening\n", elMarkCoarsen);
  }

  void Marker::markElement(AdaptInfo *adaptInfo, ElInfo *elInfo) {
    Element *el = elInfo->getElement();
    double lError = el->getEstimation(row);
Thomas Witkowski's avatar
Thomas Witkowski committed
50

51
    if (adaptInfo->isRefinementAllowed(row == -1 ? 0 : row) && lError > markRLimit) {
52
      if ((maxRefineLevel == -1) || (elInfo->getLevel() < maxRefineLevel)) { 
Thomas Witkowski's avatar
Thomas Witkowski committed
53
54
	setMark(el, adaptInfo->getRefineBisections(row == -1 ? 0 : row));
      }
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    } else {
      if (adaptInfo->isCoarseningAllowed(row == -1 ? 0 : row) && lError <= markCLimit) {
	if (!el->getElementData()->getElementData(COARSENABLE) || 
	    (lError + el->getCoarseningEstimation(row)) <= markCLimit) {
	  setMark(el, -adaptInfo->getCoarseBisections(row == -1 ? 0 : row));
	}
      }
    }
  }

  Flag Marker::markMesh(AdaptInfo *adaptInfo, Mesh *mesh) {
    initMarking(adaptInfo, mesh);
    
    if (!adaptInfo->isCoarseningAllowed(row == -1 ? 0 : row) && 
	!adaptInfo->isRefinementAllowed(row == -1 ? 0 : row))  {
      return 0;
    }
    
    TraverseStack stack;
Thomas Witkowski's avatar
Thomas Witkowski committed
74
    ElInfo *elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL);
75
    while (elInfo) {
Thomas Witkowski's avatar
Thomas Witkowski committed
76
      markElement(adaptInfo, elInfo);
77
78
79
80
81
82
83
84
85
86
87
      elInfo = stack.traverseNext(elInfo);
    }
    
    finishMarking(adaptInfo);
    
    Flag markFlag;
    if (elMarkRefine) 
      markFlag = 1;
    if (elMarkCoarsen) 
      markFlag |= 2;

Thomas Witkowski's avatar
Thomas Witkowski committed
88
    return markFlag; 
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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
156
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
  } 


  void ESMarker::initMarking(AdaptInfo *adaptInfo, Mesh *mesh) {
    FUNCNAME("ESMarker::initMarking()");
    
    Marker::initMarking(adaptInfo, mesh);
    
    double ESThetaP = pow(ESTheta, p);
    double ESThetaCP = pow(ESThetaC, p);
    
    double epsP = pow(adaptInfo->getSpaceTolerance(row == -1 ? 0 : row), p);
    
    markRLimit = ESThetaP * epsP / mesh->getNumberOfLeaves();
    markCLimit = ESThetaCP * epsP / mesh->getNumberOfLeaves();
    
    INFO(info, 2)
      ("start mark_limits: %.3le %.3le nt=%d\n",
       markRLimit, markCLimit, mesh->getNumberOfLeaves());
  }

  Flag GERSMarker::markMesh(AdaptInfo *adaptInfo, Mesh *mesh) {
    FUNCNAME("GERSMarker::markMesh()");

    initMarking(adaptInfo, mesh);

    if (!adaptInfo->isCoarseningAllowed(row == -1 ? 0 : row) && 
	!adaptInfo->isRefinementAllowed(row == -1 ? 0 : row)) {
      return 0;
    }

    GERSSum = 0.0;

    double LTheta = pow(1.0 - GERSThetaStar, p);
    double improv, redfac, wanted, epsP, GERSGamma;
    
    epsP = pow(adaptInfo->getSpaceTolerance(row == -1 ? 0 : row), p);

    if (estSum < oldErrSum) {
      improv = estSum / oldErrSum;
      wanted = 0.8 * epsP / estSum;
      redfac = std::min((1.0 - wanted) / (1.0 - improv), 1.0);
      redfac = std::max(redfac, 0.0);
      
      if (redfac < 1.0) {
	LTheta *= redfac;
	INFO(info, 1)
	  ("GERS: use extrapolated theta_star = %lf\n",
	   pow(LTheta, 1.0 / p));
      }
    }

    oldErrSum = estSum;
    GERSGamma = 1.0;

    if (adaptInfo->isRefinementAllowed(row == -1 ? 0 : row)) {
      if (LTheta > 0) {
	do {
	  GERSSum = 0.0;	  
	  GERSGamma -= GERSNu;
	  markRLimit = GERSGamma * estMax;

	  TraverseStack stack;
	  ElInfo *elInfo = NULL;
	  elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL);
	  while (elInfo) {
	    markElementForRefinement(adaptInfo, elInfo);
	    elInfo = stack.traverseNext(elInfo);
	  }
	  
	} while((GERSGamma > 0) && (GERSSum < LTheta * estSum));
      }

      INFO(info, 2)
	("GERS refinement with gamma = %.3lf\n", GERSGamma);
    }

    if (adaptInfo->isCoarseningAllowed(row == -1 ? 0 : row)) {
      GERSGamma = 0.3;
      LTheta = GERSThetaC * epsP;
      
      do {
	GERSSum = 0.0;
	GERSGamma -= GERSNu;
	markCLimit = GERSGamma * estMax;
	
	TraverseStack stack;
	ElInfo *elInfo = NULL;
	elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL);
	while (elInfo) {
	  markElementForCoarsening(adaptInfo, elInfo);
	  elInfo = stack.traverseNext(elInfo);
	}

	INFO(info, 6)
	  ("coarse loop: gamma=%.3e, sum=%.3e, limit=%.3e\n",
	   GERSGamma, GERSSum, LTheta);
      } while(GERSSum > LTheta);
      
      INFO(info, 2)
	("GERS coarsening with gamma = %.3lf\n", GERSGamma);      
    }
    
    finishMarking(adaptInfo);
    
    Flag markFlag;
    if (elMarkRefine) 
      markFlag = 1;
    if (elMarkCoarsen) 
      markFlag |= 2;
      
    return(markFlag); 
  }

  void GERSMarker::markElementForRefinement(AdaptInfo *adaptInfo, ElInfo *elInfo) {
    Element *el = elInfo->getElement();
    double lError = el->getEstimation(row);

    if (lError > markRLimit) {
      GERSSum += lError;
      setMark(el, adaptInfo->getRefineBisections(row == -1 ? 0 : row));
    }
  }

  void GERSMarker::markElementForCoarsening(AdaptInfo *adaptInfo, ElInfo *elInfo) {
    Element *el = elInfo->getElement();
    double lError = el->getEstimation(row);
    
    if (el->getMark() <= 0) {
      if (el->getElementData()->getElementData(COARSENABLE)) {
	lError += el->getCoarseningEstimation(row);
      }
      
      if (lError <= markCLimit) {
	GERSSum += lError;
	setMark(el, -adaptInfo->getCoarseBisections(row == -1 ? 0 : row));
      } else {
	setMark(el, 0);
      }
    }
  }


232
233

}