BoundaryManager.cc 5.68 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


13
14
15
16
17
18
19
20
21
22
#include "FiniteElemSpace.h"
#include "BoundaryManager.h"
#include "DOFIndexed.h"
#include "DOFVector.h"
#include "Traverse.h"
#include "BasisFunction.h"
#include "ElInfo.h"

namespace AMDiS {

23
24
25
  std::map<BoundaryType, std::vector<BoundaryCondition*> > 
  BoundaryManager::globalBoundaryMap;

Thomas Witkowski's avatar
Thomas Witkowski committed
26

Thomas Witkowski's avatar
Thomas Witkowski committed
27
28
29
  BoundaryManager::BoundaryManager(const FiniteElemSpace *feSpace)
  {
    allocatedMemoryLocalBounds = feSpace->getBasisFcts()->getNumber();
30
    localBound = new BoundaryType[allocatedMemoryLocalBounds];
Thomas Witkowski's avatar
Thomas Witkowski committed
31
32
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
33

Thomas Witkowski's avatar
Thomas Witkowski committed
34
35
36
37
  BoundaryManager::BoundaryManager(BoundaryManager &bm)
  {
    localBCs = bm.localBCs;
    allocatedMemoryLocalBounds = bm.allocatedMemoryLocalBounds;
38
    localBound = new BoundaryType[allocatedMemoryLocalBounds];
Thomas Witkowski's avatar
Thomas Witkowski committed
39
40
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
41

Thomas Witkowski's avatar
Thomas Witkowski committed
42
43
  BoundaryManager::~BoundaryManager()
  {
44
    delete [] localBound;
Thomas Witkowski's avatar
Thomas Witkowski committed
45
46
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  void BoundaryManager::addBoundaryCondition(BoundaryCondition *localBC)
  {
    FUNCNAME("BoundaryManager::addBoundaryCondition()");
  
    MSG("ADD BC\n");

    BoundaryType type = localBC->getBoundaryType();
    TEST_EXIT(localBCs[type] == NULL)
      ("There is already a condition for this type %d.\n",type);
    localBCs[type] = localBC;
    
    std::vector<BoundaryCondition*>& boundMap = globalBoundaryMap[type];
    boundMap.push_back(localBC);
  }


64
65
66
67
  double BoundaryManager::boundResidual(ElInfo *elInfo, 
					DOFMatrix *matrix,
					const DOFVectorBase<double> *dv)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
68
    double result = 0.0;
69
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
70
      if ((*it).second)
71
	result += (*it).second->boundResidual(elInfo, matrix, dv);
72
    
73
74
75
    return result;
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
76

77
78
79
  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, 
					       DOFVectorBase<double> *vec)
  {
80
    if (localBCs.size() > 0) {
81
      const FiniteElemSpace *feSpace = vec->getFeSpace();
82
83
84
      const BasisFunction *basisFcts = feSpace->getBasisFcts();
      int nBasFcts = basisFcts->getNumber();
      dofVec.resize(nBasFcts);
85

86
87
      // get boundaries of all DOFs
      basisFcts->getBound(elInfo, localBound);
88

89
      // get dof indices
Thomas Witkowski's avatar
Thomas Witkowski committed
90
91
92
      basisFcts->getLocalIndices(elInfo->getElement(),
				 feSpace->getAdmin(), 
				 dofVec);
93

94
      // apply non dirichlet boundary conditions
Thomas Witkowski's avatar
Thomas Witkowski committed
95
96
      for (BoundaryIndexMap::iterator it = localBCs.begin();
	     it != localBCs.end(); ++it)
97
98
99
	if ((*it).second && !(*it).second->isDirichlet())
	  (*it).second->fillBoundaryCondition(vec, elInfo, &dofVec[0], 
					      localBound, nBasFcts);
100

101
      // apply dirichlet boundary conditions
Thomas Witkowski's avatar
Thomas Witkowski committed
102
103
      for (BoundaryIndexMap::iterator it = localBCs.begin(); 
	   it != localBCs.end(); ++it)
104
105
106
107
108
	if ((*it).second && (*it).second->isDirichlet())
	  (*it).second->fillBoundaryCondition(vec, elInfo, &dofVec[0], 
					      localBound, nBasFcts);
    }
  }
109

Thomas Witkowski's avatar
Thomas Witkowski committed
110

111
  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, DOFMatrix *mat)
112
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
113
114
115
    if (localBCs.size() <= 0)
      return;
      
116
    const FiniteElemSpace *feSpace = mat->getRowFeSpace();
Thomas Witkowski's avatar
Thomas Witkowski committed
117
118
    const BasisFunction *basisFcts = feSpace->getBasisFcts();
    int nBasFcts = basisFcts->getNumber();
119
          dofVec.resize(nBasFcts);
120

Thomas Witkowski's avatar
Thomas Witkowski committed
121
122
123
    // get boundaries of all DOFs
    basisFcts->getBound(elInfo, localBound);
    
Thomas Witkowski's avatar
Thomas Witkowski committed
124
    // get DOF indices
125
    basisFcts->getLocalIndices(elInfo->getElement(), feSpace->getAdmin(), dofVec);
Thomas Witkowski's avatar
Thomas Witkowski committed
126
127
    
    // apply non dirichlet boundary conditions
128
129
130
131
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && !(*it).second->isDirichlet())
	(*it).second->fillBoundaryCondition(mat, elInfo, &dofVec[0], 
					    localBound, nBasFcts);
Thomas Witkowski's avatar
Thomas Witkowski committed
132
133
    
    // apply dirichlet boundary conditions
134
135
136
137
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->fillBoundaryCondition(mat, elInfo, &dofVec[0], 
					    localBound, nBasFcts);
138
139
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
140

141
142
  void BoundaryManager::initMatrix(DOFMatrix *matrix)
  {
143
144
145
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && !(*it).second->isDirichlet())
	(*it).second->initMatrix(matrix);
Thomas Witkowski's avatar
Thomas Witkowski committed
146

147
148
149
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->initMatrix(matrix);
150
151
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
152

153
154
  void BoundaryManager::exitMatrix(DOFMatrix *matrix)
  {
155
156
157
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && !(*it).second->isDirichlet())
	(*it).second->exitMatrix(matrix);
Thomas Witkowski's avatar
Thomas Witkowski committed
158

159
160
161
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->exitMatrix(matrix);
162
163
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
164

165
166
  void BoundaryManager::initVector(DOFVectorBase<double> *vector)
  {
167
168
169
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && !(*it).second->isDirichlet())
	(*it).second->initVector(vector);
Thomas Witkowski's avatar
Thomas Witkowski committed
170

171
172
173
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->initVector(vector);
174
175
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
176

177
178
  void BoundaryManager::exitVector(DOFVectorBase<double> *vector)
  {
179
180
181
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && !(*it).second->isDirichlet())
	(*it).second->exitVector(vector);
Thomas Witkowski's avatar
Thomas Witkowski committed
182

183
184
185
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->exitVector(vector);
186
187
188
  }

}