DofComm.cc 3.73 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
#include "parallel/DofComm.h"
#include "parallel/InteriorBoundary.h"
15
#include "parallel/MeshLevelData.h"
16
#include "FiniteElemSpace.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
17
18
#include "Debug.h"
#include "ElementDofIterator.h"
19
#include "DOFVector.h"
20
21
22
23
24

namespace AMDiS {

  using namespace std;

25

26
  void DofComm::init(vector<const FiniteElemSpace*> &fe)
27
28
29
30
31
32
33
  {
    FUNCNAME("DofComm::init()");
    
    feSpaces = fe;
    
    sendDofs.clear();
    recvDofs.clear();
34
    periodicDofs.clear();   
35
36
37
  }


38
  void DofComm::create(InteriorBoundary &boundary)
39
  {
40
41
    FUNCNAME("DofComm::create()");

42
43
    createContainer(boundary.getOwn(), sendDofs);
    createContainer(boundary.getOther(), recvDofs);
44
45
46
  }


47
  void DofComm::createContainer(RankToBoundMap &boundary,
48
				DataType &data)
49
  {
50
51
    FUNCNAME("DofComm::createContainer()");

52
53
54
    // === Fill data. ===

    for (unsigned int i = 0; i < feSpaces.size(); i++)
55
56
57
      for (InteriorBoundary::iterator it(boundary); !it.end(); ++it)
	it->rankObj.el->getAllDofs(feSpaces[i], it->rankObj, 
				   data[it.getRank()][feSpaces[i]]);
58
59
60


    // === Remove empty data containers. ===
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    DataIter dit = data.begin();
    while (dit != data.end()) {
      FeMapIter it = dit->second.begin();
      while (it != dit->second.end()) {
	if (it->second.size() == 0) {
	  const FiniteElemSpace *fe = it->first;
	  ++it;
	  dit->second.erase(fe);
	} else
	  ++it;
      }
      
      if (dit->second.size() == 0)
	data.erase(dit++);
      else
	++dit;
78
79
80
    }
  }

81

Thomas Witkowski's avatar
Thomas Witkowski committed
82
83
84
85
  void DofComm::serialize(ostream &out)
  {
    FUNCNAME("DofComm:serialize()");

Thomas Witkowski's avatar
Thomas Witkowski committed
86
    ERROR_EXIT("MUSS DAS WIRKLICH SEIN????\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
87
88
89
  }

  
90
  int DofComm::getNumberDofs(DataType &data, 
Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
91
92
			     const FiniteElemSpace *feSpace,
			     bool countDouble)
93
94
95
  {
    FUNCNAME("DofComm::getNumberDofs()");

Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
96
97
    DofContainerSet dofSet;
    DofContainer dofVec;
98

99
    for (DataIter rankIt = data.begin(); rankIt != data.end(); ++rankIt)
100
101
102
      for (FeMapIter feIt = rankIt->second.begin();
	   feIt != rankIt->second.end(); ++feIt)
	if (feIt->first == feSpace)
Thomas Witkowski's avatar
Blub  
Thomas Witkowski committed
103
104
105
106
107
108
109
110
	  if (countDouble)
	    dofVec.insert(dofVec.end(), feIt->second.begin(), feIt->second.end());
	  else
	    dofSet.insert(feIt->second.begin(), feIt->second.end());

    if (countDouble)
      return static_cast<int>(dofVec.size());    
    return static_cast<int>(dofSet.size());
111
112
113
  }
  

114
  bool DofComm::Iterator::setNextFeMap()
115
  {
116
117
    FUNCNAME("DofComm::Iterator::setNextFeMap()");

118
    if (dataIter != data.end()) {
119
120
      TEST_EXIT_DBG(dataIter->second.size())("Should not happen!\n");

121
122
123
      feMapIter = dataIter->second.begin();
      
      if (traverseFeSpace != NULL) {
124
125
	if ((dataIter->second.count(traverseFeSpace) == 0))
	  return false;
126
127
128
129
130
131
132
133
134
135
	
	while (feMapIter->first != traverseFeSpace &&
	       feMapIter != dataIter->second.end())
	  ++feMapIter;
	
	TEST_EXIT_DBG(feMapIter != dataIter->second.end() &&
		      feMapIter->first == traverseFeSpace)
	  ("Should not happen!\n");
      }
      
136
      dofIter = feMapIter->second.begin();      
137
138
      dofCounter = 0;
    }
139
140

    return true;
141
142
  }

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

  void MultiLevelDofComm::init(MeshLevelData &levelData,
			       vector<const FiniteElemSpace*> &fe)
  {
    FUNCNAME("MultiLevelDofComm::init()");

    int nLevel = levelData.getNumberOfLevels();
    for (int level = 0; level < nLevel; level++)
      levelDofComm[level].init(fe);
  }

  
  void MultiLevelDofComm::create(MultiLevelInteriorBoundary &boundary)
  {
    FUNCNAME("MultiLevelDofComm::create()");

    for (map<int, DofComm>::iterator it = levelDofComm.begin();
	 it != levelDofComm.end(); ++it)
      it->second.create(boundary[it->first]);
  }

164
}