ElementDofIterator.cc 3.12 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 39

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

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

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

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

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

55

56 57
  bool ElementDofIterator::next()
  {
58
    // First iterate over the dofs of one element (vertex, edge, face).
59 60 61 62 63 64 65 66 67 68 69
    dofPos++;

    if (dofPos >= nDofs) {
      // We are finished with all dofs of on element. Go to the next one.
      dofPos = 0;
      elementPos++;

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

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

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

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

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

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

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

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

100 101 102 103 104
	} else {
	  // That's all, we jave traversed all dofs of the mesh element.
	  return false;
	}

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

    return true;
Thomas Witkowski's avatar
Thomas Witkowski committed
113 114
  }

115

Thomas Witkowski's avatar
Thomas Witkowski committed
116 117 118 119 120
  bool ElementDofIterator::nextStrict()
  {
    dofPos = nDofs;
    return next();
  }
121
}