ProcKeys.hpp 3.23 KB
Newer Older
incardon's avatar
incardon committed
1
2
3
4
5
6
7
8
9
10
/*
 * ProcKeys.hpp
 *
 *  Created on: Mar 14, 2017
 *      Author: i-bird
 */

#ifndef OPENFPM_DATA_SRC_NN_CELLLIST_PROCKEYS_HPP_
#define OPENFPM_DATA_SRC_NN_CELLLIST_PROCKEYS_HPP_

incardon's avatar
incardon committed
11
12
13
14
extern "C"
{
#include "hilbertKey.h"
}
incardon's avatar
incardon committed
15
16
17
18
19
20
21
22

/* !Brief Class for a linear (1D-like) order processing of cell keys for CellList_gen implementation
 *
 * \tparam dim Dimansionality of the space
 */
template<unsigned int dim, typename CellList>
class Process_keys_lin
{
incardon's avatar
incardon committed
23
	//! stub object
incardon's avatar
incardon committed
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
	openfpm::vector<size_t> keys;

public:

	//! Particle Iterator produced by this key generator
	typedef ParticleIt_CellP<CellList> Pit;

	/*! \brief Return cellkeys vector
	 *
	 * \return vector of cell keys
	 *
	 */
	inline const openfpm::vector<size_t> & getKeys() const
	{
		return keys;
	}

	/*! \brief Get a linear (1D-like) key from the coordinates and add to the getKeys vector
	 *
	 * \tparam S Cell list type
	 *
	 * \param obj Cell list object
	 * \param gk grid key
	 * \param m order of a curve
	 */
incardon's avatar
incardon committed
49
	template<typename S> void get_hkey(S & obj, grid_key_dx<dim> gk, size_t m)
incardon's avatar
incardon committed
50
51
52
53
54
55
56
57
	{
		size_t point[dim];

		for (size_t i = 0; i < dim; i++)
		{
			point[i] = gk.get(i) + obj.getPadding(i);
		}

incardon's avatar
incardon committed
58
		keys.add(obj.getGrid().LinIdPtr(static_cast<size_t *>(point)));
incardon's avatar
incardon committed
59
60
	}

incardon's avatar
incardon committed
61
	template<typename S> void linearize_hkeys(S & obj, size_t m)
incardon's avatar
incardon committed
62
63
64
65
66
	{
		return;
	}
};

incardon's avatar
incardon committed
67
/*! \brief Class for an hilbert order processing of cell keys for CellList_gen implementation
incardon's avatar
incardon committed
68
69
70
71
72
73
 *
 * \tparam dim Dimansionality of the space
 */
template<unsigned int dim, typename CellList>
class Process_keys_hilb
{
incardon's avatar
incardon committed
74
	//! vector for storing the cell keys
incardon's avatar
incardon committed
75
76
	openfpm::vector<size_t> keys;

incardon's avatar
incardon committed
77
	//! vector for storing the particle keys
incardon's avatar
incardon committed
78
79
	openfpm::vector<size_t> p_keys;

incardon's avatar
incardon committed
80
81
	//! Order of an hilbert curve
	size_t m = 0;
incardon's avatar
incardon committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

public:

	//! Particle Iterator produced by this key generator
	typedef ParticleIt_CellP<CellList> Pit;

	/*! \brief Return cellkeys vector
	 *
	 * \return vector of cell keys
	 *
	 */
	inline const openfpm::vector<size_t> & getKeys() const
	{
		return keys;
	}

	/*! \brief Get an hilbert key from the coordinates and add to the getKeys vector
	 *
	 * \tparam S Cell list type
	 *
	 * \param obj Cell list object
	 * \param gk grid key
	 * \param m order of a curve
	 */
	template<typename S> inline void get_hkey(S & obj, grid_key_dx<dim> gk, size_t m)
	{
		//An integer to handle errors
		int err;

		uint64_t point[dim];

		for (size_t i = 0; i < dim; i++)
		{
			point[i] = gk.get(i);
		}

		size_t hkey = getHKeyFromIntCoord(m, dim, point, &err);

incardon's avatar
incardon committed
120
		keys.add(hkey);
incardon's avatar
incardon committed
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
	}

	/*! \brief Get get the coordinates from hilbert key, linearize and add to the getKeys vector
	 *
	 * \tparam S Cell list type
	 *
	 * \param obj Cell list object
	 * \param m order of a curve
	 */
	template<typename S> inline void linearize_hkeys(S & obj, size_t m)
	{
		//An integer to handle errors
		int err;

		//Array to handle output
		uint64_t coord[dim];
		size_t coord2[dim];

incardon's avatar
incardon committed
139
		keys.sort();
incardon's avatar
incardon committed
140
141
142
143
144
145
146
147
148
149
150
151

		openfpm::vector<size_t> keys_new;

		for(size_t i = 0; i < obj.getKeys().size(); i++)
		{
			getIntCoordFromHKey(coord, m, dim, obj.getKeys().get(i), &err);

			for (size_t j = 0 ; j < dim ; j++)	{coord2[j] = coord[j] + obj.getPadding(j);}

			keys_new.add(obj.getGrid().LinIdPtr(static_cast<size_t *>(coord2)));
		}

incardon's avatar
incardon committed
152
		keys.swap(keys_new);
incardon's avatar
incardon committed
153
154
155
156
	}
};

#endif /* OPENFPM_DATA_SRC_NN_CELLLIST_PROCKEYS_HPP_ */