BoundaryManager.cc 5.15 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "FiniteElemSpace.h"
//#include "BoundaryCondition.h"
#include "BoundaryManager.h"
#include "DOFIndexed.h"
#include "DOFVector.h"
#include "Traverse.h"
#include "BasisFunction.h"
#include "ElInfo.h"

namespace AMDiS {

  double BoundaryManager::boundResidual(ElInfo *elInfo, 
					DOFMatrix *matrix,
					const DOFVectorBase<double> *dv)
  {
    double result = 0;
17
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
18
19
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second)
20
21
22
23
24
25
26
27
28
29
	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();
30
31
32
33
    Vector<DegreeOfFreedom> dofIndices;
    const BasisFunction *basisFcts = feSpace->getBasisFcts();
    int nBasFcts = basisFcts->getNumber();
    DOFAdmin *admin = feSpace->getAdmin();
34

35
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
36

37
    if (localBCs.size() > 0) {
38
39

      // get boundaries of all DOFs
40
41
      BoundaryType *localBound = GET_MEMORY(BoundaryType, nBasFcts);
      basisFcts->getBound(elInfo, localBound);
42
43

      // get dof indices
44
      basisFcts->getLocalIndicesVec(elInfo->getElement(), admin, &dofIndices);
45
46

      // apply non dirichlet boundary conditions
47
48
49
      for (it = localBCs.begin(); it != localBCs.end(); ++it) {
	if ((*it).second) {
	  if (!(*it).second->isDirichlet()) {
50
	    (*it).second->fillBoundaryCondition(vec, elInfo, &dofIndices[0], localBound, nBasFcts);
51
52
53
54
55
	  }
	}
      }

      // apply dirichlet boundary conditions
56
57
58
      for (it = localBCs.begin(); it != localBCs.end(); ++it) {
	if ((*it).second) {
	  if ((*it).second->isDirichlet()) {
59
	    (*it).second->fillBoundaryCondition(vec, elInfo, &dofIndices[0], localBound, nBasFcts);
60
61
62
	  }
	}
      }
63
64

      FREE_MEMORY(localBound, BoundaryType, nBasFcts);
65
66
67
68
69
70
71
72
    }
  }

  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, 
					       DOFMatrix *mat)
  {
    // ===== fill local conditions ==============================================
    const FiniteElemSpace *feSpace = mat->getRowFESpace();
73
74
75
76
    Vector<DegreeOfFreedom> dofIndices;
    const BasisFunction *basisFcts = feSpace->getBasisFcts();
    int nBasFcts = basisFcts->getNumber();
    DOFAdmin *admin = feSpace->getAdmin();
77

78
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
79
80
81

    if (localBCs.size() > 0) {
      // get boundaries of all DOFs
82
      const BoundaryType *localBound = basisFcts->getBound(elInfo, NULL);
83
      // get dof indices
84
      basisFcts->getLocalIndicesVec(elInfo->getElement(), admin, &dofIndices);
85
86
87
88
89

      // 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
90
	    (*it).second->fillBoundaryCondition(mat, elInfo, &dofIndices[0], localBound, nBasFcts);
91
92
93
	  }
	}
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
94

95
96
97
98
      // apply dirichlet boundary conditions
      for (it = localBCs.begin(); it != localBCs.end(); ++it) {
	if ((*it).second) {
	  if ((*it).second->isDirichlet()) {
99
	    (*it).second->fillBoundaryCondition(mat, elInfo, &dofIndices[0], localBound, nBasFcts);
100
101
	  }
	}
102
      }      
103
104
105
106
107
    }
  }

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

110
111
112
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if (!(*it).second->isDirichlet()) {
113
114
115
116
	  (*it).second->initMatrix(matrix);
	}
      }
    }
117
118
119
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if ((*it).second->isDirichlet()) {
120
121
122
123
124
125
126
127
	  (*it).second->initMatrix(matrix);
	}
      }
    }
  }

  void BoundaryManager::exitMatrix(DOFMatrix *matrix)
  {
128
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
129
130
131
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if (!(*it).second->isDirichlet()) {
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
	  (*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)
  {
147
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
    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)
  {
166
    std::map<BoundaryType, BoundaryCondition*>::iterator it;
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);
	}
      }
    }
174
175
176
    for (it = localBCs.begin(); it != localBCs.end(); ++it) {
      if ((*it).second) {
	if ((*it).second->isDirichlet()) {
177
178
179
180
181
182
183
	  (*it).second->exitVector(vector);
	}
      }
    }
  }

}