CoarseningManager.cc 2.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "CoarseningManager.h"
#include "Mesh.h"
#include "AdaptStationary.h"
#include "AdaptInstationary.h"
#include "Traverse.h"
#include "MacroElement.h"
#include "RCNeighbourList.h"
#include "FixVec.h"

namespace AMDiS {

  Flag CoarseningManager::globalCoarsen(Mesh *aMesh, int mark)
  {
14
15
16
17
18
19
20
21
    if (mark >= 0) 
      return 0;

    TraverseStack stack;
    ElInfo *elInfo = stack.traverseFirst(aMesh, -1, Mesh::CALL_LEAF_EL);
    while (elInfo) {
      elInfo->getElement()->setMark(mark);
      elInfo = stack.traverseNext(elInfo);
22
    }
23
24
    
    return coarsenMesh(aMesh);
25
26
27
28
  }

  void CoarseningManager::spreadCoarsenMark()
  {
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    TraverseStack stack;
    ElInfo *elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_EVERY_EL_POSTORDER);
    while (elInfo) {
      Element *el = elInfo->getElement();

      if (el->getChild(0)) {
	// interior node of the tree
	signed char mark = max(el->getChild(0)->getMark(), el->getChild(1)->getMark());
	el->setMark(std::min(mark + 1, 0));
      } else {
	// leaf node of the tree                                 
	if (el->getMark() < 0) 
	  el->setMark(el->getMark() - 1);
      }

      elInfo = stack.traverseNext(elInfo);
    }
46
47
48
49
  }

  void CoarseningManager::cleanUpAfterCoarsen()
  {
50
51
52
53
54
55
56
    TraverseStack stack;
    ElInfo *elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL);
    while (elInfo) {
      Element *el = elInfo->getElement();
      el->setMark(max(el->getMark(), 0));
      elInfo = stack.traverseNext(elInfo);
    }
57
58
59
60
61
  }

  Flag CoarseningManager::coarsenMesh(Mesh *aMesh)
  {
    mesh = aMesh;
62
    int nElements = mesh->getNumberOfLeaves();
63
64
65

    spreadCoarsenMark();

66
    stack = new TraverseStack;
67
68
69

    do {
      doMore = false;
70
71
      ElInfo* el_info = 
	stack->traverseFirst(mesh, -1, Mesh::CALL_EVERY_EL_POSTORDER | Mesh::FILL_NEIGH);
72
      while (el_info) {
73
	coarsenFunction(el_info);
74
75
	el_info = stack->traverseNext(el_info);
      }
76
77
    } while (doMore);

78
    delete stack;
79
80
81

    cleanUpAfterCoarsen();

82
    nElements -= mesh->getNumberOfLeaves();
83

84
85
86
87
88
89
    if (nElements != 0) {
      aMesh->incChangeIndex();
      return MESH_COARSENED;
    } else {
      return Flag(0);
    }
90
91
92
  }

}