DOFAdmin.h 7.5 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
// ============================================================================
// ==                                                                        ==
// == 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

31
32
33
#include <vector>
#include <memory>
#include <list>
34
35
36
#include "Global.h"
#include "FixVec.h"
#include "Serializable.h"
37
#include "OpenMP.h"
38
#include "AMDiS_fwd.h"
39
40
41
42
43
44
45
46
47
48
49
50
51
52

namespace AMDiS {

  /** \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:
    DOFAdmin();

Thomas Witkowski's avatar
Thomas Witkowski committed
53
    /// Constructor
54
55
    DOFAdmin(Mesh* m);

Thomas Witkowski's avatar
Thomas Witkowski committed
56
    /// Constructor
57
    DOFAdmin(Mesh* m, std::string aName);
58

Thomas Witkowski's avatar
Thomas Witkowski committed
59
    /// Copy constructor
60
61
    DOFAdmin(const DOFAdmin&);

Thomas Witkowski's avatar
Thomas Witkowski committed
62
    /// Destructor
63
    ~DOFAdmin();
64
65
66
67
68
69
70

    /** \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
71
    /// assignment operator
72
73
    DOFAdmin& operator=(const DOFAdmin&);

Thomas Witkowski's avatar
Thomas Witkowski committed
74
    /// Compares two DOFAdmins by their names.
75
76
    bool operator==(const DOFAdmin&) const;

Thomas Witkowski's avatar
Thomas Witkowski committed
77
    /// Compares two DOFAdmins by their names.
78
79
    inline bool operator!=(const DOFAdmin& ad) const {
      return !(ad==*this);
80
    }
81
82
83
84
85
86
87
  
    /** \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
88
    /// Adds a DOFContainer object to the DOFAdmin.
89
90
    void addDOFContainer(DOFContainer* dofContainer);

Thomas Witkowski's avatar
Thomas Witkowski committed
91
    /// Removes the given DOFIndexedBase object from DOFAdmin.
92
93
    void removeDOFIndexed(DOFIndexedBase* dofIndexed);

Thomas Witkowski's avatar
Thomas Witkowski committed
94
    /// Removes the given DOFContainer object from DOFAdmin.
95
96
97
98
99
100
101
102
103
    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.
     */
104
    void compress(std::vector<DegreeOfFreedom> &new_dof);
105

Thomas Witkowski's avatar
Thomas Witkowski committed
106
    /// Returns an iterator to the begin of \ref dofIndexedList
107
    std::list<DOFIndexedBase*>::iterator beginDOFIndexed() {
108
      return dofIndexedList.begin();
109
    }
110

Thomas Witkowski's avatar
Thomas Witkowski committed
111
    /// Returns an iterator to the end of \ref dofIndexedList
112
    std::list<DOFIndexedBase*>::iterator endDOFIndexed() {
113
      return dofIndexedList.end();
114
    }
115
116
117
118
119

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

Thomas Witkowski's avatar
Thomas Witkowski committed
120
    /// Returns \ref sizeUsed.
121
122
    inline const int getUsedSize() const { 
      return sizeUsed; 
123
    }
124

Thomas Witkowski's avatar
Thomas Witkowski committed
125
    /// Returns \ref size
126
127
    inline const int getSize() const { 
      return size; 
128
    }
129

Thomas Witkowski's avatar
Thomas Witkowski committed
130
    /// Returns \ref usedCount
131
132
    inline const int getUsedDOFs() const { 
      return usedCount; 
133
    }
134

Thomas Witkowski's avatar
Thomas Witkowski committed
135
    /// Returns \ref holeCount
136
137
    inline const int getHoleCount() const { 
      return holeCount; 
138
    }
139

Thomas Witkowski's avatar
Thomas Witkowski committed
140
    /// Returns \ref name
141
    inline const std::string& getName() const { 
142
      return name; 
143
    }
144

Thomas Witkowski's avatar
Thomas Witkowski committed
145
    /// Returns \ref nrDOF[i], i.e., the number of dofs for the position i.
146
147
148
    inline const int getNumberOfDOFs(int i) const {
      return nrDOF[i];
    }
149
 
Thomas Witkowski's avatar
Thomas Witkowski committed
150
    /// Returns \ref nrDOF
151
152
    inline const DimVec<int>& getNumberOfDOFs() const { 
      return nrDOF; 
153
    }
154
 
Thomas Witkowski's avatar
Thomas Witkowski committed
155
    /// Returns \ref nr0DOF[i]
156
157
158
    inline const int getNumberOfPreDOFs(int i) const {
      return nr0DOF[i];
    }
159
 
Thomas Witkowski's avatar
Thomas Witkowski committed
160
    /// Returns \ref nr0DOF
161
162
    inline const DimVec<int>& getNumberOfPreDOFs() const { 
      return nr0DOF; 
163
    }
164

Thomas Witkowski's avatar
Thomas Witkowski committed
165
    /// Returns \ref mesh 
166
167
    inline const Mesh* getMesh() const { 
      return mesh; 
168
    }
169

Thomas Witkowski's avatar
Thomas Witkowski committed
170
    /// Returns \ref dofFree, the array denoting DOFs to be either free or used.
171
    inline const std::vector<bool>& getDOFFree() const { 
172
      return dofFree; 
173
    }
174

Thomas Witkowski's avatar
Thomas Witkowski committed
175
    /// Returns if the given DOF is free.
176
177
    inline const bool isDOFFree(int i) const {
      return dofFree[i];
178
    }
179
180
181
182
183
184
185

    /** \} */

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

Thomas Witkowski's avatar
Thomas Witkowski committed
186
    /// Sets \ref nrDOF[i] = v
187
    void setNumberOfDOFs(int i, int v); 
188

Thomas Witkowski's avatar
Thomas Witkowski committed
189
    /// Sets \ref nr0DOF[i] = v
190
191
    void setNumberOfPreDOFs(int i, int v);

Thomas Witkowski's avatar
Thomas Witkowski committed
192
    /// Sets \ref name = n
193
194
    inline void setName(const std::string& n) { 
      name = n; 
195
    }
196

Thomas Witkowski's avatar
Thomas Witkowski committed
197
    /// Sets \ref mesh = m
198
199
    inline void setMesh(Mesh* m) { 
      mesh = m; 
200
    }
201

202
203
    int calcMemoryUsage();

204
205
206
    /** \} */

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
207
    /// Initializes this DOFAdmin
208
209
210
211
212
213
214
215
    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
216
    /// Frees index dof. Used by Mesh::getDOF()
217
218
    void freeDOFIndex(int dof);

219
    ///
220
    void serialize(std::ostream &out);
221

222
    ///
223
    void deserialize(std::istream &in);
224
225

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
226
    /// name of this DOFAdmin
227
    std::string name;
228

Thomas Witkowski's avatar
Thomas Witkowski committed
229
    /// the mesh this DOFAdmin belongs to
230
231
    Mesh *mesh;

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

Thomas Witkowski's avatar
Thomas Witkowski committed
235
    /// index of the first free value in \ref dofFree
236
237
    int firstHole;   

Thomas Witkowski's avatar
Thomas Witkowski committed
238
    /// allocated size of managed vectors and matrices
239
240
    int size;

Thomas Witkowski's avatar
Thomas Witkowski committed
241
    /// number of used dof indices
242
243
    int usedCount;

Thomas Witkowski's avatar
Thomas Witkowski committed
244
    /// number of FREED dof indices (NOT size-sizeUsed)
245
246
    int holeCount;

Thomas Witkowski's avatar
Thomas Witkowski committed
247
    /// > max. index of a used entry
248
249
250
    int sizeUsed;

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
251
252
     * Number of dofs for each position, i.e., vertex, edge, ..., center, 
     * for this DOFAdmin.
253
254
255
     */
    DimVec<int> nrDOF;

Thomas Witkowski's avatar
Thomas Witkowski committed
256
    /// Dofs from previous DOFAdmins
257
258
    DimVec<int> nr0DOF;

Thomas Witkowski's avatar
Thomas Witkowski committed
259
    /// List of all managed DOFIndexed objects.
260
    std::list<DOFIndexedBase*> dofIndexedList;
261

Thomas Witkowski's avatar
Thomas Witkowski committed
262
    /// List of all managed DOFContainer objects
263
    std::list<DOFContainer*> dofContainerList;
264

Thomas Witkowski's avatar
Thomas Witkowski committed
265
    /// Size increment used by \ref enlargeDOFLists.
266
267
268
269
270
271
272
273
274
    static const int sizeIncrement; 

    friend class DOFIteratorBase;
    friend class Mesh;
  };

}

#endif  // AMDIS_DOFADMIN_H