1212#include " simulation/Simulation.h"
1313#include " utils/ArrayUtils.h"
1414
15- void execute2DRectBenchmark (int x , int y ) {
15+ void execute2DRectBenchmark (int rect_width , int rect_height, double spacing, double lc_cutoff ) {
1616 Logger::logger->set_level (spdlog::level::info);
17- Logger::logger->info (" Starting 2DRect-benchmark. Dimensions {}x{}..." , x, y );
17+ Logger::logger->info (" Starting 2DRect-benchmark. Dimensions {}x{}..." , rect_width, rect_height );
1818
1919 // Settings for the Linked Cells Container simulation
2020 std::array<double , 3 > domain_size = {300 , 300 , 3 };
21- double cutoff_radius = 30 ;
2221 std::array<LinkedCellsContainer::BoundaryCondition, 6 > boundary_conditions = {
2322 LinkedCellsContainer::BoundaryCondition::REFLECTIVE, LinkedCellsContainer::BoundaryCondition::REFLECTIVE,
2423 LinkedCellsContainer::BoundaryCondition::REFLECTIVE, LinkedCellsContainer::BoundaryCondition::REFLECTIVE,
2524 LinkedCellsContainer::BoundaryCondition::REFLECTIVE, LinkedCellsContainer::BoundaryCondition::REFLECTIVE};
2625
2726 // Settings for the Cuboid spawner for both simulations
2827 std::array<double , 3 > center_offset = {domain_size[0 ] / 2 , domain_size[1 ] / 2 , domain_size[2 ] / 2 };
29- CuboidSpawner spawner (center_offset - std::array<double , 3 >{x * 1.225 / 2 , y * 1.225 / 2 , 0 }, {x, y, 1 }, 1.225 , 1 , {0 , 0 , 0 }, 0 );
28+ CuboidSpawner spawner (center_offset - std::array<double , 3 >{rect_width * spacing / 2 , rect_height * spacing / 2 , 0 },
29+ {rect_width, rect_height, 1 }, spacing, 1 , {0 , 0 , 0 }, 0 );
3030
3131 // Settings for the forces for both simulations
32- std::vector<std::unique_ptr <PairwiseForceSource>> forces;
33- forces.push_back (std::make_unique <LennardJonesForce>());
32+ std::vector<std::shared_ptr <PairwiseForceSource>> forces;
33+ forces.push_back (std::make_shared <LennardJonesForce>());
3434
3535 // ############################################################
3636 // # Direct Sum Container
@@ -40,15 +40,16 @@ void execute2DRectBenchmark(int x, int y) {
4040 spawner.spawnParticles (particles_ds);
4141
4242 // Instantiation of the Direct Sum Container simulation
43- SimulationParams params_ds{" 2DParticleRect" , 0.01 , 5 , 0 , 30 , SimulationParams::DirectSumType{}, Thermostat{0 , 0 }, " none" ,
44- {" LennardJones" }, true , true };
43+
44+ SimulationParams params_ds (" 2DParticleRect.xml" , 0.01 , 5 , SimulationParams::DirectSumType{}, {}, {}, forces, true , true );
45+
4546 params_ds.num_particles = particles_ds.size ();
4647
4748 Simulation simulation_ds (particles_ds, params_ds);
4849
4950 // Simulating with Direct Sum Container
5051 params_ds.logSummary ();
51- SimulationOverview direct_sum_data = simulation_ds.runSimulationPerfTest ();
52+ SimulationOverview direct_sum_data = simulation_ds.runSimulation ();
5253 direct_sum_data.logSummary ();
5354
5455 // ############################################################
@@ -58,41 +59,52 @@ void execute2DRectBenchmark(int x, int y) {
5859 std::vector<Particle> particles_lc;
5960 spawner.spawnParticles (particles_lc);
6061 // Instantiation of the Linked Cells Container simulation
61- SimulationParams params_lc{" 2DParticleRect" ,
62+ SimulationParams params_lc{" 2DParticleRect.xml " ,
6263 0.01 ,
6364 5 ,
64- 0 ,
65- 30 ,
66- SimulationParams::LinkedCellsType{domain_size, cutoff_radius, boundary_conditions},
67- Thermostat{0 , 0 },
68- " none" ,
69- {" LennardJones" },
65+ SimulationParams::LinkedCellsType{domain_size, lc_cutoff, boundary_conditions},
66+ {},
67+ {},
68+ forces,
7069 true ,
7170 true };
71+ params_lc.num_particles = particles_lc.size ();
7272 Simulation simulation_lc (particles_lc, params_lc);
7373 // Simulating with Linked Cells Container
7474 params_lc.logSummary ();
75- SimulationOverview linked_cells_data = simulation_lc.runSimulationPerfTest ();
75+ SimulationOverview linked_cells_data = simulation_lc.runSimulation ();
7676 linked_cells_data.logSummary ();
7777
7878 // ############################################################
7979 // # Comparison Logging
8080 // ############################################################
8181
82- Logger::logger->info (" Simulation of {} particles in a {}x{} grid\n " , x * y, x, y);
82+ std::string ds_summary = " " ;
83+ for (auto & summary : direct_sum_data.interceptor_summaries ) {
84+ ds_summary += summary + " ;" ;
85+ }
86+
87+ std::string lc_summary = " " ;
88+ for (auto & summary : linked_cells_data.interceptor_summaries ) {
89+ lc_summary += summary + " ;" ;
90+ }
91+
92+ Logger::logger->info (" Simulation of {} particles in a {}x{} grid\n " , rect_width * rect_height, rect_width, rect_height);
8393
8494 Logger::logger->info (" Direct sum container:" );
8595 Logger::logger->info (" Simulation took {:.3f}s" , direct_sum_data.total_time_seconds );
8696 Logger::logger->info (" Total iterations: {}" , direct_sum_data.total_iterations );
87- Logger::logger->info (" Average time per iteration: {:.3f}ms\n " , direct_sum_data.average_time_per_iteration_millis );
97+ Logger::logger->info (" Average time per iteration: {:.3f}ms\n " , direct_sum_data.total_time_seconds / direct_sum_data.total_iterations );
98+ Logger::logger->info (" Summary {}" , ds_summary);
8899
89100 Logger::logger->info (" Linked cells container:" );
101+ Logger::logger->info (" Domain size: {:.0f}x{:.0f}x{:.0f}" , domain_size[0 ], domain_size[1 ], domain_size[2 ]);
102+ Logger::logger->info (" Linked cells cutoff radius: {:.0f}" , lc_cutoff);
90103 Logger::logger->info (" Simulation took {:.3f}s" , linked_cells_data.total_time_seconds );
91104 Logger::logger->info (" Total iterations: {}" , linked_cells_data.total_iterations );
92- Logger::logger->info (" Average time per iteration: {:.3f}ms\n " , linked_cells_data.average_time_per_iteration_millis );
93-
94- Logger::logger->info (" Ratio Linked Cells / Direct Sum: {:.3f}%\n " ,
95- linked_cells_data.total_time_seconds / direct_sum_data.total_time_seconds * 100 );
105+ Logger::logger->info (" Average time per iteration: {:.3f}ms\n " ,
106+ linked_cells_data.total_time_seconds / linked_cells_data.total_iterations );
107+ Logger::logger->info (" Summary {}" , lc_summary);
96108}
97109
98110/*
@@ -103,7 +115,7 @@ int main() {
103115 std::vector<std::pair<int , int >> sizes = {{25 , 40 }, {50 , 40 }, {50 , 80 }, {100 , 80 }};
104116
105117 for (auto [size_x, size_y] : sizes) {
106- execute2DRectBenchmark (size_x, size_y);
118+ execute2DRectBenchmark (size_x, size_y, 1.1225 , 3 );
107119 }
108120
109121 return 0 ;
0 commit comments