Peano
Loading...
Searching...
No Matches
Database.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5#include "MeshSweepData.h"
7#include "tarch/la/Vector.h"
9
10#include <functional> // needed for std::less
11#include <map>
12#include <vector>
13
14
15#if !defined(AssignmentChecks) and !defined(noAssignmentChecks) \
16 and PeanoDebug > 0
17#define AssignmentChecks
18#endif
19
20
21namespace toolbox {
22 namespace particles {
23 namespace assignmentchecks {
24 namespace internal {
25
26 using ParticleEvents = std::vector<Event>;
27
53 class Database {
54
55 // Singleton-related stuff first, actual class content later.
56 public:
58
59 static Database _database;
60 return _database;
61 }
62
63 // C++ 11 way of doing things. Explicitly delete the methods
64 // we don't want.
65 Database(const Database&) = delete;
66 void operator=(const Database&) = delete;
67
68 private:
69 // Make constructor private so nobody can make one by accident.
74
76
77 std::vector<MeshSweepData> _meshSweepData;
79
80 // tell the map to use std::less<> as comparator instead of the
81 // default std::less<key>. std::less<> invokes the `<` operator.
82 // We want that to be able to use our bespoke `<` operator
83 // for different search and ID key identifier objects.
84 std::map<ParticleIdentifier, ParticleEvents, std::less<>> _data;
85
98
99 public:
100 static constexpr int AnyTree = -1;
101
106
110 void startMeshSweep(const std::string& meshSweepName);
111
128 );
129
135 std::string particleHistory(const ParticleIdentifier& identifier);
136
141
148
157
177
189 ParticleIdentifier identifier,
190 Event& oldEvent,
191 Event& newEvent
192 );
193
199 ParticleIdentifier& identifier,
201 const int newVertexDepth
202 );
203
209 std::string toString();
210
215 void reset();
216
221
226
232 std::vector<MeshSweepData>& getMeshSweepData();
233
237 std::string sweepHistory();
238
244
254 int spacetreeId,
255 size_t nFirstEventsToSkip = 0
256 );
257
258 }; // class Database
259 } // namespace internal
260 } // namespace assignmentchecks
261 } // namespace particles
262} // namespace toolbox
stores the actual particle histories.
Definition Database.h:53
int getNumberOfSnapshots() const
Return number of snapshots.
void setMaxParticleSnapshotsToKeepTrackOf(const size_t n)
Sets the number of snapshots to keep in the database.
tarch::multicore::MultiReadSingleWriteSemaphore _semaphore
Definition Database.h:75
Event addEvent(ParticleIdentifier identifier, Event &event)
Add a new event to the database.
std::string particleHistory(const ParticleIdentifier &identifier)
Print history of one particle.
size_t _maxParticleEventsToKeepTrackOf
Of how many previous associations do we want to keep track.
Definition Database.h:97
int getTotalParticleEntries(const ParticleIdentifier &identifier)
Count total number of entries for a particle.
size_t getCurrentMeshSweepIndex() const
Grab the current index of mesh sweeps.
void startMeshSweep(const std::string &meshSweepName)
Add an entry for a new mesh sweep.
std::vector< MeshSweepData > & getMeshSweepData()
Get a handle on the mesh sweep data of the database.
ParticleEvents getParticleHistory(const ParticleIdentifier &identifier)
Return the stored event history of a particle.
std::string toString()
Dump the whole database.
std::string lastMeshSweepSnapshot()
Returns the recorded events of the latest mesh sweep.
void reset()
Delete all entries in the database and reset it to the initial state.
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.
void shiftIdentifierVertexInd(ParticleIdentifier &identifier, tarch::la::Vector< Dimensions, long long > &newVertexInd, const int newVertexDepth)
Change the particle's vertexIndex in the map identifier.
void replaceEvent(ParticleIdentifier identifier, Event &oldEvent, Event &newEvent)
Replace an (old) particle event with a new one.
std::map< ParticleIdentifier, ParticleEvents, std::less<> > _data
Definition Database.h:84
int getNumberOfTracedParticles() const
Get the number of currently traced particles in the database.
std::string sweepHistory()
Get the history of stored mesh sweep (names).
Simple vector class.
Definition Vector.h:159
ParticleIdentifier is used as a key to the 'database' map to keep the particles' history as the map's...