WarpX
ShapeFactors.H
Go to the documentation of this file.
1 /* Copyright 2019 Maxence Thevenet, Michael Rowan
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef SHAPEFACTORS_H_
8 #define SHAPEFACTORS_H_
9 
21 template <int depos_order>
23 {
24  template< typename T >
25  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
26  int operator()(T* const /*sx*/, T /*xint*/) const { return 0; }
27 };
28 
34 template <>
36 {
37  template< typename T >
38  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
39  int operator()(T* const sx, T xmid) const
40  {
41  const auto j = static_cast<int>(xmid + T(0.5));
42  sx[0] = T(1.0);
43  return j;
44  }
45 };
46 
52 template <>
54 {
55  template< typename T >
56  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
57  int operator()(T* const sx, T xmid) const
58  {
59  const auto j = static_cast<int>(xmid);
60  const T xint = xmid - T(j);
61  sx[0] = T(1.0) - xint;
62  sx[1] = xint;
63  return j;
64  }
65 };
66 
72 template <>
74 {
75  template< typename T >
76  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
77  int operator()(T* const sx, T xmid) const
78  {
79  const auto j = static_cast<int>(xmid + T(0.5));
80  const T xint = xmid - T(j);
81  sx[0] = T(0.5)*(T(0.5) - xint)*(T(0.5) - xint);
82  sx[1] = T(0.75) - xint*xint;
83  sx[2] = T(0.5)*(T(0.5) + xint)*(T(0.5) + xint);
84  // index of the leftmost cell where particle deposits
85  return j-1;
86  }
87 };
88 
94 template <>
96 {
97  template< typename T >
98  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
99  int operator()(T* const sx, T xmid) const
100  {
101  const auto j = static_cast<int>(xmid);
102  const T xint = xmid - T(j);
103  sx[0] = (T(1.0))/(T(6.0))*(T(1.0) - xint)*(T(1.0) - xint)*(T(1.0) - xint);
104  sx[1] = (T(2.0))/(T(3.0)) - xint*xint*(T(1.0) - xint/(T(2.0)));
105  sx[2] = (T(2.0))/(T(3.0)) - (T(1.0) - xint)*(T(1.0) - xint)*(T(1.0) - T(0.5)*(T(1.0) - xint));
106  sx[3] = (T(1.0))/(T(6.0))*xint*xint*xint;
107  // index of the leftmost cell where particle deposits
108  return j-1;
109  }
110 };
111 
117 template <int depos_order>
119 {
120  template< typename T >
121  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
122  int operator()(T* const sx, const T x_old, const int i_new) const;
123 };
124 
130 template <>
132 {
133  template< typename T >
134  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
135  int operator()(T* const sx, const T x_old, const int i_new) const
136  {
137  const auto i = static_cast<int>(x_old);
138  const int i_shift = i - i_new;
139  const T xint = x_old - T(i);
140  sx[1+i_shift] = T(1.0) - xint;
141  sx[2+i_shift] = xint;
142  return i;
143  }
144 };
145 
151 template <>
153 {
154  template< typename T >
155  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
156  int operator()(T* const sx, const T x_old, const int i_new) const
157  {
158  const auto i = static_cast<int>(x_old + T(0.5));
159  const int i_shift = i - (i_new + 1);
160  const T xint = x_old - T(i);
161  sx[1+i_shift] = T(0.5)*(T(0.5) - xint)*(T(0.5) - xint);
162  sx[2+i_shift] = T(0.75) - xint*xint;
163  sx[3+i_shift] = T(0.5)*(T(0.5) + xint)*(T(0.5) + xint);
164  // index of the leftmost cell where particle deposits
165  return i - 1;
166  }
167 };
168 
174 template <>
176 {
177  template< typename T >
178  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
179  int operator()(T* const sx, const T x_old, const int i_new) const
180  {
181  const auto i = static_cast<int>(x_old);
182  const int i_shift = i - (i_new + 1);
183  const T xint = x_old - i;
184  sx[1+i_shift] = (T(1.0))/(T(6.0))*(T(1.0) - xint)*(T(1.0) - xint)*(T(1.0) - xint);
185  sx[2+i_shift] = (T(2.0))/(T(3.0)) - xint*xint*(T(1.0) - xint/(T(2.0)));
186  sx[3+i_shift] = (T(2.0))/(T(3.0)) - (T(1.0) - xint)*(T(1.0) - xint)*(T(1.0) - T(0.5)*(T(1.0) - xint));
187  sx[4+i_shift] = (T(1.0))/(T(6.0))*xint*xint*xint;
188  // index of the leftmost cell where particle deposits
189  return i - 1;
190  }
191 };
192 
193 #endif // SHAPEFACTORS_H_
Definition: ShapeFactors.H:118
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(T *const sx, const T x_old, const int i_new) const
Definition: ShapeFactors.H:156
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(T *const sx, T xmid) const
Definition: ShapeFactors.H:99
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(T *const sx, T xmid) const
Definition: ShapeFactors.H:57
Definition: ShapeFactors.H:22
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(T *const sx, T xmid) const
Definition: ShapeFactors.H:77
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(T *const, T) const
Definition: ShapeFactors.H:26
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(T *const sx, T xmid) const
Definition: ShapeFactors.H:39
i
Definition: check_interp_points_and_weights.py:171
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(T *const sx, const T x_old, const int i_new) const
Definition: ShapeFactors.H:135
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(T *const sx, const T x_old, const int i_new) const
Definition: ShapeFactors.H:179