DOFAdmin.h 8.03 KB
Newer Older
1
2
3
4
5
6
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9
10
11
// ==  Institut für Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
12
13
14
15
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
16
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// ==                                                                        ==
// ============================================================================

/** \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

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

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
Thomas Witkowski's avatar
Thomas Witkowski committed
148
    inline std::string getName() const 
149
    { 
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 
    { 
180
      return mesh; 
181
    }
182

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

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

195
196
197
198
199
    /// Sets a DOF to be free or not.
    inline void setDOFFree(int i, bool b)
    {
      dofFree[i] = b;
    }
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
    
    /// Sets \ref usedSize.
    inline void setUsedSize(int i)
    {
      sizeUsed = i;
    }

    /// Sets \ref usedCount.
    inline void setUsedCount(int i)
    {
      usedCount = i;
    }

    /// Sets \ref firstHole
    inline void setFirstHole(int i)
    {
216
      TEST_EXIT_DBG(dofFree[i])("There is no hole!\n");
217
218
219

      firstHole = i;
    }
220

221
222
223
224
225
226
    /** \} */

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

Thomas Witkowski's avatar
Thomas Witkowski committed
227
    /// Sets \ref nrDOF[i] = v
228
    void setNumberOfDOFs(int i, int v); 
229

Thomas Witkowski's avatar
Thomas Witkowski committed
230
    /// Sets \ref nr0DOF[i] = v
231
232
    void setNumberOfPreDOFs(int i, int v);

Thomas Witkowski's avatar
Thomas Witkowski committed
233
    /// Sets \ref name = n
Thomas Witkowski's avatar
Thomas Witkowski committed
234
    inline void setName(std::string n) 
235
    { 
236
      name = n; 
237
    }
238

Thomas Witkowski's avatar
Thomas Witkowski committed
239
    /// Sets \ref mesh = m
240
241
    inline void setMesh(Mesh* m) 
    { 
242
      mesh = m; 
243
    }
244

245
246
    int calcMemoryUsage();

247
248
249
    /** \} */

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
250
    /// Initializes this DOFAdmin
251
252
253
254
255
256
257
258
    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
259
    /// Frees index dof. Used by Mesh::getDOF()
260
261
    void freeDOFIndex(int dof);

262
    ///
263
    void serialize(std::ostream &out);
264

265
    ///
266
    void deserialize(std::istream &in);
267
268

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
269
    /// name of this DOFAdmin
270
    std::string name;
271

Thomas Witkowski's avatar
Thomas Witkowski committed
272
    /// the mesh this DOFAdmin belongs to
273
274
    Mesh *mesh;

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

Thomas Witkowski's avatar
Thomas Witkowski committed
278
    /// index of the first free value in \ref dofFree
279
280
    int firstHole;   

Thomas Witkowski's avatar
Thomas Witkowski committed
281
    /// allocated size of managed vectors and matrices
282
283
    int size;

Thomas Witkowski's avatar
Thomas Witkowski committed
284
    /// number of used dof indices
285
286
    int usedCount;

Thomas Witkowski's avatar
Thomas Witkowski committed
287
    /// number of FREED dof indices (NOT size-sizeUsed)
288
289
    int holeCount;

Thomas Witkowski's avatar
Thomas Witkowski committed
290
    /// > max. index of a used entry
291
292
293
    int sizeUsed;

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
294
295
     * Number of dofs for each position, i.e., vertex, edge, ..., center, 
     * for this DOFAdmin.
296
297
298
     */
    DimVec<int> nrDOF;

Thomas Witkowski's avatar
Thomas Witkowski committed
299
    /// Dofs from previous DOFAdmins
300
301
    DimVec<int> nr0DOF;

Thomas Witkowski's avatar
Thomas Witkowski committed
302
    /// List of all managed DOFIndexed objects.
303
    std::list<DOFIndexedBase*> dofIndexedList;
304

Thomas Witkowski's avatar
Thomas Witkowski committed
305
    /// List of all managed DOFContainer objects
306
    std::list<DOFContainer*> dofContainerList;
307

Thomas Witkowski's avatar
Thomas Witkowski committed
308
    /// Size increment used by \ref enlargeDOFLists.
309
310
311
312
313
314
315
316
317
    static const int sizeIncrement; 

    friend class DOFIteratorBase;
    friend class Mesh;
  };

}

#endif  // AMDIS_DOFADMIN_H