ElementDofIterator.cc 3.14 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


13
14
15
16
#include "ElementDofIterator.h"
#include "Mesh.h"
#include "DOFAdmin.h"
#include "Element.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
17
#include "BasisFunction.h"
18
19
20

namespace AMDiS {

21
  void ElementDofIterator::reset(const Element* el)
22
23
24
  {
    FUNCNAME("ElementDofIterator::reset()");

Thomas Witkowski's avatar
Thomas Witkowski committed
25
26
27
28
29
    TEST_EXIT_DBG(el->getMesh() == mesh)
      ("Mesh and element does not fit together!\n");
    TEST_EXIT_DBG(el)("No element!\n");

    element = el;
30
    dofs = element->getDof();
31
32
33
34
35
36
37
38

    // Start with vertices.
    pos = 0;
    elementPos = 0;
    dofPos = 0;

    // Get geo index of vertices in the given dimension.
    posIndex = INDEX_OF_DIM(pos, dim);
39
    // Get number of DOFs per vertex (should be one in all cases).
40
    nDofs = admin->getNumberOfDofs(posIndex);
41
42
43

    TEST_EXIT_DBG(nDofs != 0)("Mh, I've to think about this situation!\n");

44
45
    // Calculate displacement. Is used if there is more than one DOF admin 
    // on the mesh.
46
    n0 = admin->getNumberOfPreDofs(posIndex);
47
    // Get first DOF index position for vertices.
48
49
50
    node0 = mesh->getNode(posIndex);
    // Get number of vertices in this dimension.
    nElements = Global::getGeo(posIndex, mesh->getDim());
Thomas Witkowski's avatar
Thomas Witkowski committed
51
52
53

    if (inOrder)
      orderPosition = basisFcts->orderOfPositionIndices(element, posIndex, 0);
54
55
  }

56

57
58
  bool ElementDofIterator::next()
  {
59
    // First iterate over the DOFs of one element (vertex, edge, face).
60
61
62
    dofPos++;

    if (dofPos >= nDofs) {
63
      // We are finished with all DOFs of on element. Go to the next one.
64
65
66
67
68
69
70
      dofPos = 0;
      elementPos++;

      if (elementPos >= nElements) {
	// We are finished with all element.
	elementPos = 0;

71
72
73
74
	// If we have iterated over all positions, we can finish the iteration.
	if (pos >= dim)
	  return false;

75
	// Increase position, i.e., go from vertices to edges to faces and search
76
	// for the next position with DOFs.
77
78
79
80
	do {
	  pos++;
	  // Get geo index posistion.
	  posIndex = INDEX_OF_DIM(pos, dim);
81
	  // Get number of DOFs in this position.
82
	  nDofs = admin->getNumberOfDofs(posIndex);
83
	} while (nDofs == 0 && pos < dim);
84

85
	if (nDofs > 0 && pos <= dim) {
86
	  // We have found on more position with DOFs.
87

88
89
	  // Get number of elements in this position, i.e, the number of 
	  // vertices, edges and faces in the given dimension.
90
	  nElements = Global::getGeo(posIndex, dim);
91

92
93
	  // Calculate displacement. Is used if there is more than one DOF 
	  // admin on the mesh.
94
	  n0 = admin->getNumberOfPreDofs(posIndex);
95

96
	  // Get first DOF index position for the geo index position.
97
	  node0 = mesh->getNode(posIndex);
Thomas Witkowski's avatar
Thomas Witkowski committed
98
99

	  if (inOrder)
100
101
	    orderPosition =
	      basisFcts->orderOfPositionIndices(element, posIndex, 0);
Thomas Witkowski's avatar
Thomas Witkowski committed
102

103
	} else {
104
	  // That's all, we jave traversed all DOFs of the mesh element.
105
106
107
	  return false;
	}

Thomas Witkowski's avatar
Thomas Witkowski committed
108
109
110
111
      } else {
	if (inOrder)
	  orderPosition = 
	    basisFcts->orderOfPositionIndices(element, posIndex, elementPos);
112
113
114
115
      }
    }

    return true;
Thomas Witkowski's avatar
Thomas Witkowski committed
116
117
  }

118

Thomas Witkowski's avatar
Thomas Witkowski committed
119
120
121
122
123
  bool ElementDofIterator::nextStrict()
  {
    dofPos = nDofs;
    return next();
  }
124
}