From 7f173458efec8955e159b72029aa727bceafd56f Mon Sep 17 00:00:00 2001 From: Jacob Date: Mon, 16 May 2022 10:24:45 +0200 Subject: [PATCH] stuff done --- .gitignore | 0 Auswertung/README.md | 0 Auswertung/fig0.png | Bin Auswertung/fig1.png | Bin Auswertung/fig2.png | Bin Auswertung/harmonic.py | 0 Auswertung/length3_2d.pdf | Bin Auswertung/main.py | 0 Auswertung/notebooks/figure.ipynb | 0 Auswertung/notebooks/kovergence.ipynb | 0 Auswertung/notebooks/length3_2d.pdf | Bin Auswertung/notebooks/out.pdf | Bin Auswertung/notebooks/out2.pdf | Bin Auswertung/requirements.txt | 0 Auswertung/sphere_2d.pdf | Bin C++/.clang-format | 0 C++/.clang-tidy | 0 C++/CMakeLists.txt | 2 + C++/README.md | 0 C++/benchmark.81f4796.fourier | 0 C++/benchmark/CMakeLists.txt | 0 C++/benchmark/bench.cpp | 0 C++/benchmark/bench_euler.cpp | 0 C++/benchmark/bench_mbd.cpp | 0 C++/cmake/Cache.cmake | 0 C++/cmake/CompilerWarnings.cmake | 0 C++/cmake/Conan.cmake | 0 C++/cmake/Doxygen.cmake | 0 C++/cmake/Linker.cmake | 0 C++/cmake/PreventInSourceBuilds.cmake | 0 C++/cmake/Sanitizers.cmake | 0 C++/cmake/StandardProjectSettings.cmake | 0 C++/cmake/StaticAnalyzers.cmake | 0 C++/conanfile.py | 1 - C++/src/CMakeLists.txt | 54 ++++++++++-------- C++/src/Data/Rod2d.cpp | 23 ++------ C++/src/Data/Rod2d.hpp | 1 + C++/src/Data/Rod2dMulti.cpp | 46 +++++++++++++++ C++/src/Data/Rod2dMulti.hpp | 31 ++++++++++ C++/src/Data/Simulation.cpp | 48 ++++++++++++++-- C++/src/Data/Simulation.h | 11 +++- C++/src/Data/tools.hpp | 27 +++++++++ C++/src/Force/ForceMulti.cpp | 41 +++++++++++++ C++/src/Force/ForceMulti.h | 20 +++++++ C++/src/{ => Force}/force_lambdas.h | 8 +-- C++/src/Integratoren/Integratoren2d.cpp | 0 C++/src/Integratoren/Integratoren2d.h | 0 C++/src/indicators/block_progress_bar.hpp | 0 C++/src/indicators/color.hpp | 0 C++/src/indicators/cursor_control.hpp | 0 C++/src/indicators/cursor_movement.hpp | 0 C++/src/indicators/details/stream_helper.hpp | 0 C++/src/indicators/display_width.hpp | 0 C++/src/indicators/dynamic_progress.hpp | 0 C++/src/indicators/font_style.hpp | 0 .../indicators/indeterminate_progress_bar.hpp | 0 C++/src/indicators/multi_progress.hpp | 0 C++/src/indicators/progress_bar.hpp | 0 C++/src/indicators/progress_spinner.hpp | 0 C++/src/indicators/progress_type.hpp | 0 C++/src/indicators/setting.hpp | 0 C++/src/indicators/termcolor.hpp | 0 C++/src/indicators/terminal_size.hpp | 0 C++/src/main.cpp | 14 ++--- C++/src/runner/konvergenz_runner.cpp | 2 +- C++/src/runner/konvergenz_runner.h | 0 C++/src/tools/Compute.cpp | 2 +- C++/src/tools/Compute.h | 0 C++/src/tools/LiveAgg.cpp | 0 C++/src/tools/LiveAgg.hpp | 0 C++/src/tools/logging.cpp | 0 C++/src/tools/logging.hpp | 0 C++/src/tools/vec_trafos.h | 0 C++/test/.clang-tidy | 0 C++/test/CMakeLists.txt | 5 +- C++/test/catch_main.cpp | 0 C++/test/test_Compute.cpp | 0 C++/test/test_ForceMulti.cpp | 38 ++++++++++++ C++/test/test_LiveAgg.cpp | 0 C++/test/test_Rod2d.cpp | 0 C++/test/test_Rod2d_multi.cpp | 34 +++++++++++ C++/test/test_Simulation.cpp | 30 ++++++++++ 82 files changed, 374 insertions(+), 64 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 Auswertung/README.md mode change 100644 => 100755 Auswertung/fig0.png mode change 100644 => 100755 Auswertung/fig1.png mode change 100644 => 100755 Auswertung/fig2.png mode change 100644 => 100755 Auswertung/harmonic.py mode change 100644 => 100755 Auswertung/length3_2d.pdf mode change 100644 => 100755 Auswertung/main.py mode change 100644 => 100755 Auswertung/notebooks/figure.ipynb mode change 100644 => 100755 Auswertung/notebooks/kovergence.ipynb mode change 100644 => 100755 Auswertung/notebooks/length3_2d.pdf mode change 100644 => 100755 Auswertung/notebooks/out.pdf mode change 100644 => 100755 Auswertung/notebooks/out2.pdf mode change 100644 => 100755 Auswertung/requirements.txt mode change 100644 => 100755 Auswertung/sphere_2d.pdf mode change 100644 => 100755 C++/.clang-format mode change 100644 => 100755 C++/.clang-tidy mode change 100644 => 100755 C++/CMakeLists.txt mode change 100644 => 100755 C++/README.md mode change 100644 => 100755 C++/benchmark.81f4796.fourier mode change 100644 => 100755 C++/benchmark/CMakeLists.txt mode change 100644 => 100755 C++/benchmark/bench.cpp mode change 100644 => 100755 C++/benchmark/bench_euler.cpp mode change 100644 => 100755 C++/benchmark/bench_mbd.cpp mode change 100644 => 100755 C++/cmake/Cache.cmake mode change 100644 => 100755 C++/cmake/CompilerWarnings.cmake mode change 100644 => 100755 C++/cmake/Conan.cmake mode change 100644 => 100755 C++/cmake/Doxygen.cmake mode change 100644 => 100755 C++/cmake/Linker.cmake mode change 100644 => 100755 C++/cmake/PreventInSourceBuilds.cmake mode change 100644 => 100755 C++/cmake/Sanitizers.cmake mode change 100644 => 100755 C++/cmake/StandardProjectSettings.cmake mode change 100644 => 100755 C++/cmake/StaticAnalyzers.cmake mode change 100644 => 100755 C++/conanfile.py mode change 100644 => 100755 C++/src/CMakeLists.txt mode change 100644 => 100755 C++/src/Data/Rod2d.cpp mode change 100644 => 100755 C++/src/Data/Rod2d.hpp create mode 100755 C++/src/Data/Rod2dMulti.cpp create mode 100755 C++/src/Data/Rod2dMulti.hpp create mode 100644 C++/src/Data/tools.hpp create mode 100644 C++/src/Force/ForceMulti.cpp create mode 100644 C++/src/Force/ForceMulti.h rename C++/src/{ => Force}/force_lambdas.h (73%) mode change 100644 => 100755 mode change 100644 => 100755 C++/src/Integratoren/Integratoren2d.cpp mode change 100644 => 100755 C++/src/Integratoren/Integratoren2d.h mode change 100644 => 100755 C++/src/indicators/block_progress_bar.hpp mode change 100644 => 100755 C++/src/indicators/color.hpp mode change 100644 => 100755 C++/src/indicators/cursor_control.hpp mode change 100644 => 100755 C++/src/indicators/cursor_movement.hpp mode change 100644 => 100755 C++/src/indicators/details/stream_helper.hpp mode change 100644 => 100755 C++/src/indicators/display_width.hpp mode change 100644 => 100755 C++/src/indicators/dynamic_progress.hpp mode change 100644 => 100755 C++/src/indicators/font_style.hpp mode change 100644 => 100755 C++/src/indicators/indeterminate_progress_bar.hpp mode change 100644 => 100755 C++/src/indicators/multi_progress.hpp mode change 100644 => 100755 C++/src/indicators/progress_bar.hpp mode change 100644 => 100755 C++/src/indicators/progress_spinner.hpp mode change 100644 => 100755 C++/src/indicators/progress_type.hpp mode change 100644 => 100755 C++/src/indicators/setting.hpp mode change 100644 => 100755 C++/src/indicators/termcolor.hpp mode change 100644 => 100755 C++/src/indicators/terminal_size.hpp mode change 100644 => 100755 C++/src/main.cpp mode change 100644 => 100755 C++/src/runner/konvergenz_runner.cpp mode change 100644 => 100755 C++/src/runner/konvergenz_runner.h mode change 100644 => 100755 C++/src/tools/Compute.cpp mode change 100644 => 100755 C++/src/tools/Compute.h mode change 100644 => 100755 C++/src/tools/LiveAgg.cpp mode change 100644 => 100755 C++/src/tools/LiveAgg.hpp mode change 100644 => 100755 C++/src/tools/logging.cpp mode change 100644 => 100755 C++/src/tools/logging.hpp mode change 100644 => 100755 C++/src/tools/vec_trafos.h mode change 100644 => 100755 C++/test/.clang-tidy mode change 100644 => 100755 C++/test/CMakeLists.txt mode change 100644 => 100755 C++/test/catch_main.cpp mode change 100644 => 100755 C++/test/test_Compute.cpp create mode 100644 C++/test/test_ForceMulti.cpp mode change 100644 => 100755 C++/test/test_LiveAgg.cpp mode change 100644 => 100755 C++/test/test_Rod2d.cpp create mode 100755 C++/test/test_Rod2d_multi.cpp create mode 100755 C++/test/test_Simulation.cpp diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/Auswertung/README.md b/Auswertung/README.md old mode 100644 new mode 100755 diff --git a/Auswertung/fig0.png b/Auswertung/fig0.png old mode 100644 new mode 100755 diff --git a/Auswertung/fig1.png b/Auswertung/fig1.png old mode 100644 new mode 100755 diff --git a/Auswertung/fig2.png b/Auswertung/fig2.png old mode 100644 new mode 100755 diff --git a/Auswertung/harmonic.py b/Auswertung/harmonic.py old mode 100644 new mode 100755 diff --git a/Auswertung/length3_2d.pdf b/Auswertung/length3_2d.pdf old mode 100644 new mode 100755 diff --git a/Auswertung/main.py b/Auswertung/main.py old mode 100644 new mode 100755 diff --git a/Auswertung/notebooks/figure.ipynb b/Auswertung/notebooks/figure.ipynb old mode 100644 new mode 100755 diff --git a/Auswertung/notebooks/kovergence.ipynb b/Auswertung/notebooks/kovergence.ipynb old mode 100644 new mode 100755 diff --git a/Auswertung/notebooks/length3_2d.pdf b/Auswertung/notebooks/length3_2d.pdf old mode 100644 new mode 100755 diff --git a/Auswertung/notebooks/out.pdf b/Auswertung/notebooks/out.pdf old mode 100644 new mode 100755 diff --git a/Auswertung/notebooks/out2.pdf b/Auswertung/notebooks/out2.pdf old mode 100644 new mode 100755 diff --git a/Auswertung/requirements.txt b/Auswertung/requirements.txt old mode 100644 new mode 100755 diff --git a/Auswertung/sphere_2d.pdf b/Auswertung/sphere_2d.pdf old mode 100644 new mode 100755 diff --git a/C++/.clang-format b/C++/.clang-format old mode 100644 new mode 100755 diff --git a/C++/.clang-tidy b/C++/.clang-tidy old mode 100644 new mode 100755 diff --git a/C++/CMakeLists.txt b/C++/CMakeLists.txt old mode 100644 new mode 100755 index 450aa32..8bfbe52 --- a/C++/CMakeLists.txt +++ b/C++/CMakeLists.txt @@ -16,6 +16,8 @@ if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") endif() endif() + + # Link this 'library' to use the warnings specified in CompilerWarnings.cmake add_library(project_warnings INTERFACE) diff --git a/C++/README.md b/C++/README.md old mode 100644 new mode 100755 diff --git a/C++/benchmark.81f4796.fourier b/C++/benchmark.81f4796.fourier old mode 100644 new mode 100755 diff --git a/C++/benchmark/CMakeLists.txt b/C++/benchmark/CMakeLists.txt old mode 100644 new mode 100755 diff --git a/C++/benchmark/bench.cpp b/C++/benchmark/bench.cpp old mode 100644 new mode 100755 diff --git a/C++/benchmark/bench_euler.cpp b/C++/benchmark/bench_euler.cpp old mode 100644 new mode 100755 diff --git a/C++/benchmark/bench_mbd.cpp b/C++/benchmark/bench_mbd.cpp old mode 100644 new mode 100755 diff --git a/C++/cmake/Cache.cmake b/C++/cmake/Cache.cmake old mode 100644 new mode 100755 diff --git a/C++/cmake/CompilerWarnings.cmake b/C++/cmake/CompilerWarnings.cmake old mode 100644 new mode 100755 diff --git a/C++/cmake/Conan.cmake b/C++/cmake/Conan.cmake old mode 100644 new mode 100755 diff --git a/C++/cmake/Doxygen.cmake b/C++/cmake/Doxygen.cmake old mode 100644 new mode 100755 diff --git a/C++/cmake/Linker.cmake b/C++/cmake/Linker.cmake old mode 100644 new mode 100755 diff --git a/C++/cmake/PreventInSourceBuilds.cmake b/C++/cmake/PreventInSourceBuilds.cmake old mode 100644 new mode 100755 diff --git a/C++/cmake/Sanitizers.cmake b/C++/cmake/Sanitizers.cmake old mode 100644 new mode 100755 diff --git a/C++/cmake/StandardProjectSettings.cmake b/C++/cmake/StandardProjectSettings.cmake old mode 100644 new mode 100755 diff --git a/C++/cmake/StaticAnalyzers.cmake b/C++/cmake/StaticAnalyzers.cmake old mode 100644 new mode 100755 diff --git a/C++/conanfile.py b/C++/conanfile.py old mode 100644 new mode 100755 index 3adeb63..5654656 --- a/C++/conanfile.py +++ b/C++/conanfile.py @@ -6,7 +6,6 @@ class CppStarterProject(ConanFile): version = "0.1" requires = ( "catch2/2.13.7", - "docopt.cpp/0.6.2", "fmt/8.0.1", "spdlog/1.9.2", "eigen/3.4.0", diff --git a/C++/src/CMakeLists.txt b/C++/src/CMakeLists.txt old mode 100644 new mode 100755 index e5928db..ee9adda --- a/C++/src/CMakeLists.txt +++ b/C++/src/CMakeLists.txt @@ -5,38 +5,44 @@ find_package(Eigen3) add_library(logging tools/logging.cpp) -add_library(integratoren SHARED tools/LiveAgg.cpp Data/Rod2d.cpp Data/Simulation.cpp - Data/Simulation.h Integratoren/Integratoren2d.cpp - tools/Compute.cpp runner/konvergenz_runner.cpp runner/konvergenz_runner.h) +add_library(integratoren SHARED + tools/LiveAgg.cpp + Data/Rod2d.cpp + Data/Simulation.cpp + Data/Rod2dMulti.cpp + Force/ForceMulti.cpp + Integratoren/Integratoren2d.cpp + tools/Compute.cpp + runner/konvergenz_runner.cpp) target_include_directories(integratoren PUBLIC .) target_link_libraries( - integratoren - PRIVATE project_options - project_warnings - fmt::fmt - spdlog::spdlog - Eigen3::Eigen3 - logging - ) + integratoren + PRIVATE project_options + project_warnings + fmt::fmt + spdlog::spdlog + Eigen3::Eigen3 + logging + ) target_include_directories(logging PUBLIC .) target_link_libraries( - logging - PRIVATE project_options - project_warnings - fmt::fmt - spdlog::spdlog) + logging + PRIVATE project_options + project_warnings + fmt::fmt + spdlog::spdlog) add_executable(main main.cpp) find_package(OpenMP) if(OpenMP_CXX_FOUND) - target_link_libraries(main PUBLIC OpenMP::OpenMP_CXX) + target_link_libraries(main PUBLIC OpenMP::OpenMP_CXX) endif() target_link_libraries( - main - PRIVATE project_options - project_warnings - integratoren - Eigen3::Eigen3 - fmt::fmt -) \ No newline at end of file + main + PRIVATE project_options + project_warnings + integratoren + Eigen3::Eigen3 + fmt::fmt + ) diff --git a/C++/src/Data/Rod2d.cpp b/C++/src/Data/Rod2d.cpp old mode 100644 new mode 100755 index 92c2f32..aae795e --- a/C++/src/Data/Rod2d.cpp +++ b/C++/src/Data/Rod2d.cpp @@ -1,34 +1,23 @@ #include "Rod2d.hpp" #include "Eigen/Dense" - -constexpr double M_Pl = 3.141592653589793238462643383279502884; /* pi */ - -void sqrt(Eigen::Matrix2d &mat) { - const auto size = static_cast(mat.size()); - for (size_t i = 0; i < size; i++) { - mat.data()[i] = sqrt(mat.data()[i]); - } -} +#include "tools.hpp" Rod2d::Rod2d(double L) : m_pos({1, 1}), m_e({1, 0}) { assert(L >= 1.0); if (L == 1.0) { m_D_rot = 3.0; m_Diff << 1, 0, 0, 1; } else { - const double D0 = 3.0 * M_Pl / L; + const double D0 = 3.0 * Tools::M_Pl / L; const double p = L; - auto D_para = - D0 / (M_Pl * 2.0) * (log(p) - 0.1401 + 1.034 / p - 0.228 / (p * p)); - auto D_ortho = D0 / (M_Pl * 4.0) * - (log(p) + 0.8369 + 0.5551 / p - 0.06066 / (p * p)); - m_D_rot = 3 * D0 / (M_Pl * L * L) * - (log(p) - 0.3512 + 0.7804 / p - 0.09801 / (p * p)); + auto D_para = Tools::D_para(D0, p); + auto D_ortho = Tools::D_ortho(D0, p); + m_D_rot = Tools::D_rot(D0, p); m_Diff << D_para, 0, 0, D_ortho; } m_Diff_sqrt = m_Diff; m_D_rot_sqrt = sqrt(m_D_rot); - sqrt(m_Diff_sqrt); + Tools::mat_sqrt(m_Diff_sqrt); } void Rod2d::setPos(const Eigen::Vector2d &Pos) { m_pos = Pos; } diff --git a/C++/src/Data/Rod2d.hpp b/C++/src/Data/Rod2d.hpp old mode 100644 new mode 100755 index 10bce4e..7781b38 --- a/C++/src/Data/Rod2d.hpp +++ b/C++/src/Data/Rod2d.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +using pos_type = Eigen::Vector2d; class Rod2d { public: explicit Rod2d(double L); diff --git a/C++/src/Data/Rod2dMulti.cpp b/C++/src/Data/Rod2dMulti.cpp new file mode 100755 index 0000000..3793eb4 --- /dev/null +++ b/C++/src/Data/Rod2dMulti.cpp @@ -0,0 +1,46 @@ +#include "Rod2dMulti.hpp" +#include "Eigen/Dense" +#include "tools.hpp" + +Rod2dMulti::Rod2dMulti(double length, size_t num_particles) + : m_pos(num_particles, Eigen::Vector2d({1, 1})), + m_e(num_particles, {1, 0}) { + assert(L >= 1.0); + if (length == 1.0) { + m_D_rot = 3; + m_Diff << 1, 0, 0, 1; + } else { + const double D0 = 3.0 * Tools::M_Pl / length; + const double p = length; + auto D_para = Tools::D_para(D0, p); + auto D_ortho = Tools::D_ortho(D0, p); + m_D_rot = Tools::D_rot(D0, p); + m_Diff << D_para, 0, 0, D_ortho; + } + m_Diff_sqrt = m_Diff; + m_D_rot_sqrt = sqrt(m_D_rot); + Tools::mat_sqrt(m_Diff_sqrt); +} + +void Rod2dMulti::setPos(const Eigen::Vector2d &Pos, size_t pos) { + assert(pos < m_pos.size()); + m_pos[pos] = Pos; +} + +double Rod2dMulti::getDRot() const { return m_D_rot; } + +const Eigen::Vector2d &Rod2dMulti::getPos(size_t pos) const { + return m_pos[pos]; +} + +const Eigen::Matrix2d &Rod2dMulti::getDiff() const { return m_Diff; } + +const Eigen::Matrix2d &Rod2dMulti::getDiff_Sqrt() const { return m_Diff_sqrt; } + +double Rod2dMulti::getDRot_Sqrt() const { return m_D_rot_sqrt; } + +const Eigen::Vector2d &Rod2dMulti::getE(size_t pos) const { return m_e[pos]; } +size_t Rod2dMulti::num_parts() const{ +return m_e.size(); +} +void Rod2dMulti::setE(const Eigen::Vector2d &mE, size_t pos) { m_e[pos] = mE; } diff --git a/C++/src/Data/Rod2dMulti.hpp b/C++/src/Data/Rod2dMulti.hpp new file mode 100755 index 0000000..9309133 --- /dev/null +++ b/C++/src/Data/Rod2dMulti.hpp @@ -0,0 +1,31 @@ +#pragma once +#include +#include +class Rod2dMulti { + public: + explicit Rod2dMulti(double length, size_t num_particles); + + [[nodiscard]] const Eigen::Matrix2d &getDiff() const; + + [[nodiscard]] double getDRot() const; + + [[nodiscard]] const Eigen::Vector2d &getPos(size_t pos) const; + + void setPos(const Eigen::Vector2d &Pos, size_t pos); + + [[nodiscard]] const Eigen::Matrix2d &getDiff_Sqrt() const; + + [[nodiscard]] const Eigen::Vector2d &getE(size_t pos) const; + + void setE(const Eigen::Vector2d &mE, size_t pos); + + [[nodiscard]] double getDRot_Sqrt() const; + [[nodiscard]] size_t num_parts()const; + private: + Eigen::Matrix2d m_Diff; + Eigen::Matrix2d m_Diff_sqrt; + double m_D_rot; + double m_D_rot_sqrt; + std::vector m_pos; // position + std::vector m_e; +}; diff --git a/C++/src/Data/Simulation.cpp b/C++/src/Data/Simulation.cpp index e862ac1..ba693ec 100644 --- a/C++/src/Data/Simulation.cpp +++ b/C++/src/Data/Simulation.cpp @@ -4,17 +4,53 @@ #include "Simulation.h" -double Simulation::getNorm(double t_norm) { - //return 0.0; - return t_norm * m_norm(m_generator); -} - Simulation::Simulation(double t_delta_T, size_t seed) - : m_delta_T(t_delta_T), + : m_xBorder(100), + m_yBorder(100), + m_delta_T(t_delta_T), m_std(std::sqrt(t_delta_T * 2.0)), m_generator(seed), m_norm(0, 1.0) {} +double Simulation::getNorm(double t_norm) { + return t_norm * m_norm(m_generator); +} + double Simulation::getMDeltaT() const { return m_delta_T; } double Simulation::getSTD() const { return m_std; } + +void Simulation::set_xBorder(double border) { + m_enable_border = true; + m_xBorder = border; +}; +void Simulation::set_yBorder(double border) { + m_enable_border = true; + m_yBorder = border; +}; +pos_type Simulation::boundaryPos(pos_type pos) const { + if (not m_enable_border) { + return pos; + } + if (pos[0] > m_xBorder) { + pos[0] -= m_xBorder; + } + if (pos[1] > m_yBorder) { + pos[1] -= m_yBorder; + } + return pos; +} + +pos_type Simulation::boundaryDistance(const pos_type& pos1, const pos_type& pos2) const { + pos_type distance = pos2 - pos1; + if (not m_enable_border) { + return distance; + } + if (distance[0] > m_xBorder / 2) { + distance[0] -= m_xBorder; + } + if (distance[1] > m_yBorder / 2) { + distance[1] -= m_yBorder; + } + return distance; +} diff --git a/C++/src/Data/Simulation.h b/C++/src/Data/Simulation.h index c42c7a0..1bf1cf2 100644 --- a/C++/src/Data/Simulation.h +++ b/C++/src/Data/Simulation.h @@ -5,19 +5,26 @@ #pragma once #include - +#include "Rod2d.hpp" class Simulation { public: explicit Simulation(double t_delta_T, size_t seed); double getNorm(double t_norm); + void set_xBorder(double border); + void set_yBorder(double border); private: + bool m_enable_border = false; + double m_xBorder; + double m_yBorder; double m_delta_T; double m_std; std::mt19937_64 m_generator; std::normal_distribution m_norm; -public: + public: [[nodiscard]] double getMDeltaT() const; [[nodiscard]] double getSTD() const; + [[nodiscard]] pos_type boundaryPos(pos_type pos) const; + [[nodiscard]] pos_type boundaryDistance(const pos_type& pos1, const pos_type& pos2) const; }; diff --git a/C++/src/Data/tools.hpp b/C++/src/Data/tools.hpp new file mode 100644 index 0000000..7b22d7a --- /dev/null +++ b/C++/src/Data/tools.hpp @@ -0,0 +1,27 @@ +#include +#include "Eigen/Dense" +class Tools { + public: + constexpr static void mat_sqrt(Eigen::Matrix2d &mat) { + const auto size = static_cast(mat.size()); + for (unsigned long index = 0; index < size; index++) { + mat.data()[index] = sqrt(mat.data()[index]); + } + } + + constexpr static double M_Pl = + 3.141592653589793238462643383279502884; /* pi */ + + constexpr static double D_para(double D0, double p) { + return D0 / (M_Pl * 2.0) * + (log(p) - 0.1401 + 1.034 / p - 0.228 / (p * p)); + } + constexpr static double D_ortho(double D0, double p) { + return D0 / (M_Pl * 4.0) * + (log(p) + 0.8369 + 0.5551 / p - 0.06066 / (p * p)); + } + constexpr static double D_rot(double D0, double p) { + return 3 * D0 / (M_Pl * p * p) * + (log(p) - 0.3512 + 0.7804 / p - 0.09801 / (p * p)); + } +}; // namespace Tools diff --git a/C++/src/Force/ForceMulti.cpp b/C++/src/Force/ForceMulti.cpp new file mode 100644 index 0000000..f3e19f1 --- /dev/null +++ b/C++/src/Force/ForceMulti.cpp @@ -0,0 +1,41 @@ +#include "ForceMulti.h" +ForceMulti::ForceMulti(size_t num_particles) + : m_force(num_particles, {0.0, 0.0}), m_torque(num_particles, 0.0){}; + +Eigen::Vector2d ForceMulti::force(Eigen::Vector2d pos1, Eigen::Vector2d pos2, + const Simulation& sim) { + auto distance = sim.boundaryDistance(pos1, pos2); + auto r = distance.norm(); + auto e = distance.normalized(); + return r * e; +} + +double ForceMulti::torque(Eigen::Vector2d pos1, Eigen::Vector2d e1, + Eigen::Vector2d pos2, Eigen::Vector2d e2, + const Simulation& sim) { + auto distance = sim.boundaryDistance(pos1, pos2); + auto r = distance.norm(); + auto e = distance.normalized(); + return r; +} + +void ForceMulti::force_torque(const Rod2dMulti& rods, const Simulation& sim) { + for (size_t index_1 = 0; index_1 < rods.num_parts(); ++index_1) { + for (size_t index_2 = index_1 + 1; index_2 < rods.num_parts(); + ++index_2) { + auto f = force(rods.getPos(index_1), rods.getPos(index_2), sim); + m_force[index_1] += f; + m_force[index_2] -= f; + + auto t = torque(rods.getPos(index_1), rods.getE(index_1), + rods.getPos(index_2), rods.getE(index_2), sim); + m_torque[index_1] += t; + m_torque[index_2] -= t; + } + } +}; + +const std::vector& ForceMulti::get_torque() const { return m_torque; } +const std::vector& ForceMulti::get_force() const { + return m_force; +} diff --git a/C++/src/Force/ForceMulti.h b/C++/src/Force/ForceMulti.h new file mode 100644 index 0000000..b05a29d --- /dev/null +++ b/C++/src/Force/ForceMulti.h @@ -0,0 +1,20 @@ +#pragma once +#include +#include "Data/Rod2dMulti.hpp" +#include "Data/Simulation.h" +class ForceMulti { + private: + std::vector m_force; + std::vector m_torque; + + public: + explicit ForceMulti(size_t num_particles); + Eigen::Vector2d force(Eigen::Vector2d pos1, Eigen::Vector2d pos2, + const Simulation& sim); + double torque(Eigen::Vector2d pos1, Eigen::Vector2d e1, + Eigen::Vector2d pos2, Eigen::Vector2d e2, + const Simulation& sim); + void force_torque(const Rod2dMulti& rods, const Simulation &sim); + [[nodiscard]] const std::vector& get_torque() const; + [[nodiscard]] const std::vector& get_force() const; +}; diff --git a/C++/src/force_lambdas.h b/C++/src/Force/force_lambdas.h old mode 100644 new mode 100755 similarity index 73% rename from C++/src/force_lambdas.h rename to C++/src/Force/force_lambdas.h index a801b74..bdea3a7 --- a/C++/src/force_lambdas.h +++ b/C++/src/Force/force_lambdas.h @@ -5,21 +5,21 @@ #pragma once [[maybe_unused]] const static auto harmonic_Force = [](const Eigen::Vector2d &pos, - const Eigen::Vector2d & /*torque*/) -> Eigen::Vector2d { + const Eigen::Vector2d & /*e_vec*/) -> Eigen::Vector2d { return -1.0 * pos; }; [[maybe_unused]] const static auto const_Force = [](const Eigen::Vector2d & /*pos*/, - const Eigen::Vector2d & /*torque*/) -> Eigen::Vector2d { + const Eigen::Vector2d & /*e_vec*/) -> Eigen::Vector2d { return {1,1}; }; [[maybe_unused]] const static auto zero_Force = [](const Eigen::Vector2d & /*pos*/, - const Eigen::Vector2d & /*torque*/) -> Eigen::Vector2d { + const Eigen::Vector2d & /*e_vec*/) -> Eigen::Vector2d { return {0.0, 0.0}; }; [[maybe_unused]] const static auto zero_Torque = [](const Eigen::Vector2d & /*pos*/, - const Eigen::Vector2d & /*torque*/) -> double { + const Eigen::Vector2d & /*e_vec*/) -> double { return 0.0; }; diff --git a/C++/src/Integratoren/Integratoren2d.cpp b/C++/src/Integratoren/Integratoren2d.cpp old mode 100644 new mode 100755 diff --git a/C++/src/Integratoren/Integratoren2d.h b/C++/src/Integratoren/Integratoren2d.h old mode 100644 new mode 100755 diff --git a/C++/src/indicators/block_progress_bar.hpp b/C++/src/indicators/block_progress_bar.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/color.hpp b/C++/src/indicators/color.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/cursor_control.hpp b/C++/src/indicators/cursor_control.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/cursor_movement.hpp b/C++/src/indicators/cursor_movement.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/details/stream_helper.hpp b/C++/src/indicators/details/stream_helper.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/display_width.hpp b/C++/src/indicators/display_width.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/dynamic_progress.hpp b/C++/src/indicators/dynamic_progress.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/font_style.hpp b/C++/src/indicators/font_style.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/indeterminate_progress_bar.hpp b/C++/src/indicators/indeterminate_progress_bar.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/multi_progress.hpp b/C++/src/indicators/multi_progress.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/progress_bar.hpp b/C++/src/indicators/progress_bar.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/progress_spinner.hpp b/C++/src/indicators/progress_spinner.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/progress_type.hpp b/C++/src/indicators/progress_type.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/setting.hpp b/C++/src/indicators/setting.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/termcolor.hpp b/C++/src/indicators/termcolor.hpp old mode 100644 new mode 100755 diff --git a/C++/src/indicators/terminal_size.hpp b/C++/src/indicators/terminal_size.hpp old mode 100644 new mode 100755 diff --git a/C++/src/main.cpp b/C++/src/main.cpp old mode 100644 new mode 100755 index 0159ead..43809b1 --- a/C++/src/main.cpp +++ b/C++/src/main.cpp @@ -67,17 +67,17 @@ constexpr int num_threads = 5; int main() { // TIME std::cout<<"no_force"< #include #include -#include "force_lambdas.h" +#include "Force/force_lambdas.h" #include diff --git a/C++/src/runner/konvergenz_runner.h b/C++/src/runner/konvergenz_runner.h old mode 100644 new mode 100755 diff --git a/C++/src/tools/Compute.cpp b/C++/src/tools/Compute.cpp old mode 100644 new mode 100755 index 85e11f1..1be29da --- a/C++/src/tools/Compute.cpp +++ b/C++/src/tools/Compute.cpp @@ -111,7 +111,7 @@ Compute::Compute(Rod2d rod, Type t_type, Force force, size_t t_every, case Force::harmonic_F: target = 2 * (1 - 2 * std::exp(-time) + std::exp(-2 * time)) + - 2 * (1 - std::exp(-2 * time)); + 2 * (1 - std::exp(-2 * time)) - 2 * (rod.getDiff().trace()) * time; break; } break; diff --git a/C++/src/tools/Compute.h b/C++/src/tools/Compute.h old mode 100644 new mode 100755 diff --git a/C++/src/tools/LiveAgg.cpp b/C++/src/tools/LiveAgg.cpp old mode 100644 new mode 100755 diff --git a/C++/src/tools/LiveAgg.hpp b/C++/src/tools/LiveAgg.hpp old mode 100644 new mode 100755 diff --git a/C++/src/tools/logging.cpp b/C++/src/tools/logging.cpp old mode 100644 new mode 100755 diff --git a/C++/src/tools/logging.hpp b/C++/src/tools/logging.hpp old mode 100644 new mode 100755 diff --git a/C++/src/tools/vec_trafos.h b/C++/src/tools/vec_trafos.h old mode 100644 new mode 100755 diff --git a/C++/test/.clang-tidy b/C++/test/.clang-tidy old mode 100644 new mode 100755 diff --git a/C++/test/CMakeLists.txt b/C++/test/CMakeLists.txt old mode 100644 new mode 100755 index ba9a7a4..20de2d2 --- a/C++/test/CMakeLists.txt +++ b/C++/test/CMakeLists.txt @@ -9,8 +9,11 @@ target_link_libraries(catch_main PUBLIC Catch2::Catch2 logging) target_link_libraries(catch_main PRIVATE project_options) set(TEST_FILES - test_LiveAgg.cpp + test_ForceMulti.cpp + test_Simulation.cpp + test_LiveAgg.cpp test_Rod2d.cpp + test_Rod2d_multi.cpp test_Compute.cpp) add_executable(tests ${TEST_FILES}) diff --git a/C++/test/catch_main.cpp b/C++/test/catch_main.cpp old mode 100644 new mode 100755 diff --git a/C++/test/test_Compute.cpp b/C++/test/test_Compute.cpp old mode 100644 new mode 100755 diff --git a/C++/test/test_ForceMulti.cpp b/C++/test/test_ForceMulti.cpp new file mode 100644 index 0000000..abf3437 --- /dev/null +++ b/C++/test/test_ForceMulti.cpp @@ -0,0 +1,38 @@ +#include +#include "Data/Rod2dMulti.hpp" +#include "Force/ForceMulti.h" + +TEST_CASE("Forces") { + ForceMulti force(100); + Rod2dMulti rod(1, 100); + Simulation sim(1, 123); + sim.set_xBorder(100); + Eigen::Vector2d zero_pos{0.0, 0.0}; + Eigen::Vector2d one_pos{1.0, 0.0}; + Eigen::Vector2d per_zero_pos{100, 100}; + SECTION("Basic Force") { + auto F00 = force.force(zero_pos, zero_pos, sim); + auto F11 = force.force(one_pos, one_pos, sim); + + auto F01 = force.force(zero_pos, one_pos, sim); + auto F10 = force.force(one_pos, zero_pos, sim); + + CHECK(F11 == F00); + CHECK(F01 == -F10); + } + SECTION("Basic Torque") {} + SECTION("Peridoic Torque") {} + SECTION("Complete Calculation") { + force.force_torque(rod, sim); + const auto F = force.get_force(); + auto F0 = F[0]; + for (const auto &f : F) { + CHECK(F0 == f); + } + const auto T = force.get_torque(); + auto T0 = T[0]; + for (const auto &f : T) { + CHECK(T0 == f); + } + } +} diff --git a/C++/test/test_LiveAgg.cpp b/C++/test/test_LiveAgg.cpp old mode 100644 new mode 100755 diff --git a/C++/test/test_Rod2d.cpp b/C++/test/test_Rod2d.cpp old mode 100644 new mode 100755 diff --git a/C++/test/test_Rod2d_multi.cpp b/C++/test/test_Rod2d_multi.cpp new file mode 100755 index 0000000..37c10ea --- /dev/null +++ b/C++/test/test_Rod2d_multi.cpp @@ -0,0 +1,34 @@ +// +// Created by jholder on 21.10.21. +// + +#include +#include + +#include "Data/Rod2dMulti.hpp" +#include "tools/vec_trafos.h" + +TEST_CASE("Multi Rods") { + Rod2dMulti sphere(1, 100); + Rod2dMulti rod(2, 100); + SECTION("Checking translation") { + rod.setPos({0, 0}, 0); + rod.setPos(rod.getPos(0) + Eigen::Vector2d(1, -1), 0); + auto newPos = rod.getPos(0); + REQUIRE(newPos[0] == 1); + REQUIRE(newPos[1] == -1); + REQUIRE(sphere.getDiff_Sqrt()(0, 0) == 1.0); + REQUIRE(sphere.getDiff_Sqrt()(0, 1) == 0.0); + REQUIRE(sphere.getDiff_Sqrt()(1, 0) == 0.0); + REQUIRE(sphere.getDiff_Sqrt()(1, 1) == 1.0); + } + SECTION("Checking rotation") { + double f1 = GENERATE(take(10, random(-100, 100))); + double f2 = GENERATE(take(10, random(-100, 100))); + rod.setE(Eigen::Vector2d({f1, f2}).normalized(), 0); + auto test = Eigen::Vector2d({1, 0}); + auto e = rod.getE(0); + auto erg = (rotation_Matrix(e) * test).normalized(); + REQUIRE(erg.isApprox(e)); + } +} diff --git a/C++/test/test_Simulation.cpp b/C++/test/test_Simulation.cpp new file mode 100755 index 0000000..1a99d1b --- /dev/null +++ b/C++/test/test_Simulation.cpp @@ -0,0 +1,30 @@ +// +// Created by jholder on 21.10.21. +// + +#include +#include + +#include "Data/Simulation.h" +#include "tools/vec_trafos.h" + +TEST_CASE("Simulation") { + Simulation sim(0.1, 1234); + SECTION("Checking Simulation with non periodic settings") { + pos_type pos_Inside {10,10}; + pos_type pos_Outside {200,200}; + CHECK(pos_Inside == sim.boundaryPos(pos_Inside)); + CHECK(pos_Outside == sim.boundaryPos(pos_Outside)); + CHECK(pos_Outside-pos_Inside == sim.boundaryDistance(pos_Inside,pos_Outside)); + } + SECTION("Checking Simulation with periodic settings") { + pos_type pos_Inside {10,10}; + pos_type pos_Outside {200,200}; + pos_type per_pos_Outside {100,100}; + sim.set_xBorder(100); + sim.set_yBorder(100); + CHECK(pos_Inside == sim.boundaryPos(pos_Inside)); + CHECK(per_pos_Outside == sim.boundaryPos(pos_Outside)); + //CHECK(pos_Outside-pos_Inside == sim.boundaryDistance(pos_Inside,pos_Outside)); + } +}