BoundaryManager.cc 5.18 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
100
101
102
103
104
105
106
107
108
109
110
#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;
    for(it = localBCs.begin(); it != localBCs.end(); ++it) {
      if((*it).second)
	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;

    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(vec, elInfo, dofIndices, localBound, nBasFcts);
	  }
	}
      }

      // apply dirichlet boundary conditions
      for(it = localBCs.begin(); it != localBCs.end(); ++it) {
	if((*it).second) {
	  if((*it).second->isDirichlet()) {
	    (*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()) {
	     (*it).second->fillBoundaryCondition(mat, elInfo, dofIndices, localBound, nBasFcts);
	  }
	}
      }
    }
  }

  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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
	  (*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;
    for(it = localBCs.begin(); it != localBCs.end(); ++it) {
      if((*it).second) {
	if(!(*it).second->isDirichlet()) {
	  (*it).second->exitVector(vector);
	}
      }
    }
    for(it = localBCs.begin(); it != localBCs.end(); ++it) {
      if((*it).second) {
	if((*it).second->isDirichlet()) {
	  (*it).second->exitVector(vector);
	}
      }
    }
  }

}