From f09f4a721af5ecf2ad737edd7ca2c7690f3e2de7 Mon Sep 17 00:00:00 2001 From: Timofey Zakharchuk Date: Sun, 1 Feb 2026 14:00:43 +0300 Subject: [PATCH 1/6] Create adaptive.h --- src/dt/adaptive.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/dt/adaptive.h diff --git a/src/dt/adaptive.h b/src/dt/adaptive.h new file mode 100644 index 0000000..5af823c --- /dev/null +++ b/src/dt/adaptive.h @@ -0,0 +1,31 @@ +#pragma once +#include "struct/particle.h" +#include +#include +#include +#include "floatdef.h" + +real computeAdaptiveDt(const std::vector& p, real base_dt) +{ + real maxSpeed = 0; + + for (const auto& a : p) + { + real speed = std::sqrt(a.vx*a.vx + a.vy*a.vy + a.vz*a.vz); + if (speed > maxSpeed) + maxSpeed = speed; + } + + // If everything is basically stationary, use base dt + if (maxSpeed < real(1e-8)) + return base_dt; + + // Smaller dt when speeds are high + real dt = base_dt / (1 + maxSpeed); + + // Clamp dt to a reasonable range + dt = std::max(dt, base_dt * real(0.01)); // never smaller than 1% of base + dt = std::min(dt, base_dt * real(1.0)); // never larger than base + + return dt; +} From eccf0ea263c4cd98fb8f5d23b435dc3118b269f2 Mon Sep 17 00:00:00 2001 From: Timofey Zakharchuk Date: Sun, 1 Feb 2026 14:01:46 +0300 Subject: [PATCH 2/6] Update begrun.cpp --- src/begrun.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/begrun.cpp b/src/begrun.cpp index bcc006e..fe75e06 100644 --- a/src/begrun.cpp +++ b/src/begrun.cpp @@ -2,6 +2,7 @@ #include #include #include"floatdef.h" +#include"adaptive.h" std::vector LoadParticlesFromFile(const std::string& filename) { @@ -26,23 +27,24 @@ int main(int argc, char** argv) { << "NN NN EEEEEEE XX XX TTT \n" << "Newtonian EXact Trajectories\n"; - if (argc != 2) + if (argc != 3) { - std::cerr << "Usage: next \n"; + std::cerr << "Usage: next
\n"; return 1; } const char* filename = argv[1]; + real dt = std::stod(argv[2]); std::vector particles = LoadParticlesFromFile(filename); - real dt = 0.01; while (true) { - Step(particles, dt); + real dtAdaptive = computeAdaptiveDt(particles, dt); + Step(particles, dtAdaptive); } return 0; -} \ No newline at end of file +} From 90c2abf1d8626c3a8c2a1f131a8c20903787c12b Mon Sep 17 00:00:00 2001 From: Timofey Zakharchuk Date: Sun, 1 Feb 2026 14:03:04 +0300 Subject: [PATCH 3/6] Update CMakeLists.txt --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b34d78..4a86f10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,9 @@ endif() # Includes and sources include_directories(${CMAKE_SOURCE_DIR}/include) +include_directories(${CMAKE_SOURCE_DIR}/src) file(GLOB SRC_FILES ${CMAKE_SOURCE_DIR}/src/*.cpp) # Build executable add_executable(next ${SRC_FILES}) + From b552b009ff1e225d637a60d5959a21c114b04bdf Mon Sep 17 00:00:00 2001 From: Timofey Zakharchuk Date: Sun, 1 Feb 2026 14:05:36 +0300 Subject: [PATCH 4/6] Update cmake-multi-platform.yml --- .github/workflows/cmake-multi-platform.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 7ab1b4d..5ea9740 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -4,7 +4,9 @@ name: CMake on multiple platforms on: push: - branches: [ "main" ] + branches: + - main + - aDt pull_request: branches: [ "main" ] From ef30d76349d177d5cd4bf11378dc88c9f84887f5 Mon Sep 17 00:00:00 2001 From: Timofey Zakharchuk Date: Sun, 1 Feb 2026 14:07:11 +0300 Subject: [PATCH 5/6] Update cmake-multi-platform.yml --- .github/workflows/cmake-multi-platform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 5ea9740..dffe897 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -6,7 +6,7 @@ on: push: branches: - main - - aDt + - adaptiveDt pull_request: branches: [ "main" ] From a14a3a44c603fbabb405a09dc4bada159e98a280 Mon Sep 17 00:00:00 2001 From: Timofey Zakharchuk Date: Sun, 1 Feb 2026 14:08:40 +0300 Subject: [PATCH 6/6] Update begrun.cpp --- src/begrun.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/begrun.cpp b/src/begrun.cpp index fe75e06..baf97ec 100644 --- a/src/begrun.cpp +++ b/src/begrun.cpp @@ -2,7 +2,7 @@ #include #include #include"floatdef.h" -#include"adaptive.h" +#include"dt/adaptive.h" std::vector LoadParticlesFromFile(const std::string& filename) { @@ -48,3 +48,4 @@ int main(int argc, char** argv) { } +