ARTEMIS
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 <AMReX.H>
11 #include <AMReX_GpuQualifiers.H>
12 
13 
25 template <int depos_order>
27 {
28  template< typename T >
31  T* const sx,
32  T xmid) const
33  {
34  if constexpr (depos_order == 0){
35  const auto j = static_cast<int>(xmid + T(0.5));
36  sx[0] = T(1.0);
37  return j;
38  }
39  else if constexpr (depos_order == 1){
40  const auto j = static_cast<int>(xmid);
41  const T xint = xmid - T(j);
42  sx[0] = T(1.0) - xint;
43  sx[1] = xint;
44  return j;
45  }
46  else if constexpr (depos_order == 2){
47  const auto j = static_cast<int>(xmid + T(0.5));
48  const T xint = xmid - T(j);
49  sx[0] = T(0.5)*(T(0.5) - xint)*(T(0.5) - xint);
50  sx[1] = T(0.75) - xint*xint;
51  sx[2] = T(0.5)*(T(0.5) + xint)*(T(0.5) + xint);
52  // index of the leftmost cell where particle deposits
53  return j-1;
54  }
55  else if constexpr (depos_order == 3){
56  const auto j = static_cast<int>(xmid);
57  const T xint = xmid - T(j);
58  sx[0] = (T(1.0))/(T(6.0))*(T(1.0) - xint)*(T(1.0) - xint)*(T(1.0) - xint);
59  sx[1] = (T(2.0))/(T(3.0)) - xint*xint*(T(1.0) - xint/(T(2.0)));
60  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));
61  sx[3] = (T(1.0))/(T(6.0))*xint*xint*xint;
62  // index of the leftmost cell where particle deposits
63  return j-1;
64  }
65  else{
66  amrex::Abort("Unknown particle shape selected in Compute_shape_factor");
67  amrex::ignore_unused(sx, xmid);
68  }
69  return 0;
70  }
71 };
72 
73 
74 
80 template <int depos_order>
82 {
83  template< typename T >
86  T* const sx,
87  const T x_old,
88  const int i_new) const
89  {
90  if constexpr (depos_order == 1){
91  const auto i = static_cast<int>(x_old);
92  const int i_shift = i - i_new;
93  const T xint = x_old - T(i);
94  sx[1+i_shift] = T(1.0) - xint;
95  sx[2+i_shift] = xint;
96  return i;
97  }
98  else if constexpr (depos_order == 2){
99  const auto i = static_cast<int>(x_old + T(0.5));
100  const int i_shift = i - (i_new + 1);
101  const T xint = x_old - T(i);
102  sx[1+i_shift] = T(0.5)*(T(0.5) - xint)*(T(0.5) - xint);
103  sx[2+i_shift] = T(0.75) - xint*xint;
104  sx[3+i_shift] = T(0.5)*(T(0.5) + xint)*(T(0.5) + xint);
105  // index of the leftmost cell where particle deposits
106  return i - 1;
107  }
108  else if constexpr (depos_order == 3){
109  const auto i = static_cast<int>(x_old);
110  const int i_shift = i - (i_new + 1);
111  const T xint = x_old - i;
112  sx[1+i_shift] = (T(1.0))/(T(6.0))*(T(1.0) - xint)*(T(1.0) - xint)*(T(1.0) - xint);
113  sx[2+i_shift] = (T(2.0))/(T(3.0)) - xint*xint*(T(1.0) - xint/(T(2.0)));
114  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));
115  sx[4+i_shift] = (T(1.0))/(T(6.0))*xint*xint*xint;
116  // index of the leftmost cell where particle deposits
117  return i - 1;
118  }
119  else{
120  amrex::Abort("Unknown particle shape selected in Compute_shifted_shape_factor");
121  amrex::ignore_unused(sx, x_old, i_new);
122  }
123  return 0;
124  }
125 };
126 
127 #endif // SHAPEFACTORS_H_
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
void Abort(const std::string &msg)
i
Definition: check_interp_points_and_weights.py:174
Definition: ShapeFactors.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(T *const sx, T xmid) const
Definition: ShapeFactors.H:30
Definition: ShapeFactors.H:82
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator()(T *const sx, const T x_old, const int i_new) const
Definition: ShapeFactors.H:85