ComponentTraverseInfo.h 5.85 KB
Newer Older
Thomas Witkowski's avatar
Thomas Witkowski committed
1
2
3
4
5
6
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
Thomas Witkowski's avatar
Thomas Witkowski committed
8
// ==                                                                        ==
9
10
11
// ==  Institut fr Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
Thomas Witkowski's avatar
Thomas Witkowski committed
12
13
14
15
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
16
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
Thomas Witkowski's avatar
Thomas Witkowski committed
17
18
19
20
21
22
23
24
25
// ==                                                                        ==
// ============================================================================

/** \file ComponentTraverseInfo.h */

#ifndef AMDIS_COMPONENTTRAVERSEINFO_H
#define AMDIS_COMPONENTTRAVERSEINFO_H

#include <vector>
26
#include "Global.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
27
28
29
30
31
32
33
34
#include "FiniteElemSpace.h"

namespace AMDiS {

  class SingleComponentInfo
  {      
  public:
    SingleComponentInfo()
35
36
37
      : rowFeSpace(NULL),
	colFeSpace(NULL),
	auxFeSpaces(0),
Thomas Witkowski's avatar
Thomas Witkowski committed
38
39
40
	status(0)
      {}
    
41
    void setFeSpace(FiniteElemSpace *row, FiniteElemSpace *col = NULL) 
Thomas Witkowski's avatar
Thomas Witkowski committed
42
    {
43
44
      rowFeSpace = row;
      colFeSpace = col;
Thomas Witkowski's avatar
Thomas Witkowski committed
45
46
    }
    
47
    void setAuxFeSpaces(std::vector<const FiniteElemSpace*> feSpaces) 
Thomas Witkowski's avatar
Thomas Witkowski committed
48
    {
49
      auxFeSpaces = feSpaces;
Thomas Witkowski's avatar
Thomas Witkowski committed
50
51
    }

52
    void addAuxFeSpace(const FiniteElemSpace *fe) 
Thomas Witkowski's avatar
Thomas Witkowski committed
53
    {
54
      auxFeSpaces.push_back(fe);
Thomas Witkowski's avatar
Thomas Witkowski committed
55
56
    }
    
57
    bool hasFeSpace() 
Thomas Witkowski's avatar
Thomas Witkowski committed
58
    {
59
      return rowFeSpace != NULL;
Thomas Witkowski's avatar
Thomas Witkowski committed
60
61
62
63
    }

    void updateStatus();
    
64
    int getNumAuxFeSpaces() 
Thomas Witkowski's avatar
Thomas Witkowski committed
65
    {
66
      return auxFeSpaces.size();
Thomas Witkowski's avatar
Thomas Witkowski committed
67
68
    }
    
69
    FiniteElemSpace *getRowFeSpace() 
Thomas Witkowski's avatar
Thomas Witkowski committed
70
    {
71
      return rowFeSpace;
Thomas Witkowski's avatar
Thomas Witkowski committed
72
73
    }
    
74
    FiniteElemSpace *getColFeSpace() 
Thomas Witkowski's avatar
Thomas Witkowski committed
75
    {
76
      return colFeSpace;
Thomas Witkowski's avatar
Thomas Witkowski committed
77
78
    }
    
79
    const FiniteElemSpace *getAuxFeSpace(int i) 
Thomas Witkowski's avatar
Thomas Witkowski committed
80
    {
81
      return ((i < static_cast<int>(auxFeSpaces.size())) ? auxFeSpaces[i] : NULL);
82
83
    }

84
    void setAuxFeSpace(const FiniteElemSpace* fe, int pos) 
Thomas Witkowski's avatar
Thomas Witkowski committed
85
    {
86
      auxFeSpaces[pos] = fe;
Thomas Witkowski's avatar
Thomas Witkowski committed
87
88
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
89
90
    int getStatus() 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
91
92
93
94
      return status;
    }
    
  protected:      
95
    FiniteElemSpace *rowFeSpace;
Thomas Witkowski's avatar
Thomas Witkowski committed
96
    
97
    FiniteElemSpace *colFeSpace;
Thomas Witkowski's avatar
Thomas Witkowski committed
98
    
99
    std::vector<const FiniteElemSpace*> auxFeSpaces;
Thomas Witkowski's avatar
Thomas Witkowski committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

    /// Status of the component, see the possible status flags below.
    int status;

  public:
    /// Single component status flag: empty component, no fe spaces
    static const int EMPTY;

    /// Single component status flag: row = col, no aux
    static const int EQ_SPACES_NO_AUX;

    /// Single component status flag: row = col = aux
    static const int EQ_SPACES_WITH_AUX;

    /// Single component status flag: row = col, different aux
    static const int EQ_SPACES_WITH_DIF_AUX;

    /// Single component status flag: row, col, no aux
    static const int DIF_SPACES_NO_AUX;

    /// Single component status flag: row, col, aux either equal to row or to col
    static const int DIF_SPACES_WITH_AUX;

    /// Single component status flag: row, col, aux (at least 3 different fe spaces)
    static const int DIF_SPACES_WITH_DIF_AUX;
  };

  
  class ComponentTraverseInfo
  {
  public: 
    ComponentTraverseInfo(int n) 
      : nComponents(n)
    {
      resize(n);
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
137
138
    void resize(int n) 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
139
140
141
142
143
      nComponents = n;

      matrixComponents.resize(n);
      vectorComponents.resize(n);

Thomas Witkowski's avatar
Thomas Witkowski committed
144
      for (int i = 0; i < n; i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
145
146
147
	matrixComponents[i].resize(n);
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
148
149
    void updateStatus() 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
150
      for (int i = 0; i < nComponents; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
151
	for (int j = 0; j < nComponents; j++)
Thomas Witkowski's avatar
Thomas Witkowski committed
152
	  matrixComponents[i][j].updateStatus();
Thomas Witkowski's avatar
Thomas Witkowski committed
153

Thomas Witkowski's avatar
Thomas Witkowski committed
154
155
156
157
	vectorComponents[i].updateStatus();
      }
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
158
159
    SingleComponentInfo &getMatrix(int row, int col) 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
160
161
162
      return matrixComponents[row][col];
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
163
164
    SingleComponentInfo &getVector(int row) 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
165
166
167
      return vectorComponents[row];
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
168
169
    int getStatus(int row, int col) 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
170
171
172
      return matrixComponents[row][col].getStatus();
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
173
174
    int getStatus(int row) 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
175
176
177
      return vectorComponents[row].getStatus();
    }

178
    const FiniteElemSpace* getAuxFeSpace(int row, int col) 
Thomas Witkowski's avatar
Thomas Witkowski committed
179
    {
180
      return matrixComponents[row][col].getAuxFeSpace(0);
Thomas Witkowski's avatar
Thomas Witkowski committed
181
182
    }

183
    const FiniteElemSpace* getAuxFeSpace(int row) 
Thomas Witkowski's avatar
Thomas Witkowski committed
184
    {
185
      return vectorComponents[row].getAuxFeSpace(0);
Thomas Witkowski's avatar
Thomas Witkowski committed
186
    }
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
    
    /** \brief
     * Returns the row FE space for a given row number, i.e., the FE space
     * of the diagonal matrix.
     *
     * \param[in]  row   Row number of the matrix line for which the FE space
     *                   should be returned.
     */    
    const FiniteElemSpace* getRowFeSpace(int row);


    /** \brief
     * Returns the non row FE space for a given row number. This is either the
     * col FE space of an off diagonal matrix or the aux fe space of another
     * matrix in the row or of the right hand side vector. If there is no non row
     * FE space, this function returns a null pointer.
     *
     * \param[in]  row   Row number of the matrix line for which the non FE space
     *                   should be returned.
     */
    const FiniteElemSpace* getNonRowFeSpace(int row);
Thomas Witkowski's avatar
Thomas Witkowski committed
208
209
210
211
212
213
214
215
216
217
218
219

  protected:
    int nComponents;

    std::vector<std::vector<SingleComponentInfo> > matrixComponents;

    std::vector<SingleComponentInfo> vectorComponents;
  };

}

#endif