BoundaryManager.cc 5.65 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
Thomas Witkowski's avatar
Thomas Witkowski committed
65
      basisFcts->getLocalIndicesVec(elInfo->getElement(), feSpace->getAdmin(), &dofVec);
66
67

      // apply non dirichlet boundary conditions
Thomas Witkowski's avatar
Thomas Witkowski committed
68
69
70
71
      for (it = localBCs.begin(); it != localBCs.end(); ++it)
	if ((*it).second && !(*it).second->isDirichlet())
	  (*it).second->fillBoundaryCondition(vec, elInfo, &dofVec[0], 
					      localBound, nBasFcts);
72
73

      // apply dirichlet boundary conditions
Thomas Witkowski's avatar
Thomas Witkowski committed
74
75
76
77
      for (it = localBCs.begin(); it != localBCs.end(); ++it)
	if ((*it).second && (*it).second->isDirichlet())
	  (*it).second->fillBoundaryCondition(vec, elInfo, &dofVec[0], 
					      localBound, nBasFcts);
78
79
80
81
82
83
    }
  }

  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, 
					       DOFMatrix *mat)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
    if (localBCs.size() <= 0)
      return;
      
    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;
    
    // get boundaries of all DOFs
    BoundaryType *localBound = localBounds[omp_get_thread_num()];
    basisFcts->getBound(elInfo, localBound);
    
    // get dof indices
    basisFcts->getLocalIndicesVec(elInfo->getElement(), 
				  feSpace->getAdmin(), &dofVec);
    
    // apply non dirichlet boundary conditions
    for (it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second)
	if (!(*it).second->isDirichlet())
	  (*it).second->fillBoundaryCondition(mat, elInfo, &dofVec[0], 
					      localBound, nBasFcts);
    
    // apply dirichlet boundary conditions
    for (it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second)
	if ((*it).second->isDirichlet())
	  (*it).second->fillBoundaryCondition(mat, elInfo, &dofVec[0], 
					      localBound, nBasFcts);
114
115
116
117
  }

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

Thomas Witkowski's avatar
Thomas Witkowski committed
120
121
122
    for (it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second)
	if (!(*it).second->isDirichlet())
123
	  (*it).second->initMatrix(matrix);
Thomas Witkowski's avatar
Thomas Witkowski committed
124
125
126
127

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

  void BoundaryManager::exitMatrix(DOFMatrix *matrix)
  {
133
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
Thomas Witkowski's avatar
Thomas Witkowski committed
134
135
136
    for (it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second)
	if (!(*it).second->isDirichlet())
137
	  (*it).second->exitMatrix(matrix);
Thomas Witkowski's avatar
Thomas Witkowski committed
138
139
140
141

    for (it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second)
	if ((*it).second->isDirichlet())
142
143
144
145
146
	  (*it).second->exitMatrix(matrix);
  }

  void BoundaryManager::initVector(DOFVectorBase<double> *vector)
  {
147
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
Thomas Witkowski's avatar
Thomas Witkowski committed
148
149
150
    for (it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second)
	if (!(*it).second->isDirichlet())
151
	  (*it).second->initVector(vector);
Thomas Witkowski's avatar
Thomas Witkowski committed
152
153
154
155

    for (it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second)
	if ((*it).second->isDirichlet())
156
157
158
159
160
	  (*it).second->initVector(vector);
  }

  void BoundaryManager::exitVector(DOFVectorBase<double> *vector)
  {
161
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
Thomas Witkowski's avatar
Thomas Witkowski committed
162
163
164
    for (it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second)
	if (!(*it).second->isDirichlet())
165
	  (*it).second->exitVector(vector);
Thomas Witkowski's avatar
Thomas Witkowski committed
166
167
168
169

    for (it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second)
	if ((*it).second->isDirichlet())
170
171
172
173
	  (*it).second->exitVector(vector);
  }

}