24 #ifndef __SIMULATION_SIMULATION_H__
25 #define __SIMULATION_SIMULATION_H__
27 #include "../CellList/CellListFast.h"
28 #include "../EventCalendar/EventCalendar.h"
29 #include "../EventCalendar/EventType.h"
30 #include "../Particle/Particle.h"
31 #include "../RPK/RPK.h"
32 #include "../Vector/Vector.hpp"
34 #include "./CollisionRecord.h"
35 #include "./Statistics.h"
40 namespace MDSimulation
134 static const int MAX_BINS = 48;
137 static const size_t COLLISION_RECORDS = 100000;
139 typedef std::unique_ptr<EventCalendar> CalendarPtr;
144 CalendarPtr Calendar;
146 std::vector<Particle> Particles;
147 std::vector<double> ConeTime;
148 std::vector<double> WallTime;
162 double LastRebinRadius;
164 double LastSnapshotTime;
172 clock_t PerformanceClock;
189 template <
class Controller>
190 inline void PredictEvents(
const int na,
const int nb,
const EventType ev);
203 int CellCrossingTimes(
const int na,
DoubleVector& times);
215 double ConeCollisionTime(
const int na);
224 double WallCollisionTime(
const int na);
243 template <
class Controller>
244 void ScheduleParticleCollisions(
const int na, Controller& con,
254 template <
class Controller>
255 void ScheduleParticleCollisions(
const int na, Controller& con);
274 void ProcessCellCrossing();
281 void ProcessBubbleWall();
288 void ProcessCollision();
302 void DissociateParticle(
const int na);
319 void ProcessUpdateSystem();
328 void ProcessReadPGauge();
362 int ComputeParticlesInSystem()
const;
368 void InitializeParticles();
374 void PopulateCalendar();
380 void WriteSnapshot();
388 void WriteCollisionEnergy();
392 friend std::ostream& operator<<(std::ostream& stream,
const Simulation& sim);
404 explicit Simulation(
const InfoStruct& info,
const std::string& outDir =
"",
const bool save =
true);
430 std::vector<Particle>::const_iterator
begin();
436 std::vector<Particle>::const_iterator
end();
467 template <
typename Writer>
478 template <
typename Controller>
479 void Simulation::PredictEvents(
const int na,
const int nb,
const EventType ev)
487 const int evCode = this->CellCrossingTimes(na, cellTime);
488 cellTime[evCode] += this->CurrentTime;
493 if (ev != CellCrossingEvent)
495 this->ConeTime[na] = this->ConeCollisionTime(na) + this->CurrentTime;
500 if (ev != ConeWallEvent)
502 this->WallTime[na] = this->WallCollisionTime(na);
507 if (cellTime[evCode] < this->ConeTime[na])
509 if (cellTime[evCode] < this->WallTime[na])
512 this->Calendar->ScheduleEvent(
513 cellTime[evCode], CellCrossingEvent, na, evCode);
519 this->Calendar->ScheduleEvent(
520 this->WallTime[na], BubbleWallEvent, na, -1);
525 if (this->ConeTime[na] < this->WallTime[na])
529 this->Calendar->ScheduleEvent(
530 this->ConeTime[na], ConeWallEvent, na, -1);
536 this->Calendar->ScheduleEvent(
537 this->WallTime[na], BubbleWallEvent, na, -1);
551 if (ev == CellCrossingEvent)
563 this->ScheduleParticleCollisions<Controller>(na, con, low, high);
566 template <
typename Controller>
567 void Simulation::ScheduleParticleCollisions(
const int na, Controller& con)
571 this->ScheduleParticleCollisions<Controller>(na, con, low, high);
589 template <
typename Controller>
590 void Simulation::ScheduleParticleCollisions(
591 const int na, Controller& con,
596 assert((
unsigned) na < Particles.size());
598 Particle& pa = Particles[na];
602 for (; it.HasNext(); ++it)
604 if (*it != na && con(*it))
606 Particle& pb = Particles[*it];
607 pb.UpdateParticle(this->CurrentTime);
609 const double time = ComputeIntersectionTime(pa, pb);
613 this->Calendar->ScheduleEvent(
614 this->CurrentTime + time, CollisionEvent, na, *it);
620 template <
typename Writer>
623 writer.String(
"Info") , Info.Serialize(writer);
624 writer.String(
"RPKEquation") , RPKEquation.
Serialize(writer);
626 writer.String(
"CurrentTime") , writer.Double(CurrentTime);
627 writer.String(
"TotalCollisions") , writer.UInt64(Stats.
TotalCollisions);
631 writer.String(
"TotalConeBoundaryCollisions");
634 writer.String(
"FusionRate"), writer.UInt64(Stats.
FusionRate);
637 writer.String(
"Particles");
639 std::for_each(Particles.begin(), Particles.end(), [&writer](
const Particle& p)
unsigned long long TotalCollisions
number of collision events
Definition: Statistics.h:33
bool operator()(const int pa)
Reject only when the the Skip value is given.
Definition: Simulation.h:117
NeighborCellIterator BeginNeighborCell(const int particle, const IntVector &low, const IntVector &high)
Create an iterator into the neighboring cells of a given particle.
Definition: CellListFast.cpp:109
unsigned long long TotalCellCrossings
number of cell crossing events
Definition: Statistics.h:34
This class provides the functionality of a three dimensional cell list.
Definition: CellListFast.h:20
void Serialize(Writer &writer) const
New serialization method that makes use of the ptree library.
Definition: RPK.h:204
unsigned long long TotalConeBoundaryCollisions
number of boundary collisions
Definition: Statistics.h:36
This module defines the RPK class.
Definition: RPK.h:41
EventType
Enumeration of the various event types in the system.
Definition: EventType.h:28
int GetParticleCount() const
Get the current number of particles in the system.
Definition: Simulation.cpp:1013
bool HasRebounded() const
Returns whether or not the bubble wall has rebounded yet.
Definition: Simulation.cpp:910
double GetCurrentTime() const
Definition: Simulation.cpp:978
EventType NextStep()
Advance the simulation by one step.
Definition: Simulation.cpp:915
tvmet::Vector< double, 3UL > DoubleVector
Vector type for representing particle positions and velocities as double precision floating point val...
Definition: Vector.hpp:23
LessThan(const int i)
Build the object with the upper bound.
Definition: Simulation.h:81
Function object to regulate the ScheduleParticleCollisions function.
Definition: Simulation.h:100
AllParticles(const int)
Build the object.
Definition: Simulation.h:54
std::vector< Particle >::const_iterator begin()
Beginning iterator for the particles in the system.
Definition: Simulation.cpp:966
Function object to regulate the ScheduleParticleCollisions function.
Definition: Simulation.h:47
void UpdateParticle(const double currentTime)
Update the particle to the current system time.
Definition: Particle.cpp:33
Definition: Statistics.h:18
DoubleVector Velocity
Velocity of the particle in simulation units.
Definition: Particle.h:26
The Simulation class is the environment in which the simulation occurs.
Definition: Simulation.h:129
const double NEVER
Time value for an event that will never occur.
Definition: Constants.h:35
double FusionRate
number of fusions that have occurred
Definition: Statistics.h:38
unsigned long long GetCollisionCount() const
Get the collision count from the simulation.
Definition: Simulation.cpp:993
unsigned long long GetConeBoundaryCount() const
Get the number of cone boundary events so far.
Definition: Simulation.cpp:1008
std::vector< Particle >::const_iterator end()
Ending iterator used to determine the stopping criteria for the particle iterator.
Definition: Simulation.cpp:972
void PurgeEvents()
Prints all the events in the calendar to standard out if we are in debug mode.
Definition: Simulation.cpp:957
Function object to regulate the ScheduleParticleCollisions function.
Definition: Simulation.h:72
unsigned long long GetWallCollisionCount() const
Get the number of cell wall events so far.
Definition: Simulation.cpp:1003
bool operator()(const int pa)
Test for acceptance.
Definition: Simulation.h:88
Skipping(const int s)
Create the object with the value to skip.
Definition: Simulation.h:110
Defines the structure used to hold the configurable constants of the simulation.
Definition: InfoStruct.h:36
Simulation(const InfoStruct &info, const std::string &outDir="", const bool save=true)
A templatized version of the constructor that takes a particle factory as a type. ...
Definition: Simulation.cpp:843
void Serialize(Writer &writer) const
Serialize the simulation to the writer being given.
Definition: Simulation.h:621
Definition of a basic particle type.
Definition: Particle.h:23
unsigned long long GetCellCrossingCount() const
Get the number of cell crossing events so far.
Definition: Simulation.cpp:998
tvmet::Vector< int, 3UL > IntVector
A vector of integer values to hold a particle's position in the grid of cells.
Definition: Vector.hpp:29
unsigned long long TotalWallCollisions
number of wall collision events
Definition: Statistics.h:35
bool operator()(const int)
Test true for all given particle indices.
Definition: Simulation.h:61