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

/** \file DOFAdmin.h */

/** \defgroup DOFAdministration DOF adaministration module
 * @{ <img src="dof.png"> @}
 * \brief
 * Contains all classes used for the DOF administration.
 */

#ifndef AMDIS_DOFADMIN_H
#define AMDIS_DOFADMIN_H

#include "Global.h"
#include "FixVec.h"
#include "MemoryManager.h"
#include "Serializable.h"
35
#include "OpenMP.h"
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
#include <vector>
#include <memory>
#include <list>

namespace AMDiS {

  class Mesh;
  class FiniteElemSpace;
  class ElInfo;
  class DOFAdmin;
  class BasisFunction;
  class DOFIndexedBase;
  class DOFContainer;

  template<typename T> class DOFVector;

  /** \ingroup DOFAdministration
   * \brief
   * Holds all data about one set of DOFs. It includes information about used and
   * unused DOF indices, as well as lists of DOFIndexed objects and DOFContainer
   * objects, that are automatically resized and resorted during mesh changes. 
   */
  class DOFAdmin : public Serializable
  {
  public:
    MEMORY_MANAGED(DOFAdmin);

    DOFAdmin();

Thomas Witkowski's avatar
Thomas Witkowski committed
65
    /// Constructor
66
67
    DOFAdmin(Mesh* m);

Thomas Witkowski's avatar
Thomas Witkowski committed
68
    /// Constructor
69
    DOFAdmin(Mesh* m, std::string aName);
70

Thomas Witkowski's avatar
Thomas Witkowski committed
71
    /// Copy constructor
72
73
    DOFAdmin(const DOFAdmin&);

Thomas Witkowski's avatar
Thomas Witkowski committed
74
    /// Destructor
75
    ~DOFAdmin();
76
77
78
79
80
81
82

    /** \brief
     * Enlarges the number of DOFs that can be managed at least to minsize by 
     * a step size of \ref sizeIncrement.
     */
    void enlargeDOFLists(int minsize);

Thomas Witkowski's avatar
Thomas Witkowski committed
83
    /// assignment operator
84
85
    DOFAdmin& operator=(const DOFAdmin&);

Thomas Witkowski's avatar
Thomas Witkowski committed
86
    /// Compares two DOFAdmins by their names.
87
88
    bool operator==(const DOFAdmin&) const;

Thomas Witkowski's avatar
Thomas Witkowski committed
89
    /// Compares two DOFAdmins by their names.
90
91
    inline bool operator!=(const DOFAdmin& ad) const {
      return !(ad==*this);
92
    }
93
94
95
96
97
98
99
  
    /** \brief
     * Adds a DOFIndexedBase object to the DOFAdmin. This object will be
     * managed by DOFAdmin from now on.
     */
    void addDOFIndexed(DOFIndexedBase* dofIndexed);

Thomas Witkowski's avatar
Thomas Witkowski committed
100
    /// Adds a DOFContainer object to the DOFAdmin.
101
102
    void addDOFContainer(DOFContainer* dofContainer);

Thomas Witkowski's avatar
Thomas Witkowski committed
103
    /// Removes the given DOFIndexedBase object from DOFAdmin.
104
105
    void removeDOFIndexed(DOFIndexedBase* dofIndexed);

Thomas Witkowski's avatar
Thomas Witkowski committed
106
    /// Removes the given DOFContainer object from DOFAdmin.
107
108
109
110
111
112
113
114
115
    void removeDOFContainer(DOFContainer* dofContainer);

    /** \brief
     * Removes all holes of unused DOF indices by compressing the used range of
     * indices (it does not resize the vectors). While the global index of a DOF
     * may change, the relative order of DOF indices remains unchanged during
     * compression. This method is usually called after mesh adaption involving
     * higher order elements or coarsening.
     */
116
    void compress(std::vector<DegreeOfFreedom> &new_dof);
117

Thomas Witkowski's avatar
Thomas Witkowski committed
118
    /// Returns an iterator to the begin of \ref dofIndexedList
119
    std::list<DOFIndexedBase*>::iterator beginDOFIndexed() {
120
      return dofIndexedList.begin();
121
    }
122

Thomas Witkowski's avatar
Thomas Witkowski committed
123
    /// Returns an iterator to the end of \ref dofIndexedList
124
    std::list<DOFIndexedBase*>::iterator endDOFIndexed() {
125
      return dofIndexedList.end();
126
    }
127
128
129
130
131

    /** \name getting methods
     * \{
     */

Thomas Witkowski's avatar
Thomas Witkowski committed
132
    /// Returns \ref sizeUsed.
133
134
    inline const int getUsedSize() const { 
      return sizeUsed; 
135
    }
136

Thomas Witkowski's avatar
Thomas Witkowski committed
137
    /// Returns \ref size
138
139
    inline const int getSize() const { 
      return size; 
140
    }
141

Thomas Witkowski's avatar
Thomas Witkowski committed
142
    /// Returns \ref usedCount
143
144
    inline const int getUsedDOFs() const { 
      return usedCount; 
145
    }
146

Thomas Witkowski's avatar
Thomas Witkowski committed
147
    /// Returns \ref holeCount
148
149
    inline const int getHoleCount() const { 
      return holeCount; 
150
    }
151

Thomas Witkowski's avatar
Thomas Witkowski committed
152
    /// Returns \ref name
153
    inline const std::string& getName() const { 
154
      return name; 
155
    }
156

Thomas Witkowski's avatar
Thomas Witkowski committed
157
    /// Returns \ref nrDOF[i], i.e., the number of dofs for the position i.
158
159
160
    inline const int getNumberOfDOFs(int i) const {
      return nrDOF[i];
    }
161
 
Thomas Witkowski's avatar
Thomas Witkowski committed
162
    /// Returns \ref nrDOF
163
164
    inline const DimVec<int>& getNumberOfDOFs() const { 
      return nrDOF; 
165
    }
166
 
Thomas Witkowski's avatar
Thomas Witkowski committed
167
    /// Returns \ref nr0DOF[i]
168
169
170
    inline const int getNumberOfPreDOFs(int i) const {
      return nr0DOF[i];
    }
171
 
Thomas Witkowski's avatar
Thomas Witkowski committed
172
    /// Returns \ref nr0DOF
173
174
    inline const DimVec<int>& getNumberOfPreDOFs() const { 
      return nr0DOF; 
175
    }
176

Thomas Witkowski's avatar
Thomas Witkowski committed
177
    /// Returns \ref mesh 
178
179
    inline const Mesh* getMesh() const { 
      return mesh; 
180
    }
181

Thomas Witkowski's avatar
Thomas Witkowski committed
182
    /// Returns \ref dofFree, the array denoting DOFs to be either free or used.
183
    inline const std::vector<bool>& getDOFFree() const { 
184
      return dofFree; 
185
    }
186

Thomas Witkowski's avatar
Thomas Witkowski committed
187
    /// Returns if the given DOF is free.
188
189
    inline const bool isDOFFree(int i) const {
      return dofFree[i];
190
    }
191
192
193
194
195
196
197

    /** \} */

    /** \name setting methods
     * \{
     */

Thomas Witkowski's avatar
Thomas Witkowski committed
198
    /// Sets \ref nrDOF[i] = v
199
    void setNumberOfDOFs(int i, int v); 
200

Thomas Witkowski's avatar
Thomas Witkowski committed
201
    /// Sets \ref nr0DOF[i] = v
202
203
    void setNumberOfPreDOFs(int i, int v);

Thomas Witkowski's avatar
Thomas Witkowski committed
204
    /// Sets \ref name = n
205
206
    inline void setName(const std::string& n) { 
      name = n; 
207
    }
208

Thomas Witkowski's avatar
Thomas Witkowski committed
209
    /// Sets \ref mesh = m
210
211
    inline void setMesh(Mesh* m) { 
      mesh = m; 
212
    }
213

214
215
    int calcMemoryUsage();

216
217
218
    /** \} */

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
219
    /// Initializes this DOFAdmin
220
221
222
223
224
225
226
227
    void init();

    /** \brief
     * Adds one index to all DOF lists. Used by Mesh::getDOF() to provide 
     * DOFS for a specific position
     */
    int getDOFIndex();

Thomas Witkowski's avatar
Thomas Witkowski committed
228
    /// Frees index dof. Used by Mesh::getDOF()
229
230
    void freeDOFIndex(int dof);

231
    ///
232
    void serialize(std::ostream &out);
233

234
    ///
235
    void deserialize(std::istream &in);
236
237

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
238
    /// name of this DOFAdmin
239
    std::string name;
240

Thomas Witkowski's avatar
Thomas Witkowski committed
241
    /// the mesh this DOFAdmin belongs to
242
243
    Mesh *mesh;

Thomas Witkowski's avatar
Thomas Witkowski committed
244
    /// The dofFree vector stores for each index whether it is used or not
245
    std::vector<bool> dofFree;
246

Thomas Witkowski's avatar
Thomas Witkowski committed
247
    /// index of the first free value in \ref dofFree
248
249
    int firstHole;   

Thomas Witkowski's avatar
Thomas Witkowski committed
250
    /// allocated size of managed vectors and matrices
251
252
    int size;

Thomas Witkowski's avatar
Thomas Witkowski committed
253
    /// number of used dof indices
254
255
    int usedCount;

Thomas Witkowski's avatar
Thomas Witkowski committed
256
    /// number of FREED dof indices (NOT size-sizeUsed)
257
258
    int holeCount;

Thomas Witkowski's avatar
Thomas Witkowski committed
259
    /// > max. index of a used entry
260
261
262
    int sizeUsed;

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
263
264
     * Number of dofs for each position, i.e., vertex, edge, ..., center, 
     * for this DOFAdmin.
265
266
267
     */
    DimVec<int> nrDOF;

Thomas Witkowski's avatar
Thomas Witkowski committed
268
    /// Dofs from previous DOFAdmins
269
270
    DimVec<int> nr0DOF;

Thomas Witkowski's avatar
Thomas Witkowski committed
271
    /// List of all managed DOFIndexed objects.
272
    std::list<DOFIndexedBase*> dofIndexedList;
273

Thomas Witkowski's avatar
Thomas Witkowski committed
274
    /// List of all managed DOFContainer objects
275
    std::list<DOFContainer*> dofContainerList;
276

Thomas Witkowski's avatar
Thomas Witkowski committed
277
    /// Size increment used by \ref enlargeDOFLists.
278
279
280
281
282
283
284
285
286
    static const int sizeIncrement; 

    friend class DOFIteratorBase;
    friend class Mesh;
  };

}

#endif  // AMDIS_DOFADMIN_H