OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
Vandermonde.hpp
1 //
2 // Created by tommaso on 21/03/19.
3 //
4 
5 #ifndef OPENFPM_PDATA_VANDERMONDE_HPP
6 #define OPENFPM_PDATA_VANDERMONDE_HPP
7 
8 #include "MonomialBasis.hpp"
9 #include "VandermondeRowBuilder.hpp"
10 #include "Support.hpp"
11 
12 template<unsigned int dim, typename T, typename MatrixType>
14 {
15 private:
16  const Point<dim, T> point;
17  std::vector<Point<dim, T>> offsets;
18  const MonomialBasis<dim> monomialBasis;
19  T eps;
20 
21 public:
22 /* Vandermonde(const Point<dim, T> &point, const std::vector<Point<dim, T>> &neighbours,
23  const MonomialBasis<dim> &monomialBasis);*/
24 
25  template<typename vector_type>
26  Vandermonde(const Support &support,
27  const MonomialBasis<dim> &monomialBasis,
28  const vector_type & particles)
29  : point(particles.getPosOrig(support.getReferencePointKey())),
30  monomialBasis(monomialBasis)
31  {
32  initialize(support,particles);
33  }
34 
35 
36  MatrixType &getMatrix(MatrixType &M)
37  {
38  // Build the Vandermonde matrix, row-by-row
39  VandermondeRowBuilder<dim, T> vrb(monomialBasis);
40  unsigned int row = 0;
41  for (auto &offset : offsets)
42  {
43  vrb.buildRow(M, row, offset, eps);
44  ++row;
45  }
46  return M;
47  }
48 
49  T getEps()
50  {
51  return eps;
52  }
53 
54 private:
55 
56 
57  void computeEps(T factor)
58  {
59  T avgNeighbourSpacing = 0;
60  for (auto &offset : offsets)
61  {
62  avgNeighbourSpacing += computeAbsSum(offset);
63  }
64  avgNeighbourSpacing /= offsets.size();
65  eps = factor * avgNeighbourSpacing;
66  assert(eps != 0);
67  }
68 
69  static T computeAbsSum(const Point<dim, T> &x)
70  {
71  T absSum = 0;
72  for (unsigned int i = 0; i < dim; ++i)
73  {
74  absSum += fabs(x.value(i));
75  }
76  return absSum;
77  }
78 
79  template<typename vector_type>
80  void initialize(const Support &sup, const vector_type & particles)
81  {
82  auto & keys = sup.getKeys();
83 
84  for (int i = 0 ; i < keys.size() ; i++)
85  {
86  Point<dim,T> p = particles.getPosOrig(sup.getReferencePointKey());
87  p -= particles.getPosOrig(keys[i]);
88  offsets.push_back(p);
89  }
90 
91  // First check that the number of points given is enough for building the Vandermonde matrix
92  if (offsets.size() < monomialBasis.size())
93  {
94  ACTION_ON_ERROR(std::length_error("Not enough neighbour points passed for Vandermonde matrix construction!"));
95  }
96  // Compute eps for this point
97  //factor here. This is C factor.
98  computeEps(2);
99  }
100 
101 };
102 
103 
104 
105 #endif //OPENFPM_PDATA_VANDERMONDE_HPP
auto getPosOrig(vect_dist_key_dx vec_key) const -> decltype(v_pos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:27
Distributed vector.