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

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

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

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
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
44
      if ((*it).second)
45
	result += (*it).second->boundResidual(elInfo, matrix, dv);
46
    
47
48
49
    return result;
  }

50

51
52
53
  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, 
					       DOFVectorBase<double> *vec)
  {
54
    FUNCNAME("BoundaryManager::fillBoundaryConditions()");
55

56
57
    if (localBCs.size() <= 0)
      return;
58

59
60
61
    const FiniteElemSpace *feSpace = vec->getFESpace();
    const BasisFunction *basisFcts = feSpace->getBasisFcts();
    int nBasFcts = basisFcts->getNumber();
62

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    // get boundaries of all DOFs
    BoundaryType *localBound = localBounds[omp_get_thread_num()];
    basisFcts->getBound(elInfo, localBound);
    
    // get dof indices
    std::vector<DegreeOfFreedom> &dofVec = elInfo->getLocalIndices(feSpace);
    TEST_EXIT_DBG(static_cast<int>(dofVec.size()) == nBasFcts)
      ("Local index vector is too small!\n");
    
    // 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);
    
    // 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);    
83
84
  }

85

86
  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, DOFMatrix *mat)
87
  {
88
89
    FUNCNAME("BoundaryManager::fillBoundaryConditions()");

Thomas Witkowski's avatar
Thomas Witkowski committed
90
91
92
93
94
95
    if (localBCs.size() <= 0)
      return;
      
    const FiniteElemSpace *feSpace = mat->getRowFESpace();
    const BasisFunction *basisFcts = feSpace->getBasisFcts();
    int nBasFcts = basisFcts->getNumber();
96

Thomas Witkowski's avatar
Thomas Witkowski committed
97
98
99
100
101
    // get boundaries of all DOFs
    BoundaryType *localBound = localBounds[omp_get_thread_num()];
    basisFcts->getBound(elInfo, localBound);
    
    // get dof indices
102
103
104
    std::vector<DegreeOfFreedom> &dofVec = elInfo->getLocalIndices(feSpace);
    TEST_EXIT_DBG(static_cast<int>(dofVec.size()) == nBasFcts)
      ("Local index vector is too small!\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
105
106
    
    // apply non dirichlet boundary conditions
107
108
109
110
    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
111
112
    
    // apply dirichlet boundary conditions
113
114
115
116
    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);
117
118
119
120
  }

  void BoundaryManager::initMatrix(DOFMatrix *matrix)
  {
121
122
123
    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
124

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

  void BoundaryManager::exitMatrix(DOFMatrix *matrix)
  {
132
133
134
    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
135

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

  void BoundaryManager::initVector(DOFVectorBase<double> *vector)
  {
143
144
145
    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
146

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

  void BoundaryManager::exitVector(DOFVectorBase<double> *vector)
  {
154
155
156
    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
157

158
159
160
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->exitVector(vector);
161
162
163
  }

}