ElementDofIterator.h 4.74 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
// ============================================================================
// ==                                                                        ==
// == 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"
Thomas Witkowski's avatar
Thomas Witkowski committed
27
#include "Mesh.h"
28
29
30
31
32
33
34
35
36

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:
   *
37
   *    ElementDofIterator elDofIter(feSpace);
38
39
40
41
42
43
44
45
46
47
   *    elDofIter.reset(el);
   *    do {
   *       elDofIter.getDOF();
   *    } while (elDofIter.next());
   *
   */
  class ElementDofIterator
  {
  public:
    /// Constructor.
Thomas Witkowski's avatar
Thomas Witkowski committed
48
49
50
51
52
53
    ElementDofIterator(const FiniteElemSpace* feSpace, bool inOrderPos = false)
      : admin(feSpace->getAdmin()),
	basisFcts(feSpace->getBasisFcts()),
	mesh(feSpace->getMesh()),
	dim(mesh->getDim()),
	inOrder(inOrderPos)
54
55
56
57
58
59
60
61
    {}

    /// 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();

Thomas Witkowski's avatar
Thomas Witkowski committed
62
63
    bool nextStrict();

64
    /// Returns the dof index of the current dof.
65
    inline DegreeOfFreedom getDof()
66
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
67
68
69
70
      if (inOrder) 
	return dofs[node0 + elementPos][n0 + orderPosition[dofPos]];
      else
	return dofs[node0 + elementPos][n0 + dofPos];
71
72
73
    }
    
    /// Returns a pointer to the current dof.
Thomas Witkowski's avatar
Thomas Witkowski committed
74
    inline const DegreeOfFreedom* getDofPtr()
75
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
76
77
78
79
      if (inOrder)
	return &dofs[node0 + elementPos][n0 + orderPosition[dofPos]];
      else
	return &dofs[node0 + elementPos][n0 + dofPos];
80
81
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
82
    /// Returns \ref pos, the current position (vertex, edge, face) of the traverse.
Thomas Witkowski's avatar
Thomas Witkowski committed
83
    inline int getCurrentPos()
Thomas Witkowski's avatar
Thomas Witkowski committed
84
85
86
87
88
    {
      return pos;
    }

    /// Returns \ref elementPos, the number of vertex, edge or face that is traversed.
Thomas Witkowski's avatar
Thomas Witkowski committed
89
    inline int getCurrentElementPos()
Thomas Witkowski's avatar
Thomas Witkowski committed
90
91
92
93
    {
      return elementPos;
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
94
95
96
97
98
    inline GeoIndex getPosIndex()
    {
      return posIndex;
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
99
      
100
101
102
103
  protected:
    /// The dof admin for which dofs should be traversed.
    const DOFAdmin* admin;

Thomas Witkowski's avatar
Thomas Witkowski committed
104
105
    const BasisFunction* basisFcts;

106
107
108
109
110
111
112
113
114
    /// 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;

Thomas Witkowski's avatar
Thomas Witkowski committed
115
116
117
118
119
120
    bool inOrder;

    int* orderPosition;

    Element* element;

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
    /// 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;

Thomas Witkowski's avatar
Thomas Witkowski committed
150
    /// Current element, i.e., ith vertex, edge or face, that is traversed.
151
152
153
154
155
156
157
158
    int elementPos;

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

#endif // AMDIS_ELEMENTDOFITERATOR_H