DOFAdmin.h 7.57 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 
    {
80
      return !(ad==*this);
81
    }
82
83
84
85
86
87
88
  
    /** \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
89
    /// Adds a DOFContainer object to the DOFAdmin.
90
91
    void addDOFContainer(DOFContainer* dofContainer);

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

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

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
123
    /// Returns \ref sizeUsed.
124
125
    inline const int getUsedSize() const 
    { 
126
      return sizeUsed; 
127
    }
128

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
147
    /// Returns \ref name
148
149
    inline const std::string& getName() const 
    { 
150
      return name; 
151
    }
152

Thomas Witkowski's avatar
Thomas Witkowski committed
153
    /// Returns \ref nrDOF[i], i.e., the number of dofs for the position i.
154
155
    inline const int getNumberOfDOFs(int i) const 
    {
156
157
      return nrDOF[i];
    }
158
 
Thomas Witkowski's avatar
Thomas Witkowski committed
159
    /// Returns \ref nrDOF
160
161
    inline const DimVec<int>& getNumberOfDOFs() const 
    { 
162
      return nrDOF; 
163
    }
164
 
Thomas Witkowski's avatar
Thomas Witkowski committed
165
    /// Returns \ref nr0DOF[i]
166
167
    inline const int getNumberOfPreDOFs(int i) const 
    {
168
169
      return nr0DOF[i];
    }
170
 
Thomas Witkowski's avatar
Thomas Witkowski committed
171
    /// Returns \ref nr0DOF
172
173
    inline const DimVec<int>& getNumberOfPreDOFs() const 
    { 
174
      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
184
    inline const std::vector<bool>& getDOFFree() const 
    { 
185
      return dofFree; 
186
    }
187

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

    /** \} */

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

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
212
    /// Sets \ref mesh = m
213
214
    inline void setMesh(Mesh* m) 
    { 
215
      mesh = m; 
216
    }
217

218
219
    int calcMemoryUsage();

220
221
222
    /** \} */

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
223
    /// Initializes this DOFAdmin
224
225
226
227
228
229
230
231
    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
232
    /// Frees index dof. Used by Mesh::getDOF()
233
234
    void freeDOFIndex(int dof);

235
    ///
236
    void serialize(std::ostream &out);
237

238
    ///
239
    void deserialize(std::istream &in);
240
241

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
242
    /// name of this DOFAdmin
243
    std::string name;
244

Thomas Witkowski's avatar
Thomas Witkowski committed
245
    /// the mesh this DOFAdmin belongs to
246
247
    Mesh *mesh;

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

Thomas Witkowski's avatar
Thomas Witkowski committed
251
    /// index of the first free value in \ref dofFree
252
253
    int firstHole;   

Thomas Witkowski's avatar
Thomas Witkowski committed
254
    /// allocated size of managed vectors and matrices
255
256
    int size;

Thomas Witkowski's avatar
Thomas Witkowski committed
257
    /// number of used dof indices
258
259
    int usedCount;

Thomas Witkowski's avatar
Thomas Witkowski committed
260
    /// number of FREED dof indices (NOT size-sizeUsed)
261
262
    int holeCount;

Thomas Witkowski's avatar
Thomas Witkowski committed
263
    /// > max. index of a used entry
264
265
266
    int sizeUsed;

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

Thomas Witkowski's avatar
Thomas Witkowski committed
272
    /// Dofs from previous DOFAdmins
273
274
    DimVec<int> nr0DOF;

Thomas Witkowski's avatar
Thomas Witkowski committed
275
    /// List of all managed DOFIndexed objects.
276
    std::list<DOFIndexedBase*> dofIndexedList;
277

Thomas Witkowski's avatar
Thomas Witkowski committed
278
    /// List of all managed DOFContainer objects
279
    std::list<DOFContainer*> dofContainerList;
280

Thomas Witkowski's avatar
Thomas Witkowski committed
281
    /// Size increment used by \ref enlargeDOFLists.
282
283
284
285
286
287
288
289
290
    static const int sizeIncrement; 

    friend class DOFIteratorBase;
    friend class Mesh;
  };

}

#endif  // AMDIS_DOFADMIN_H