Molecular Dynamics Simulation  1.0
Public Member Functions | Private Attributes | List of all members
ParticleUpdateCounterInterceptor Class Reference

#include <ParticleUpdateCounterInterceptor.h>

Inheritance diagram for ParticleUpdateCounterInterceptor:
Inheritance graph
Collaboration diagram for ParticleUpdateCounterInterceptor:
Collaboration graph

Public Member Functions

void onSimulationStart (Simulation &simulation) override
 This function is sets the particle_updates to 0 and initializes the start time of the simulation. More...
 
void operator() (size_t iteration, Simulation &simulation) override
 This function is called on every nth iteration. It counts the number of particle updates which have been performed. More...
 
void onSimulationEnd (size_t iteration, Simulation &simulation) override
 This function is empty as the thermostat doesnt need to do anything at the end of the simulation. More...
 
 operator std::string () const override
 The string representation of this interceptor. More...
 
void logSummary (int depth) const override
 Logs the summary of the particle update counter. More...
 
double getParticleUpdatesPerSecond () const
 Get the particle updates per second. More...
 
- Public Member Functions inherited from SimulationInterceptor
virtual ~SimulationInterceptor ()=default
 Destroy the Simulation Interceptor object. More...
 
void notify (size_t iteration, Simulation &simulation)
 This function is called by the simulation loop on every iteration. Whenever the iteration is a multiple of every_nth_iteration, the operator() function is called. More...
 

Private Attributes

size_t particle_updates = 0
 
std::chrono::high_resolution_clock::time_point t_start
 
std::chrono::high_resolution_clock::time_point t_end
 
std::chrono::milliseconds::rep t_diff {}
 
double particle_updates_per_second {}
 

Additional Inherited Members

- Protected Attributes inherited from SimulationInterceptor
size_t every_nth_iteration = 1
 

Detailed Description

Definition at line 7 of file ParticleUpdateCounterInterceptor.h.

Member Function Documentation

◆ getParticleUpdatesPerSecond()

double ParticleUpdateCounterInterceptor::getParticleUpdatesPerSecond ( ) const

Get the particle updates per second.

Returns
double

Definition at line 25 of file ParticleUpdateCounterInterceptor.cpp.

◆ logSummary()

void ParticleUpdateCounterInterceptor::logSummary ( int  depth) const
overridevirtual

Logs the summary of the particle update counter.

Implements SimulationInterceptor.

Definition at line 27 of file ParticleUpdateCounterInterceptor.cpp.

27  {
28  std::string indent = std::string(depth * 2, ' ');
29 
30  Logger::logger->info("{}╟┤{}ParticleUpdateCounter: {}", indent, ansi_orange_bold, ansi_end);
31  Logger::logger->info("{}║ ├Enabled", indent);
32 }
const std::string ansi_end
Definition: Logger.h:13
const std::string ansi_orange_bold
Definition: Logger.h:10
static std::shared_ptr< spdlog::logger > logger
Publically accessible shared pointer to the logger.
Definition: Logger.h:35

◆ onSimulationEnd()

void ParticleUpdateCounterInterceptor::onSimulationEnd ( size_t  iteration,
Simulation simulation 
)
overridevirtual

This function is empty as the thermostat doesnt need to do anything at the end of the simulation.

Parameters
iterationThe current iteration
simulationThe simulation object

Implements SimulationInterceptor.

Definition at line 18 of file ParticleUpdateCounterInterceptor.cpp.

18  {
19  t_end = std::chrono::high_resolution_clock::now();
20  t_diff = std::chrono::duration_cast<std::chrono::milliseconds>(t_end - t_start).count();
21 
22  particle_updates_per_second = 1000.0 * static_cast<double>(particle_updates) / static_cast<double>(t_diff);
23 }
std::chrono::high_resolution_clock::time_point t_end
std::chrono::high_resolution_clock::time_point t_start

◆ onSimulationStart()

void ParticleUpdateCounterInterceptor::onSimulationStart ( Simulation simulation)
overridevirtual

This function is sets the particle_updates to 0 and initializes the start time of the simulation.

Parameters
simulationThe simulation object

Implements SimulationInterceptor.

Definition at line 7 of file ParticleUpdateCounterInterceptor.cpp.

7  {
9  t_start = std::chrono::high_resolution_clock::now();
10 
12 }

◆ operator std::string()

ParticleUpdateCounterInterceptor::operator std::string ( ) const
explicitoverridevirtual

The string representation of this interceptor.

Returns
std::string

This is used to write the final summary of the Interceptors to the console.

Implements SimulationInterceptor.

Definition at line 34 of file ParticleUpdateCounterInterceptor.cpp.

34  {
35  return "ParticleUpdateCalculator: " + std::to_string(particle_updates_per_second) + " particle updates per second";
36 }
std::string to_string(const Container &container, const std::string &delimiter=", ", const std::array< std::string, 2 > &surround={"[", "]"})
Definition: ArrayUtils.h:97

◆ operator()()

void ParticleUpdateCounterInterceptor::operator() ( size_t  iteration,
Simulation simulation 
)
overridevirtual

This function is called on every nth iteration. It counts the number of particle updates which have been performed.

Parameters
iterationThe current iteration
simulationThe simulation object

Implements SimulationInterceptor.

Definition at line 14 of file ParticleUpdateCounterInterceptor.cpp.

14  {
15  particle_updates += simulation.particle_container->size();
16 }
std::unique_ptr< ParticleContainer > particle_container
Reference to the ParticleContainer on whose content the simulation is performed.
Definition: Simulation.h:50

Member Data Documentation

◆ particle_updates

size_t ParticleUpdateCounterInterceptor::particle_updates = 0
private

Definition at line 58 of file ParticleUpdateCounterInterceptor.h.

◆ particle_updates_per_second

double ParticleUpdateCounterInterceptor::particle_updates_per_second {}
private

Definition at line 62 of file ParticleUpdateCounterInterceptor.h.

◆ t_diff

std::chrono::milliseconds::rep ParticleUpdateCounterInterceptor::t_diff {}
private

Definition at line 61 of file ParticleUpdateCounterInterceptor.h.

◆ t_end

std::chrono::high_resolution_clock::time_point ParticleUpdateCounterInterceptor::t_end
private

Definition at line 60 of file ParticleUpdateCounterInterceptor.h.

◆ t_start

std::chrono::high_resolution_clock::time_point ParticleUpdateCounterInterceptor::t_start
private

Definition at line 59 of file ParticleUpdateCounterInterceptor.h.


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