WarpX
Loading...
Searching...
No Matches
CylindricalYeeAlgorithm.H
Go to the documentation of this file.
1/* Copyright 2020 Remi Lehe
2 *
3 * This file is part of WarpX.
4 *
5 * License: BSD-3-Clause-LBNL
6 */
7
8#ifndef WARPX_FINITE_DIFFERENCE_ALGORITHM_CYLINDRICAL_YEE_H_
9#define WARPX_FINITE_DIFFERENCE_ALGORITHM_CYLINDRICAL_YEE_H_
10
11#include "Utils/WarpXConst.H"
12
13#include <AMReX.H>
14#include <AMReX_Array4.H>
15#include <AMReX_Gpu.H>
16#include <AMReX_REAL.H>
17
18#include <array>
19#include <cmath>
20
21
27
29 std::array<amrex::Real,3>& cell_size,
30 amrex::Vector<amrex::Real>& stencil_coefs_r,
31 amrex::Vector<amrex::Real>& stencil_coefs_z ) {
32
33 using namespace amrex;
34 // Store the inverse cell size along each direction in the coefficients
35 stencil_coefs_r.resize(1);
36 stencil_coefs_r[0] = 1._rt/cell_size[0]; // 1./dr
37 stencil_coefs_z.resize(1);
38 stencil_coefs_z[0] = 1._rt/cell_size[2]; // 1./dz
39 }
40
46 static amrex::Real ComputeMaxDt ( amrex::Real const * const dx,
47 int const n_rz_azimuthal_modes ) {
48 using namespace amrex::literals;
49#ifdef WARPX_DIM_RZ
50 // In the rz case, the Courant limit has been evaluated
51 // semi-analytically by R. Lehe, and resulted in the following
52 // coefficients.
53 std::array< amrex::Real, 6 > const multimode_coeffs = {{ 0.2105_rt, 1.0_rt, 3.5234_rt, 8.5104_rt, 15.5059_rt, 24.5037_rt }};
54 const amrex::Real multimode_alpha = (n_rz_azimuthal_modes < 7)?
55 multimode_coeffs[n_rz_azimuthal_modes-1]: // Use the table of the coefficients
56 (n_rz_azimuthal_modes - 1._rt)*(n_rz_azimuthal_modes - 1._rt) - 0.4_rt; // Use a realistic extrapolation
57 const amrex::Real delta_t = 1._rt / ( std::sqrt(
58 (1._rt + multimode_alpha) / (dx[0]*dx[0])
59 + 1._rt / (dx[1]*dx[1])
60 ) * PhysConst::c );
61#elif defined(WARPX_DIM_RCYLINDER)
62 // The numerical value of the max Dt below was determined empirically (for one case)
63 amrex::ignore_unused(n_rz_azimuthal_modes);
64 const amrex::Real delta_t = 0.8_rt * dx[0] / PhysConst::c;
65#endif
66 return delta_t;
67 }
68
73 // The cylindrical solver requires one guard cell in each dimension
74 return amrex::IntVect{AMREX_D_DECL(1,1,1)};
75 }
76
82 static amrex::Real UpwardDrr_over_r (
84 amrex::Real const r, amrex::Real const dr,
85 amrex::Real const * const coefs_r, int const n_coefs_r,
86 int const i, int const j, int const k, int const comp ) {
87
88 using namespace amrex;
89 ignore_unused(n_coefs_r);
90
91 Real const inv_dr = coefs_r[0];
92 return 1._rt/r * inv_dr*( (r+0.5_rt*dr)*F(i+1,j,k,comp) - (r-0.5_rt*dr)*F(i,j,k,comp) );
93 }
94
100 static amrex::Real DownwardDrr_over_r (
102 amrex::Real const r, amrex::Real const dr,
103 amrex::Real const * const coefs_r, int const n_coefs_r,
104 int const i, int const j, int const k, int const comp ) {
105
106 using namespace amrex;
107 ignore_unused(n_coefs_r);
108
109 Real const inv_dr = coefs_r[0];
110 return 1._rt/r * inv_dr*( (r+0.5_rt*dr)*F(i,j,k,comp) - (r-0.5_rt*dr)*F(i-1,j,k,comp) );
111 }
112
116 static amrex::Real UpwardDr (
118 amrex::Real const * const coefs_r, int const n_coefs_r,
119 int const i, int const j, int const k, int const comp ) {
120
121 using namespace amrex;
122 ignore_unused(n_coefs_r);
123
124 Real const inv_dr = coefs_r[0];
125 return inv_dr*( F(i+1,j,k,comp) - F(i,j,k,comp) );
126 }
127
131 static amrex::Real DownwardDr (
133 amrex::Real const * const coefs_r, int const n_coefs_r,
134 int const i, int const j, int const k, int const comp ) {
135
136 using namespace amrex;
137 ignore_unused(n_coefs_r);
138
139 Real const inv_dr = coefs_r[0];
140 return inv_dr*( F(i,j,k,comp) - F(i-1,j,k,comp) );
141 }
142
146 template< typename T_Field>
148 static amrex::Real Dr_rDr_over_r (
149 T_Field const& F,
150 amrex::Real const r, amrex::Real const dr,
151 amrex::Real const * const coefs_r, int const /*n_coefs_r*/,
152 int const i, int const j, int const k, int const comp ) {
153
154 using namespace amrex;
155
156 Real const inv_dr2 = coefs_r[0]*coefs_r[0];
157 return 1._rt/r * inv_dr2*( (r+0.5_rt*dr)*(F(i+1,j,k,comp) - F(i,j,k,comp))
158 - (r-0.5_rt*dr)*(F(i,j,k,comp) - F(i-1,j,k,comp)) );
159 }
160
164 static amrex::Real UpwardDz (
166 amrex::Real const * const coefs_z, int const n_coefs_z,
167 int const i, int const j, int const k, int const comp ) {
168
169 amrex::ignore_unused(n_coefs_z);
170
171#ifdef WARPX_DIM_RZ
172 amrex::Real const inv_dz = coefs_z[0];
173 return inv_dz*( F(i,j+1,k,comp) - F(i,j,k,comp) );
174#elif defined(WARPX_DIM_RCYLINDER)
175 using namespace amrex::literals;
176 amrex::ignore_unused(F, coefs_z, i, j, k, comp);
177 return 0._rt;
178#endif
179 }
180
184 static amrex::Real DownwardDz (
186 amrex::Real const * const coefs_z, int const n_coefs_z,
187 int const i, int const j, int const k, int const comp ) {
188
189 amrex::ignore_unused(n_coefs_z);
190
191#ifdef WARPX_DIM_RZ
192 amrex::Real const inv_dz = coefs_z[0];
193 return inv_dz*( F(i,j,k,comp) - F(i,j-1,k,comp) );
194#elif defined(WARPX_DIM_RCYLINDER)
195 using namespace amrex::literals;
196 amrex::ignore_unused(F, coefs_z, i, j, k, comp);
197 return 0._rt;
198#endif
199 }
200
203 template< typename T_Field>
205 static amrex::Real Dzz (
206 T_Field const& F,
207 amrex::Real const * const coefs_z, int const /*n_coefs_z*/,
208 int const i, int const j, int const k, int const ncomp=0 ) {
209
210 using namespace amrex;
211
212#ifdef WARPX_DIM_RZ
213 Real const inv_dz2 = coefs_z[0]*coefs_z[0];
214 return inv_dz2*( F(i,j-1,k,ncomp) - 2._rt*F(i,j,k,ncomp) + F(i,j+1,k,ncomp) );
215#elif defined(WARPX_DIM_RCYLINDER)
216 amrex::ignore_unused(F, coefs_z, i, j, k, ncomp);
217 return 0._rt;
218#endif
219 }
220
221};
222
223#endif // WARPX_FINITE_DIFFERENCE_ALGORITHM_CYLINDRICAL_YEE_H_
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
#define AMREX_D_DECL(a, b, c)
constexpr auto c
vacuum speed of light [m/s]
Definition constant.H:149
__host__ __device__ void ignore_unused(const Ts &...)
IntVectND< 3 > IntVect
Definition CylindricalYeeAlgorithm.H:26
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real Dzz(T_Field const &F, amrex::Real const *const coefs_z, int const, int const i, int const j, int const k, int const ncomp=0)
Definition CylindricalYeeAlgorithm.H:205
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real DownwardDr(amrex::Array4< amrex::Real const > const &F, amrex::Real const *const coefs_r, int const n_coefs_r, int const i, int const j, int const k, int const comp)
Definition CylindricalYeeAlgorithm.H:131
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real DownwardDrr_over_r(amrex::Array4< amrex::Real const > const &F, amrex::Real const r, amrex::Real const dr, amrex::Real const *const coefs_r, int const n_coefs_r, int const i, int const j, int const k, int const comp)
Definition CylindricalYeeAlgorithm.H:100
static amrex::IntVect GetMaxGuardCell()
Returns maximum number of guard cells required by the field-solve.
Definition CylindricalYeeAlgorithm.H:72
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real UpwardDrr_over_r(amrex::Array4< amrex::Real const > const &F, amrex::Real const r, amrex::Real const dr, amrex::Real const *const coefs_r, int const n_coefs_r, int const i, int const j, int const k, int const comp)
Definition CylindricalYeeAlgorithm.H:82
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real Dr_rDr_over_r(T_Field const &F, amrex::Real const r, amrex::Real const dr, amrex::Real const *const coefs_r, int const, int const i, int const j, int const k, int const comp)
Definition CylindricalYeeAlgorithm.H:148
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real DownwardDz(amrex::Array4< amrex::Real const > const &F, amrex::Real const *const coefs_z, int const n_coefs_z, int const i, int const j, int const k, int const comp)
Definition CylindricalYeeAlgorithm.H:184
static amrex::Real ComputeMaxDt(amrex::Real const *const dx, int const n_rz_azimuthal_modes)
Definition CylindricalYeeAlgorithm.H:46
static void InitializeStencilCoefficients(std::array< amrex::Real, 3 > &cell_size, amrex::Vector< amrex::Real > &stencil_coefs_r, amrex::Vector< amrex::Real > &stencil_coefs_z)
Definition CylindricalYeeAlgorithm.H:28
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real UpwardDz(amrex::Array4< amrex::Real const > const &F, amrex::Real const *const coefs_z, int const n_coefs_z, int const i, int const j, int const k, int const comp)
Definition CylindricalYeeAlgorithm.H:164
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real UpwardDr(amrex::Array4< amrex::Real const > const &F, amrex::Real const *const coefs_r, int const n_coefs_r, int const i, int const j, int const k, int const comp)
Definition CylindricalYeeAlgorithm.H:116