OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
DcpseDiagonalScalingMatrix.hpp
1//
2// Created by tommaso on 29/03/19.
3// Modified by Serhii
4//
5
6#ifndef OPENFPM_PDATA_DCPSEDIAGONALSCALINGMATRIX_HPP
7#define OPENFPM_PDATA_DCPSEDIAGONALSCALINGMATRIX_HPP
8
9#include "MonomialBasis.hpp"
10#include "Support.hpp"
11
12
13template <unsigned int dim, typename monomialBasis_type = MonomialBasis<dim>>
15{
16private:
17 const monomialBasis_type& monomialBasis;
18
19public:
20 DcpseDiagonalScalingMatrix(const monomialBasis_type &monomialBasis) : monomialBasis(monomialBasis) {}
21
22 template <typename T, typename MatrixType, typename vector_type, typename vector_type2>
23 void buildMatrix(MatrixType &M, Support support, T eps, vector_type & particlesFrom , vector_type2 & particlesTo)
24 {
25 // Check that all the dimension constraints are met
26 assert(support.size() >= monomialBasis.size());
27 assert(M.rows() == support.size());
28 assert(M.cols() == support.size());
29
30 Point<dim,typename vector_type::stype> ref_p = particlesTo.getPosOrig(support.getReferencePointKey());
31
32 // Fill the diagonal matrix
33 M.setZero(); // Make sure the rest of the matrix is zero!
34 const auto& support_keys = support.getKeys();
35 size_t N = support_keys.size();
36 for (size_t i = 0; i < N; ++i)
37 {
38 const auto& pt = support_keys.get(i);
40 p -= particlesFrom.getPosOrig(pt);
41
42 M(i,i) = exp(- norm2(p) / (2.0 * eps * eps));
43 }
44 }
45
46 template <typename T, typename vector_type, typename vector_type2>
47 __host__ __device__ void buildMatrix(T* M, size_t supportRefKey, size_t supportKeysSize, const size_t* supportKeys, T eps, vector_type & particlesFrom, vector_type2 & particlesTo)
48 {
49 // Check that all the dimension constraints are met
50 assert(supportKeysSize >= monomialBasis.size());
51
52 Point<dim,typename vector_type::stype> ref_p = particlesTo.getPos(supportRefKey);
53
54 for (size_t i = 0; i < supportKeysSize; ++i)
55 {
56 size_t pt = supportKeys[i];
58 p -= particlesFrom.getPos(pt);
59
60 M[i] = exp(- norm2(p) / (2.0 * eps * eps));
61 }
62 }
63};
64
65#endif //OPENFPM_PDATA_DCPSEDIAGONALSCALINGMATRIX_HPP
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
auto getPosOrig(vect_dist_key_dx vec_key) -> decltype(vd.getPos(vec_key))
Get the position of an element.
auto getPos(vect_dist_key_dx vec_key) -> decltype(vd.getPos(vec_key))
Get the position of an element.
Distributed vector.
auto getPos(vect_dist_key_dx vec_key) -> decltype(v_pos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
auto getPosOrig(vect_dist_key_dx vec_key) const -> decltype(v_pos.template get< 0 >(vec_key.getKey()))
Get the position of an element.