OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
EmittedFromFile.h
Go to the documentation of this file.
1
6#ifndef OPALX_EMITTED_FROM_FILE_H
7#define OPALX_EMITTED_FROM_FILE_H
8
9#include <algorithm>
10#include <memory>
11#include <string>
12#include <vector>
13
14#include "Distribution.h"
15#include "Ippl.h"
16#include "OPALTypes.h"
17#include "SamplingBase.hpp"
18
29public:
30 using size_type = ippl::detail::size_type;
31
40 std::shared_ptr<ParticleContainer_t> pc, std::shared_ptr<FieldContainer_t> fc,
41 Distribution_t* opalDist);
42
54 std::shared_ptr<ParticleContainer_t> pc, std::shared_ptr<FieldContainer_t> fc,
55 const std::string& filename);
56
63 void generateParticles(size_t& numberOfParticles, Vector_t<double, 3> nr) override;
64
71 void emitParticles(double t, double dt) override;
72
78 bool isEmissionDone(double /*t*/) const override {
80 }
81
87 bool hasInitialReferenceMomentum() const override { return inventoryBuilt_m; }
88
93
99 double getGlobalTimeShift() const override {
100 return std::max(0.0, 0.5 * emissionTime_m - t0_m);
101 }
102
108 double getEmissionTimeStep() const override {
109 return emissionSteps_m > 0 && emissionTime_m > 0.0
110 ? emissionTime_m / static_cast<double>(emissionSteps_m)
111 : 0.0;
112 }
113
117 double getEmissionTime() const { return emissionTime_m; }
118
133 size_type nlocalBefore, size_t globalBegin, size_t nNew, double tStart, double dt);
134
135private:
139 struct RawRecord {
140 double x = 0.0;
141 double px = 0.0;
142 double y = 0.0;
143 double py = 0.0;
144 double fileTime = 0.0;
145 double pz = 0.0;
146 };
147
151 struct Record {
153 double birthTime = 0.0;
154 };
155
160
170 void readFile(const std::string& filename);
171
177 void buildInventory(size_t requested);
178
185 std::pair<size_t, size_t> computeLocalEmitRange(size_t totalToEmit) const;
186
187 std::string filename_m;
188 std::vector<RawRecord> rawRecords_m;
189 std::vector<Record> records_m;
190 size_t nextGlobalIndex_m = 0;
191 bool inventoryBuilt_m = false;
193 double emissionTime_m = 0.0;
194 size_t emissionSteps_m = 100;
195};
196
197#endif // OPALX_EMITTED_FROM_FILE_H
ippl::Vector< T, Dim > Vector_t
const int nr
ippl::detail::size_type size_type
Reads old-OPAL emitted distribution dumps and emits particles by file time.
double py
Vertical momentum offset from the file.
RawRecord raw
Original parsed file row.
double birthTime
Birth time in the OPALX tracker convention.
double fileTime
Old-OPAL pre-emission time column.
bool inventoryBuilt_m
True once records_m is ready for emission.
double x
Horizontal position from the file.
void emitParticles(double t, double dt) override
Emits all file records whose birth times fall into the current step.
double emissionTime_m
Total emission time spanned by records_m.
void generateLocalParticles(size_type nlocalBefore, size_t globalBegin, size_t nNew, double tStart, double dt)
Generates the local particles assigned to this rank for one emission step.
double getGlobalTimeShift() const override
Returns the global time shift needed to center old-OPAL file times.
std::pair< size_t, size_t > computeLocalEmitRange(size_t totalToEmit) const
Computes the local contiguous subrange of a global emission batch.
ippl::detail::size_type size_type
bool hasInitialReferenceMomentum() const override
Reports whether an initial reference momentum is available.
size_t nextGlobalIndex_m
First global record index not emitted yet.
Vector_t< double, 3 > getInitialReferenceMomentum() const override
Returns the average initial reference momentum from selected records.
void readFile(const std::string &filename)
Reads and parses an old-OPAL emitted particle file.
std::string filename_m
File path to read emitted particle data from.
bool isEmissionDone(double) const override
Returns whether all file records in the inventory have been emitted.
Vector_t< double, 3 > initialRefP_m
Average initial reference momentum.
void resolveFilenameFromInput()
Resolves relative file paths against the active input file directory.
double pz
Longitudinal momentum offset from the file.
double getEmissionTime() const
Returns the total emission time spanned by selected file records.
void buildInventory(size_t requested)
Selects records, converts file times to birth times, and sorts them.
std::vector< RawRecord > rawRecords_m
Parsed file rows before selection and sorting.
size_t emissionSteps_m
Number of steps used to derive emission dt.
double px
Horizontal momentum offset from the file.
double getEmissionTimeStep() const override
Returns the preferred emission time step.
std::vector< Record > records_m
Selected records sorted by tracker birth time.
void generateParticles(size_t &numberOfParticles, Vector_t< double, 3 > nr) override
Reads the selected file records and builds the birth-time inventory.
double y
Vertical position from the file.
Raw row parsed from an old-OPAL emitted distribution dump.
Selected file row plus its converted tracker birth time.