FeSpaceMapping.h 3.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ==  http://www.amdis-fem.org                                              ==
// ==                                                                        ==
// ============================================================================
//
// 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.



/** \file FeSpaceMapping.h */

#include <map>
#include "parallel/MpiHelper.h"
#include "parallel/ParallelTypes.h"

#ifndef AMDIS_FE_SPACE_MAPPING_H
#define AMDIS_FE_SPACE_MAPPING_H

namespace AMDiS {
  using namespace std;

  class GlobalDofMap
  {
  public:
    GlobalDofMap(MPI::Intracomm* m)
      : mpiComm(m),
	nRankDofs(0),
	nOverallDofs(0),
	rStartDofs(0)
    {}
    
    void clear()
    {
      dofMap.clear();
      nRankDofs = 0;
      nOverallDofs = 0;
      rStartDofs = 0;
    }
    
    DegreeOfFreedom operator[](DegreeOfFreedom d)
    {
      TEST_EXIT_DBG(dofMap.count(d))("Should not happen!\n");

      return dofMap[d];
    }
    
    void insertRankDof(DegreeOfFreedom dof0, DegreeOfFreedom dof1 = -1)
    {
      FUNCNAME("GlobalDofMap::insertRankDof()");
      
      TEST_EXIT_DBG(dofMap.count(dof0) == 0)("Should not happen!\n");
      
      dofMap[dof0] = (dof1 >= 0 ? dof1 : nRankDofs);
      nRankDofs++;
    }
    
    void insert(DegreeOfFreedom dof0, DegreeOfFreedom dof1)
    {
      FUNCNAME("GlobalDofMap::insert()");
      
      TEST_EXIT_DBG(dofMap.count(dof0) == 0)("Should not happen!\n");
      
      dofMap[dof0] = dof1;
    }
    
    bool isSet(DegreeOfFreedom dof)
    {
      return static_cast<bool>(dofMap.count(dof));
    }
    
    unsigned int size()
    {
      return dofMap.size();
    }
    
    DofMapping& getMap()
    {
      return dofMap;
    }
    
    void update(bool add = true)
    {
      nOverallDofs = 0;
      rStartDofs = 0;
      mpi::getDofNumbering(*mpiComm, nRankDofs, rStartDofs, nOverallDofs);

      if (add)
	addOffset(rStartDofs);
    }

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

  private:
    MPI::Intracomm* mpiComm;
    
    /// 
    DofMapping dofMap;    

  public:
    /// 
    int nRankDofs, nOverallDofs, rStartDofs;   
  };
  

  template<typename T>
  class FeSpaceData
  {
  public:
    FeSpaceData() {} 

    void setMpiComm(MPI::Intracomm *m)
    {
      mpiComm = m;
    }

    T& operator[](const FiniteElemSpace* feSpace)
    {
      FUNCNAME("FeSpaceData::operator[]()");

      TEST_EXIT_DBG(data.count(feSpace))("Should not happen!\n");

      return data.find(feSpace)->second;
    }

    void addFeSpace(const FiniteElemSpace* feSpace)
    {
      FUNCNAME("FeSpaceData::addFeSpace()");
      
      if (data.count(feSpace))
	data.find(feSpace)->second.clear();
      else
	data.insert(make_pair(feSpace, T(mpiComm)));
    }    

  private:
    MPI::Intracomm* mpiComm;
    
    map<const FiniteElemSpace*, T> data;
  };

}

#endif