BoundaryManager.cc 5.64 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 {

12
13
14
  std::map<BoundaryType, std::vector<BoundaryCondition*> > 
  BoundaryManager::globalBoundaryMap;

Thomas Witkowski's avatar
Thomas Witkowski committed
15

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

Thomas Witkowski's avatar
Thomas Witkowski committed
25

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

Thomas Witkowski's avatar
Thomas Witkowski committed
36

Thomas Witkowski's avatar
Thomas Witkowski committed
37
38
  BoundaryManager::~BoundaryManager()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
39
    for (unsigned int i = 0; i < localBounds.size(); i++)
40
      delete [] localBounds[i];
Thomas Witkowski's avatar
Thomas Witkowski committed
41
42
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
43

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

Thomas Witkowski's avatar
Thomas Witkowski committed
56

57
58
59
  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, 
					       DOFVectorBase<double> *vec)
  {
60
    if (localBCs.size() > 0) {
61
      const FiniteElemSpace *feSpace = vec->getFeSpace();
62
63
64
65
      std::vector<DegreeOfFreedom> &dofVec = dofIndices[omp_get_thread_num()];
      const BasisFunction *basisFcts = feSpace->getBasisFcts();
      int nBasFcts = basisFcts->getNumber();
      dofVec.resize(nBasFcts);
66

67
68
69
      // get boundaries of all DOFs
      BoundaryType *localBound = localBounds[omp_get_thread_num()];
      basisFcts->getBound(elInfo, localBound);
70

71
72
      // get dof indices
      basisFcts->getLocalIndices(elInfo->getElement(), feSpace->getAdmin(), dofVec);
73

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
88

89
  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, DOFMatrix *mat)
90
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
91
92
93
    if (localBCs.size() <= 0)
      return;
      
94
    const FiniteElemSpace *feSpace = mat->getRowFeSpace();
95
    std::vector<DegreeOfFreedom> &dofVec = dofIndices[omp_get_thread_num()];
Thomas Witkowski's avatar
Thomas Witkowski committed
96
97
    const BasisFunction *basisFcts = feSpace->getBasisFcts();
    int nBasFcts = basisFcts->getNumber();
98
          dofVec.resize(nBasFcts);
99

Thomas Witkowski's avatar
Thomas Witkowski committed
100
101
102
103
104
    // get boundaries of all DOFs
    BoundaryType *localBound = localBounds[omp_get_thread_num()];
    basisFcts->getBound(elInfo, localBound);
    
    // get dof indices
105
    basisFcts->getLocalIndices(elInfo->getElement(), feSpace->getAdmin(), dofVec);
Thomas Witkowski's avatar
Thomas Witkowski committed
106
107
    
    // apply non dirichlet boundary conditions
108
109
110
111
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && !(*it).second->isDirichlet())
	(*it).second->fillBoundaryCondition(mat, elInfo, &dofVec[0], 
					    localBound, nBasFcts);
Thomas Witkowski's avatar
Thomas Witkowski committed
112
113
    
    // apply dirichlet boundary conditions
114
115
116
117
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->fillBoundaryCondition(mat, elInfo, &dofVec[0], 
					    localBound, nBasFcts);
118
119
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
120

121
122
  void BoundaryManager::initMatrix(DOFMatrix *matrix)
  {
123
124
125
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && !(*it).second->isDirichlet())
	(*it).second->initMatrix(matrix);
Thomas Witkowski's avatar
Thomas Witkowski committed
126

127
128
129
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->initMatrix(matrix);
130
131
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
132

133
134
  void BoundaryManager::exitMatrix(DOFMatrix *matrix)
  {
135
136
137
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && !(*it).second->isDirichlet())
	(*it).second->exitMatrix(matrix);
Thomas Witkowski's avatar
Thomas Witkowski committed
138

139
140
141
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->exitMatrix(matrix);
142
143
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
144

145
146
  void BoundaryManager::initVector(DOFVectorBase<double> *vector)
  {
147
148
149
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && !(*it).second->isDirichlet())
	(*it).second->initVector(vector);
Thomas Witkowski's avatar
Thomas Witkowski committed
150

151
152
153
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->initVector(vector);
154
155
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
156

157
158
  void BoundaryManager::exitVector(DOFVectorBase<double> *vector)
  {
159
160
161
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && !(*it).second->isDirichlet())
	(*it).second->exitVector(vector);
Thomas Witkowski's avatar
Thomas Witkowski committed
162

163
164
165
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->exitVector(vector);
166
167
168
  }

}