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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
/* Copyright 2019 Andrew Myers, Axel Huebl, David Grote
* Luca Fedeli, Maxence Thevenet, Revathi Jambunathan
* Weiqun Zhang, levinem, Yinjian Zhao
*
* This file is part of WarpX.
*
* License: BSD-3-Clause-LBNL
*/
#include "Particles/ParticleIO.H"
#include "Particles/MultiParticleContainer.H"
#include "Particles/PhysicalParticleContainer.H"
#include "Particles/LaserParticleContainer.H"
#include "Particles/RigidInjectedParticleContainer.H"
#include "Particles/SpeciesPhysicalProperties.H"
#include "Particles/WarpXParticleContainer.H"
#include "Utils/TextMsg.H"
#include "Utils/WarpXConst.H"
#include "Utils/WarpXProfilerWrapper.H"
#include "WarpX.H"
#include <AMReX_BLassert.H>
#include <AMReX_Config.H>
#include <AMReX_Extension.H>
#include <AMReX_GpuControl.H>
#include <AMReX_GpuLaunch.H>
#include <AMReX_GpuQualifiers.H>
#include <AMReX_PODVector.H>
#include <AMReX_ParIter.H>
#include <AMReX_ParticleIO.H>
#include <AMReX_REAL.H>
#include <AMReX_Vector.H>
#include <algorithm>
#include <array>
#include <istream>
#include <memory>
#include <string>
#include <sstream>
#include <vector>
using namespace amrex;
void
LaserParticleContainer::ReadHeader (std::istream& is)
{
if (do_continuous_injection) {
m_updated_position.resize(3);
for (int i = 0; i < 3; ++i) {
is >> m_updated_position[i];
WarpX::GotoNextLine(is);
}
}
}
void
LaserParticleContainer::WriteHeader (std::ostream& os) const
{
if (do_continuous_injection) {
for (int i = 0; i < 3; ++i) {
os << m_updated_position[i] << "\n";
}
}
}
void
RigidInjectedParticleContainer::ReadHeader (std::istream& is)
{
// Call parent class
PhysicalParticleContainer::ReadHeader( is );
// Read quantities that are specific to rigid-injected species
int nlevs;
is >> nlevs;
WarpX::GotoNextLine(is);
AMREX_ASSERT(zinject_plane_levels.size() == 0);
for (int i = 0; i < nlevs; ++i)
{
amrex::Real zinject_plane_tmp;
is >> zinject_plane_tmp;
zinject_plane_levels.push_back(zinject_plane_tmp);
WarpX::GotoNextLine(is);
}
is >> vzbeam_ave_boosted;
WarpX::GotoNextLine(is);
}
void
RigidInjectedParticleContainer::WriteHeader (std::ostream& os) const
{
// Call parent class
PhysicalParticleContainer::WriteHeader( os );
// Write quantities that are specific to the rigid-injected species
int nlevs = zinject_plane_levels.size();
os << nlevs << "\n";
for (int i = 0; i < nlevs; ++i)
{
os << zinject_plane_levels[i] << "\n";
}
os << vzbeam_ave_boosted << "\n";
}
void
PhysicalParticleContainer::ReadHeader (std::istream& is)
{
is >> charge >> mass;
WarpX::GotoNextLine(is);
}
void
PhysicalParticleContainer::WriteHeader (std::ostream& os) const
{
// no need to write species_id
os << charge << " " << mass << "\n";
}
void
MultiParticleContainer::Restart (const std::string& dir)
{
// note: all containers is sorted like this
// - species_names
// - lasers_names
// we don't need to read back the laser particle charge/mass
for (unsigned i = 0, n = species_names.size(); i < n; ++i) {
WarpXParticleContainer* pc = allcontainers.at(i).get();
std::string header_fn = dir + "/" + species_names[i] + "/Header";
Vector<char> fileCharPtr;
ParallelDescriptor::ReadAndBcastFile(header_fn, fileCharPtr);
std::string fileCharPtrString(fileCharPtr.dataPtr());
std::istringstream is(fileCharPtrString, std::istringstream::in);
is.exceptions(std::ios_base::failbit | std::ios_base::badbit);
std::string line, word;
std::getline(is, line); // Version
std::getline(is, line); // SpaceDim
int nr;
is >> nr;
std::vector<std::string> real_comp_names;
for (int j = 0; j < nr; ++j) {
std::string comp_name;
is >> comp_name;
real_comp_names.push_back(comp_name);
}
for (auto const& comp : pc->getParticleRuntimeComps()) {
auto search = std::find(real_comp_names.begin(), real_comp_names.end(), comp.first);
if (search == real_comp_names.end()) {
amrex::Abort(Utils::TextMsg::Err(
"Species " + species_names[i]
+ "needs runtime real component " + comp.first
+ ", but it was not found in the checkpoint file."
));
}
}
for (int j = PIdx::nattribs; j < nr; ++j) {
const auto& comp_name = real_comp_names[j];
auto current_comp_names = pc->getParticleComps();
auto search = current_comp_names.find(comp_name);
if (search == current_comp_names.end()) {
amrex::Print() << Utils::TextMsg::Info(
"Runtime real component " + comp_name
+ " was found in the checkpoint file, but it has not been added yet. "
+ " Adding it now."
);
pc->AddRealComp(comp_name);
}
}
int ni;
is >> ni;
std::vector<std::string> int_comp_names;
for (int j = 0; j < ni; ++j) {
std::string comp_name;
is >> comp_name;
int_comp_names.push_back(comp_name);
}
for (auto const& comp : pc->getParticleRuntimeiComps()) {
auto search = std::find(int_comp_names.begin(), int_comp_names.end(), comp.first);
if (search == int_comp_names.end()) {
std::stringstream ss;
ss << "Species " << species_names[i] << "needs runtime int component " << comp.first;
ss << ", but it was not found in the checkpoint file. \n";
amrex::Abort(ss.str());
}
}
for (int j = 0; j < ni; ++j) {
const auto& comp_name = int_comp_names[j];
auto current_comp_names = pc->getParticleiComps();
auto search = current_comp_names.find(comp_name);
if (search == current_comp_names.end()) {
amrex::Print()<< Utils::TextMsg::Info(
"Runtime int component " + comp_name
+ " was found in the checkpoint file, but it has not been added yet. "
+ " Adding it now."
);
pc->AddIntComp(comp_name);
}
}
pc->Restart(dir, species_names.at(i));
}
for (unsigned i = species_names.size(); i < species_names.size()+lasers_names.size(); ++i) {
allcontainers.at(i)->Restart(dir, lasers_names.at(i-species_names.size()));
}
}
void
MultiParticleContainer::ReadHeader (std::istream& is)
{
// note: all containers is sorted like this
// - species_names
// - lasers_names
for (unsigned i = 0, n = species_names.size()+lasers_names.size(); i < n; ++i) {
allcontainers.at(i)->ReadHeader(is);
}
}
void
MultiParticleContainer::WriteHeader (std::ostream& os) const
{
// note: all containers is sorted like this
// - species_names
// - lasers_names
for (unsigned i = 0, n = species_names.size()+lasers_names.size(); i < n; ++i) {
allcontainers.at(i)->WriteHeader(os);
}
}
void
PhysicalParticleContainer::ConvertUnits (ConvertDirection convert_direction)
{
WARPX_PROFILE("PhysicalParticleContainer::ConvertUnits()");
// Account for the special case of photons
const auto t_mass =
this->AmIA<PhysicalSpecies::photon>() ? PhysConst::m_e : this->getMass();
particlesConvertUnits(convert_direction, this, t_mass);
}
|