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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
#include <numeric>
#include <AMReX_ParallelDescriptor.H>
#include <WarpX.H>
#include <WarpX_f.H>
using namespace amrex;
void
WarpX::InitData ()
{
BL_PROFILE("WarpX::InitData()");
if (restart_chkfile.empty())
{
InitFromScratch();
ComputeDt();
}
else
{
InitFromCheckpoint();
PostRestart();
if (is_synchronized) {
ComputeDt();
}
}
ComputePMLFactors();
InitDiagnostics();
if (ParallelDescriptor::IOProcessor()) {
std::cout << "\nGrids Summary:\n";
printGridSummary(std::cout, 0, finestLevel());
}
if (restart_chkfile.empty())
{
if (plot_int > 0) {
WritePlotFile();
}
if (check_int > 0) {
WriteCheckPointFile();
}
}
}
void
WarpX::InitDiagnostics () {
if (do_boosted_frame_diagnostic) {
const Real* current_lo = geom[0].ProbLo();
const Real* current_hi = geom[0].ProbHi();
Real dt_boost = dt[0];
myBFD.reset(new BoostedFrameDiagnostic(current_lo[moving_window_dir],
current_hi[moving_window_dir],
moving_window_v, dt_snapshots_lab,
num_snapshots_lab, gamma_boost, dt_boost,
moving_window_dir));
}
}
void
WarpX::InitFromScratch ()
{
const Real time = 0.0;
AmrCore::InitFromScratch(time); // This will call MakeNewLevelFromScratch
mypc->AllocData();
mypc->InitData();
#ifdef USE_OPENBC_POISSON
InitOpenbc();
#endif
InitPML();
if (do_electrostatic) {
getLevelMasks(masks);
// the plus one is to convert from num_cells to num_nodes
getLevelMasks(gather_masks, n_buffer + 1);
}
}
void
WarpX::InitPML ()
{
if (do_pml)
{
pml[0].reset(new PML(boxArray(0), DistributionMap(0), &Geom(0), nullptr,
pml_ncell, pml_delta, 0, do_dive_cleaning, do_moving_window));
for (int lev = 1; lev <= finest_level; ++lev)
{
pml[lev].reset(new PML(boxArray(lev), DistributionMap(lev),
&Geom(lev), &Geom(lev-1),
pml_ncell, pml_delta, refRatio(lev-1)[0], do_dive_cleaning,
do_moving_window));
}
}
}
void
WarpX::ComputePMLFactors ()
{
if (do_pml)
{
for (int lev = 0; lev <= finest_level; ++lev)
{
pml[lev]->ComputePMLFactors(dt[lev],pml_type);
}
}
}
void
WarpX::PostRestart ()
{
mypc->PostRestart();
}
#ifdef USE_OPENBC_POISSON
void
WarpX::InitOpenbc ()
{
#ifndef BL_USE_MPI
static_assert(false, "must use MPI");
#endif
static_assert(BL_SPACEDIM == 3, "Openbc is 3D only");
BL_ASSERT(finestLevel() == 0);
const int lev = 0;
const Geometry& gm = Geom(lev);
const Box& gbox = gm.Domain();
int lohi[6];
warpx_openbc_decompose(gbox.loVect(), gbox.hiVect(), lohi, lohi+3);
int nprocs = ParallelDescriptor::NProcs();
int myproc = ParallelDescriptor::MyProc();
Vector<int> alllohi(6*nprocs,100000);
MPI_Allgather(lohi, 6, MPI_INT, alllohi.data(), 6, MPI_INT, ParallelDescriptor::Communicator());
BoxList bl{IndexType::TheNodeType()};
for (int i = 0; i < nprocs; ++i)
{
bl.push_back(Box(IntVect(alllohi[6*i ],alllohi[6*i+1],alllohi[6*i+2]),
IntVect(alllohi[6*i+3],alllohi[6*i+4],alllohi[6*i+5]),
IndexType::TheNodeType()));
}
BoxArray ba{bl};
Vector<int> iprocmap(nprocs+1);
std::iota(iprocmap.begin(), iprocmap.end(), 0);
iprocmap.back() = myproc;
DistributionMapping dm{iprocmap};
MultiFab rho_openbc(ba, dm, 1, 0);
MultiFab phi_openbc(ba, dm, 1, 0);
bool local = true;
const std::unique_ptr<MultiFab>& rho = mypc->GetChargeDensity(lev, local);
rho_openbc.setVal(0.0);
rho_openbc.copy(*rho, 0, 0, 1, rho->nGrow(), 0, gm.periodicity(), FabArrayBase::ADD);
const Real* dx = gm.CellSize();
warpx_openbc_potential(rho_openbc[myproc].dataPtr(), phi_openbc[myproc].dataPtr(), dx);
BoxArray nba = boxArray(lev);
nba.surroundingNodes();
MultiFab phi(nba, DistributionMap(lev), 1, 0);
phi.copy(phi_openbc, gm.periodicity());
#ifdef _OPENMP
#pragma omp parallel
#endif
for (MFIter mfi(phi); mfi.isValid(); ++mfi)
{
const Box& bx = mfi.validbox();
warpx_compute_E(bx.loVect(), bx.hiVect(),
BL_TO_FORTRAN_3D(phi[mfi]),
BL_TO_FORTRAN_3D((*Efield[lev][0])[mfi]),
BL_TO_FORTRAN_3D((*Efield[lev][1])[mfi]),
BL_TO_FORTRAN_3D((*Efield[lev][2])[mfi]),
dx);
}
}
#endif
|