DOFSerializer.cc 4.03 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
#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();
  }
  
31
32
  TEST_EXIT(mesh_ == vec->getFeSpace()->getMesh())("Incompatible meshes!\n");
  
Praetorius, Simon's avatar
Praetorius, Simon committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  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)))  {
56
    int entities = mesh_->getGeo(geo);
Praetorius, Simon's avatar
Praetorius, Simon committed
57
58
    int nd0 = admin_->getNumberOfPreDofs(geo);
    int n0 = mesh_->getNode(geo);
59
    for (int n = 0; n < entities; n++) {
Praetorius, Simon's avatar
Praetorius, Simon committed
60
61
      for(int d = 0; d < nd; d++) {
        DegreeOfFreedom globalDof = elInfo->getElement()->getDof(n0 + n, nd0 + d);
62
        TEST_EXIT(globalDof < visited_.size())("visited container not large enough!\n");
Praetorius, Simon's avatar
Praetorius, Simon committed
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
        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;
  }
  
92
93
  TEST_EXIT(mesh_ == vec->getFeSpace()->getMesh())("Incompatible meshes!\n");
  
Praetorius, Simon's avatar
Praetorius, Simon committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  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)))  {
117
    int entities = mesh_->getGeo(geo);
Praetorius, Simon's avatar
Praetorius, Simon committed
118
119
    int nd0 = admin_->getNumberOfPreDofs(geo);
    int n0 = mesh_->getNode(geo);
120
    for (int n = 0; n < entities; n++) {
Praetorius, Simon's avatar
Praetorius, Simon committed
121
122
      for(int d = 0; d < nd; d++) {
        DegreeOfFreedom globalDof = elInfo->getElement()->getDof(n0 + n, nd0 + d);
123
        TEST_EXIT(globalDof < visited_.size())("visited container not large enough!\n");
Praetorius, Simon's avatar
Praetorius, Simon committed
124
125
        if (!visited_[globalDof]) {
          visited_[globalDof] = true;
126
          TEST_EXIT(counter_ < values.size())("Not enough values in value-container!\n");
Praetorius, Simon's avatar
Praetorius, Simon committed
127
128
129
130
131
132
133
134
135
          (*vec)[globalDof] = values[counter_++];
        }
      }
    }
  }
}


} // end namespace AMDiS