DofComm.h 4.45 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
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ==  http://www.amdis-fem.org                                              ==
// ==                                                                        ==
// ============================================================================
//
// 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.



/** \file DofComm.h */

#ifndef AMDIS_DOF_COMM_H
#define AMDIS_DOF_COMM_H

#include <map>
27
#include "parallel/ParallelTypes.h"
28
29
30
31
32
33
34
35
36
37
#include "FiniteElemSpace.h"
#include "Global.h"

namespace AMDiS {

  using namespace std;

  class DofComm
  {
  public:
38
39
40
    DofComm() 
      : data(1)
    {}
41
42
43
    
    typedef map<const FiniteElemSpace*, DofContainer> FeMapType;
    typedef FeMapType::iterator FeMapIter;
44
    typedef map<int, FeMapType> DataType;
45
    typedef DataType::iterator DataIter;
46
47
    // meshLevel: map[rank -> map[feSpace -> DofContainer]]
    typedef vector<DataType> LevelDataType;
48

49
50
51
    inline DofContainer& getDofContainer(int rank, 
					 const FiniteElemSpace *feSpace, 
					 int level = 0)
52
    {
53
      return data[level][rank][feSpace];
54
55
    }

56
    void init(int n, vector<const FiniteElemSpace*> &fe)
57
    {
58
59
60
      nLevel = n;
      feSpaces = fe;

61
      data.clear();
62
      data.resize(nLevel);
63
64
    }

65
    DataType& getData(int level = 0)
66
    {
67
      return data[level];
68
69
    }

70
71
    int getNumberDofs(int level, const FiniteElemSpace *feSpace);

72
73
    void create(RankToBoundMap &boundary);

74
  protected:
75
    LevelDataType data;
76

77
78
79
80
    int nLevel;

    vector<const FiniteElemSpace*> feSpaces;

81
82
83
84
85
86
87
88
89
90
    friend class Iterator;

  public:
    class Iterator
    {
    public:
      Iterator(DofComm &dc,
	       const FiniteElemSpace *fe = NULL)
	: dofComm(dc),
	  dofCounter(-1),
91
92
	  traverseFeSpace(fe),
	  traverseLevel(0)
93
      {
94
95
	goFirst();
      }
96

97
98
99
100
101
102
103
104
105
      Iterator(DofComm &dc,
	       int level,
	       const FiniteElemSpace *fe = NULL)
	: dofComm(dc),
	  dofCounter(-1),
	  traverseFeSpace(fe),
	  traverseLevel(level)
      {
	goFirst();
106
107
108
109
      }

      inline bool end()
      {
110
	return (dataIter == dofComm.data[traverseLevel].end());
111
112
113
114
      }
      
      inline void nextRank()
      {
115
116
117
	do {
	  ++dataIter;
	} while (setNextFeMap() == false);
118
119
120
121
122
123
124
      }

      inline void nextFeSpace()
      {
	++feMapIter;
      }

125
126
127
128
      inline void next()
      {
	++feMapIter;
	if (feMapIter == dataIter->second.end()) {
129
130
131
	  do {
	    ++dataIter;
	  } while (setNextFeMap() == false);
132
133
134
135
136
137
	} else {
	  dofIter = feMapIter->second.begin();
	  dofCounter = 0;
	}
      }

138
139
140
141
142
143
144
145
146
147
148
149
      inline void beginDofIter(const FiniteElemSpace *fe = NULL)
      {
	FUNCNAME("DofComm::Iterator::beginDofIter()");

	if (fe != NULL) {
	  feMapIter = dataIter->second.begin();

	  while (feMapIter->first != fe &&
		 feMapIter != dataIter->second.end())
	    ++feMapIter;
	}

150
151
152
153
	if (feMapIter != dataIter->second.end()) {
	  dofIter = feMapIter->second.begin();
	  dofCounter = 0;
	}
154
155
156
157
      }

      inline bool endDofIter()
      {
158
159
160
	if (feMapIter == dataIter->second.end())
	  return true;

161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
	return (dofIter == feMapIter->second.end());
      }
      
      inline void nextDof()
      {
	++dofIter;
	++dofCounter;
      }

      inline int getRank()
      {
	return dataIter->first;
      }

      inline const FiniteElemSpace* getFeSpace()
      {
	return feMapIter->first;
      }

      inline DofContainer& getDofs()
      {
	return feMapIter->second;
      }

      inline const DegreeOfFreedom* getDof()
      {
	return *dofIter;
      }

      inline DegreeOfFreedom getDofIndex()
      {
	return **dofIter;
      }

      inline int getDofCounter()
      {
	return dofCounter;
      }

    protected:
201
202
203
204
205
206
207
208
      void goFirst()
      {
	dataIter = dofComm.data[traverseLevel].begin();

	while (setNextFeMap() == false)
	  ++dataIter;
      }

209
      bool setNextFeMap();
210
211
212
213
214
215
216
217
218
219
220
221
222

    protected:
      DofComm &dofComm;
      
      DofComm::DataIter dataIter;
      
      DofComm::FeMapIter feMapIter;

      DofContainer::iterator dofIter;

      int dofCounter;

      const FiniteElemSpace *traverseFeSpace;
223
224

      int traverseLevel;
225
226
227
228
229
230
231
232
    };


  };

}

#endif // AMDIS_DOF_COMM_H