1/*
2 * stencil_type.hpp
3 *
4 * Created on: Jun 25, 2017
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_DATA_SRC_GRID_ITERATORS_STENCIL_TYPE_HPP_
9#define OPENFPM_DATA_SRC_GRID_ITERATORS_STENCIL_TYPE_HPP_
10
11/*! \brief Structure for stencil iterator
12 *
13 *
14 * \tparam Np number of stencil points
15 *
16 */
17template<unsigned int dim, unsigned int Np>
18struct stencil_offset_compute
19{
20 //! Number of stencil points
21 static const unsigned int nsp = Np;
22
23 //! set of offsets for the stencil
24 long int stencil_offset[Np];
25
26 //! Stencil points
27 grid_key_dx<dim> stencil_pnt[Np];
28
29
30 /*! \brief Set the stencil points
31 *
32 * \param stencil points
33 *
34 */
35 template<unsigned int dim2> void set_stencil(const grid_key_dx<dim2> (& stencil_pnt)[Np])
36 {
37 for (size_t i = 0 ; i < Np ; i++)
38 {this->stencil_pnt[i] = stencil_pnt[i];}
39 }
40
41 /*! \brief Get the calculated stencil offset
42 *
43 * \tparam id stencil point
44 *
45 * \return the point
46 *
47 */
48 template<unsigned int id> size_t getStencil() const
49 {
50 return stencil_offset[id];
51 }
52
53 /*! \brief Calculate the offsets of the stencil points
54 *
55 * \param g object storing the grid information
56 * \param start_p starting point where we calculate the stencil offsets
57 *
58 *
59 */
60 template<unsigned int dim2, typename ginfo>
61 inline void calc_offsets(const ginfo & g,
62 const grid_key_dx<dim2> & start_p)
63 {
64 for (size_t i = 0 ; i < Np ; i++)
65 {
66 grid_key_dx<dim2> zero;
67 zero = start_p + stencil_pnt[i];
68
69 stencil_offset[i] = g.LinId(zero);
70 }
71 }
72
73 /*! \brief Calculate the offsets of the stencil points
74 *
75 * \tparam dim dimensionality
76 * \tparam ginfo grid information object
77 *
78 * \param g information of the grid
79 * \param start_p starting point
80 * \param stencil_pnt stencil points in the grid
81 *
82 *
83 */
84 template<unsigned int dim2,typename ginfo>
85 inline void calc_offsets(const ginfo & g,
86 const grid_key_dx<dim2> & start_p,
87 const grid_key_dx<dim2> (& stencil_pnt)[Np])
88 {
89 for (size_t i = 0 ; i < Np ; i++)
90 {
91 grid_key_dx<dim2> offset_point;
92 this->stencil_pnt[i] = stencil_pnt[i];
93 offset_point = start_p + stencil_pnt[i];
94 stencil_offset[i] = g.LinId(offset_point);
95 }
96 }
97
98 /*! \brief Increment the offsets by one
99 *
100 *
101 */
102 inline void increment()
103 {
104 // update the offsets
105 for (size_t i = 0 ; i < Np ; i++)
106 stencil_offset[i] += 1;
107 }
108
109 /*! \brief Adjust the offset
110 *
111 * \param i component
112 * \param idr component
113 * \param grid_base obbect containing the grid informations
114 *
115 */
116 template<typename ginfo> inline void adjust_offset(size_t i, size_t idr, const ginfo & grid_base)
117 {
118 size_t str_dw = (i == 0)?1:grid_base.size_s(i-1);
119
120 // update the offsets
121 for (size_t k = 0 ; k < Np ; k++)
122 {stencil_offset[k] += -str_dw*idr + grid_base.size_s(i);}
123 }
124
125 /*! \brief Sum a template constant
126 *
127 * \tparam compile-time offset
128 *
129 */
130 template<unsigned int tot_add>
131 inline void private_sum()
132 {
133 for (size_t i = 0 ; i < Np ; i++)
134 {stencil_offset[i] += tot_add;}
135 }
136
137 /*! \brief Sum a template constant
138 *
139 * \param tot_add Add an offset to all the pointer
140 *
141 */
142 inline void private_adjust(size_t tot_add)
143 {
144 for (size_t i = 0 ; i < Np ; i++)
145 {stencil_offset[i] += tot_add;}
146 }
147
148};
149
150/*! \brief no stencil
151 *
152 */
153struct no_stencil
154{
155 //! dimensions of space, should be zero but is one 1
156 //! otherwise can produce zero length arrays
157 static const unsigned int nsp = 1;
158
159 /*! \brief get stencil point
160 *
161 * do nothing
162 *
163 * \return 0
164 *
165 */
166 template<unsigned int id> size_t getStencil() const
167 {return 0;}
168
169
170 /*! \brief Calculate the stencil offsets
171 *
172 * \tparam ginfo grid information object
173 * \tparam dim2 dimensionality of the starting point
174 *
175 * do nothing
176 *
177 * \param g grid information
178 * \param start_p starting point
179 *
180 */
181 template<unsigned int dim2, typename ginfo>
182 inline void calc_offsets(const ginfo & g,
183 const grid_key_dx<dim2> & start_p)
184 {}
185
186 /*! \brief Increment do nothing
187 *
188 * do nothing
189 *
190 */
191 inline void increment()
192 {}
193
194 /*! \brief Set the stencil points
195 *
196 * \param stencil_pnt stencil points
197 *
198 */
199 template<unsigned int dim2> void set_stencil(const grid_key_dx<dim2> (& stencil_pnt)[1])
200 {
201 }
202
203 /*! \brief Adjust the offset
204 *
205 * do nothing
206 *
207 * \param i component
208 * \param idr previous component value
209 * \param grid_base information of the grid
210 *
211 */
212 template<typename ginfo> inline void adjust_offset(size_t i, size_t idr, const ginfo & grid_base)
213 {}
214};
215
216
217
218#endif /* OPENFPM_DATA_SRC_GRID_ITERATORS_STENCIL_TYPE_HPP_ */
219