OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
stencil_type.hpp
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 
17 template<unsigned int dim, unsigned int Np>
19 {
21  static const unsigned int nsp = Np;
22 
24  long int stencil_offset[Np];
25 
28 
29 
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 
48  template<unsigned int id> size_t getStencil() const
49  {
50  return stencil_offset[id];
51  }
52 
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 
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 
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 
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 
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 
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 
154 {
157  static const unsigned int nsp = 1;
158 
166  template<unsigned int id> size_t getStencil() const
167  {return 0;}
168 
169 
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 
191  inline void increment()
192  {}
193 
199  template<unsigned int dim2> void set_stencil(const grid_key_dx<dim2> (& stencil_pnt)[1])
200  {
201  }
202 
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_ */
void private_sum()
Sum a template constant.
void calc_offsets(const ginfo &g, const grid_key_dx< dim2 > &start_p)
Calculate the offsets of the stencil points.
void adjust_offset(size_t i, size_t idr, const ginfo &grid_base)
Adjust the offset.
grid_key_dx< dim > stencil_pnt[Np]
Stencil points.
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
void adjust_offset(size_t i, size_t idr, const ginfo &grid_base)
Adjust the offset.
long int stencil_offset[Np]
set of offsets for the stencil
void increment()
Increment do nothing.
Structure for stencil iterator.
static const unsigned int nsp
size_t getStencil() const
Get the calculated stencil offset.
void set_stencil(const grid_key_dx< dim2 >(&stencil_pnt)[1])
Set the stencil points.
void calc_offsets(const ginfo &g, const grid_key_dx< dim2 > &start_p)
Calculate the stencil offsets.
void calc_offsets(const ginfo &g, const grid_key_dx< dim2 > &start_p, const grid_key_dx< dim2 >(&stencil_pnt)[Np])
Calculate the offsets of the stencil points.
void increment()
Increment the offsets by one.
static const unsigned int nsp
Number of stencil points.
no stencil
size_t getStencil() const
get stencil point
void private_adjust(size_t tot_add)
Sum a template constant.
void set_stencil(const grid_key_dx< dim2 >(&stencil_pnt)[Np])
Set the stencil points.