forked from BLAST-WarpX/warpx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoundaryScrapingDiagnostics.cpp
162 lines (135 loc) · 5.32 KB
/
BoundaryScrapingDiagnostics.cpp
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
/* Copyright 2022 Remi Lehe
*
* This file is part of WarpX.
*
* License: BSD-3-Clause-LBNL
*/
#include "BoundaryScrapingDiagnostics.H"
#include "ComputeDiagFunctors/ComputeDiagFunctor.H"
#include "Diagnostics/Diagnostics.H"
#include "Diagnostics/FlushFormats/FlushFormat.H"
#include "Particles/ParticleBoundaryBuffer.H"
#include "Utils/TextMsg.H"
#include "WarpX.H"
#include <AMReX.H>
#include <AMReX_ParmParse.H>
#include <set>
#include <string>
using namespace amrex::literals;
BoundaryScrapingDiagnostics::BoundaryScrapingDiagnostics (int i, std::string name)
: Diagnostics(i, name)
{
ReadParameters();
}
void
BoundaryScrapingDiagnostics::ReadParameters ()
{
BaseReadParameters();
// Modify some of the quantities that were initialized by default
// in the function `BaseReadParameters`
m_varnames_fields = {}; // No fields in boundary scraping diagnostics
m_varnames = {}; // No fields in boundary scraping diagnostics
// num_buffers corresponds to the number of boundaries
// (upper/lower domain boundary in each dimension)
// + the EB boundary if available
m_num_buffers = AMREX_SPACEDIM*2;
#ifdef AMREX_USE_EB
m_num_buffers += 1;
#endif
// Do a few checks
#ifndef WARPX_USE_OPENPMD
WARPX_ABORT_WITH_MESSAGE("You need to compile WarpX with openPMD support, in order to use BoundaryScrapingDiagnostic: -DWarpX_OPENPMD=ON");
#endif
// Check that the output format is openPMD
const std::string error_string = std::string("You need to set `")
.append(m_diag_name)
.append(".format=openpmd` for the BoundaryScrapingDiagnostic.");
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
m_format == "openpmd",
error_string);
// Check for the optional intervals parameter
const amrex::ParmParse pp_diag_name(m_diag_name);
std::vector<std::string> intervals_string_vec = {"0"};
pp_diag_name.queryarr("intervals", intervals_string_vec);
m_intervals = utils::parser::IntervalsParser(intervals_string_vec);
}
void
BoundaryScrapingDiagnostics::InitializeFieldFunctors (int /*lev*/)
{
// This function is usually used for field output
// Nothing to do here for boundary scraping output,
// since it only outputs particles
}
void
BoundaryScrapingDiagnostics::InitializeBufferData (int /*i_buffer*/, int /*lev*/, bool /*restart*/)
{
// This function is usually used for field output
// Nothing to do here for boundary scraping output,
// since it only outputs particles
}
void
BoundaryScrapingDiagnostics::InitializeParticleBuffer ()
{
auto & warpx = WarpX::GetInstance();
const MultiParticleContainer& mpc = warpx.GetPartContainer();
// If the user does not specify any species, dump all species
if (m_output_species_names.empty()) {
m_output_species_names = mpc.GetSpeciesNames();
}
// Initialize one ParticleDiag per species requested
ParticleBoundaryBuffer& particle_buffer = warpx.GetParticleBoundaryBuffer();
for (int i_buffer = 0; i_buffer < m_num_buffers; ++i_buffer) {
for (auto const& species_name : m_output_species_names){
WarpXParticleContainer* pc = &mpc.GetParticleContainerFromName(species_name);
PinnedMemoryParticleContainer* bnd_buffer = particle_buffer.getParticleBufferPointer(species_name, i_buffer);
m_output_species[i_buffer].push_back(ParticleDiag(m_diag_name, species_name, pc, bnd_buffer));
}
}
}
bool
BoundaryScrapingDiagnostics::DoComputeAndPack (int /*step*/, bool /*force_flush*/)
{
return false;
}
bool
BoundaryScrapingDiagnostics::DoDump (int step, int /*i_buffer*/, bool force_flush)
{
if (force_flush) {
return true;
} else {
return (m_intervals.contains(step+1));
}
}
void
BoundaryScrapingDiagnostics::Flush (int i_buffer, bool /* force_flush */)
{
auto & warpx = WarpX::GetInstance();
ParticleBoundaryBuffer& particle_buffer = warpx.GetParticleBoundaryBuffer();
int n_particles = 0;
for (auto const& species_name : m_output_species_names) {
n_particles += particle_buffer.getNumParticlesInContainer(species_name, i_buffer, false);
}
// If the saving of the particles was not set up for any of the species for this boundary
// or if no particles have been lost, then don't write anything out.
if (n_particles == 0) { return; }
// This is not a backtransform diagnostics
bool const isBTD = false;
bool const isLastBTD = false;
int const bufferID = 0;
int const numBTDBuffers = 0;
// The data being written out is saved in a pinned particle container
bool const use_pinned_pc = true;
const amrex::Geometry& geom = warpx.Geom(0); // For compatibility with `WriteToFile` ; not used
// The data for each boundary is written out to a separate directory with the boundary name
const std::string file_prefix = m_file_prefix + "/particles_at_" + particle_buffer.boundaryName(i_buffer);
m_flush_format->WriteToFile(
m_varnames, m_mf_output.at(i_buffer), m_geom_output.at(i_buffer), warpx.getistep(),
warpx.gett_new(0),
m_output_species.at(i_buffer),
nlev_output, file_prefix,
m_file_min_digits, false, false, use_pinned_pc, isBTD,
warpx.getistep(0), bufferID, numBTDBuffers, geom,
isLastBTD);
// Now that the data has been written out, clear out the buffer
particle_buffer.clearParticles(i_buffer);
}