PeriodicMap.cc 4.36 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.


Thomas Witkowski's avatar
Thomas Witkowski committed
13
#include <map>
14
#include <fstream>
Thomas Witkowski's avatar
Thomas Witkowski committed
15
#include "Global.h"
16
#include "parallel/ElementObjectDatabase.h"
17
#include "parallel/PeriodicMap.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
18
#include "parallel/ParallelTypes.h"
19
20
21

namespace AMDiS {

Thomas Witkowski's avatar
Thomas Witkowski committed
22
23
  using namespace std;

24
  void PeriodicMap::add(const FiniteElemSpace *feSpace,
25
			PeriodicDofMap &newMap)
26
27
28
  {
    FUNCNAME("PeriodicMap::add()");
    
Thomas Witkowski's avatar
Thomas Witkowski committed
29
30
    for (PeriodicDofMap::iterator it = newMap.begin(); it != newMap.end(); ++it) {
      for (std::map<DegreeOfFreedom, DegreeOfFreedom>::iterator dofIt = it->second.begin();
31
	   dofIt != it->second.end(); ++dofIt)
32
	add(feSpace, it->first, dofIt->second, dofIt->first);
Thomas Witkowski's avatar
Thomas Witkowski committed
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
  void PeriodicMap::fillAssociations(const FiniteElemSpace* feSpace,
				     int globalDofIndex,
				     const ElementObjectDatabase &elObjDb,
				     std::set<int>& perAsc)
  {
    if (isPeriodic(feSpace, globalDofIndex) == false)
      return;

    std::set<int>& tmpAsc = getAssociations(feSpace, globalDofIndex);
    for (std::set<int>::iterator it = tmpAsc.begin(); it != tmpAsc.end(); ++it)
      if (elObjDb.isValidPeriodicType(*it))
	perAsc.insert(*it);
  }


  void PeriodicMap::mapDof(const FiniteElemSpace* feSpace,
			   int globalDofIndex, 
			   const std::set<int>& perAsc, 
			   vector<int>& mappedDofs)
  {
    mappedDofs.clear();
    mappedDofs.push_back(globalDofIndex);
    
    for (std::set<int>::const_iterator it = perAsc.begin();
	 it != perAsc.end(); ++it) {
      int nDofs = static_cast<int>(mappedDofs.size());
      
      for (int i = 0; i < nDofs; i++) {
	TEST_EXIT_DBG(isPeriodic(feSpace, *it, mappedDofs[i]))
	  ("Wrong periodic DOF associations at boundary %d with DOF %d!\n",
	   *it, mappedDofs[i]);
	
	mappedDofs.push_back(map(feSpace, *it, mappedDofs[i]));
      }
    }
  }


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
  void PeriodicMap::serialize(ostream &out, 
			      vector<const FiniteElemSpace*> feSpaces)
  {
    FUNCNAME("PeriodicMap::serialize()");
    
    int nFeSpace = static_cast<int>(feSpaces.size());
    
    for (int i = 0; i < nFeSpace; i++)
      serialize(out, periodicDofMap[feSpaces[i]]);
    
    for (int i = 0; i < nFeSpace; i++)
      serialize(out, periodicDofAssociations[feSpaces[i]]);
  }


  void PeriodicMap::deserialize(istream &in, 
				vector<const FiniteElemSpace*> feSpaces)
  {      
    FUNCNAME("PeriodicMap::deserialize()");
    
    int nFeSpace = static_cast<int>(feSpaces.size());
    
    for (int i = 0; i < nFeSpace; i++)
      deserialize(in, periodicDofMap[feSpaces[i]]);
    
    for (int i = 0; i < nFeSpace; i++)
      deserialize(in, periodicDofAssociations[feSpaces[i]]);
  }
  
  
  void PeriodicMap::serialize(ostream &out, PeriodicDofMap &data)
  {
    int mapSize = data.size();
    SerUtil::serialize(out, mapSize);
    
    for (PeriodicDofMap::iterator it = data.begin(); it != data.end(); ++it) {
      int type = it->first;
Thomas Witkowski's avatar
Thomas Witkowski committed
112
      std::map<DegreeOfFreedom, DegreeOfFreedom> dofMap = it->second;
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
      
      SerUtil::serialize(out, type);
      SerUtil::serialize(out, dofMap);
    }
  }
  

  void PeriodicMap::serialize(ostream &out, std::map<int, std::set<int> >& data)
  {
    int mapSize = data.size();
    SerUtil::serialize(out, mapSize);
    
    for (std::map<int, std::set<int> >::iterator it = data.begin(); 
	 it != data.end(); ++it) {
      int dof = it->first;
      std::set<int> typeSet = it->second;
      
      SerUtil::serialize(out, dof);
      SerUtil::serialize(out, typeSet);
    }
  }
  
  
  void PeriodicMap::deserialize(istream &in, PeriodicDofMap &data)
  {
    data.clear();
    
    int mapSize = 0;
    SerUtil::deserialize(in, mapSize);
    
    for (int i = 0; i < mapSize; i++) {
      int type;
Thomas Witkowski's avatar
Thomas Witkowski committed
145
      std::map<DegreeOfFreedom, DegreeOfFreedom> dofMap;
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
      
      SerUtil::deserialize(in, type);
      SerUtil::deserialize(in, dofMap);
      
      data[type] = dofMap;
    }
  }
  
  
  void PeriodicMap::deserialize(istream &in, std::map<int, std::set<int> >& data)
  {
    data.clear();
    
    int mapSize = 0;
    SerUtil::deserialize(in, mapSize);
    
    for (int i = 0; i < mapSize; i++) {
      int dof;
      std::set<int> typeSet;
      
      SerUtil::deserialize(in, dof);
      SerUtil::deserialize(in, typeSet);
      
      data[dof] = typeSet;
    }
  }
  
}