diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index a412f63..5fa6f4d 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -2,14 +2,23 @@ find_package(Eigen3) find_package(Catch2 REQUIRED) -add_executable(benchmark bench.cpp) +set(BENCH_SOURCES bench.cpp bench_euler.cpp bench_mbd.cpp) + +foreach( benchsourcefile ${BENCH_SOURCES} ) + # I used a simple string replace, to cut off .cpp. + string( REPLACE ".cpp" "" benchmarkname ${benchsourcefile} ) + add_executable( ${benchmarkname} ${benchsourcefile} ) + # Make sure YourLib is linked to each app + target_link_libraries( + ${benchmarkname} + PRIVATE project_options + project_warnings + Eigen3::Eigen3 + Catch2::Catch2 + integratoren + ) +endforeach( benchsourcefile ${BENCH_SOURCES} ) + + -target_link_libraries( - benchmark - PRIVATE project_options - project_warnings - Eigen3::Eigen3 - Catch2::Catch2 - integratoren -) diff --git a/benchmark/bench_euler.cpp b/benchmark/bench_euler.cpp new file mode 100644 index 0000000..5034487 --- /dev/null +++ b/benchmark/bench_euler.cpp @@ -0,0 +1,14 @@ +// +// Created by jholder on 10/25/21. +// +#include "Rod2d.hpp" +#include "Simulation.h" +#include "Integratoren2d_forceless.h" +int main(){ + Rod2d rod(1.0); + Simulation sim(0.01, 1); + for (int i = 0; i < 10000000; ++i) { + Integratoren2d_forceless::Set1_Euler(rod, sim); + } + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/benchmark/bench_mbd.cpp b/benchmark/bench_mbd.cpp new file mode 100644 index 0000000..d45e6e9 --- /dev/null +++ b/benchmark/bench_mbd.cpp @@ -0,0 +1,15 @@ +// +// Created by jholder on 10/25/21. +// + +#include "Rod2d.hpp" +#include "Simulation.h" +#include "Integratoren2d_forceless.h" +int main(){ + Rod2d rod(1.0); + Simulation sim(0.01, 1); + for (int i = 0; i < 10000000; ++i) { + Integratoren2d_forceless::Set5_MBD(rod, sim); + } + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/src/Integratoren2d_force.cpp b/src/Integratoren2d_force.cpp index 9bcd80e..a85e4aa 100644 --- a/src/Integratoren2d_force.cpp +++ b/src/Integratoren2d_force.cpp @@ -23,22 +23,22 @@ void Integratoren2d_force::Set1_Euler( const std::function &force, const std::function &torque) { auto std = sim.getSTD(); // sqrt(2*delta_T) + auto e = rod2D.getE(); // translation Vector rand = {sim.getNorm(std), sim.getNorm(std)}; // gaussian noise Vector trans_part = rod2D.getDiff_Sqrt() * rand; - Vector trans_lab = rotation_Matrix(rod2D.getE()) * trans_part; + Vector trans_lab = rotation_Matrix(e) * trans_part; // Force - Vector F_lab = force(rod2D.getPos(), rod2D.getE()); - Vector F_part = rotation_Matrix(rod2D.getE()).inverse() * F_lab; + Vector F_lab = force(rod2D.getPos(), e); + Vector F_part = rotation_Matrix(e).inverse() * F_lab; Vector F_trans = rod2D.getDiff_Sqrt() * F_part; F_trans *= sim.getMDeltaT(); // rotation double rot = sim.getNorm(std) * rod2D.getDRot_Sqrt(); // rotationsmatrix verwenden. - Vector e = rod2D.getE(); - double M_rot = torque(rod2D.getPos(), rod2D.getE()) * rod2D.getDRot() * sim.getMDeltaT(); + double M_rot = torque(rod2D.getPos(), e) * rod2D.getDRot() * sim.getMDeltaT(); Vector new_e = e + (rot + M_rot) * ortho(e); new_e.normalize(); // apply diff --git a/src/Simulation.h b/src/Simulation.h index aa0ed0d..c42c7a0 100644 --- a/src/Simulation.h +++ b/src/Simulation.h @@ -17,7 +17,7 @@ class Simulation { std::mt19937_64 m_generator; std::normal_distribution m_norm; - public: +public: [[nodiscard]] double getMDeltaT() const; [[nodiscard]] double getSTD() const; };