WarpX
Loading...
Searching...
No Matches
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
17namespace DistanceToEB
18{
19
21amrex::Real dot_product (const amrex::RealVect& a, const amrex::RealVect& b) noexcept
22{
23 return AMREX_D_TERM(a[0]*b[0], + a[1]*b[1], + a[2]*b[2]);
24}
25
27void normalize (amrex::RealVect& a) noexcept
28{
29 using namespace amrex::literals;
30 amrex::Real const inv_norm = 1.0_rt / std::sqrt(dot_product(a, a));
31 AMREX_D_DECL(a[0] *= inv_norm,
32 a[1] *= inv_norm,
33 a[2] *= inv_norm);
34}
35
36
37
38// This function calculates the normal vector using the nodal and cell-centered data.
39// i,j,k are the index of the nearest node to the left of the point at which we interpolate.
40// W are the interpolation weight for the left and right nodes (for the 0th component and 1st component respectively)
41// ic,jc,kc are the index of the nearest cell-center to the left of the point at which we interpolate.
43amrex::RealVect interp_normal (int i, int j, int k, const amrex::Real W[AMREX_SPACEDIM][2],
44 int ic, int jc, int kc, const amrex::Real Wc[AMREX_SPACEDIM][2],
47{
48 using namespace amrex::literals;
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 const icstart = ic + iic;
57 amrex::Real const sign = (ii%2)*2._rt - 1._rt;
58 int const wccomp = static_cast<int>(iic%2);
59 int const w1comp = static_cast<int>(jj%2);
60 int const 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 const jcstart = jc + iic;
71 amrex::Real const sign = (jj%2)*2._rt - 1._rt;
72 int const wccomp = static_cast<int>(iic%2);
73 int const w1comp = static_cast<int>(ii%2);
74 int const 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 const kcstart = kc + iic;
85 amrex::Real const sign = (kk%2)*2._rt - 1._rt;
86 int const wccomp = static_cast<int>(iic%2);
87 int const w1comp = static_cast<int>(ii%2);
88 int const 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 const icstart = ic + iic;
101 amrex::Real const sign = (ii%2)*2._rt - 1._rt;
102 int const wccomp = static_cast<int>(iic%2);
103 int const 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 const jcstart = jc + iic;
112 amrex::Real const sign = (jj%2)*2._rt - 1._rt;
113 int const wccomp = static_cast<int>(iic%2);
114 int const 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);
124
127 ))
129 WARPX_ABORT_WITH_MESSAGE("Error: interp_normal not yet implemented in 1D");
130 ))
131
132#endif
133 return normal;
134}
135}
136#endif // WARPX_DISTANCETOEB_H_
#define AMREX_INLINE
#define AMREX_DEVICE_ASSERT(flag)
#define AMREX_IF_ON_DEVICE(CODE)
#define AMREX_IF_ON_HOST(CODE)
#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
Definition DistanceToEB.H:18
AMREX_GPU_HOST_DEVICE AMREX_INLINE void normalize(amrex::RealVect &a) noexcept
Definition DistanceToEB.H:27
AMREX_GPU_HOST_DEVICE AMREX_INLINE amrex::RealVect interp_normal(int i, int j, int k, const amrex::Real W[3][2], int ic, int jc, int kc, const amrex::Real Wc[3][2], amrex::Array4< const amrex::Real > const &phi, amrex::GpuArray< amrex::Real, 3 > const &dxi) noexcept
Definition DistanceToEB.H:43
AMREX_GPU_HOST_DEVICE AMREX_INLINE amrex::Real dot_product(const amrex::RealVect &a, const amrex::RealVect &b) noexcept
Definition DistanceToEB.H:21
__host__ __device__ void ignore_unused(const Ts &...)
RealVectND< 3 > RealVect