DOFSerializer.h 2.87 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
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors:
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 *
 ******************************************************************************/



/** \file DOFSerializer.h */

#ifndef AMDIS_DOFSERIALIZER_H
#define AMDIS_DOFSERIALIZER_H

#include <vector>
#include <algorithm>

#include "DOFAdmin.h"
#include "ElInfo.h"
#include "Global.h"
#include "Mesh.h"
#include "Traverse.h"

namespace AMDiS
{
  // Collect all DOFValues into a std::vector, by traversing the mesh macro-elenment wise
  // Can be used to transfer data on macro elements or to store values in a file, e.g. in ARHWriter
  class DOFSerializer
  {
  public:
    
    /// Constructor, stores a pointer to the DOFAdmin. If the number of values to store can be estimated,
    /// pass a second argument `numValues`
    DOFSerializer(DOFAdmin* admin, std::size_t numValues = 0)
      : admin_(admin)
      , mesh_(admin->getMesh())
      , visited_(admin->getUsedSize(), false)
    {}
    
    
    // satre values of DOFVector on all macro elements to internal container
    void gather(DOFVector<double> const* vec, std::vector<double>& values);
    
    // satre values of DOFVector on macro element `macroIndex` to internal container
    void gather(int macroIndex, DOFVector<double> const* vec, std::vector<double>& values, bool reset = true);
    
    
    // assign stored values to DOFVector, for all macro elements
    void scatter(std::vector<double> const& values, DOFVector<double>* vec) const;
    
    // assign stored values to DOFVector, on macroElement with index `macroIndex`
    void scatter(int macroIndex, std::vector<double> const& values, DOFVector<double>* vec, bool reset = true) const;

      
  protected:
    
    // collect values of one geometry-type
    void gather(GeoIndex geo, ElInfo* elInfo, DOFVector<double> const* vec, std::vector<double>& values);
    
    // assign values of one geometry type
    void scatter(GeoIndex geo, ElInfo* elInfo, std::vector<double> const& values, DOFVector<double>* vec) const;
    
    
  protected:
    
    DOFAdmin* admin_;
    Mesh* mesh_;
    
    // stored which DOFs were already visited during traversal
    mutable std::vector<bool> visited_;
    
    // a counter used during assignment of values. To guarantee the same order as during gather
    mutable std::size_t counter_ = 0u;
  };

} // end namespace AMDiS

#endif // AMDIS_DOFSERIALIZER_H