FeSpaceMapping.cc 2.54 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();
44 45 46 47 48 49 50 51 52
  }


  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
53 54 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 94 95 96 97 98 99 100 101 102 103
  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++];
    }
  }


  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);
  }
104
}