DOFSerializer.cc 3.65 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
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
#include "DOFSerializer.h"

#include <algorithm>

#include "DOFVector.h"
#include "Global.h"
#include "Traverse.h"

namespace AMDiS
{    
    
// satre values of DOFVector on all macro elements to internal container
void DOFSerializer::gather(DOFVector<double> const* vec, std::vector<double>& values)
{
  std::fill(visited_.begin(), visited_.end(), false);
  values.clear();
    
  for (auto* macroEl : mesh_->getMacroElements())
    gather(macroEl->getIndex(), vec, values, false);
}


// satre values of DOFVector on macro element `macroIndex` to internal container
void DOFSerializer::gather(int macroIndex, DOFVector<double> const* vec, std::vector<double>& values, bool reset)
{
  if (reset) {
    std::fill(visited_.begin(), visited_.end(), false);
    values.clear();
  }
  
  TraverseStack stack;
  ElInfo *elInfo = stack.traverseFirstOneMacro(mesh_, macroIndex, -1, Mesh::CALL_EVERY_EL_PREORDER);
  while (elInfo) {
    Element *el = elInfo->getElement();
    
    if (el->isLeaf()) {
      gather(VERTEX, elInfo, vec, values);
      if (mesh_->getDim() > 1)
        gather(EDGE, elInfo, vec, values);
      if (mesh_->getDim() == 3)
        gather(FACE, elInfo, vec, values);
      gather(CENTER, elInfo, vec, values);
    }
    
    elInfo = stack.traverseNext(elInfo);
  }
}


void DOFSerializer::gather(GeoIndex geo, ElInfo* elInfo, DOFVector<double> const* vec, std::vector<double>& values) 
{
  int nd;
  if ((nd = admin_->getNumberOfDofs(geo)))  {
    int vertices = mesh_->getGeo(geo);
    int nd0 = admin_->getNumberOfPreDofs(geo);
    int n0 = mesh_->getNode(geo);
    for (int n = 0; n < vertices; n++) {
      for(int d = 0; d < nd; d++) {
        DegreeOfFreedom globalDof = elInfo->getElement()->getDof(n0 + n, nd0 + d);
        if (!visited_[globalDof]) {
          visited_[globalDof] = true;
          values.push_back((*vec)[globalDof]);
        }
      }
    }
  }
}


// assign stored values to DOFVector, for all macro elements
void DOFSerializer::scatter(std::vector<double> const& values, DOFVector<double>* vec) const
{
  std::fill(visited_.begin(), visited_.end(), false);
  counter_ = 0u;
    
  for (auto* macroEl : mesh_->getMacroElements())
    scatter(macroEl->getIndex(), values, vec, false);
}


// assign stored values to DOFVector, on macroElement with index `macroIndex`
void DOFSerializer::scatter(int macroIndex, std::vector<double> const& values, DOFVector<double>* vec, bool reset) const
{    
  if (reset) {
    std::fill(visited_.begin(), visited_.end(), false);
    counter_ = 0u;
  }
  
  TraverseStack stack;
  ElInfo *elInfo = stack.traverseFirstOneMacro(mesh_, macroIndex, -1, Mesh::CALL_EVERY_EL_PREORDER);
  while (elInfo) {
    Element *el = elInfo->getElement();
    
    if (el->isLeaf()) {
      scatter(VERTEX, elInfo, values, vec);
      if (mesh_->getDim() > 1)
        scatter(EDGE, elInfo, values, vec);
      if (mesh_->getDim() == 3)
        scatter(FACE, elInfo, values, vec);
      scatter(CENTER, elInfo, values, vec);
    }
    
    elInfo = stack.traverseNext(elInfo);
  }
}


void DOFSerializer::scatter(GeoIndex geo, ElInfo* elInfo, std::vector<double> const& values, DOFVector<double>* vec) const
{
  int nd;
  if ((nd = admin_->getNumberOfDofs(geo)))  {
    int vertices = mesh_->getGeo(geo);
    int nd0 = admin_->getNumberOfPreDofs(geo);
    int n0 = mesh_->getNode(geo);
    for (int n = 0; n < vertices; n++) {
      for(int d = 0; d < nd; d++) {
        DegreeOfFreedom globalDof = elInfo->getElement()->getDof(n0 + n, nd0 + d);
        if (!visited_[globalDof]) {
          visited_[globalDof] = true;
          assert( values.size() < counter_);
          (*vec)[globalDof] = values[counter_++];
        }
      }
    }
  }
}


} // end namespace AMDiS