Liebe Gitlab-Nutzer, lieber Gitlab-Nutzer,
es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Die Konten der externen Nutzer:innen sind über den Reiter "Standard" erreichbar.
Die Administratoren


Dear Gitlab user,
it is now possible to log in to our service using the ZIH login/LDAP. The accounts of external users can be accessed via the "Standard" tab.
The administrators

BoundaryManager.cc 6.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/
20 21


22 23 24 25 26 27 28 29 30 31
#include "FiniteElemSpace.h"
#include "BoundaryManager.h"
#include "DOFIndexed.h"
#include "DOFVector.h"
#include "Traverse.h"
#include "BasisFunction.h"
#include "ElInfo.h"

namespace AMDiS {

32 33 34
  std::map<BoundaryType, std::vector<BoundaryCondition*> > 
  BoundaryManager::globalBoundaryMap;

Thomas Witkowski's avatar
Thomas Witkowski committed
35

Thomas Witkowski's avatar
Thomas Witkowski committed
36 37 38
  BoundaryManager::BoundaryManager(const FiniteElemSpace *feSpace)
  {
    allocatedMemoryLocalBounds = feSpace->getBasisFcts()->getNumber();
39
    localBound = new BoundaryType[allocatedMemoryLocalBounds];
Thomas Witkowski's avatar
Thomas Witkowski committed
40 41
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
42

Thomas Witkowski's avatar
Thomas Witkowski committed
43 44 45 46
  BoundaryManager::BoundaryManager(BoundaryManager &bm)
  {
    localBCs = bm.localBCs;
    allocatedMemoryLocalBounds = bm.allocatedMemoryLocalBounds;
47
    localBound = new BoundaryType[allocatedMemoryLocalBounds];
Thomas Witkowski's avatar
Thomas Witkowski committed
48 49
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
50

Thomas Witkowski's avatar
Thomas Witkowski committed
51 52
  BoundaryManager::~BoundaryManager()
  {
53
    delete [] localBound;
Thomas Witkowski's avatar
Thomas Witkowski committed
54 55
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
56

57 58 59 60 61
  void BoundaryManager::addBoundaryCondition(BoundaryCondition *localBC)
  {
    FUNCNAME("BoundaryManager::addBoundaryCondition()");
  
    BoundaryType type = localBC->getBoundaryType();
62
    TEST_EXIT(localBCs[type] == nullptr)
63 64 65 66 67 68 69 70
      ("There is already a condition for this type %d.\n",type);
    localBCs[type] = localBC;
    
    std::vector<BoundaryCondition*>& boundMap = globalBoundaryMap[type];
    boundMap.push_back(localBC);
  }


71 72 73 74
  double BoundaryManager::boundResidual(ElInfo *elInfo, 
					DOFMatrix *matrix,
					const DOFVectorBase<double> *dv)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
75
    double result = 0.0;
76
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
77
      if ((*it).second)
78
	result += (*it).second->boundResidual(elInfo, matrix, dv);
79
    
80 81 82
    return result;
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
83

84 85 86
  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, 
					       DOFVectorBase<double> *vec)
  {
87
    if (localBCs.size() > 0) {
88
      const FiniteElemSpace *feSpace = vec->getFeSpace();
89 90 91
      const BasisFunction *basisFcts = feSpace->getBasisFcts();
      int nBasFcts = basisFcts->getNumber();
      dofVec.resize(nBasFcts);
92

93 94
      // get boundaries of all DOFs
      basisFcts->getBound(elInfo, localBound);
95

96
      // get dof indices
Thomas Witkowski's avatar
Thomas Witkowski committed
97 98 99
      basisFcts->getLocalIndices(elInfo->getElement(),
				 feSpace->getAdmin(), 
				 dofVec);
100

101
      // apply non 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
	if ((*it).second && !(*it).second->isDirichlet())
	  (*it).second->fillBoundaryCondition(vec, elInfo, &dofVec[0], 
					      localBound, nBasFcts);
107

108
      // apply dirichlet boundary conditions
Thomas Witkowski's avatar
Thomas Witkowski committed
109 110
      for (BoundaryIndexMap::iterator it = localBCs.begin(); 
	   it != localBCs.end(); ++it)
111 112 113 114 115
	if ((*it).second && (*it).second->isDirichlet())
	  (*it).second->fillBoundaryCondition(vec, elInfo, &dofVec[0], 
					      localBound, nBasFcts);
    }
  }
116

Thomas Witkowski's avatar
Thomas Witkowski committed
117

118
  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, DOFMatrix *mat)
119
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
120 121 122
    if (localBCs.size() <= 0)
      return;
      
123
    const FiniteElemSpace *feSpace = mat->getRowFeSpace();
Thomas Witkowski's avatar
Thomas Witkowski committed
124 125
    const BasisFunction *basisFcts = feSpace->getBasisFcts();
    int nBasFcts = basisFcts->getNumber();
126
          dofVec.resize(nBasFcts);
127

Thomas Witkowski's avatar
Thomas Witkowski committed
128 129 130
    // get boundaries of all DOFs
    basisFcts->getBound(elInfo, localBound);
    
Thomas Witkowski's avatar
Thomas Witkowski committed
131
    // get DOF indices
132
    basisFcts->getLocalIndices(elInfo->getElement(), feSpace->getAdmin(), dofVec);
Thomas Witkowski's avatar
Thomas Witkowski committed
133 134
    
    // apply non dirichlet boundary conditions
135 136 137 138
    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
139 140
    
    // apply dirichlet boundary conditions
141 142 143 144
    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);
145 146
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
147

148 149
  void BoundaryManager::initMatrix(DOFMatrix *matrix)
  {
150 151 152
    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
153

154 155 156
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->initMatrix(matrix);
157 158
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
159

160 161
  void BoundaryManager::exitMatrix(DOFMatrix *matrix)
  {
162 163 164
    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
165

166 167 168
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->exitMatrix(matrix);
169 170
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
171

172 173
  void BoundaryManager::initVector(DOFVectorBase<double> *vector)
  {
174 175 176
    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
177

178 179 180
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->initVector(vector);
181 182
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
183

184 185
  void BoundaryManager::exitVector(DOFVectorBase<double> *vector)
  {
186 187 188
    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
189

190 191 192
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->exitVector(vector);
193 194 195
  }

}