BoundaryManager.cc 6.02 KB
Newer Older
1
2
3
4
5
6
7
#include "FiniteElemSpace.h"
#include "BoundaryManager.h"
#include "DOFIndexed.h"
#include "DOFVector.h"
#include "Traverse.h"
#include "BasisFunction.h"
#include "ElInfo.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
8
#include "OpenMP.h"
9
10
11

namespace AMDiS {

Thomas Witkowski's avatar
Thomas Witkowski committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  BoundaryManager::BoundaryManager(const FiniteElemSpace *feSpace)
  {
    localBounds.resize(omp_get_max_threads());
    allocatedMemoryLocalBounds = feSpace->getBasisFcts()->getNumber();
    for (int i = 0; i < static_cast<int>(localBounds.size()); i++) {
      localBounds[i] = GET_MEMORY(BoundaryType, allocatedMemoryLocalBounds);
    }    
  }

  BoundaryManager::BoundaryManager(BoundaryManager &bm)
  {
    localBCs = bm.localBCs;
    allocatedMemoryLocalBounds = bm.allocatedMemoryLocalBounds;
    localBounds.resize(bm.localBounds.size());
    for (int i = 0; i < static_cast<int>(localBounds.size()); i++) {
      localBounds[i] = GET_MEMORY(BoundaryType, allocatedMemoryLocalBounds);
    }    
  }

  BoundaryManager::~BoundaryManager()
  {
    for (int i = 0; i < static_cast<int>(localBounds.size()); i++) {
      FREE_MEMORY(localBounds[i], BoundaryType, allocatedMemoryLocalBounds);
    }
  }

38
39
40
41
  double BoundaryManager::boundResidual(ElInfo *elInfo, 
					DOFMatrix *matrix,
					const DOFVectorBase<double> *dv)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
42
    double result = 0.0;
43
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
44
45
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second)
46
47
48
49
50
51
52
53
54
55
	result += (*it).second->boundResidual(elInfo, matrix, dv);
    }
    return result;
  }

  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, 
					       DOFVectorBase<double> *vec)
  {
    // ===== fill local conditions ==============================================
    const FiniteElemSpace *feSpace = vec->getFESpace();
56
57
58
59
    Vector<DegreeOfFreedom> dofIndices;
    const BasisFunction *basisFcts = feSpace->getBasisFcts();
    int nBasFcts = basisFcts->getNumber();
    DOFAdmin *admin = feSpace->getAdmin();
60

61
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
62

63
    if (localBCs.size() > 0) {
64
65

      // get boundaries of all DOFs
Thomas Witkowski's avatar
Thomas Witkowski committed
66
      BoundaryType *localBound = localBounds[omp_get_thread_num()];
67
      basisFcts->getBound(elInfo, localBound);
68
69

      // get dof indices
70
      basisFcts->getLocalIndicesVec(elInfo->getElement(), admin, &dofIndices);
71
72

      // apply non dirichlet boundary conditions
73
74
75
      for (it = localBCs.begin(); it != localBCs.end(); ++it) {
	if ((*it).second) {
	  if (!(*it).second->isDirichlet()) {
76
	    (*it).second->fillBoundaryCondition(vec, elInfo, &dofIndices[0], localBound, nBasFcts);
77
78
79
80
81
	  }
	}
      }

      // apply dirichlet boundary conditions
82
83
84
      for (it = localBCs.begin(); it != localBCs.end(); ++it) {
	if ((*it).second) {
	  if ((*it).second->isDirichlet()) {
85
	    (*it).second->fillBoundaryCondition(vec, elInfo, &dofIndices[0], localBound, nBasFcts);
86
87
88
89
90
91
92
93
94
95
96
	  }
	}
      }
    }
  }

  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, 
					       DOFMatrix *mat)
  {
    // ===== fill local conditions ==============================================
    const FiniteElemSpace *feSpace = mat->getRowFESpace();
97
98
99
100
    Vector<DegreeOfFreedom> dofIndices;
    const BasisFunction *basisFcts = feSpace->getBasisFcts();
    int nBasFcts = basisFcts->getNumber();
    DOFAdmin *admin = feSpace->getAdmin();
101

102
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
103
104
105

    if (localBCs.size() > 0) {
      // get boundaries of all DOFs
Thomas Witkowski's avatar
Thomas Witkowski committed
106
107
108
      BoundaryType *localBound = localBounds[omp_get_thread_num()];
      basisFcts->getBound(elInfo, localBound);

109
      // get dof indices
110
      basisFcts->getLocalIndicesVec(elInfo->getElement(), admin, &dofIndices);
111
112
113
114
115

      // apply non dirichlet boundary conditions
      for (it = localBCs.begin(); it != localBCs.end(); ++it) {
	if ((*it).second) {
	  if (!(*it).second->isDirichlet()) {
Thomas Witkowski's avatar
Thomas Witkowski committed
116
	    (*it).second->fillBoundaryCondition(mat, elInfo, &dofIndices[0], localBound, nBasFcts);
117
118
119
	  }
	}
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
120

121
122
123
124
      // apply dirichlet boundary conditions
      for (it = localBCs.begin(); it != localBCs.end(); ++it) {
	if ((*it).second) {
	  if ((*it).second->isDirichlet()) {
125
	    (*it).second->fillBoundaryCondition(mat, elInfo, &dofIndices[0], localBound, nBasFcts);
126
127
	  }
	}
128
      }      
129
130
131
132
133
    }
  }

  void BoundaryManager::initMatrix(DOFMatrix *matrix)
  {
134
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
135

136
137
138
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if (!(*it).second->isDirichlet()) {
139
140
141
142
	  (*it).second->initMatrix(matrix);
	}
      }
    }
143
144
145
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if ((*it).second->isDirichlet()) {
146
147
148
149
150
151
152
153
	  (*it).second->initMatrix(matrix);
	}
      }
    }
  }

  void BoundaryManager::exitMatrix(DOFMatrix *matrix)
  {
154
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
155
156
157
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if (!(*it).second->isDirichlet()) {
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
	  (*it).second->exitMatrix(matrix);
	}
      }
    }
    for(it = localBCs.begin(); it != localBCs.end(); ++it) {
      if((*it).second) {
	if((*it).second->isDirichlet()) {
	  (*it).second->exitMatrix(matrix);
	}
      }
    }
  }

  void BoundaryManager::initVector(DOFVectorBase<double> *vector)
  {
173
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    for(it = localBCs.begin(); it != localBCs.end(); ++it) {
      if((*it).second) {
	if(!(*it).second->isDirichlet()) {
	  (*it).second->initVector(vector);
	}
      }
    }
    for(it = localBCs.begin(); it != localBCs.end(); ++it) {
      if((*it).second) {
	if((*it).second->isDirichlet()) {
	  (*it).second->initVector(vector);
	}
      }
    }
  }

  void BoundaryManager::exitVector(DOFVectorBase<double> *vector)
  {
192
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
193
194
195
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if (!(*it).second->isDirichlet()) {
196
197
198
199
	  (*it).second->exitVector(vector);
	}
      }
    }
200
201
202
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if ((*it).second->isDirichlet()) {
203
204
205
206
207
208
209
	  (*it).second->exitVector(vector);
	}
      }
    }
  }

}