BackgroundMesh.h 3.18 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/** \file BackgroundMesh.h */

#ifndef BACKGROUND_MESH_H
#define BACKGROUND_MESH_H

// AMDiS-includes
#include "DOFVector.h"		// DOFVector
#include "FiniteElemSpace.h"	// FiniteElemSpace
#include "FixVec.h"		// WorldVector
#include "Global.h"		// DegreeOfFreedom

#ifndef USE_EXPERIMENTAL
#define USE_EXPERIMENTAL
#endif

namespace experimental {

  using namespace AMDiS;
  
  typedef WorldVector<double> PointType;
  
Praetorius, Simon's avatar
Praetorius, Simon committed
22
  inline double distance(const PointType &x, const PointType &y, unsigned int n)
23
24
25
26
27
28
29
  {
    double d = 0.0;
    for (unsigned int i = 0; i < n; i++)
      d += sqr(x[i]-y[i]);
    return sqrt(d);
  }
  
Praetorius, Simon's avatar
Praetorius, Simon committed
30
  inline double distance2(const PointType &x, const PointType &y, unsigned int n)
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  {
    double d = 0.0;
    for (unsigned int i = 0; i < n; i++)
      d += sqr(x[i]-y[i]);
    return d;
  }
  
  typedef std::pair<DegreeOfFreedom, PointType> DataType;

  struct Box {

    Box(int DOW_, std::vector<int> N_);
    Box(int DOW_, PointType min_corner_, PointType max_corner_, std::vector<int> N_);
    void init();

    void fillBox(const FiniteElemSpace* feSpace);
    void clearBox();
    void clearBoxData();

    int getMaxBoxSize();

Praetorius, Simon's avatar
Praetorius, Simon committed
52
53
    bool inBox(const PointType& x);
    int getBox(const PointType& x);
54

Praetorius, Simon's avatar
Praetorius, Simon committed
55
56
    bool getNearestData(const PointType& x, DataType& data);
    bool getNearestData(const PointType& x, std::vector<DataType>& data, int nData);
57
58
59
60
61
62
63
64
65

    /**
    * strategies:
    * 0 .. get nearest point to x and eval DOFVector at this DOF-index
    * 1 .. get n nearest points, calc weighted sum of data at these points
    * 2 .. get n nearest points, calc regression plane and eval at x
    * 3 .. get n nearest points, calc weighted regression plane and eval at x
    **/
    template<typename T>
Praetorius, Simon's avatar
Praetorius, Simon committed
66
    T evalAtPoint(const DOFVector<T>& vec, const PointType& x, int strategy = 0, int nrOfPoints = -1);
67
68
69
70
71
72
73
74
75

    static Box* provideBackgroundMesh(const FiniteElemSpace* feSpace);
    static void delete_all();

    void addData(PointType x, DataType data);

  protected:

    template<typename T>
Praetorius, Simon's avatar
Praetorius, Simon committed
76
    T evalAtPoint_simple(const DOFVector<T>& vec, const PointType& x);
77
78

    template<typename T>
Praetorius, Simon's avatar
Praetorius, Simon committed
79
    T evalAtPoint_weighted_sum(const DOFVector<T>& vec, const PointType& x, int nrOfPoints);
80
81

    template<typename T>
Praetorius, Simon's avatar
Praetorius, Simon committed
82
    T evalAtPoint_regression(const DOFVector<T>& vec, const PointType& x, int nrOfPoints);
83
84

    template<typename T>
Praetorius, Simon's avatar
Praetorius, Simon committed
85
    T evalAtPoint_weighted_regression(const DOFVector<T>& vec, const PointType& x, int nrOfPoints);
86
87
88
89
90
91
92
93
94
95
96

    inline int idx2nr(std::vector<int>& idx);

    inline void nr2idx(int nr, std::vector<int>& idx);


    void getSurroundingBoxes(int nr, std::set<int> &surrounding_nrs);
    void getSurroundingBoxes(int center, int radius, std::set<int> &nrs);
    void getSurroundingBoxes(std::set<int> &nrs, std::set<int> &surrounding_nrs);

    /// berechne die minimale Entfernung der Ränder der Box zu x
Praetorius, Simon's avatar
Praetorius, Simon committed
97
    double getBoxBoundaryDist(int nr, const PointType& x);
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

    static std::map<const FiniteElemSpace*, std::pair<int, Box*> > boxMap;

  private:

    int DOW;
    std::vector<int> N;
    bool boxFilled;

    PointType min_corner;
    PointType max_corner;

    std::vector<std::vector<DataType> > boxData;
  };

} // end namespace experimental

#include "BackgroundMesh.hh"

#endif // BACKGROUND_MESH_H