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 == 1){
93  const auto i = static_cast<int>(x_old);
94  const int i_shift = i - i_new;
95  const T xint = x_old - T(i);
96  sx[1+i_shift] = T(1.0) - xint;
97  sx[2+i_shift] = xint;
98  return i;
99  }
100  else if constexpr (depos_order == 2){
101  const auto i = static_cast<int>(x_old + T(0.5));
102  const int i_shift = i - (i_new + 1);
103  const T xint = x_old - T(i);
104  sx[1+i_shift] = T(0.5)*(T(0.5) - xint)*(T(0.5) - xint);
105  sx[2+i_shift] = T(0.75) - xint*xint;
106  sx[3+i_shift] = T(0.5)*(T(0.5) + xint)*(T(0.5) + xint);
107  // index of the leftmost cell where particle deposits
108  return i - 1;
109  }
110  else if constexpr (depos_order == 3){
111  const auto i = static_cast<int>(x_old);
112  const int i_shift = i - (i_new + 1);
113  const T xint = x_old - i;
114  sx[1+i_shift] = (T(1.0))/(T(6.0))*(T(1.0) - xint)*(T(1.0) - xint)*(T(1.0) - xint);
115  sx[2+i_shift] = (T(2.0))/(T(3.0)) - xint*xint*(T(1.0) - xint/(T(2.0)));
116  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));
117  sx[4+i_shift] = (T(1.0))/(T(6.0))*xint*xint*xint;
118  // index of the leftmost cell where particle deposits
119  return i - 1;
120  }
121  else{
122  WARPX_ABORT_WITH_MESSAGE("Unknown particle shape selected in Compute_shifted_shape_factor");
123  amrex::ignore_unused(sx, x_old, i_new);
124  }
125  return 0;
126  }
127 };
128 
129 #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