ElementDofIterator.cc 3.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/
20 21


22 23 24 25
#include "ElementDofIterator.h"
#include "Mesh.h"
#include "DOFAdmin.h"
#include "Element.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
26
#include "BasisFunction.h"
27 28 29

namespace AMDiS {

30
  void ElementDofIterator::reset(const Element* el)
31
  {
32
    FUNCNAME_DBG("ElementDofIterator::reset()");
33

Thomas Witkowski's avatar
Thomas Witkowski committed
34 35 36 37 38
    TEST_EXIT_DBG(el->getMesh() == mesh)
      ("Mesh and element does not fit together!\n");
    TEST_EXIT_DBG(el)("No element!\n");

    element = el;
39
    dofs = element->getDof();
40 41 42 43 44 45 46 47

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

    // Get geo index of vertices in the given dimension.
    posIndex = INDEX_OF_DIM(pos, dim);
48
    // Get number of DOFs per vertex (should be one in all cases).
49
    nDofs = admin->getNumberOfDofs(posIndex);
50 51 52

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

53 54
    // Calculate displacement. Is used if there is more than one DOF admin 
    // on the mesh.
55
    n0 = admin->getNumberOfPreDofs(posIndex);
56
    // Get first DOF index position for vertices.
57 58 59
    node0 = mesh->getNode(posIndex);
    // Get number of vertices in this dimension.
    nElements = Global::getGeo(posIndex, mesh->getDim());
Thomas Witkowski's avatar
Thomas Witkowski committed
60 61 62

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

65

66 67
  bool ElementDofIterator::next()
  {
68
    // First iterate over the DOFs of one element (vertex, edge, face).
69 70 71
    dofPos++;

    if (dofPos >= nDofs) {
72
      // We are finished with all DOFs of on element. Go to the next one.
73 74 75 76 77 78 79
      dofPos = 0;
      elementPos++;

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

80 81 82 83
	// If we have iterated over all positions, we can finish the iteration.
	if (pos >= dim)
	  return false;

84
	// Increase position, i.e., go from vertices to edges to faces and search
85
	// for the next position with DOFs.
86 87 88 89
	do {
	  pos++;
	  // Get geo index posistion.
	  posIndex = INDEX_OF_DIM(pos, dim);
90
	  // Get number of DOFs in this position.
91
	  nDofs = admin->getNumberOfDofs(posIndex);
92
	} while (nDofs == 0 && pos < dim);
93

94
	if (nDofs > 0 && pos <= dim) {
95
	  // We have found on more position with DOFs.
96

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

101 102
	  // Calculate displacement. Is used if there is more than one DOF 
	  // admin on the mesh.
103
	  n0 = admin->getNumberOfPreDofs(posIndex);
104

105
	  // Get first DOF index position for the geo index position.
106
	  node0 = mesh->getNode(posIndex);
Thomas Witkowski's avatar
Thomas Witkowski committed
107 108

	  if (inOrder)
109 110
	    orderPosition =
	      basisFcts->orderOfPositionIndices(element, posIndex, 0);
Thomas Witkowski's avatar
Thomas Witkowski committed
111

112
	} else {
113
	  // That's all, we jave traversed all DOFs of the mesh element.
114 115 116
	  return false;
	}

Thomas Witkowski's avatar
Thomas Witkowski committed
117 118 119 120
      } else {
	if (inOrder)
	  orderPosition = 
	    basisFcts->orderOfPositionIndices(element, posIndex, elementPos);
121 122 123 124
      }
    }

    return true;
Thomas Witkowski's avatar
Thomas Witkowski committed
125 126
  }

127

Thomas Witkowski's avatar
Thomas Witkowski committed
128 129 130 131 132
  bool ElementDofIterator::nextStrict()
  {
    dofPos = nDofs;
    return next();
  }
133
}