FeSpaceMapping.cc 3.86 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
//
// 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.


#include "parallel/FeSpaceMapping.h"
Thomas Witkowski's avatar
FETI-DP    
Thomas Witkowski committed
14
#include "parallel/StdMpi.h"
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

namespace AMDiS {

  using namespace std;

  void GlobalDofMap::clear()
  {
    dofMap.clear();
    nRankDofs = 0;
    nOverallDofs = 0;
    rStartDofs = 0;
  }


  void GlobalDofMap::update(bool add)
  {
    for (DofMapping::iterator it = dofMap.begin(); it != dofMap.end(); ++it)
Thomas Witkowski's avatar
FETI-DP    
Thomas Witkowski committed
32
      if (it->second == -1 && nonRankDofs.count(it->first) == 0)
33
34
35
36
37
38
39
40
	it->second = nRankDofs++;
    
    nOverallDofs = 0;
    rStartDofs = 0;
    mpi::getDofNumbering(*mpiComm, nRankDofs, rStartDofs, nOverallDofs);
    
    if (add)
      addOffset(rStartDofs);
Thomas Witkowski's avatar
FETI-DP    
Thomas Witkowski committed
41
42
43

    if (overlap)
      computeNonLocalIndices();
Thomas Witkowski's avatar
Thomas Witkowski committed
44
45

    computeMatIndex(0);
46
47
48
49
50
51
52
53
54
  }


  void GlobalDofMap::addOffset(int offset)
  {
    for (DofMapping::iterator it = dofMap.begin(); it != dofMap.end(); ++it)
      it->second += offset;
  }

Thomas Witkowski's avatar
FETI-DP    
Thomas Witkowski committed
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
  void GlobalDofMap::computeNonLocalIndices()
  {
    FUNCNAME("GlobalDofMap::computeNonLocalIndices()");

    typedef map<int, map<const FiniteElemSpace*, DofContainer> >::iterator it_type;

    StdMpi<vector<int> > stdMpi(*mpiComm);
    for (DofComm::Iterator it(*sendDofs, feSpace); !it.end(); it.nextRank())
      for (; !it.endDofIter(); it.nextDof())
	if (dofMap.count(it.getDofIndex()) && !nonRankDofs.count(it.getDofIndex()))
	  stdMpi.getSendData(it.getRank()).push_back(dofMap[it.getDofIndex()]);

    stdMpi.updateSendDataSize();

    for (DofComm::Iterator it(*recvDofs, feSpace); !it.end(); it.nextRank()) {
      bool recvFromRank = false;
      for (; !it.endDofIter(); it.nextDof()) {
	if (nonRankDofs.count(it.getDofIndex())) {
	  recvFromRank = true;
	  break;
	}
      }

      if (recvFromRank) 
	stdMpi.recv(it.getRank());
    }

    stdMpi.startCommunication();

    for (DofComm::Iterator it(*recvDofs, feSpace);
	 !it.end(); it.nextRank()) {
      int i = 0;
      for (; !it.endDofIter(); it.nextDof())
	if (nonRankDofs.count(it.getDofIndex()))
	  dofMap[it.getDofIndex()] = stdMpi.getRecvData(it.getRank())[i++];
    }
  }


Thomas Witkowski's avatar
Thomas Witkowski committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  void GlobalDofMap::computeMatIndex(int offset)
  {
    FUNCNAME("GlobalDofMap::computeMatIndex()");

    map<DegreeOfFreedom, int> dofToMatIndex;

    for (DofMapping::iterator it = dofMap.begin(); it != dofMap.end(); ++it) {
      if (!nonRankDofs.count(it->first)) {
	int globalMatIndex = it->second - rStartDofs + offset;
	dofToMatIndex[it->first] = globalMatIndex;
      }
    }

    if (!overlap)
      return;

    TEST_EXIT_DBG(sendDofs != NULL && recvDofs != NULL)
      ("No communicator given!\n");

    StdMpi<vector<DegreeOfFreedom> > stdMpi(*mpiComm);
    for (DofComm::Iterator it(*sendDofs, feSpace); !it.end(); it.nextRank()) {
      vector<DegreeOfFreedom> sendGlobalDofs;

      for (; !it.endDofIter(); it.nextDof())
	if (dofMap.count(it.getDofIndex()))
	  sendGlobalDofs.push_back(dofToMatIndex[it.getDofIndex()]);

      stdMpi.send(it.getRank(), sendGlobalDofs);
    }

    for (DofComm::Iterator it(*recvDofs, feSpace); !it.end(); it.nextRank())
      stdMpi.recv(it.getRank());

    stdMpi.startCommunication();

    {
      int i = 0;
      for (DofComm::Iterator it(*recvDofs, feSpace); !it.end(); it.nextRank()) 
	for (; !it.endDofIter(); it.nextDof())
	  if (dofMap.count(it.getDofIndex()))
	    dofToMatIndex[it.getDofIndex()] = 
	      stdMpi.getRecvData(it.getRank())[i++];
    }
  }


Thomas Witkowski's avatar
FETI-DP    
Thomas Witkowski committed
140
141
142
143
144
145
146
147
148
149
150
151
  void GlobalDofMap::print()
  {
    FUNCNAME("GlobalDofMap::print()");
    
    MSG("Local to global mapping on this rank: \n");

    for (DofMapping::iterator it = dofMap.begin(); it != dofMap.end(); ++it)
      if (nonRankDofs.count(it->first) == 0)	
	MSG("  %d -> %d  (rank-dof)\n", it->first, it->second);
      else
	MSG("  %d -> %d  \n", it->first, it->second);
  }
152
}