ElementDofIterator.h 3.88 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
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file ElementDofIterator.h */

#ifndef AMDIS_ELEMENTDOFITERATOR_H
#define AMDIS_ELEMENTDOFITERATOR_H

#include "AMDiS_fwd.h"
#include "Global.h"

namespace AMDiS {

  /** \brief
   * This class implements an iterator to iterate over all dofs of one element
   * independet of dimension and the degree of basis functions.
   *
   * Should be used in the following way:
   *
   *    ElementDofIterator elDofIter(admin);
   *    elDofIter.reset(el);
   *    do {
   *       elDofIter.getDOF();
   *    } while (elDofIter.next());
   *
   */
  class ElementDofIterator
  {
  public:
    /// Constructor.
    ElementDofIterator(const DOFAdmin* dofAdmin)
      : admin(dofAdmin)
    {}

    /// Start a new traverse with the given element.
    void reset(Element* el);

    /// Go to next dof. Returns false, if there is dof anymore.
    bool next();

    /// Returns the dof index of the current dof.
    const DegreeOfFreedom getDof()
    {
      return dofs[node0 + elementPos][n0 + dofPos];
    }
    
    /// Returns a pointer to the current dof.
    const DegreeOfFreedom* getDofPtr()
    {
      return &dofs[node0 + elementPos][n0 + dofPos];
    }

  protected:
    /// The dof admin for which dofs should be traversed.
    const DOFAdmin* admin;

    /// Pointer to the dofs that should be traversed.
    const DegreeOfFreedom **dofs;

    /// Mesh on which the element is defined.
    Mesh* mesh;

    /// Dimension of the mesh.
    int dim;

    /// Current position (i.e., vertex, edge, face) of the traverse.
    int pos;

    /// Dimension dependent geo index of the current position in traverse.
    GeoIndex posIndex;

    /** \brief
     * Number of dofs at the current traverse position. Examples: independent of 
     * dimension and  degree of basis functions there is only one dof per vertex. 
     * But in 2d and with 3rd degree lagrange basis functions there are two 
     * dofs per edge.
     */
    int nDofs;

    /** \brief
     * Displacement of dof indices. Used of more than one dof admin is defined 
     * on the mesh.
     */
    int n0;

    /// Dof index of the first dof at this geo index position.
    int node0;
    
    /** \brief
     * Number of elements in the current geo position. Examples: 3 vertices in 2d,
     * 1 face in 2d, 4 faces in 3d, etc.
     */
    int nElements;

    /// Current element (vertex, edge, face) that is traversed.
    int elementPos;

    /// Currrent dof that is traversed on the current element;
    int dofPos;
  };
}

#endif // AMDIS_ELEMENTDOFITERATOR_H