ImpactX
Loading...
Searching...
No Matches
BeamMonitor.H
Go to the documentation of this file.
1/* Copyright 2022-2023 The Regents of the University of California, through Lawrence
2 * Berkeley National Laboratory (subject to receipt of any required
3 * approvals from the U.S. Dept. of Energy). All rights reserved.
4 *
5 * This file is part of ImpactX.
6 *
7 * Authors: Axel Huebl
8 * License: BSD-3-Clause-LBNL
9 */
10#ifndef IMPACTX_ELEMENTS_DIAGS_BEAMMONITOR_H
11#define IMPACTX_ELEMENTS_DIAGS_BEAMMONITOR_H
12
13#include "elements/mixin/thin.H"
17
18#include <AMReX_Extension.H>
19#include <AMReX_REAL.H>
20
21#include <any>
22#include <string>
23#include <unordered_map>
24#include <vector>
25
26
28{
29namespace detail
30{
32 public:
34 using ParticleIter = typename ParticleContainer::ParIterType;
35
37
38 unsigned long GetTotalNumParticles () { return m_Total; }
39
40 std::vector<unsigned long long> m_ParticleOffsetAtRank;
41 std::vector<unsigned long long> m_ParticleSizeAtRank;
42 private:
49 void GetParticleOffsetOfProcessor (const long &numParticles,
50 unsigned long long &offset,
51 unsigned long long &sum) const;
52
53 int m_MPIRank = 0;
54 int m_MPISize = 1;
55
56 unsigned long long m_Total = 0;
57
58 std::vector<unsigned long long> m_ParticleCounterByLevel;
59 };
60} // namespace detail
61
68 : public mixin::LinearTransport<BeamMonitor>,
69 public mixin::Thin
70 {
71 static constexpr auto type = "BeamMonitor";
74
84 BeamMonitor (std::string series_name, std::string backend="default", std::string encoding="g", int period_sample_intervals=1);
85
86 BeamMonitor (BeamMonitor const & other) = default;
87 BeamMonitor (BeamMonitor && other) = default;
88 BeamMonitor& operator= (BeamMonitor const & other) = default;
89 BeamMonitor& operator= (BeamMonitor && other) = default;
90
101 void prepare (
102 PinnedContainer & pc,
103 std::vector<std::string> const & real_soa_names,
104 std::vector<std::string> const & int_soa_names,
105 RefPart const & ref_part,
106 int step
107 );
108
117 void operator() (
119 int step,
120 int period
121 );
122
130 void operator() (
131 PinnedContainer::ParIterType & pti,
132 std::vector<std::string> const & real_soa_names,
133 std::vector<std::string> const & int_soa_names,
134 RefPart const & ref_part
135 );
136
138 using Thin::operator();
139
141 using LinearTransport::operator();
142
149 Map6x6
150 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
151 {
152 // nothing to do
153 return Map6x6::Identity();
154 }
155
161 std::string name () const { return m_series_name; }
162
165 bool has_name () const { return true; }
166
171 static inline std::map<std::string, std::any> m_unique_series = {};
172
175 void
176 finalize ();
177
178 private:
180 void open ();
181
182 std::string m_series_name;
183 std::string m_OpenPMDFileType;
184 std::string m_encoding;
185 std::any m_series;
186 int m_step = 0;
187
189
191
196 std::vector<uint64_t> m_offset;
197
202 std::unordered_map<std::string, amrex::ParticleReal> m_rbc;
203
204 };
205
211 void
213 std::string const & element_name,
215 );
216
217} // namespace impactx::diagnostics
218
219#endif // IMPACTX_ELEMENTS_DIAGS_BEAMMONITOR_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST
Array4< int const > offset
amrex::ParticleContainer_impl< ParticleType, NArrayReal, NArrayInt, NewAllocator > ContainerLike
Definition ImpactXParticleContainer.H:133
std::vector< unsigned long long > m_ParticleSizeAtRank
Definition BeamMonitor.H:41
std::vector< unsigned long long > m_ParticleOffsetAtRank
Definition BeamMonitor.H:40
unsigned long GetTotalNumParticles()
Definition BeamMonitor.H:38
void GetParticleOffsetOfProcessor(const long &numParticles, unsigned long long &offset, unsigned long long &sum) const
Definition BeamMonitor.cpp:84
typename ImpactXParticleContainer::ContainerLike< amrex::PinnedArenaAllocator > ParticleContainer
Definition BeamMonitor.H:33
ImpactXParticleCounter(ParticleContainer &pc)
Definition BeamMonitor.cpp:38
typename ParticleContainer::ParIterType ParticleIter
Definition BeamMonitor.H:34
std::vector< unsigned long long > m_ParticleCounterByLevel
Definition BeamMonitor.H:58
unsigned long long m_Total
Definition BeamMonitor.H:56
Definition BeamMonitor.cpp:37
Definition AdditionalProperties.cpp:27
void add_optional_properties(std::string const &element_name, ImpactXParticleContainer &pc)
Definition AdditionalProperties.cpp:29
amrex::SmallMatrix< amrex::ParticleReal, 6, 6, amrex::Order::F, 1 > Map6x6
Definition CovarianceMatrix.H:20
static constexpr __host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > Identity() noexcept
Definition ReferenceParticle.H:31
typename ImpactXParticleContainer::ParticleType PType
Definition BeamMonitor.H:72
std::string m_OpenPMDFileType
openPMD filename
Definition BeamMonitor.H:183
void prepare(PinnedContainer &pc, std::vector< std::string > const &real_soa_names, std::vector< std::string > const &int_soa_names, RefPart const &ref_part, int step)
Definition BeamMonitor.cpp:213
AMREX_FORCE_INLINE std::string name() const
Definition BeamMonitor.H:161
typename ImpactXParticleContainer::ContainerLike< amrex::PinnedArenaAllocator > PinnedContainer
Definition BeamMonitor.H:73
static constexpr auto type
Definition BeamMonitor.H:71
BeamMonitor(std::string series_name, std::string backend="default", std::string encoding="g", int period_sample_intervals=1)
Definition BeamMonitor.cpp:126
std::unordered_map< std::string, amrex::ParticleReal > m_rbc
Definition BeamMonitor.H:202
std::string m_series_name
Definition BeamMonitor.H:182
BeamMonitor(BeamMonitor const &other)=default
void finalize()
Definition BeamMonitor.cpp:109
BeamMonitor(BeamMonitor &&other)=default
std::any m_series
openPMD iteration encoding: "v"ariable based, "f"ile based, "g"roup based (default)
Definition BeamMonitor.H:185
AMREX_FORCE_INLINE bool has_name() const
Definition BeamMonitor.H:165
int m_file_min_digits
global step for output
Definition BeamMonitor.H:188
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition BeamMonitor.H:150
int m_period_sample_intervals
minimum number of digits to iteration number in file name
Definition BeamMonitor.H:190
int m_step
openPMD::Series that holds potentially multiple outputs
Definition BeamMonitor.H:186
static std::map< std::string, std::any > m_unique_series
Definition BeamMonitor.H:171
void open()
Definition BeamMonitor.cpp:130
std::vector< uint64_t > m_offset
only output every Nth period (turn or cycle) of periodic lattices
Definition BeamMonitor.H:196
BeamMonitor & operator=(BeamMonitor const &other)=default
std::string m_encoding
openPMD backend: usually HDF5 (h5) or ADIOS2 (bp/bp4/bp5) or ADIOS2 SST (sst)
Definition BeamMonitor.H:184
void operator()(ImpactXParticleContainer &pc, int step, int period)
Definition BeamMonitor.cpp:306
Definition lineartransport.H:29
Definition thin.H:24