DOFAdmin.h 7.66 KB
Newer Older
1
2
3
4
5
6
7
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
8
 * Authors:
9
10
11
12
13
14
15
16
17
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
18
 *
19
 ******************************************************************************/
20
21


22
23
24
25
26
27
28
29
30
31
32
33

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

34
35
36
#include <vector>
#include <memory>
#include <list>
37
38
39
#include "Global.h"
#include "FixVec.h"
#include "Serializable.h"
40
#include "AMDiS_fwd.h"
41
42
43
44
45
46
47

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
48
   * objects, that are automatically resized and resorted during mesh changes.
49
50
51
52
53
54
   */
  class DOFAdmin : public Serializable
  {
  public:
    DOFAdmin();

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
64
    /// Destructor
65
    ~DOFAdmin();
66
67

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

Thomas Witkowski's avatar
Thomas Witkowski committed
73
    /// assignment operator
74
75
    DOFAdmin& operator=(const DOFAdmin&);

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

Thomas Witkowski's avatar
Thomas Witkowski committed
79
    /// Compares two DOFAdmins by their names.
80
    inline bool operator!=(const DOFAdmin& ad) const
81
    {
82
      return !(ad == *this);
83
    }
84

85
86
87
88
89
90
    /** \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
91
    /// Adds a DOFContainer object to the DOFAdmin.
92
93
    void addDOFContainer(DOFContainer* dofContainer);

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

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

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
125
    /// Returns \ref sizeUsed.
126
127
128
    inline DofIndex::size_type getUsedSize() const
    {
      return sizeUsed;
129
    }
130

Thomas Witkowski's avatar
Thomas Witkowski committed
131
    /// Returns \ref size
132
    inline DofIndex::size_type getSize() const
133
134
    {
      return size;
135
    }
136

Thomas Witkowski's avatar
Thomas Witkowski committed
137
    /// Returns \ref usedCount
138
139
140
    inline DofIndex::size_type getUsedDofs() const
    {
      return usedCount;
141
    }
142

Thomas Witkowski's avatar
Thomas Witkowski committed
143
    /// Returns \ref holeCount
144
145
146
    inline DofIndex::size_type getHoleCount() const
    {
      return holeCount;
147
    }
148

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

155
    /// Returns \ref nDof[i], i.e., the number of DOFs for the position i.
156
    inline int getNumberOfDofs(int i) const
157
    {
158
      return nDof[i];
159
    }
160

161
    /// Returns \ref nDof
162
163
164
    inline const DimVec<int>& getNumberOfDofs() const
    {
      return nDof;
165
    }
166

167
    /// Returns \ref nPreDof[i]
168
    inline int getNumberOfPreDofs(int i) const
169
    {
170
      return nPreDof[i];
171
    }
172

173
    /// Returns \ref nPreDof
174
175
176
    inline const DimVec<int>& getNumberOfPreDofs() const
    {
      return nPreDof;
177
    }
178

179
180
181
182
    /// Returns \ref mesh
    inline const Mesh* getMesh() const
    {
      return mesh;
183
    }
184

Praetorius, Simon's avatar
Praetorius, Simon committed
185
186
187
188
189
190
    /// Returns \ref mesh
    inline Mesh* getMesh()
    {
      return mesh;
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
191
    /// Returns \ref dofFree, the array denoting DOFs to be either free or used.
192
193
194
    inline const std::vector<bool>& getDofFree() const
    {
      return dofFree;
195
    }
196

Thomas Witkowski's avatar
Thomas Witkowski committed
197
    /// Returns if the given DOF is free.
198
    inline bool isDofFree(DofIndex::size_type i) const
199
    {
200
      return dofFree[i];
201
    }
202

203
    /// Sets a DOF to be free or not.
204
    inline void setDofFree(DofIndex::size_type i, bool b)
205
206
207
    {
      dofFree[i] = b;
    }
208

209
    /// Sets \ref usedSize.
210
    inline void setUsedSize(DofIndex::size_type i)
211
212
213
214
215
    {
      sizeUsed = i;
    }

    /// Sets \ref usedCount.
216
    inline void setUsedCount(DofIndex::size_type i)
217
218
219
220
221
    {
      usedCount = i;
    }

    /// Sets \ref firstHole
222
    inline void setFirstHole(DofIndex::size_type i)
223
    {
224
      TEST_EXIT_DBG(dofFree[i])("There is no hole!\n");
225
226
227

      firstHole = i;
    }
228

229
230
231
232
233
234
    /** \} */

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

235
236
    /// Sets \ref nDof[i] = v
    void setNumberOfDofs(int i, int v);
237

238
239
    /// Sets all values of \ref nDof
    void setNumberOfDofs(DimVec<int> v)
240
    {
241
      nDof = v;
242
    }
243

244
245
    /// Sets \ref nPreDof[i] = v
    void setNumberOfPreDofs(int i, int v);
246

Thomas Witkowski's avatar
Thomas Witkowski committed
247
    /// Sets \ref name = n
248
249
250
    inline void setName(std::string n)
    {
      name = n;
251
    }
252

Thomas Witkowski's avatar
Thomas Witkowski committed
253
    /// Sets \ref mesh = m
254
255
256
    inline void setMesh(Mesh* m)
    {
      mesh = m;
257
    }
258

259
    int calcMemoryUsage();
260

261
262
263
264
    void reset()
    {
      init();
    }
265

266
267
268
    /** \} */

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
269
    /// Initializes this DOFAdmin
270
271
272
    void init();

    /** \brief
273
     * Adds one index to all DOF lists. Used by Mesh::getDof() to provide
274
275
     * DOFS for a specific position
     */
276
    DegreeOfFreedom getDOFIndex();
277

278
    /// Frees index DOF. Used by Mesh::getDof()
279
    void freeDofIndex(DegreeOfFreedom dof);
280

281
    ///
282
    void serialize(std::ostream &out);
283

284
    ///
285
    void deserialize(std::istream &in);
286
287

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
288
    /// name of this DOFAdmin
289
    std::string name;
290

Thomas Witkowski's avatar
Thomas Witkowski committed
291
    /// the mesh this DOFAdmin belongs to
292
293
    Mesh *mesh;

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

Thomas Witkowski's avatar
Thomas Witkowski committed
297
    /// index of the first free value in \ref dofFree
298
    DegreeOfFreedom firstHole;
299

Thomas Witkowski's avatar
Thomas Witkowski committed
300
    /// allocated size of managed vectors and matrices
301
    DofIndex::size_type size;
302

303
    /// number of used DOF indices
304
    DofIndex::size_type usedCount;
305

306
    /// number of FREED DOF indices (NOT size - sizeUsed)
307
    DofIndex::size_type holeCount;
308

Thomas Witkowski's avatar
Thomas Witkowski committed
309
    /// > max. index of a used entry
310
    DofIndex::size_type sizeUsed;
311
312

    /** \brief
313
     * Number of dofs for each position, i.e., vertex, edge, ..., center,
Thomas Witkowski's avatar
Thomas Witkowski committed
314
     * for this DOFAdmin.
315
     */
316
    DimVec<int> nDof;
317

318
    /// DOFs from previous DOFAdmins
319
    DimVec<int> nPreDof;
320

Thomas Witkowski's avatar
Thomas Witkowski committed
321
    /// List of all managed DOFIndexed objects.
322
    std::list<DOFIndexedBase*> dofIndexedList;
323

Thomas Witkowski's avatar
Thomas Witkowski committed
324
    /// List of all managed DOFContainer objects
325
    std::list<DOFContainer*> dofContainerList;
326

Thomas Witkowski's avatar
Thomas Witkowski committed
327
    /// Size increment used by \ref enlargeDOFLists.
328
    static const int sizeIncrement;
329
330
331
332
333
334
335

    friend class DOFIteratorBase;
    friend class Mesh;
  };

}

336
#endif  // AMDIS_DOFADMIN_H