BoundaryManager.cc 5.88 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
  BoundaryManager::BoundaryManager(const FiniteElemSpace *feSpace)
  {
14
    localBounds.resize(omp_get_overall_max_threads());
15
    dofIndices.resize(omp_get_overall_max_threads());
Thomas Witkowski's avatar
Thomas Witkowski committed
16
    allocatedMemoryLocalBounds = feSpace->getBasisFcts()->getNumber();
Thomas Witkowski's avatar
Thomas Witkowski committed
17
    for (int i = 0; i < static_cast<int>(localBounds.size()); i++)
18
      localBounds[i] = new BoundaryType[allocatedMemoryLocalBounds];
Thomas Witkowski's avatar
Thomas Witkowski committed
19
20
21
22
23
24
25
  }

  BoundaryManager::BoundaryManager(BoundaryManager &bm)
  {
    localBCs = bm.localBCs;
    allocatedMemoryLocalBounds = bm.allocatedMemoryLocalBounds;
    localBounds.resize(bm.localBounds.size());
26
    dofIndices.resize(bm.localBounds.size());
Thomas Witkowski's avatar
Thomas Witkowski committed
27
    for (int i = 0; i < static_cast<int>(localBounds.size()); i++)
28
      localBounds[i] = new BoundaryType[allocatedMemoryLocalBounds];
Thomas Witkowski's avatar
Thomas Witkowski committed
29
30
31
32
  }

  BoundaryManager::~BoundaryManager()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
33
    for (int i = 0; i < static_cast<int>(localBounds.size()); i++)
34
      delete [] localBounds[i];
Thomas Witkowski's avatar
Thomas Witkowski committed
35
36
  }

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

  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, 
					       DOFVectorBase<double> *vec)
  {
53
    if (localBCs.size() > 0) {
54
55
56
57
58
      const FiniteElemSpace *feSpace = vec->getFESpace();
      Vector<DegreeOfFreedom> &dofVec = dofIndices[omp_get_thread_num()];
      const BasisFunction *basisFcts = feSpace->getBasisFcts();
      int nBasFcts = basisFcts->getNumber();
      std::map<BoundaryType, BoundaryCondition*>::iterator it;
59
60

      // get boundaries of all DOFs
Thomas Witkowski's avatar
Thomas Witkowski committed
61
      BoundaryType *localBound = localBounds[omp_get_thread_num()];
62
      basisFcts->getBound(elInfo, localBound);
63
64

      // get dof indices
65
66
      basisFcts->getLocalIndicesVec(elInfo->getElement(),
				    feSpace->getAdmin(), &dofVec);
67
68

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

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

  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, 
					       DOFMatrix *mat)
  {
    if (localBCs.size() > 0) {
92
93
94
95
96
97
      const FiniteElemSpace *feSpace = mat->getRowFESpace();
      Vector<DegreeOfFreedom> &dofVec = dofIndices[omp_get_thread_num()];
      const BasisFunction *basisFcts = feSpace->getBasisFcts();
      int nBasFcts = basisFcts->getNumber();
      std::map<BoundaryType, BoundaryCondition*>::iterator it;

98
      // get boundaries of all DOFs
Thomas Witkowski's avatar
Thomas Witkowski committed
99
100
101
      BoundaryType *localBound = localBounds[omp_get_thread_num()];
      basisFcts->getBound(elInfo, localBound);

102
      // get dof indices
103
104
      basisFcts->getLocalIndicesVec(elInfo->getElement(), 
				    feSpace->getAdmin(), &dofVec);
105
106
107
108
109

      // apply non dirichlet boundary conditions
      for (it = localBCs.begin(); it != localBCs.end(); ++it) {
	if ((*it).second) {
	  if (!(*it).second->isDirichlet()) {
110
	    (*it).second->fillBoundaryCondition(mat, elInfo, &dofVec[0], localBound, nBasFcts);
111
112
113
	  }
	}
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
114

115
116
117
118
      // apply dirichlet boundary conditions
      for (it = localBCs.begin(); it != localBCs.end(); ++it) {
	if ((*it).second) {
	  if ((*it).second->isDirichlet()) {
119
	    (*it).second->fillBoundaryCondition(mat, elInfo, &dofVec[0], localBound, nBasFcts);
120
121
	  }
	}
122
      }      
123
124
125
126
127
    }
  }

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

130
131
132
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if (!(*it).second->isDirichlet()) {
133
134
135
136
	  (*it).second->initMatrix(matrix);
	}
      }
    }
137
138
139
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if ((*it).second->isDirichlet()) {
140
141
142
143
144
145
146
147
	  (*it).second->initMatrix(matrix);
	}
      }
    }
  }

  void BoundaryManager::exitMatrix(DOFMatrix *matrix)
  {
148
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
149
150
151
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if (!(*it).second->isDirichlet()) {
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
	  (*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)
  {
167
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
    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)
  {
186
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
187
188
189
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if (!(*it).second->isDirichlet()) {
190
191
192
193
	  (*it).second->exitVector(vector);
	}
      }
    }
194
195
196
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if ((*it).second->isDirichlet()) {
197
198
199
200
201
202
203
	  (*it).second->exitVector(vector);
	}
      }
    }
  }

}