Peano
Loading...
Searching...
No Matches
toolbox::particles::assignmentchecks::internal::Database Class Reference

stores the actual particle histories. More...

#include <Database.h>

Collaboration diagram for toolbox::particles::assignmentchecks::internal::Database:

Public Member Functions

 Database (const Database &)=delete
 
void operator= (const Database &)=delete
 
void setMaxParticleSnapshotsToKeepTrackOf (const size_t n)
 Sets the number of snapshots to keep in the database.
 
void startMeshSweep (const std::string &meshSweepName)
 Add an entry for a new mesh sweep.
 
ParticleEvents getParticleHistory (const ParticleIdentifier &identifier)
 Return the stored event history of a particle.
 
std::string particleHistory (const ParticleIdentifier &identifier)
 Print history of one particle.
 
std::string lastMeshSweepSnapshot ()
 Returns the recorded events of the latest mesh sweep.
 
int getTotalParticleEntries (const ParticleIdentifier &identifier)
 Count total number of entries for a particle.
 
int getNumberOfSnapshots () const
 Return number of snapshots.
 
Event addEvent (ParticleIdentifier identifier, Event &event)
 Add a new event to the database.
 
void replaceEvent (ParticleIdentifier identifier, Event &oldEvent, Event &newEvent)
 Replace an (old) particle event with a new one.
 
void shiftIdentifierVertexInd (ParticleIdentifier &identifier, tarch::la::Vector< Dimensions, long long > &newVertexInd, const int newVertexDepth)
 Change the particle's vertexIndex in the map identifier.
 
std::string toString ()
 Dump the whole database.
 
void reset ()
 Delete all entries in the database and reset it to the initial state.
 
size_t getCurrentMeshSweepIndex () const
 Grab the current index of mesh sweeps.
 
int getNumberOfTracedParticles () const
 Get the number of currently traced particles in the database.
 
std::vector< MeshSweepData > & getMeshSweepData ()
 Get a handle on the mesh sweep data of the database.
 
std::string sweepHistory ()
 Get the history of stored mesh sweep (names).
 
void eliminateExistingParticles ()
 Eliminate existing particles from the database.
 
Event getPreviousEvent (ParticleEvents &particleHistory, int spacetreeId, size_t nFirstEventsToSkip=0)
 get the previous event from a particle history.
 

Static Public Member Functions

static Database & getInstance ()
 

Static Public Attributes

static constexpr int AnyTree = -1
 

Private Member Functions

 Database ()
 

Private Attributes

tarch::multicore::MultiReadSingleWriteSemaphore _semaphore
 
std::vector< MeshSweepData > _meshSweepData
 
int _currentMeshSweepIndex
 
std::map< ParticleIdentifier, ParticleEvents, std::less<> > _data
 
size_t _maxParticleEventsToKeepTrackOf
 Of how many previous associations do we want to keep track.
 

Detailed Description

stores the actual particle histories.

Particles are traced via a map, where the keys are instances of the ParticleIdentifier class. The database itself is implemented as a singleton. To access it, use the getInstance() method.

The database will track all events on all spacetrees on this MPI rank. Per particle (and per spacetree), we store up to _maxParticleEventsToKeepTrackOf particle events. Once that number is exceeded, the past history will be condensed into a single event, signifying that it had been compacted.

Additionally, something we come across very often is that particles, once assigned to a vertex, very often stay assigned to the same vertex for a long time (=many sweeps) and only experiences small movements. Rather than tracing every single move event individually, the database will mark consecutive move events using a special event type, Event::Type::ConsecutiveMoveEvent. It will also keep track the original position of the particle, before the first move event of that sequence has occurred, as well as the current particle position.

Definition at line 53 of file Database.h.

Constructor & Destructor Documentation

◆ Database() [1/2]

toolbox::particles::assignmentchecks::internal::Database::Database ( const Database &  )
delete

◆ Database() [2/2]

toolbox::particles::assignmentchecks::internal::Database::Database ( )
private

Definition at line 70 of file Database.h.

References reset(), and setMaxParticleSnapshotsToKeepTrackOf().

Here is the call graph for this function:

Member Function Documentation

◆ addEvent()

Event toolbox::particles::assignmentchecks::internal::Database::addEvent ( ParticleIdentifier  identifier,
Event &  event 
)

Add a new event to the database.

If there is not yet an entry for identifier in the current snapshot, we create one. Afterwards, we append event to this new dataset for particle identifier and clean up the database, i.e. throw away irrelevant old data.

If the number of events for a particle exceeds the limit set by _maxParticleEventsToKeepTrackOf, this routine will squash them together into a single event signifying that this compression has occurred, while keeping the event type of the last recorded event. The other events in the history will be deleted.

Returns
the last event on the spacetree with id treeId before the newly added one.

◆ eliminateExistingParticles()

void toolbox::particles::assignmentchecks::internal::Database::eliminateExistingParticles ( )

Eliminate existing particles from the database.

See documentation in TracingAPI.h:eliminateExistingParticles() for more.

◆ getCurrentMeshSweepIndex()

size_t toolbox::particles::assignmentchecks::internal::Database::getCurrentMeshSweepIndex ( ) const

Grab the current index of mesh sweeps.

◆ getInstance()

static Database & toolbox::particles::assignmentchecks::internal::Database::getInstance ( )
static

Definition at line 57 of file Database.h.

◆ getMeshSweepData()

std::vector< MeshSweepData > & toolbox::particles::assignmentchecks::internal::Database::getMeshSweepData ( )

Get a handle on the mesh sweep data of the database.

You shouldn't ever need this in your code. This only exists to verify the database integrity in unit tests.

◆ getNumberOfSnapshots()

int toolbox::particles::assignmentchecks::internal::Database::getNumberOfSnapshots ( ) const

Return number of snapshots.

These are the active snapshots still held in the database. addEvent()'s garbage collection might have removed some of them already.

◆ getNumberOfTracedParticles()

int toolbox::particles::assignmentchecks::internal::Database::getNumberOfTracedParticles ( ) const

Get the number of currently traced particles in the database.

◆ getParticleHistory()

ParticleEvents toolbox::particles::assignmentchecks::internal::Database::getParticleHistory ( const ParticleIdentifier &  identifier)

Return the stored event history of a particle.

If there's none, this routine returns a history containing an invalid event. This history containing an invalid event will alloc a new ParticleEvents and add a singleevent of type NotFound if there is no history. Make sure to delete that after you use it.

Cannot be const as we have a semaphore to be thread-safe. Returns a copy, not a reference, so that once semaphore is lifted, the state of the history remains accurate.

Returns
The history of the particle.

◆ getPreviousEvent()

Event toolbox::particles::assignmentchecks::internal::Database::getPreviousEvent ( ParticleEvents &  particleHistory,
int  spacetreeId,
size_t  nFirstEventsToSkip = 0 
)

get the previous event from a particle history.

nFirstEventsToSkip: skip this many events. Useful if you've just added something to the database using addEvent and are trying to re-use the history it returns.

◆ getTotalParticleEntries()

int toolbox::particles::assignmentchecks::internal::Database::getTotalParticleEntries ( const ParticleIdentifier &  identifier)

Count total number of entries for a particle.

Cannot be const as we have a semaphore to be thread-safe.

◆ lastMeshSweepSnapshot()

std::string toolbox::particles::assignmentchecks::internal::Database::lastMeshSweepSnapshot ( )

Returns the recorded events of the latest mesh sweep.

◆ operator=()

void toolbox::particles::assignmentchecks::internal::Database::operator= ( const Database &  )
delete

◆ particleHistory()

std::string toolbox::particles::assignmentchecks::internal::Database::particleHistory ( const ParticleIdentifier &  identifier)

Print history of one particle.

Cannot be const as we have a semaphore to be thread-safe.

◆ replaceEvent()

void toolbox::particles::assignmentchecks::internal::Database::replaceEvent ( ParticleIdentifier  identifier,
Event &  oldEvent,
Event &  newEvent 
)

Replace an (old) particle event with a new one.

This is used e.g. in case where we replace a move event with a consecutive move event. Put into this function for thread safety and minimizing lock time of the database.

Just like addEvent(), it adds the current mesh sweep index to the newEvent.

◆ reset()

void toolbox::particles::assignmentchecks::internal::Database::reset ( )

Delete all entries in the database and reset it to the initial state.

Then re-initialize the database.

Referenced by Database().

Here is the caller graph for this function:

◆ setMaxParticleSnapshotsToKeepTrackOf()

void toolbox::particles::assignmentchecks::internal::Database::setMaxParticleSnapshotsToKeepTrackOf ( const size_t  n)

Sets the number of snapshots to keep in the database.

Referenced by Database().

Here is the caller graph for this function:

◆ shiftIdentifierVertexInd()

void toolbox::particles::assignmentchecks::internal::Database::shiftIdentifierVertexInd ( ParticleIdentifier &  identifier,
tarch::la::Vector< Dimensions, long long > &  newVertexInd,
const int  newVertexDepth 
)

Change the particle's vertexIndex in the map identifier.

Particle must be findable with the passed identifier.

◆ startMeshSweep()

void toolbox::particles::assignmentchecks::internal::Database::startMeshSweep ( const std::string &  meshSweepName)

Add an entry for a new mesh sweep.

◆ sweepHistory()

std::string toolbox::particles::assignmentchecks::internal::Database::sweepHistory ( )

Get the history of stored mesh sweep (names).

◆ toString()

std::string toolbox::particles::assignmentchecks::internal::Database::toString ( )

Dump the whole database.

Cannot be const as we have a semaphore to be thread-safe.

Field Documentation

◆ _currentMeshSweepIndex

int toolbox::particles::assignmentchecks::internal::Database::_currentMeshSweepIndex
private

Definition at line 78 of file Database.h.

◆ _data

◆ _maxParticleEventsToKeepTrackOf

size_t toolbox::particles::assignmentchecks::internal::Database::_maxParticleEventsToKeepTrackOf
private

Of how many previous associations do we want to keep track.

If we do not clean up the database every now and then, we will run into situations where the memory footprint exceeds the available mem. More importantly, the validation steps will last for ages. So we clean up the database of old data every now and then. This threshold indicates how many old data entries to keep. Set it to std::numerics<int>::max() to disable this type of garbage collection on the history.

Definition at line 97 of file Database.h.

◆ _meshSweepData

std::vector<MeshSweepData> toolbox::particles::assignmentchecks::internal::Database::_meshSweepData
private

Definition at line 77 of file Database.h.

◆ _semaphore

tarch::multicore::MultiReadSingleWriteSemaphore toolbox::particles::assignmentchecks::internal::Database::_semaphore
private

Definition at line 75 of file Database.h.

◆ AnyTree

constexpr int toolbox::particles::assignmentchecks::internal::Database::AnyTree = -1
staticconstexpr

Definition at line 100 of file Database.h.


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