aboutsummaryrefslogtreecommitdiff
path: root/Source/Particles/ShapeFactors.H
blob: 6258f05af7dfa9a807f2bd154c476295cc34bbcc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef SHAPEFACTORS_H_
#define SHAPEFACTORS_H_

using namespace amrex;

// Compute shape factor and return index of leftmost cell where 
// particle writes.
// Specialized templates are defined below for orders 1, 2 and 3.
template <int depos_order>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
int compute_shape_factor(Real* const sx, Real xint) {return 0;};

// Compute shape factor for order 0.
template <>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
int compute_shape_factor <0> (Real* const sx, Real xmid){
    int j = (int) (xmid+0.5);
    sx[0] = 1.0;
    return j;
}

// Compute shape factor for order 1.
template <>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
int compute_shape_factor <1> (Real* const sx, Real xmid){
    int j = (int) xmid;
    Real xint = xmid-j;
    sx[0] = 1.0 - xint;
    sx[1] = xint;
    return j;
}

// Compute shape factor for order 2.
template <>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
int compute_shape_factor <2> (Real* const sx, Real xmid){
    int j = (int) (xmid+0.5);
    Real xint = xmid-j;
    sx[0] = 0.5*(0.5-xint)*(0.5-xint);
    sx[1] = 0.75-xint*xint;
    sx[2] = 0.5*(0.5+xint)*(0.5+xint);
    // index of the leftmost cell where particle deposits
    return j-1;
}

// Compute shape factor for order 3.
template <>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
int compute_shape_factor <3> (Real* const sx, Real xmid){
    int j = (int) xmid;
    Real xint = xmid-j;
    sx[0] = 1.0/6.0*(1.0-xint)*(1.0-xint)*(1.0-xint);
    sx[1] = 2.0/3.0-xint*xint*(1-xint/2.0);
    sx[2] = 2.0/3.0-(1-xint)*(1-xint)*(1.0-0.5*(1-xint));
    sx[3] = 1.0/6.0*xint*xint*xint;
    // index of the leftmost cell where particle deposits
    return j-1;
}

#endif // SHAPEFACTORS_H_