OpenFPM  5.2.0
Project that contain the implementation of distributed structures
poly_levelset.hpp
1 /*
2  * Regression module
3  * Obtains polynomial models for data from vector_dist
4  * author : sachin (sthekke@mpi-cbg.de)
5  * date : 18.01.2023
6  *
7  */
8 #ifndef OPENFPM_NUMERICS_POLYLEVELSET_HPP
9 #define OPENFPM_NUMERICS_POLYLEVELSET_HPP
10 
11 #include "Vector/map_vector.hpp"
12 #include "Space/Shape/Point.hpp"
13 #include "DMatrix/EMatrix.hpp"
14 
15 #include "minter/minter.h"
16 
17 
18 template<int spatial_dim, typename MatType = EMatrixXd, typename VecType = EVectorXd>
20 {
21  minter::LevelsetPoly<spatial_dim, MatType, VecType> *model;
22 
23 public:
24  template<typename vector_type>
25  PolyLevelset(vector_type &vd, double tol)
26  {
27  constexpr int dim = vector_type::dims;
28 
29  MatType points(vd.size_local(), dim);
30 
31  auto it = vd.getDomainIterator();
32  int i = 0;
33  while(it.isNext())
34  {
35  auto key = it.get();
36  for(int j = 0;j < dim;++j)
37  points(i,j) = vd.getPos(key)[j];
38 
39  ++i;
40  ++it;
41  }
42 
43  // construct polynomial model
44  model = new minter::LevelsetPoly<spatial_dim, MatType, VecType>(points, tol);
45  }
46 
47 
48  ~PolyLevelset()
49  {
50  if(model)
51  delete model;
52  }
53 
54  // T : Point<vector_type::dims, typename vector_type::stype>
55  template<typename T>
56  double eval(T pos)
57  {
58  int dim = pos.dims;
59  MatType point(1,dim);
60  for(int j = 0;j < dim;++j)
61  point(0,j) = pos.get(j);
62 
63  return model->eval(point)(0);
64  }
65 
66  // T1 : Point<vector_type::dims, typename vector_type::stype>
67  // T2 : Point<vector_type::dims, int>
68  template<typename T1, typename T2>
69  double deriv(T1 pos, T2 deriv_order)
70  {
71  int dim = pos.dims;
72  MatType point(1,dim);
73  for(int j = 0;j < dim;++j)
74  point(0,j) = pos.get(j);
75 
76  std::vector<int> order;
77  for(int j = 0;j < dim;++j)
78  order.push_back(deriv_order.get(j));
79 
80  return model->deriv_eval(point, order)(0);
81  }
82 
83  // T : Point<vector_type::dims, typename vector_type::stype>
84  template<typename T>
85  T estimate_normals_at(T pos)
86  {
87  int dim = pos.dims;
88  MatType point(1,dim);
89  for(int j = 0;j < dim;++j)
90  point(0,j) = pos.get(j);
91 
92  T normal;
93  auto normal_minter = model->estimate_normals_at(point);
94 
95  for(int j = 0;j < dim;++j)
96  normal.get(j) = normal_minter(0,j);
97 
98  return normal;
99  }
100 
101  // T : Point<vector_type::dims, typename vector_type::stype>
102  template<typename T>
103  double estimate_mean_curvature_at(T pos)
104  {
105  int dim = pos.dims;
106  MatType point(1,dim);
107  for(int j = 0;j < dim;++j)
108  point(0,j) = pos.get(j);
109 
110  auto mc = model->estimate_mean_curvature_at(point);
111 
112  return mc(0);
113  }
114 };
115 
116 
117 
118 #endif /* POLYLEVELSET_HPP_ */
vect_dist_key_dx get()
Get the actual key.
Distributed vector.
size_t size_local() const
return the local size of the vector
static const unsigned int dims
template parameters typedefs
auto getPos(vect_dist_key_dx vec_key) -> decltype(vPos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
vector_dist_iterator getDomainIterator() const
Get an iterator that traverse the particles in the domain.