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 WARPX_DISTANCETOEB_H_
8 #define WARPX_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 
37 
38 
39 // This function calculates the normal vector using the nodal and cell-centered data.
40 // i,j,k are the index of the nearest node to the left of the point at which we interpolate.
41 // W are the interpolation weight for the left and right nodes (for the 0th component and 1st component respectively)
42 // ic,jc,kc are the index of the nearest cell-center to the left of the point at which we interpolate.
44 amrex::RealVect interp_normal (int i, int j, int k, const amrex::Real W[AMREX_SPACEDIM][2],
45  int ic, int jc, int kc, const amrex::Real Wc[AMREX_SPACEDIM][2],
48 {
49 
50 #if (defined WARPX_DIM_3D)
51  amrex::RealVect normal{0.0, 0.0, 0.0};
52  for (int iic = 0; iic < 2; ++iic) {
53  for (int kk = 0; kk < 2; ++kk) {
54  for (int jj=0; jj< 2; ++jj) {
55  for (int ii = 0; ii < 2; ++ii) {
56  int icstart = ic + iic;
57  amrex::Real sign = (ii%2)*2. - 1.;
58  int wccomp = static_cast<int>(iic%2);
59  int w1comp = static_cast<int>(jj%2);
60  int w2comp = static_cast<int>(kk%2);
61  normal[0] += sign * phi(icstart + ii, j + jj, k + kk) * dxi[0] * Wc[0][wccomp] * W[1][w1comp] * W[2][w2comp];
62  }
63  }
64  }
65  }
66  for (int iic = 0; iic < 2; ++iic) {
67  for (int kk = 0; kk < 2; ++kk) {
68  for (int ii=0; ii< 2; ++ii) {
69  for (int jj = 0; jj < 2; ++jj) {
70  int jcstart = jc + iic;
71  amrex::Real sign = (jj%2)*2. - 1.;
72  int wccomp = static_cast<int>(iic%2);
73  int w1comp = static_cast<int>(ii%2);
74  int w2comp = static_cast<int>(kk%2);
75  normal[1] += sign * phi(i + ii, jcstart + jj, k + kk) * dxi[1] * W[0][w1comp] * Wc[1][wccomp] * W[2][w2comp];
76  }
77  }
78  }
79  }
80  for (int iic = 0; iic < 2; ++iic) {
81  for (int jj = 0; jj < 2; ++jj) {
82  for (int ii=0; ii< 2; ++ii) {
83  for (int kk = 0; kk < 2; ++kk) {
84  int kcstart = kc + iic;
85  amrex::Real sign = (kk%2)*2. - 1.;
86  int wccomp = static_cast<int>(iic%2);
87  int w1comp = static_cast<int>(ii%2);
88  int w2comp = static_cast<int>(jj%2);
89  normal[2] += sign * phi(i + ii, j + jj, kcstart + kk) * dxi[2] * W[0][w1comp] * W[1][w2comp] * Wc[2][wccomp];
90  }
91  }
92  }
93  }
94 
95 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
96  amrex::RealVect normal{0.0, 0.0};
97  for (int iic = 0; iic < 2; ++iic) {
98  for (int jj=0; jj< 2; ++jj) {
99  for (int ii = 0; ii < 2; ++ii) {
100  int icstart = ic + iic;
101  amrex::Real sign = (ii%2)*2. - 1.;
102  int wccomp = static_cast<int>(iic%2);
103  int w1comp = static_cast<int>(jj%2);
104  normal[0] += sign * phi(icstart + ii, j + jj, k) * dxi[0] * Wc[0][wccomp] * W[1][w1comp];
105  }
106  }
107  }
108  for (int iic = 0; iic < 2; ++iic) {
109  for (int ii=0; ii< 2; ++ii) {
110  for (int jj = 0; jj < 2; ++jj) {
111  int jcstart = jc + iic;
112  amrex::Real sign = (jj%2)*2. - 1.;
113  int wccomp = static_cast<int>(iic%2);
114  int w1comp = static_cast<int>(ii%2);
115  normal[1] += sign * phi(i + ii, jcstart + jj, k) * dxi[1] * W[0][w1comp] * Wc[1][wccomp];
116  }
117  }
118  }
120 
121 #else
122  amrex::ignore_unused(i, j, k, ic, jc, kc, W, Wc, phi, dxi);
123  amrex::RealVect normal{0.0, 0.0};
124  WARPX_ABORT_WITH_MESSAGE("Error: interp_distance not yet implemented in 1D");
125 
126 #endif
127  return normal;
128 }
129 }
130 
131 #endif // AMREX_USE_EB
132 #endif // WARPX_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
ii
Definition: check_interp_points_and_weights.py:148
jj
Definition: check_interp_points_and_weights.py:160