WarpX
DistanceToEB.H
Go to the documentation of this file.
1 /* Copyright 2021 Andrew Myers
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef DISTANCETOEB_H_
8 #define DISTANCETOEB_H_
9 
10 #include "Utils/TextMsg.H"
11 
12 #include <AMReX.H>
13 #include <AMReX_REAL.H>
14 #include <AMReX_RealVect.H>
15 #include <AMReX_Array.H>
16 
17 #ifdef AMREX_USE_EB
18 
19 namespace DistanceToEB
20 {
21 
23 amrex::Real dot_product (const amrex::RealVect& a, const amrex::RealVect& b) noexcept
24 {
25  return AMREX_D_TERM(a[0]*b[0], + a[1]*b[1], + a[2]*b[2]);
26 }
27 
29 void normalize (amrex::RealVect& a) noexcept
30 {
31  amrex::Real inv_norm = 1.0/std::sqrt(dot_product(a,a));
32  AMREX_D_DECL(a[0] *= inv_norm,
33  a[1] *= inv_norm,
34  a[2] *= inv_norm);
35 }
36 
38 amrex::RealVect interp_normal (int i, int j, int k, const amrex::Real W[AMREX_SPACEDIM][2],
41 {
42 #if (defined WARPX_DIM_3D)
43  amrex::RealVect normal{0.0, 0.0, 0.0};
44 
45  normal[0] -= phi(i, j , k ) * dxi[0] * W[1][0] * W[2][0];
46  normal[0] += phi(i+1, j , k ) * dxi[0] * W[1][0] * W[2][0];
47  normal[0] -= phi(i, j+1, k ) * dxi[0] * W[1][1] * W[2][0];
48  normal[0] += phi(i+1, j+1, k ) * dxi[0] * W[1][1] * W[2][0];
49  normal[0] -= phi(i, j , k+1) * dxi[0] * W[1][0] * W[2][1];
50  normal[0] += phi(i+1, j , k+1) * dxi[0] * W[1][0] * W[2][1];
51  normal[0] -= phi(i , j+1, k+1) * dxi[0] * W[1][1] * W[2][1];
52  normal[0] += phi(i+1, j+1, k+1) * dxi[0] * W[1][1] * W[2][1];
53 
54  normal[1] -= phi(i, j , k ) * dxi[1] * W[0][0] * W[2][0];
55  normal[1] += phi(i , j+1, k ) * dxi[1] * W[0][0] * W[2][0];
56  normal[1] -= phi(i+1, j , k ) * dxi[1] * W[0][1] * W[2][0];
57  normal[1] += phi(i+1, j+1, k ) * dxi[1] * W[0][1] * W[2][0];
58  normal[1] -= phi(i, j , k+1) * dxi[1] * W[0][0] * W[2][1];
59  normal[1] += phi(i , j+1, k+1) * dxi[1] * W[0][0] * W[2][1];
60  normal[1] -= phi(i+1, j , k+1) * dxi[1] * W[0][1] * W[2][1];
61  normal[1] += phi(i+1, j+1, k+1) * dxi[1] * W[0][1] * W[2][1];
62 
63  normal[2] -= phi(i , j , k ) * dxi[2] * W[0][0] * W[1][0];
64  normal[2] += phi(i , j , k+1) * dxi[2] * W[0][0] * W[1][0];
65  normal[2] -= phi(i+1, j , k ) * dxi[2] * W[0][1] * W[1][0];
66  normal[2] += phi(i+1, j , k+1) * dxi[2] * W[0][1] * W[1][0];
67  normal[2] -= phi(i, j+1, k ) * dxi[2] * W[0][0] * W[1][1];
68  normal[2] += phi(i , j+1, k+1) * dxi[2] * W[0][0] * W[1][1];
69  normal[2] -= phi(i+1, j+1, k ) * dxi[2] * W[0][1] * W[1][1];
70  normal[2] += phi(i+1, j+1, k+1) * dxi[2] * W[0][1] * W[1][1];
71 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
72  amrex::RealVect normal{0.0, 0.0};
73 
74  normal[0] -= phi(i, j , k) * dxi[0] * W[1][0];
75  normal[0] += phi(i+1, j , k) * dxi[0] * W[1][0];
76  normal[0] -= phi(i, j+1, k) * dxi[0] * W[1][1];
77  normal[0] += phi(i+1, j+1, k) * dxi[0] * W[1][1];
78 
79  normal[1] -= phi(i, j , k) * dxi[1] * W[0][0];
80  normal[1] += phi(i , j+1, k) * dxi[1] * W[0][0];
81  normal[1] -= phi(i+1, j , k) * dxi[1] * W[0][1];
82  normal[1] += phi(i+1, j+1, k) * dxi[1] * W[0][1];
83 #else
84  amrex::RealVect normal{0.0, 0.0};
85  amrex::ignore_unused(i, j, k, W, phi, dxi);
86  WARPX_ABORT_WITH_MESSAGE("Error: interp_distance not yet implemented in 1D");
87 #endif
88  return normal;
89 }
90 }
91 
92 #endif // AMREX_USE_EB
93 #endif // DISTANCETOEB_H_
#define AMREX_INLINE
#define AMREX_GPU_HOST_DEVICE
#define AMREX_D_TERM(a, b, c)
#define AMREX_D_DECL(a, b, c)
#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