Liebe Gitlab-Nutzerin, lieber Gitlab-Nutzer,
es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Die Konten der externen Nutzer:innen sind über den Reiter "Standard" erreichbar.
Die Administratoren


Dear Gitlab user,
it is now possible to log in to our service using the ZIH login/LDAP. The accounts of external users can be accessed via the "Standard" tab.
The administrators

DOFAdmin.h 8.13 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 229 230 231 232 233 234
    void setNumberOfDOFs(int i, int v);

    /// Sets all values of \ref nrDOF
    void setNumberOfDOFs(DimVec<int> v)
    {
      nrDOF = v;
    }
235

Thomas Witkowski's avatar
Thomas Witkowski committed
236
    /// Sets \ref nr0DOF[i] = v
237 238
    void setNumberOfPreDOFs(int i, int v);

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;

Thomas Witkowski's avatar
Thomas Witkowski committed
290
    /// number of used dof indices
291 292
    int usedCount;

Thomas Witkowski's avatar
Thomas Witkowski committed
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 304
     */
    DimVec<int> nrDOF;

Thomas Witkowski's avatar
Thomas Witkowski committed
305
    /// Dofs from previous DOFAdmins
306 307
    DimVec<int> nr0DOF;

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