RefinementManager1d.cc 5 KB
Newer Older
1
2
3
4
5
6
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
#include "RefinementManager.h"
#include "Mesh.h"
#include "Traverse.h"
#include "ElInfo.h"
#include "DOFAdmin.h"
#include "AdaptStationary.h"
#include "AdaptInstationary.h"
#include "FixVec.h"
#include "RCNeighbourList.h"
#include "ProblemStatBase.h"
#include "DOFIndexed.h"
#include "Projection.h"

namespace AMDiS {

  int RefinementManager1d::recursiveRefineFunction(ElInfo* el_info)
  {
    Line       *el = dynamic_cast<Line*>(const_cast<Element*>( el_info->getElement())), *child[2];

    Mesh* mesh = el_info->getMesh();

    if(el_info->getProjection(0)) {
      traversePtr->newCoord(true);
    }

    if (el->getMark() <= 0)
      return 0;

    child[0] = dynamic_cast<Line*>( mesh->createNewElement(el));
    child[1] = dynamic_cast<Line*>( mesh->createNewElement(el));

    int mark = max(0, el->getMark() - 1);
    child[0]->setMark(mark);
    child[1]->setMark(mark);
    el->setMark(0);

    /*--------------------------------------------------------------------------*/
    /*  transfer hided data from parent to children                             */
    /*--------------------------------------------------------------------------*/

    el->refineElementData(child[0], child[1]);

    el->setFirstChild(child[0]);
    el->setSecondChild(child[1]);
  
    if (child[0]->getMark() > 0) traversePtr->doMoreRecursiveRefine = true;

    DegreeOfFreedom *newVertexDOFs = mesh->getDOF(VERTEX);
    child[0]->setDOF(1, newVertexDOFs);
    child[1]->setDOF(0, newVertexDOFs);

    /*--------------------------------------------------------------------------*/
    /*  the other vertices are handed on from the parent                        */
    /*--------------------------------------------------------------------------*/
    child[0]->setDOF(0, const_cast<int*>( el->getDOF(0)));
    child[1]->setDOF(1, const_cast<int*>( el->getDOF(1)));

    /*--------------------------------------------------------------------------*/
    /*  there is one more leaf element, two hierachical elements,               */
    /*  one more vertex                                                         */
    /*--------------------------------------------------------------------------*/

    mesh->incrementNumberOfLeaves(1);
    mesh->incrementNumberOfVertices(1);
    mesh->incrementNumberOfElements(2);

    if (mesh->getNumberOfDOFs(CENTER))
      {
	/*--------------------------------------------------------------------------*/
	/* there are dofs at the barycenter of the triangles                        */
	/*--------------------------------------------------------------------------*/
	child[0]->setDOF(mesh->getNode(CENTER), const_cast<int*>( mesh->getDOF(CENTER)));
	child[1]->setDOF(mesh->getNode(CENTER), const_cast<int*>( mesh->getDOF(CENTER)));
      }

    /*--------------------------------------------------------------------------*/
    /*  if there are functions to interpolate data to the finer grid, do so     */
    /*--------------------------------------------------------------------------*/
  
    RCNeighbourList  ref_list(1);  // = {{nil, 0, 0}};
    ref_list.setElement(0, el);
 
    int iadmin;
    int nrAdmin = mesh->getNumberOfDOFAdmin();
    for(iadmin = 0; iadmin < nrAdmin; iadmin++) {
      ::std::list<DOFIndexedBase*>::iterator it;
      DOFAdmin* admin = const_cast<DOFAdmin*>(&mesh->getDOFAdmin(iadmin));
      ::std::list<DOFIndexedBase*>::iterator end = admin->endDOFIndexed();
      for(it = admin->beginDOFIndexed(); it != end; it++)
	(*it)->refineInterpol(ref_list, 1);
    }

    if (!mesh->queryCoarseDOFs() && mesh->getNumberOfDOFs(CENTER))
      {
	mesh->freeDOF(const_cast<int*>( el->getDOF(mesh->getNode(CENTER))), CENTER);
	el->setDOF(mesh->getNode(CENTER), NULL);
      }

    return 0;
  }

  Flag RefinementManager1d::refineMesh(Mesh *aMesh)
  {
    int           n_elements;

    mesh = aMesh;

    n_elements = mesh->getNumberOfLeaves();

    doMoreRecursiveRefine = true;
    while (doMoreRecursiveRefine)
      {
	doMoreRecursiveRefine = false;
	traversePtr = this;
	mesh->traverse(-1, 
		       Mesh::CALL_LEAF_EL |
		       Mesh::FILL_BOUND |
		       Mesh::FILL_COORDS,
		       recursiveRefineFunction);
      }
  
    n_elements = mesh->getNumberOfLeaves() - n_elements;

    if(newCoords) {
      setNewCoords(); // call of sub-class method  
    }

    return(n_elements ? MESH_REFINED : Flag(0));
  }

  int RefinementManager1d::newCoordsFct(ElInfo *el_info)
  {
    Element *el = el_info->getElement();
    int j;
    int dow = Global::getGeo(WORLD);

    Projection *projector = el_info->getProjection(0);

    if (el->getFirstChild() && projector && (!el->isNewCoordSet()))
      {
	WorldVector<double> *new_coord = NEW WorldVector<double>;

	for (j = 0; j < dow; j++)
	  (*new_coord)[j] = (el_info->getCoord(0)[j] + el_info->getCoord(1)[j])*0.5;

	projector->project(*new_coord);

	el->setNewCoord(new_coord);
      }

    return 0;
  }

  void RefinementManager1d::setNewCoords()
  {
    Flag fillFlag = Mesh::CALL_EVERY_EL_PREORDER|
      Mesh::FILL_BOUND|
      Mesh::FILL_COORDS;
  
    mesh->traverse(-1, fillFlag, newCoordsFct);
  }

}