OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
EmittedFromFile Class Reference

Reads old-OPAL emitted distribution dumps and emits particles by file time. More...

#include <EmittedFromFile.h>

Inheritance diagram for EmittedFromFile:
Inheritance graph
Collaboration diagram for EmittedFromFile:
Collaboration graph

Classes

struct  RawRecord
 Raw row parsed from an old-OPAL emitted distribution dump. More...
 
struct  Record
 Selected file row plus its converted tracker birth time. More...
 

Public Types

using size_type = ippl::detail::size_type
 

Public Member Functions

 EmittedFromFile (std::shared_ptr< ParticleContainer_t > pc, std::shared_ptr< FieldContainer_t > fc, Distribution_t *opalDist)
 Constructor for EmittedFromFile.
 
 EmittedFromFile (std::shared_ptr< ParticleContainer_t > pc, std::shared_ptr< FieldContainer_t > fc, const std::string &filename)
 Convenience constructor that takes the filename directly.
 
void generateParticles (size_t &numberOfParticles, Vector_t< double, 3 > nr) override
 Reads the selected file records and builds the birth-time inventory.
 
void emitParticles (double t, double dt) override
 Emits all file records whose birth times fall into the current step.
 
bool isEmissionDone (double) const override
 Returns whether all file records in the inventory have been emitted.
 
bool hasInitialReferenceMomentum () const override
 Reports whether an initial reference momentum is available.
 
Vector_t< double, 3 > getInitialReferenceMomentum () const override
 Returns the average initial reference momentum from selected records.
 
double getGlobalTimeShift () const override
 Returns the global time shift needed to center old-OPAL file times.
 
double getEmissionTimeStep () const override
 Returns the preferred emission time step.
 
double getEmissionTime () const
 Returns the total emission time spanned by selected file records.
 
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.
 
void setEmissionOffsets (ippl::Vector< double, 3 > R0, ippl::Vector< double, 3 > P0, double t0, const std::string &emissionModel="NONE")
 
void setInitialPolarization (const ippl::Vector< double, 3 > &pol)
 
void fillPolarization (size_t startIdx, size_t count)
 
Vector_t< double, 3 > getEmissionR0 () const
 
virtual void testNumEmitParticles (size_t, double)
 
virtual void testEmitParticles (size_t, double)
 
virtual void initDomainDecomp (double)
 
virtual void setWithDomainDecomp (bool)
 
size_t computeLocalEmitCount (size_t totalToSample) const
 Computes the number of particles this rank should emit so that the global total equals totalToSample and no rank exceeds its capacity (space left).
 

Protected Attributes

std::shared_ptr< ParticleContainer_tpc_m
 
std::shared_ptr< FieldContainer_tfc_m
 
Distribution_topalDist_m = nullptr
 
std::string samplingMethod_m
 
Vector_t< double, 3 > R0_m = 0.0
 Emission source offset: position R0, momentum P0, start time t0 (applied in sample step).
 
Vector_t< double, 3 > P0_m = 0.0
 
double t0_m = 0.0
 
std::string emissionModel_m = "NONE"
 
Vector_t< double, 3 > initialPol_m = 0.0
 
bool hasEmittedOnce_m = false
 For one-shot emitters (e.g. Gaussian at delayed t0): guard to avoid double sampling.
 

Private Member Functions

void resolveFilenameFromInput ()
 Resolves relative file paths against the active input file directory.
 
void readFile (const std::string &filename)
 Reads and parses an old-OPAL emitted particle file.
 
void buildInventory (size_t requested)
 Selects records, converts file times to birth times, and sorts them.
 
std::pair< size_t, size_t > computeLocalEmitRange (size_t totalToEmit) const
 Computes the local contiguous subrange of a global emission batch.
 

Private Attributes

std::string filename_m
 File path to read emitted particle data from.
 
std::vector< RawRecordrawRecords_m
 Parsed file rows before selection and sorting.
 
std::vector< Recordrecords_m
 Selected records sorted by tracker birth time.
 
size_t nextGlobalIndex_m = 0
 First global record index not emitted yet.
 
bool inventoryBuilt_m = false
 True once records_m is ready for emission.
 
Vector_t< double, 3 > initialRefP_m = 0.0
 Average initial reference momentum.
 
double emissionTime_m = 0.0
 Total emission time spanned by records_m.
 
size_t emissionSteps_m = 100
 Number of steps used to derive emission dt.
 

Detailed Description

Reads old-OPAL emitted distribution dumps and emits particles by file time.

The data rows are interpreted positionally as x px y py t pz [optional-bin]. The file time is an old-OPAL pre-emission time, so a row with t = -6e-13 is emitted at t = +6e-13 when the source t0 is zero.

Definition at line 28 of file EmittedFromFile.h.


Class Documentation

◆ EmittedFromFile::RawRecord

struct EmittedFromFile::RawRecord

Raw row parsed from an old-OPAL emitted distribution dump.

Definition at line 139 of file EmittedFromFile.h.

Collaboration diagram for EmittedFromFile::RawRecord:
Collaboration graph
Class Members
double fileTime = 0.0 Old-OPAL pre-emission time column.
double px = 0.0 Horizontal momentum offset from the file.
double py = 0.0 Vertical momentum offset from the file.
double pz = 0.0 Longitudinal momentum offset from the file.
double x = 0.0 Horizontal position from the file.
double y = 0.0 Vertical position from the file.

◆ EmittedFromFile::Record

struct EmittedFromFile::Record

Selected file row plus its converted tracker birth time.

Definition at line 151 of file EmittedFromFile.h.

Collaboration diagram for EmittedFromFile::Record:
Collaboration graph
Class Members
double birthTime = 0.0 Birth time in the OPALX tracker convention.
RawRecord raw Original parsed file row.

Member Typedef Documentation

◆ size_type

using EmittedFromFile::size_type = ippl::detail::size_type

Definition at line 30 of file EmittedFromFile.h.

Constructor & Destructor Documentation

◆ EmittedFromFile() [1/2]

EmittedFromFile::EmittedFromFile ( std::shared_ptr< ParticleContainer_t pc,
std::shared_ptr< FieldContainer_t fc,
Distribution_t opalDist 
)

Constructor for EmittedFromFile.

Parameters
pcShared pointer to ParticleContainer.
fcShared pointer to FieldContainer.
opalDistBorrowed Distribution.

Definition at line 67 of file EmittedFromFile.cpp.

References emissionSteps_m, filename_m, Distribution::getEmissionSteps(), Distribution::getFilename(), readFile(), and resolveFilenameFromInput().

Here is the call graph for this function:

◆ EmittedFromFile() [2/2]

EmittedFromFile::EmittedFromFile ( std::shared_ptr< ParticleContainer_t pc,
std::shared_ptr< FieldContainer_t fc,
const std::string &  filename 
)

Convenience constructor that takes the filename directly.

This is primarily intended for tests, where constructing a full OPALX Distribution object is unnecessary.

Parameters
pcShared pointer to ParticleContainer.
fcShared pointer to FieldContainer.
filenamePath to the emitted particle file.

Definition at line 83 of file EmittedFromFile.cpp.

References filename_m, and readFile().

Here is the call graph for this function:

Member Function Documentation

◆ buildInventory()

void EmittedFromFile::buildInventory ( size_t  requested)
private

Selects records, converts file times to birth times, and sorts them.

Parameters
requestedNumber of records requested; zero selects all records.

Definition at line 223 of file EmittedFromFile.cpp.

References EmittedFromFile::Record::birthTime, emissionTime_m, EmittedFromFile::RawRecord::fileTime, initialRefP_m, inventoryBuilt_m, nextGlobalIndex_m, SamplingBase::opalDist_m, SamplingBase::P0_m, EmittedFromFile::RawRecord::px, EmittedFromFile::RawRecord::py, EmittedFromFile::RawRecord::pz, EmittedFromFile::Record::raw, rawRecords_m, records_m, Distribution::setTEmission(), and SamplingBase::t0_m.

Referenced by generateParticles().

Here is the call graph for this function:

◆ computeLocalEmitCount()

size_t SamplingBase::computeLocalEmitCount ( size_t  totalToSample) const
inherited

Computes the number of particles this rank should emit so that the global total equals totalToSample and no rank exceeds its capacity (space left).

Parameters
totalToSampleGlobal number of particles to emit this timestep.
Returns
Local number of particles this rank should create/emit.

Definition at line 6 of file SamplingBase.cpp.

References SamplingBase::pc_m.

Referenced by FlatTop::countEnteringParticlesPerRank(), FromFile::generateParticles(), Gaussian::generateParticles(), and MultiVariateGaussian::generateParticles().

◆ computeLocalEmitRange()

std::pair< size_t, size_t > EmittedFromFile::computeLocalEmitRange ( size_t  totalToEmit) const
private

Computes the local contiguous subrange of a global emission batch.

Parameters
totalToEmitNumber of particles emitted globally in the current step.
Returns
Pair of local offset into the global batch and local particle count.

Definition at line 279 of file EmittedFromFile.cpp.

References SamplingBase::pc_m.

Referenced by emitParticles().

◆ emitParticles()

void EmittedFromFile::emitParticles ( double  t,
double  dt 
)
overridevirtual

Emits all file records whose birth times fall into the current step.

Parameters
tStart time of the current tracker step.
dtTime step size.

Reimplemented from SamplingBase.

Definition at line 340 of file EmittedFromFile.cpp.

References computeLocalEmitRange(), generateLocalParticles(), inventoryBuilt_m, nextGlobalIndex_m, SamplingBase::pc_m, and records_m.

Referenced by TEST_F(), TEST_F(), and TEST_F().

Here is the call graph for this function:

◆ fillPolarization()

void SamplingBase::fillPolarization ( size_t  startIdx,
size_t  count 
)
inlineinherited

Fill the Pol particle attribute with initialPol_m on the half-open range [startIdx, startIdx + count). No-op when the container does not store spin. Must be called after the particles have been created and before they are pushed downstream.

Definition at line 63 of file SamplingBase.hpp.

References SamplingBase::initialPol_m, and SamplingBase::pc_m.

Referenced by FlatTop::emitParticles(), FromFile::generateParticles(), Gaussian::generateParticles(), and MultiVariateGaussian::generateParticles().

◆ generateLocalParticles()

void EmittedFromFile::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.

Particle coordinates and momentum offsets come from the file. Each particle receives a per-particle fractional step based on its birth time and is drifted for half of that effective step.

Parameters
nlocalBeforeLocal particle count before allocation.
globalBeginFirst global record index assigned to this rank.
nNewNumber of local particles to generate.
tStartStart time of the current tracker step.
dtTime step size.

Definition at line 376 of file EmittedFromFile.cpp.

References EmittedFromFile::Record::birthTime, Physics::c, SamplingBase::P0_m, SamplingBase::pc_m, EmittedFromFile::RawRecord::px, EmittedFromFile::RawRecord::py, EmittedFromFile::RawRecord::pz, SamplingBase::R0_m, EmittedFromFile::Record::raw, records_m, EmittedFromFile::RawRecord::x, and EmittedFromFile::RawRecord::y.

Referenced by emitParticles().

◆ generateParticles()

void EmittedFromFile::generateParticles ( size_t &  numberOfParticles,
Vector_t< double, 3 >  nr 
)
overridevirtual

Reads the selected file records and builds the birth-time inventory.

Parameters
numberOfParticlesNumber of particles requested by the caller.
nrNumber of grid points per direction (not used here).

Reimplemented from SamplingBase.

Definition at line 206 of file EmittedFromFile.cpp.

References buildInventory(), SamplingBase::emissionModel_m, Distribution::getNumParticles(), SamplingBase::opalDist_m, and records_m.

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

Here is the call graph for this function:

◆ getEmissionR0()

Vector_t< double, 3 > SamplingBase::getEmissionR0 ( ) const
inlineinherited

Definition at line 78 of file SamplingBase.hpp.

References SamplingBase::R0_m.

◆ getEmissionTime()

double EmittedFromFile::getEmissionTime ( ) const
inline

Returns the total emission time spanned by selected file records.

Definition at line 117 of file EmittedFromFile.h.

References emissionTime_m.

Referenced by TEST_F().

◆ getEmissionTimeStep()

double EmittedFromFile::getEmissionTimeStep ( ) const
inlineoverridevirtual

Returns the preferred emission time step.

Returns
emissionTime divided by the configured number of emission steps.

Reimplemented from SamplingBase.

Definition at line 108 of file EmittedFromFile.h.

References emissionSteps_m, and emissionTime_m.

Referenced by TEST_F().

◆ getGlobalTimeShift()

double EmittedFromFile::getGlobalTimeShift ( ) const
inlineoverridevirtual

Returns the global time shift needed to center old-OPAL file times.

Returns
Non-negative shift from source time to the midpoint of the emission window.

Reimplemented from SamplingBase.

Definition at line 99 of file EmittedFromFile.h.

References emissionTime_m, and SamplingBase::t0_m.

Referenced by TEST_F(), TEST_F(), and TEST_F().

◆ getInitialReferenceMomentum()

Vector_t< double, 3 > EmittedFromFile::getInitialReferenceMomentum ( ) const
inlineoverridevirtual

Returns the average initial reference momentum from selected records.

Reimplemented from SamplingBase.

Definition at line 92 of file EmittedFromFile.h.

References initialRefP_m.

Referenced by TEST_F(), and TEST_F().

◆ hasInitialReferenceMomentum()

bool EmittedFromFile::hasInitialReferenceMomentum ( ) const
inlineoverridevirtual

Reports whether an initial reference momentum is available.

Returns
True after the file inventory has been built.

Reimplemented from SamplingBase.

Definition at line 87 of file EmittedFromFile.h.

References inventoryBuilt_m.

Referenced by TEST_F().

◆ initDomainDecomp()

virtual void SamplingBase::initDomainDecomp ( double  )
inlinevirtualinherited

Reimplemented in FlatTop, and OpalFlatTop.

Definition at line 110 of file SamplingBase.hpp.

◆ isEmissionDone()

bool EmittedFromFile::isEmissionDone ( double  ) const
inlineoverridevirtual

Returns whether all file records in the inventory have been emitted.

Returns
True if the inventory exists and the next global index is past its end.

Reimplemented from SamplingBase.

Definition at line 78 of file EmittedFromFile.h.

References inventoryBuilt_m, nextGlobalIndex_m, and records_m.

Referenced by TEST_F().

◆ readFile()

void EmittedFromFile::readFile ( const std::string &  filename)
private

Reads and parses an old-OPAL emitted particle file.

Accepted files may contain a leading particle count and header, or a comment header. Data rows are interpreted positionally as x px y py t pz [optional-bin].

Parameters
filenamePath to the file to read.

Definition at line 109 of file EmittedFromFile.cpp.

References EmittedFromFile::RawRecord::fileTime, EmittedFromFile::RawRecord::px, EmittedFromFile::RawRecord::py, EmittedFromFile::RawRecord::pz, rawRecords_m, EmittedFromFile::RawRecord::x, and EmittedFromFile::RawRecord::y.

Referenced by EmittedFromFile(), and EmittedFromFile().

◆ resolveFilenameFromInput()

void EmittedFromFile::resolveFilenameFromInput ( )
private

Resolves relative file paths against the active input file directory.

Definition at line 94 of file EmittedFromFile.cpp.

References filename_m, OpalData::getInputFn(), and OpalData::getInstance().

Referenced by EmittedFromFile().

Here is the call graph for this function:

◆ setEmissionOffsets()

void SamplingBase::setEmissionOffsets ( ippl::Vector< double, 3 >  R0,
ippl::Vector< double, 3 >  P0,
double  t0,
const std::string &  emissionModel = "NONE" 
)
inlineinherited

◆ setInitialPolarization()

void SamplingBase::setInitialPolarization ( const ippl::Vector< double, 3 > &  pol)
inlineinherited

Definition at line 57 of file SamplingBase.hpp.

References SamplingBase::initialPol_m.

◆ setWithDomainDecomp()

virtual void SamplingBase::setWithDomainDecomp ( bool  )
inlinevirtualinherited

Reimplemented in FlatTop, and OpalFlatTop.

Definition at line 112 of file SamplingBase.hpp.

◆ testEmitParticles()

virtual void SamplingBase::testEmitParticles ( size_t  ,
double   
)
inlinevirtualinherited

Definition at line 108 of file SamplingBase.hpp.

◆ testNumEmitParticles()

virtual void SamplingBase::testNumEmitParticles ( size_t  ,
double   
)
inlinevirtualinherited

Definition at line 105 of file SamplingBase.hpp.

Member Data Documentation

◆ emissionModel_m

◆ emissionSteps_m

size_t EmittedFromFile::emissionSteps_m = 100
private

Number of steps used to derive emission dt.

Definition at line 194 of file EmittedFromFile.h.

Referenced by EmittedFromFile(), and getEmissionTimeStep().

◆ emissionTime_m

double EmittedFromFile::emissionTime_m = 0.0
private

Total emission time spanned by records_m.

Definition at line 193 of file EmittedFromFile.h.

Referenced by buildInventory(), getEmissionTime(), getEmissionTimeStep(), and getGlobalTimeShift().

◆ fc_m

std::shared_ptr<FieldContainer_t> SamplingBase::fc_m
protectedinherited

◆ filename_m

std::string EmittedFromFile::filename_m
private

File path to read emitted particle data from.

Definition at line 187 of file EmittedFromFile.h.

Referenced by EmittedFromFile(), EmittedFromFile(), and resolveFilenameFromInput().

◆ hasEmittedOnce_m

bool SamplingBase::hasEmittedOnce_m = false
protectedinherited

◆ initialPol_m

Vector_t<double, 3> SamplingBase::initialPol_m = 0.0
protectedinherited

Initial polarization vector P applied to every particle this sampler creates. Rest-frame Pauli expectations along lab-frame axes; |Pol| in [0, 1]. Ignored when the container does not have a spin attribute (hasSpin() == false).

Definition at line 30 of file SamplingBase.hpp.

Referenced by SamplingBase::fillPolarization(), and SamplingBase::setInitialPolarization().

◆ initialRefP_m

Vector_t<double, 3> EmittedFromFile::initialRefP_m = 0.0
private

Average initial reference momentum.

Definition at line 192 of file EmittedFromFile.h.

Referenced by buildInventory(), and getInitialReferenceMomentum().

◆ inventoryBuilt_m

bool EmittedFromFile::inventoryBuilt_m = false
private

True once records_m is ready for emission.

Definition at line 191 of file EmittedFromFile.h.

Referenced by buildInventory(), emitParticles(), hasInitialReferenceMomentum(), and isEmissionDone().

◆ nextGlobalIndex_m

size_t EmittedFromFile::nextGlobalIndex_m = 0
private

First global record index not emitted yet.

Definition at line 190 of file EmittedFromFile.h.

Referenced by buildInventory(), emitParticles(), and isEmissionDone().

◆ opalDist_m

◆ P0_m

◆ pc_m

◆ R0_m

Vector_t<double, 3> SamplingBase::R0_m = 0.0
protectedinherited

◆ rawRecords_m

std::vector<RawRecord> EmittedFromFile::rawRecords_m
private

Parsed file rows before selection and sorting.

Definition at line 188 of file EmittedFromFile.h.

Referenced by buildInventory(), and readFile().

◆ records_m

std::vector<Record> EmittedFromFile::records_m
private

Selected records sorted by tracker birth time.

Definition at line 189 of file EmittedFromFile.h.

Referenced by buildInventory(), emitParticles(), generateLocalParticles(), generateParticles(), and isEmissionDone().

◆ samplingMethod_m

std::string SamplingBase::samplingMethod_m
protectedinherited

Definition at line 20 of file SamplingBase.hpp.

◆ t0_m


The documentation for this class was generated from the following files: