ElementDofIterator.h 4.14 KB
Newer Older
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// 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.


20
21
22
23
24
25
26
27

/** \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
28
#include "Mesh.h"
29
30
31
32
33
34
35
36
37

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

    /// Start a new traverse with the given element.
58
    void reset(const Element* el);
59
60
61
62

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

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

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

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

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

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

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

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

107
108
109
110
111
112
113
114
115
    /// 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
116
117
118
119
    bool inOrder;

    int* orderPosition;

120
    const Element* element;
Thomas Witkowski's avatar
Thomas Witkowski committed
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
150
    /// 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
151
    /// Current element, i.e., ith vertex, edge or face, that is traversed.
152
153
154
155
156
157
158
159
    int elementPos;

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

#endif // AMDIS_ELEMENTDOFITERATOR_H