BoundaryManager.cc 5.2 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
30
31
32
33
34
35
36
37
	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();
    const BoundaryType    *localBound = NULL;
    const DegreeOfFreedom *dofIndices = NULL;
    const BasisFunction   *basisFcts = feSpace->getBasisFcts();
    int                    nBasFcts = basisFcts->getNumber();
    DOFAdmin              *admin = feSpace->getAdmin();

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

38
    if (localBCs.size() > 0) {
39
40
41
42
43
44
45
46
47

      // get boundaries of all DOFs
      localBound = basisFcts->getBound(elInfo, NULL);

      // get dof indices
      dofIndices = basisFcts->getLocalIndices(elInfo->getElement(),
					      admin, NULL);

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

      // apply dirichlet boundary conditions
57
58
59
      for (it = localBCs.begin(); it != localBCs.end(); ++it) {
	if ((*it).second) {
	  if ((*it).second->isDirichlet()) {
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
	    (*it).second->fillBoundaryCondition(vec, elInfo, dofIndices, localBound, nBasFcts);
	  }
	}
      }
    }
  }

  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, 
					       DOFMatrix *mat)
  {
    // ===== fill local conditions ==============================================
    const FiniteElemSpace *feSpace = mat->getRowFESpace();
    const BoundaryType    *localBound = NULL;
    const DegreeOfFreedom *dofIndices = NULL;
    const BasisFunction   *basisFcts = feSpace->getBasisFcts();
    int                    nBasFcts = basisFcts->getNumber();
    DOFAdmin              *admin = feSpace->getAdmin();

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

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

      // get dof indices
      dofIndices = basisFcts->getLocalIndices(elInfo->getElement(), admin, NULL);

      // 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, dofIndices, localBound, nBasFcts);
	  }
	}
      }

      // 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, 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);
	}
      }
    }
  }

}