WarpX
ShapeFactors.H
Go to the documentation of this file.
1 /* Copyright 2019-2021 Maxence Thevenet, Michael Rowan, Luca Fedeli, Axel Huebl
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 
10 #include "Utils/TextMsg.H"
11 
12 #include <AMReX.H>
13 #include <AMReX_GpuQualifiers.H>
14 
15 
27 template <int depos_order>
29 {
30  template< typename T >
33  T* const sx,
34  T xmid) const
35  {
36  if constexpr (depos_order == 0){
37  const auto j = static_cast<int>(xmid + T(0.5));
38  sx[0] = T(1.0);
39  return j;
40  }
41  else if constexpr (depos_order == 1){
42  const auto j = static_cast<int>(xmid);
43  const T xint = xmid - T(j);
44  sx[0] = T(1.0) - xint;
45  sx[1] = xint;
46  return j;
47  }
48  else if constexpr (depos_order == 2){
49  const auto j = static_cast<int>(xmid + T(0.5));
50  const T xint = xmid - T(j);
51  sx[0] = T(0.5)*(T(0.5) - xint)*(T(0.5) - xint);
52  sx[1] = T(0.75) - xint*xint;
53  sx[2] = T(0.5)*(T(0.5) + xint)*(T(0.5) + xint);
54  // index of the leftmost cell where particle deposits
55  return j-1;
56  }
57  else if constexpr (depos_order == 3){
58  const auto j = static_cast<int>(xmid);
59  const T xint = xmid - T(j);
60  sx[0] = (T(1.0))/(T(6.0))*(T(1.0) - xint)*(T(1.0) - xint)*(T(1.0) - xint);
61  sx[1] = (T(2.0))/(T(3.0)) - xint*xint*(T(1.0) - xint/(T(2.0)));
62  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));
63  sx[3] = (T(1.0))/(T(6.0))*xint*xint*xint;
64  // index of the leftmost cell where particle deposits
65  return j-1;
66  }
67  else{
68  WARPX_ABORT_WITH_MESSAGE("Unknown particle shape selected in Compute_shape_factor");
69  amrex::ignore_unused(sx, xmid);
70  }
71  return 0;
72  }
73 };
74 
75 
76 
82 template <int depos_order>
84 {
85  template< typename T >
88  T* const sx,
89  const T x_old,
90  const int i_new) const
91  {
92  if constexpr (depos_order == 0){
93  const auto i = static_cast<int>(std::floor(x_old + T(0.5)));
94  const int i_shift = i - i_new;
95  sx[1+i_shift] = T(1.0);
96  return i;
97  }
98  else if constexpr (depos_order == 1){
99  const auto i = static_cast<int>(std::floor(x_old));
100  const int i_shift = i - i_new;
101  const T xint = x_old - T(i);
102  sx[1+i_shift] = T(1.0) - xint;
103  sx[2+i_shift] = xint;
104  return i;
105  }
106  else if constexpr (depos_order == 2){
107  const auto i = static_cast<int>(x_old + T(0.5));
108  const int i_shift = i - (i_new + 1);
109  const T xint = x_old - T(i);
110  sx[1+i_shift] = T(0.5)*(T(0.5) - xint)*(T(0.5) - xint);
111  sx[2+i_shift] = T(0.75) - xint*xint;
112  sx[3+i_shift] = T(0.5)*(T(0.5) + xint)*(T(0.5) + xint);
113  // index of the leftmost cell where particle deposits
114  return i - 1;
115  }
116  else if constexpr (depos_order == 3){
117  const auto i = static_cast<int>(x_old);
118  const int i_shift = i - (i_new + 1);
119  const T xint = x_old - i;
120  sx[1+i_shift] = (T(1.0))/(T(6.0))*(T(1.0) - xint)*(T(1.0) - xint)*(T(1.0) - xint);
121  sx[2+i_shift] = (T(2.0))/(T(3.0)) - xint*xint*(T(1.0) - xint/(T(2.0)));
122  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));
123  sx[4+i_shift] = (T(1.0))/(T(6.0))*xint*xint*xint;
124  // index of the leftmost cell where particle deposits
125  return i - 1;
126  }
127  else{
128  WARPX_ABORT_WITH_MESSAGE("Unknown particle shape selected in Compute_shifted_shape_factor");
129  amrex::ignore_unused(sx, x_old, i_new);
130  }
131  return 0;
132  }
133 };
134 
135 #endif // SHAPEFACTORS_H_
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
#define WARPX_ABORT_WITH_MESSAGE(MSG)
Definition: TextMsg.H:15
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
i
Definition: check_interp_points_and_weights.py:174
Definition: ShapeFactors.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(T *const sx, T xmid) const
Definition: ShapeFactors.H:32
Definition: ShapeFactors.H:84
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(T *const sx, const T x_old, const int i_new) const
Definition: ShapeFactors.H:87