Liebe Gitlab-Nutzerin, 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 5.6 KB
Newer Older
1 2 3 4 5 6 7
#include "FiniteElemSpace.h"
#include "BoundaryManager.h"
#include "DOFIndexed.h"
#include "DOFVector.h"
#include "Traverse.h"
#include "BasisFunction.h"
#include "ElInfo.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
8
#include "OpenMP.h"
9 10 11

namespace AMDiS {

12 13 14
  std::map<BoundaryType, std::vector<BoundaryCondition*> > 
  BoundaryManager::globalBoundaryMap;

Thomas Witkowski's avatar
Thomas Witkowski committed
15 16
  BoundaryManager::BoundaryManager(const FiniteElemSpace *feSpace)
  {
17
    localBounds.resize(omp_get_overall_max_threads());
18
    dofIndices.resize(omp_get_overall_max_threads());
Thomas Witkowski's avatar
Thomas Witkowski committed
19
    allocatedMemoryLocalBounds = feSpace->getBasisFcts()->getNumber();
Thomas Witkowski's avatar
Thomas Witkowski committed
20
    for (int i = 0; i < static_cast<int>(localBounds.size()); i++)
21
      localBounds[i] = new BoundaryType[allocatedMemoryLocalBounds];
Thomas Witkowski's avatar
Thomas Witkowski committed
22 23 24 25 26 27 28
  }

  BoundaryManager::BoundaryManager(BoundaryManager &bm)
  {
    localBCs = bm.localBCs;
    allocatedMemoryLocalBounds = bm.allocatedMemoryLocalBounds;
    localBounds.resize(bm.localBounds.size());
29
    dofIndices.resize(bm.localBounds.size());
Thomas Witkowski's avatar
Thomas Witkowski committed
30
    for (int i = 0; i < static_cast<int>(localBounds.size()); i++)
31
      localBounds[i] = new BoundaryType[allocatedMemoryLocalBounds];
Thomas Witkowski's avatar
Thomas Witkowski committed
32 33 34 35
  }

  BoundaryManager::~BoundaryManager()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
36
    for (int i = 0; i < static_cast<int>(localBounds.size()); i++)
37
      delete [] localBounds[i];
Thomas Witkowski's avatar
Thomas Witkowski committed
38 39
  }

40 41 42 43
  double BoundaryManager::boundResidual(ElInfo *elInfo, 
					DOFMatrix *matrix,
					const DOFVectorBase<double> *dv)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
44
    double result = 0.0;
45
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
46
      if ((*it).second)
47
	result += (*it).second->boundResidual(elInfo, matrix, dv);
48
    
49 50 51 52 53 54
    return result;
  }

  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, 
					       DOFVectorBase<double> *vec)
  {
55
    if (localBCs.size() > 0) {
56
      const FiniteElemSpace *feSpace = vec->getFESpace();
57
      std::vector<DegreeOfFreedom> &dofVec = dofIndices[omp_get_thread_num()];
58 59
      const BasisFunction *basisFcts = feSpace->getBasisFcts();
      int nBasFcts = basisFcts->getNumber();
60 61

      // get boundaries of all DOFs
Thomas Witkowski's avatar
Thomas Witkowski committed
62
      BoundaryType *localBound = localBounds[omp_get_thread_num()];
63
      basisFcts->getBound(elInfo, localBound);
64 65

      // get dof indices
66
      basisFcts->getLocalIndices(elInfo->getElement(), feSpace->getAdmin(), dofVec);
67 68

      // apply non dirichlet boundary conditions
69
      for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
Thomas Witkowski's avatar
Thomas Witkowski committed
70 71 72
	if ((*it).second && !(*it).second->isDirichlet())
	  (*it).second->fillBoundaryCondition(vec, elInfo, &dofVec[0], 
					      localBound, nBasFcts);
73 74

      // apply dirichlet boundary conditions
75
      for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
Thomas Witkowski's avatar
Thomas Witkowski committed
76 77 78
	if ((*it).second && (*it).second->isDirichlet())
	  (*it).second->fillBoundaryCondition(vec, elInfo, &dofVec[0], 
					      localBound, nBasFcts);
79 80 81
    }
  }

82
  void BoundaryManager::fillBoundaryConditions(ElInfo *elInfo, DOFMatrix *mat)
83
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
84 85 86 87
    if (localBCs.size() <= 0)
      return;
      
    const FiniteElemSpace *feSpace = mat->getRowFESpace();
88
    std::vector<DegreeOfFreedom> &dofVec = dofIndices[omp_get_thread_num()];
Thomas Witkowski's avatar
Thomas Witkowski committed
89 90 91 92 93 94 95 96
    const BasisFunction *basisFcts = feSpace->getBasisFcts();
    int nBasFcts = basisFcts->getNumber();
    
    // get boundaries of all DOFs
    BoundaryType *localBound = localBounds[omp_get_thread_num()];
    basisFcts->getBound(elInfo, localBound);
    
    // get dof indices
97
    basisFcts->getLocalIndices(elInfo->getElement(), feSpace->getAdmin(), dofVec);
Thomas Witkowski's avatar
Thomas Witkowski committed
98 99
    
    // apply non dirichlet boundary conditions
100 101 102 103
    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
104 105
    
    // apply dirichlet boundary conditions
106 107 108 109
    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);
110 111 112 113
  }

  void BoundaryManager::initMatrix(DOFMatrix *matrix)
  {
114 115 116
    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
117

118 119 120
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->initMatrix(matrix);
121 122 123 124
  }

  void BoundaryManager::exitMatrix(DOFMatrix *matrix)
  {
125 126 127
    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
128

129 130 131
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->exitMatrix(matrix);
132 133 134 135
  }

  void BoundaryManager::initVector(DOFVectorBase<double> *vector)
  {
136 137 138
    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
139

140 141 142
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->initVector(vector);
143 144 145 146
  }

  void BoundaryManager::exitVector(DOFVectorBase<double> *vector)
  {
147 148 149
    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
150

151 152 153
    for (BoundaryIndexMap::iterator it = localBCs.begin(); it != localBCs.end(); ++it)
      if ((*it).second && (*it).second->isDirichlet())
	(*it).second->exitVector(vector);
154 155 156
  }

}