DOFAdmin.h 7.47 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
28
29
30
31

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

32
33
34
#include <vector>
#include <memory>
#include <list>
35
36
37
#include "Global.h"
#include "FixVec.h"
#include "Serializable.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> &newDofIndex);
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
    inline int getUsedSize() const 
125
    { 
126
      return sizeUsed; 
127
    }
128

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
141
    /// Returns \ref holeCount
142
    inline int getHoleCount() const 
143
    { 
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

153
    /// Returns \ref nDof[i], i.e., the number of DOFs for the position i.
154
    inline int getNumberOfDofs(int i) const 
155
    {
156
      return nDof[i];
157
    }
158
 
159
    /// Returns \ref nDof
160
    inline const DimVec<int>& getNumberOfDofs() const 
161
    { 
162
      return nDof; 
163
    }
164
 
165
    /// Returns \ref nPreDof[i]
166
    inline int getNumberOfPreDofs(int i) const 
167
    {
168
      return nPreDof[i];
169
    }
170
 
171
172
    /// Returns \ref nPreDof
    inline const DimVec<int>& getNumberOfPreDofs() const 
173
    { 
174
      return nPreDof; 
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
    inline const std::vector<bool>& getDofFree() const 
185
    { 
186
      return dofFree; 
187
    }
188

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

195
    /// Sets a DOF to be free or not.
196
    inline void setDofFree(int i, bool b)
197
198
199
    {
      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
     * \{
     */

227
228
    /// Sets \ref nDof[i] = v
    void setNumberOfDofs(int i, int v);
229

230
231
    /// Sets all values of \ref nDof
    void setNumberOfDofs(DimVec<int> v)
232
    {
233
      nDof = v;
234
    }
235

236
237
    /// Sets \ref nPreDof[i] = v
    void setNumberOfPreDofs(int i, int v);
238

Thomas Witkowski's avatar
Thomas Witkowski committed
239
    /// Sets \ref name = n
Thomas Witkowski's avatar
Thomas Witkowski committed
240
    inline void setName(std::string n) 
241
    { 
242
      name = n; 
243
    }
244

Thomas Witkowski's avatar
Thomas Witkowski committed
245
    /// Sets \ref mesh = m
246
247
    inline void setMesh(Mesh* m) 
    { 
248
      mesh = m; 
249
    }
250

251
252
    int calcMemoryUsage();

253
254
255
    /** \} */

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
256
    /// Initializes this DOFAdmin
257
258
259
    void init();

    /** \brief
260
     * Adds one index to all DOF lists. Used by Mesh::getDof() to provide 
261
262
263
264
     * DOFS for a specific position
     */
    int getDOFIndex();

265
    /// Frees index DOF. Used by Mesh::getDof()
266
    void freeDofIndex(int dof);
267

268
    ///
269
    void serialize(std::ostream &out);
270

271
    ///
272
    void deserialize(std::istream &in);
273
274

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
275
    /// name of this DOFAdmin
276
    std::string name;
277

Thomas Witkowski's avatar
Thomas Witkowski committed
278
    /// the mesh this DOFAdmin belongs to
279
280
    Mesh *mesh;

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

Thomas Witkowski's avatar
Thomas Witkowski committed
284
    /// index of the first free value in \ref dofFree
285
286
    int firstHole;   

Thomas Witkowski's avatar
Thomas Witkowski committed
287
    /// allocated size of managed vectors and matrices
288
289
    int size;

290
    /// number of used DOF indices
291
292
    int usedCount;

293
    /// number of FREED DOF indices (NOT size - sizeUsed)
294
295
    int holeCount;

Thomas Witkowski's avatar
Thomas Witkowski committed
296
    /// > max. index of a used entry
297
298
299
    int sizeUsed;

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
300
301
     * Number of dofs for each position, i.e., vertex, edge, ..., center, 
     * for this DOFAdmin.
302
     */
303
    DimVec<int> nDof;
304

305
    /// DOFs from previous DOFAdmins
306
    DimVec<int> nPreDof;
307

Thomas Witkowski's avatar
Thomas Witkowski committed
308
    /// List of all managed DOFIndexed objects.
309
    std::list<DOFIndexedBase*> dofIndexedList;
310

Thomas Witkowski's avatar
Thomas Witkowski committed
311
    /// List of all managed DOFContainer objects
312
    std::list<DOFContainer*> dofContainerList;
313

Thomas Witkowski's avatar
Thomas Witkowski committed
314
    /// Size increment used by \ref enlargeDOFLists.
315
316
317
318
319
320
321
322
323
    static const int sizeIncrement; 

    friend class DOFIteratorBase;
    friend class Mesh;
  };

}

#endif  // AMDIS_DOFADMIN_H