ElementDofIterator.h 4.45 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

namespace AMDiS {

  /** \brief
33
   * This class implements an iterator to iterate over all DOFs of one element
34
35
36
37
   * 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
    /// Go to next DOF. Returns false, if there is no DOF anymore.
61
62
    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
    }

83
84
    /// Returns a pointer to the starting position of the current DOF
    /// array. Makes only sence, if \ref nextStrict() is used for traverse.
85
    inline const DegreeOfFreedom* getBaseDof()
86
87
88
89
90
91
    {
      return dofs[node0 + elementPos];
    }

    /// Returns \ref pos, the current position (vertex, edge, face) of 
    /// the traverse.
Thomas Witkowski's avatar
Thomas Witkowski committed
92
    inline int getCurrentPos()
Thomas Witkowski's avatar
Thomas Witkowski committed
93
94
95
96
    {
      return pos;
    }

97
98
99
100
101
102
    /// Returns \ref node0
    inline int getCurrentNode0()
    {
      return node0;
    }

103
104
    /// Returns \ref elementPos, the number of vertex, edge or face that 
    /// is traversed.
Thomas Witkowski's avatar
Thomas Witkowski committed
105
    inline int getCurrentElementPos()
Thomas Witkowski's avatar
Thomas Witkowski committed
106
107
108
109
    {
      return elementPos;
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
110
111
112
113
114
    inline GeoIndex getPosIndex()
    {
      return posIndex;
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
115
      
116
  protected:
117
    /// The DOF admin for which DOFs should be traversed.
118
119
    const DOFAdmin* admin;

Thomas Witkowski's avatar
Thomas Witkowski committed
120
121
    const BasisFunction* basisFcts;

122
    /// Pointer to the DOFs that should be traversed.
123
124
125
126
127
128
129
130
    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
131
132
133
134
    bool inOrder;

    int* orderPosition;

135
    const Element* element;
Thomas Witkowski's avatar
Thomas Witkowski committed
136

137
138
139
140
141
142
143
    /// 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
144
145
146
147
     * 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.
148
149
150
     */
    int nDofs;

151
152
    /// Displacement of DOF indices. Used if more than one DOF admin is defined 
    /// on the mesh.
153
154
    int n0;

155
    /// DOF index of the first DOF at this geo index position.
156
157
    int node0;
    
158
159
    /// Number of elements in the current geo position. Examples: 3 vertices in
    /// 2d, 1 face in 2d, 4 faces in 3d, etc.
160
161
    int nElements;

Thomas Witkowski's avatar
Thomas Witkowski committed
162
    /// Current element, i.e., ith vertex, edge or face, that is traversed.
163
164
    int elementPos;

165
    /// Currrent DOF that is traversed on the current element;
166
167
168
169
170
    int dofPos;
  };
}

#endif // AMDIS_ELEMENTDOFITERATOR_H