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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/* Copyright 2022 David Grote
*
* This file is part of WarpX.
*
* License: BSD-3-Clause-LBNL
*/
#include "WarpX.H"
#include "LatticeElementFinder.H"
#include "LatticeElements/HardEdgedQuadrupole.H"
#include "LatticeElements/HardEdgedPlasmaLens.H"
#include <AMReX_ParmParse.H>
#include <AMReX_REAL.H>
using namespace amrex::literals;
void
LatticeElementFinder::InitElementFinder (int const lev, amrex::MFIter const& a_mfi,
AcceleratorLattice const& accelerator_lattice)
{
// The lattice is assumed to extend in the z-direction
// Get the number of nodes where indices will be setup
const amrex::Box box = a_mfi.tilebox();
m_nz = box.size()[WARPX_ZINDEX];
m_dz = WarpX::CellSize(lev)[2];
m_gamma_boost = WarpX::gamma_boost;
m_uz_boost = std::sqrt(WarpX::gamma_boost*WarpX::gamma_boost - 1._prt)*PhysConst::c;
AllocateIndices(accelerator_lattice);
UpdateIndices(lev, a_mfi, accelerator_lattice);
}
void
LatticeElementFinder::AllocateIndices (AcceleratorLattice const& accelerator_lattice)
{
// Allocate the space for the indices for each element type.
// Note that this uses m_nz since the information is saved per node.
if (accelerator_lattice.h_quad.nelements > 0) {
d_quad_indices.resize(m_nz);
}
if (accelerator_lattice.h_plasmalens.nelements > 0) {
d_plasmalens_indices.resize(m_nz);
}
}
void
LatticeElementFinder::UpdateIndices (int const lev, amrex::MFIter const& a_mfi,
AcceleratorLattice const& accelerator_lattice)
{
auto& warpx = WarpX::GetInstance();
// Update the location of the index grid.
// Note that the current box is used since the box may have been updated since
// the initialization in InitElementFinder.
const amrex::Box box = a_mfi.tilebox();
m_zmin = WarpX::LowerCorner(box, lev, 0._rt)[2];
m_time = warpx.gett_new(lev);
if (accelerator_lattice.h_quad.nelements > 0) {
setup_lattice_indices(accelerator_lattice.h_quad.d_zs,
accelerator_lattice.h_quad.d_ze,
d_quad_indices);
}
if (accelerator_lattice.h_plasmalens.nelements > 0) {
setup_lattice_indices(accelerator_lattice.h_plasmalens.d_zs,
accelerator_lattice.h_plasmalens.d_ze,
d_plasmalens_indices);
}
}
LatticeElementFinderDevice
LatticeElementFinder::GetFinderDeviceInstance (WarpXParIter const& a_pti, int const a_offset,
AcceleratorLattice const& accelerator_lattice)
{
LatticeElementFinderDevice result;
result.InitLatticeElementFinderDevice(a_pti, a_offset, accelerator_lattice, *this);
return result;
}
void
LatticeElementFinderDevice::InitLatticeElementFinderDevice (WarpXParIter const& a_pti, int const a_offset,
AcceleratorLattice const& accelerator_lattice,
LatticeElementFinder const & h_finder)
{
auto& warpx = WarpX::GetInstance();
int const lev = a_pti.GetLevel();
m_get_position = GetParticlePosition(a_pti, a_offset);
auto& attribs = a_pti.GetAttribs();
m_ux = attribs[PIdx::ux].dataPtr() + a_offset;
m_uy = attribs[PIdx::uy].dataPtr() + a_offset;
m_uz = attribs[PIdx::uz].dataPtr() + a_offset;
m_dt = warpx.getdt(lev);
m_gamma_boost = WarpX::gamma_boost;
m_uz_boost = std::sqrt(WarpX::gamma_boost*WarpX::gamma_boost - 1._prt)*PhysConst::c;
m_zmin = h_finder.m_zmin;
m_dz = h_finder.m_dz;
m_time = h_finder.m_time;
if (accelerator_lattice.h_quad.nelements > 0) {
d_quad = accelerator_lattice.h_quad.GetDeviceInstance();
d_quad_indices_arr = h_finder.d_quad_indices.data();
}
if (accelerator_lattice.h_plasmalens.nelements > 0) {
d_plasmalens = accelerator_lattice.h_plasmalens.GetDeviceInstance();
d_plasmalens_indices_arr = h_finder.d_plasmalens_indices.data();
}
}
|