BoundaryManager.cc 5.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#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;
    ::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
36

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

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
79
80
81

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

    if (localBCs.size() > 0) {
      // get boundaries of all DOFs
82
      const BoundaryType *localBound = basisFcts->getBound(elInfo, NULL);
83
84

      // get dof indices
85
      basisFcts->getLocalIndicesVec(elInfo->getElement(), admin, &dofIndices);
86
87
88
89
90

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

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

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

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

}