From bbf2f81929daee475d3d407a303b08314f0ca3aa Mon Sep 17 00:00:00 2001 From: TMahlatini Date: Wed, 14 Aug 2024 10:02:27 -0700 Subject: [PATCH 01/10] deleted dead code --- DDEINT | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DDEINT b/DDEINT index 58487c7..6a0a799 160000 --- a/DDEINT +++ b/DDEINT @@ -1 +1 @@ -Subproject commit 58487c76ce516ef76b615e3d7ed813d623757474 +Subproject commit 6a0a799439149ce06ff8d131f72908f5b40cc9ee From 3f0ed1473cbc5f76e37fad69a7bfeb7b015faef6 Mon Sep 17 00:00:00 2001 From: TMahlatini Date: Wed, 14 Aug 2024 11:13:41 -0700 Subject: [PATCH 02/10] refactored continue integration to match new interface --- DDEINT | 2 +- .../data/heat_equation_output.csv | 26 +++++++++---------- test/2D_Heat_Equation/heat_equation.cpp | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/DDEINT b/DDEINT index 6a0a799..1cdc076 160000 --- a/DDEINT +++ b/DDEINT @@ -1 +1 @@ -Subproject commit 6a0a799439149ce06ff8d131f72908f5b40cc9ee +Subproject commit 1cdc0760db7312b20f101251578556f48c9171b1 diff --git a/test/2D_Heat_Equation/data/heat_equation_output.csv b/test/2D_Heat_Equation/data/heat_equation_output.csv index 3ebc184..7fe2e4a 100644 --- a/test/2D_Heat_Equation/data/heat_equation_output.csv +++ b/test/2D_Heat_Equation/data/heat_equation_output.csv @@ -1,17 +1,17 @@ time,||u||_rms -0.05,0.355218 -0.1,0.329894 -0.15,0.289597 -0.2,0.239044 -0.25,0.18277 -0.3,0.126448 -0.35,0.0755917 -0.4,0.0351711 -0.45,0.00915344 -0.5,5.53161e-05 -0.55,0.0088895 -0.6,0.0345773 -0.65,0.0748176 +0.05,0.355255 +0.1,0.329855 +0.15,0.289473 +0.2,0.239114 +0.25,0.182833 +0.3,0.126491 +0.35,0.0756139 +0.4,0.0351864 +0.45,0.00916183 +0.5,5.53773e-05 +0.55,0.00889539 +0.6,0.0345715 +0.65,0.0748174 0.7,0.125529 0.75,0.181808 0.8,0.23813 diff --git a/test/2D_Heat_Equation/heat_equation.cpp b/test/2D_Heat_Equation/heat_equation.cpp index 017188b..7223c02 100644 --- a/test/2D_Heat_Equation/heat_equation.cpp +++ b/test/2D_Heat_Equation/heat_equation.cpp @@ -174,7 +174,7 @@ int main() { time.push_back(test_laplacian.get_t()); } else { // Continue the integration for subsequent steps - output = test_laplacian.continue_integration(t_end, 0.0005, 50000, 1e-10, 1e-5, false); + output = test_laplacian.continue_integration(t_end, 50000, false); snapshots.push_back(output); time.push_back(test_laplacian.get_t()); } From 5b347f2329a159c20f4d2b48a7dfa101dea3b6d9 Mon Sep 17 00:00:00 2001 From: TMahlatini Date: Wed, 14 Aug 2024 13:04:54 -0700 Subject: [PATCH 03/10] refactored to match new ddeint interface --- test/2D_Heat_Equation/heat_equation.cpp | 74 +++++++++++++------------ 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/test/2D_Heat_Equation/heat_equation.cpp b/test/2D_Heat_Equation/heat_equation.cpp index 7223c02..85c3486 100644 --- a/test/2D_Heat_Equation/heat_equation.cpp +++ b/test/2D_Heat_Equation/heat_equation.cpp @@ -153,7 +153,7 @@ int main() { // Initialize the state initialize_y(nx_loc, ny_loc, dx, dy, init_cond_laplacian); - std::vector output, time; + std::vector> output; std::vector> snapshots; snapshots.reserve(20); @@ -162,50 +162,56 @@ int main() { double dt = 0.05; // Time step double tf = 1.0; // Final time int num_steps = tf / dt; // Number of time steps - - for (int step = 0; step < num_steps; ++step) { - double t_start = step * dt; - double t_end = (step + 1) * dt; - - if (step == 0) { - // Initialize the integrator at the first step - output = test_laplacian.run(t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, false); - snapshots.push_back(output); - time.push_back(test_laplacian.get_t()); - } else { - // Continue the integration for subsequent steps - output = test_laplacian.continue_integration(t_end, 50000, false); - snapshots.push_back(output); - time.push_back(test_laplacian.get_t()); - } - } + int num_snapshots = 20; // Number of snapshots to take + double t_start = 0.0; + double t_end = 1.0; + + output = test_laplacian.run(20,t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, false); + + // for (int step = 0; step < num_steps; ++step) { + // double t_start = step * dt; + // double t_end = (step + 1) * dt; + + // if (step == 0) { + // // Initialize the integrator at the first step + // output = test_laplacian.run(t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, false); + // snapshots.push_back(output); + // time.push_back(test_laplacian.get_t()); + // } else { + // // Continue the integration for subsequent steps + // output = test_laplacian.continue_integration(t_end, 50000, false); + // snapshots.push_back(output); + // time.push_back(test_laplacian.get_t()); + // } + // } auto end_time = std::chrono::high_resolution_clock::now(); double execution_time = std::chrono::duration_cast(end_time - start_time).count(); std::cout << "Execution time: " << execution_time << " milliseconds\n"; - //output.insert(output.begin(), tf); - while (!output.empty()) { - output.pop_back(); - } - // Calculate the rms of each snapshot - int col_width = 25; - std::cout << std::left; - std::cout << std::setw(col_width) << "time" << std::setw(col_width) << "||u||_rms " << std::endl; - for (size_t i = 0; i < snapshots.size(); ++i) { - double rms = calculate_rms(snapshots[i]); - output.push_back(rms); - std::cout << std::scientific; - std::cout << std::setprecision(16); - std::cout << std::setw(col_width) << time[i] << std::setw(col_width) << rms << std::endl; + + // //output.insert(output.begin(), tf); + // while (!output.empty()) { + // output.pop_back(); + // } + // // Calculate the rms of each snapshot + // int col_width = 25; + // std::cout << std::left; + // std::cout << std::setw(col_width) << "time" << std::setw(col_width) << "||u||_rms " << std::endl; + // for (size_t i = 0; i < snapshots.size(); ++i) { + // double rms = calculate_rms(snapshots[i]); + // output.push_back(rms); + // std::cout << std::scientific; + // std::cout << std::setprecision(16); + // std::cout << std::setw(col_width) << time[i] << std::setw(col_width) << rms << std::endl; - } + // } - write_to_csv(time, output, "data/heat_equation_output.csv"); + //write_to_csv(time, output, "data/heat_equation_output.csv"); return 0; } \ No newline at end of file From f5d3b618128c86674917ff294e1f5e526e165601 Mon Sep 17 00:00:00 2001 From: TMahlatini Date: Wed, 14 Aug 2024 13:06:07 -0700 Subject: [PATCH 04/10] refactored continue and run --- DDEINT | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DDEINT b/DDEINT index 1cdc076..6b13c53 160000 --- a/DDEINT +++ b/DDEINT @@ -1 +1 @@ -Subproject commit 1cdc0760db7312b20f101251578556f48c9171b1 +Subproject commit 6b13c53e6ad9d92294f854e70254ca9fe922350f From f89d560785f12249b4695c9084033234bd964e2a Mon Sep 17 00:00:00 2001 From: TMahlatini Date: Thu, 15 Aug 2024 08:38:19 -0700 Subject: [PATCH 05/10] added callback function --- test/2D_Heat_Equation/heat_equation.cpp | 79 ++++--------------------- 1 file changed, 13 insertions(+), 66 deletions(-) diff --git a/test/2D_Heat_Equation/heat_equation.cpp b/test/2D_Heat_Equation/heat_equation.cpp index 85c3486..25055f4 100644 --- a/test/2D_Heat_Equation/heat_equation.cpp +++ b/test/2D_Heat_Equation/heat_equation.cpp @@ -95,27 +95,18 @@ void initialize_y(size_t nx_loc, size_t ny_loc, double dx, double dy, std::vecto } -void write_to_csv(const std::vector& time ,const std::vector& data, const std::string& filename) { - std::ofstream file(filename); - if (!file.is_open()) { - std::cerr << "Error opening file: " << filename << std::endl; - return; - - } - - file << "time,||u||_rms" << std::endl; - for (size_t i = 0; i < time.size(); ++i) { - file << time[i] << "," << data[i] << std::endl; +// should this be a member function of DDEint_dopri_5? +void log_step(double time, const std::vector& state, std::string filename) { + std::ofstream file(filename, std::ios::app); + file << time << ","; + for (double val : state) { + file << val << ","; } - - - - file << std::endl; - - file.close(); + std::endl(file); } + double calculate_rms(const std::vector& values) { double sum_of_squares = 0.0; for (double value : values) { @@ -125,12 +116,7 @@ double calculate_rms(const std::vector& values) { return sqrt(mean); } -//update DDE library so that it does not return a vector of all the snapshots but only the last snapshot of the time it finished. Outside of the ring buffer we are not saving any other snapshots. -//optimize m_output array. check to see where its being updated. -// change test case to take snapshots 1/20th for a 1sec. basically call run 20 times and get the last snapshot of each run -//check the DDE library to see if its not saving all the history in the ringbuffer. we not storing any data in the ringbuffer. -//parameters for ringbuffer should basically be zero in this test case. int main() { // Dummy prehistory function (returns 0.0 for all inputs) @@ -154,64 +140,25 @@ int main() { initialize_y(nx_loc, ny_loc, dx, dy, init_cond_laplacian); std::vector> output; - std::vector> snapshots; - snapshots.reserve(20); + auto start_time = std::chrono::high_resolution_clock::now(); - double dt = 0.05; // Time step - double tf = 1.0; // Final time - int num_steps = tf / dt; // Number of time steps - int num_snapshots = 20; // Number of snapshots to take double t_start = 0.0; double t_end = 1.0; - output = test_laplacian.run(20,t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, false); - - // for (int step = 0; step < num_steps; ++step) { - // double t_start = step * dt; - // double t_end = (step + 1) * dt; - - // if (step == 0) { - // // Initialize the integrator at the first step - // output = test_laplacian.run(t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, false); - // snapshots.push_back(output); - // time.push_back(test_laplacian.get_t()); - // } else { - // // Continue the integration for subsequent steps - // output = test_laplacian.continue_integration(t_end, 50000, false); - // snapshots.push_back(output); - // time.push_back(test_laplacian.get_t()); - // } - // } + //output = test_laplacian.run(20,t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, false); + test_laplacian.run(20, t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, log_step, false); + auto end_time = std::chrono::high_resolution_clock::now(); double execution_time = std::chrono::duration_cast(end_time - start_time).count(); std::cout << "Execution time: " << execution_time << " milliseconds\n"; - - // //output.insert(output.begin(), tf); - // while (!output.empty()) { - // output.pop_back(); - // } - // // Calculate the rms of each snapshot - // int col_width = 25; - // std::cout << std::left; - // std::cout << std::setw(col_width) << "time" << std::setw(col_width) << "||u||_rms " << std::endl; - // for (size_t i = 0; i < snapshots.size(); ++i) { - // double rms = calculate_rms(snapshots[i]); - // output.push_back(rms); - // std::cout << std::scientific; - // std::cout << std::setprecision(16); - // std::cout << std::setw(col_width) << time[i] << std::setw(col_width) << rms << std::endl; - - - // } - + - //write_to_csv(time, output, "data/heat_equation_output.csv"); return 0; } \ No newline at end of file From 1745d10af3976407c66cd6a8961fd71009b4f905 Mon Sep 17 00:00:00 2001 From: TMahlatini Date: Thu, 15 Aug 2024 08:40:33 -0700 Subject: [PATCH 06/10] added callback function to log each step --- DDEINT | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DDEINT b/DDEINT index 6b13c53..229541b 160000 --- a/DDEINT +++ b/DDEINT @@ -1 +1 @@ -Subproject commit 6b13c53e6ad9d92294f854e70254ca9fe922350f +Subproject commit 229541b1580a2e759b1f5f832a1dc220ffbfdb0f From 1fdd1c80cffa2ad626f16efdb54bea51bc299d19 Mon Sep 17 00:00:00 2001 From: TMahlatini Date: Fri, 16 Aug 2024 15:01:50 -0700 Subject: [PATCH 07/10] implemeted run with log_step as the callback --- DDEINT | 2 +- test/2D_Heat_Equation/heat_equation.cpp | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/DDEINT b/DDEINT index 229541b..6daa5d6 160000 --- a/DDEINT +++ b/DDEINT @@ -1 +1 @@ -Subproject commit 229541b1580a2e759b1f5f832a1dc220ffbfdb0f +Subproject commit 6daa5d6adad4c94c685a8cf62c347b8289c54a75 diff --git a/test/2D_Heat_Equation/heat_equation.cpp b/test/2D_Heat_Equation/heat_equation.cpp index 25055f4..93fc455 100644 --- a/test/2D_Heat_Equation/heat_equation.cpp +++ b/test/2D_Heat_Equation/heat_equation.cpp @@ -96,16 +96,6 @@ void initialize_y(size_t nx_loc, size_t ny_loc, double dx, double dy, std::vecto -// should this be a member function of DDEint_dopri_5? -void log_step(double time, const std::vector& state, std::string filename) { - std::ofstream file(filename, std::ios::app); - file << time << ","; - for (double val : state) { - file << val << ","; - } - std::endl(file); -} - double calculate_rms(const std::vector& values) { double sum_of_squares = 0.0; @@ -147,9 +137,9 @@ int main() { double t_start = 0.0; double t_end = 1.0; - //output = test_laplacian.run(20,t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, false); + test_laplacian.run(10 ,t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, false); - test_laplacian.run(20, t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, log_step, false); + //test_laplacian.run(0, t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, nullptr, false); auto end_time = std::chrono::high_resolution_clock::now(); From 668d85568a8cd693bec201109006ac7db2be1c03 Mon Sep 17 00:00:00 2001 From: TMahlatini Date: Fri, 16 Aug 2024 15:07:36 -0700 Subject: [PATCH 08/10] added a dummy_callback function --- test/2D_Heat_Equation/heat_equation.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/2D_Heat_Equation/heat_equation.cpp b/test/2D_Heat_Equation/heat_equation.cpp index 93fc455..75e5856 100644 --- a/test/2D_Heat_Equation/heat_equation.cpp +++ b/test/2D_Heat_Equation/heat_equation.cpp @@ -106,6 +106,9 @@ double calculate_rms(const std::vector& values) { return sqrt(mean); } +void dummy_callback(double time, const std::vector& state) { + std::cout << "Time: " << time << ", RMS: " << calculate_rms(state) << std::endl; +} int main() { @@ -137,9 +140,9 @@ int main() { double t_start = 0.0; double t_end = 1.0; - test_laplacian.run(10 ,t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, false); + //test_laplacian.run(10 ,t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, false); - //test_laplacian.run(0, t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, nullptr, false); + test_laplacian.run(10, t_start, t_end, init_cond_laplacian, 0.005, 0.0005, 50000, 1e-10, 1e-5, *dummy_callback, false); auto end_time = std::chrono::high_resolution_clock::now(); From 4da2d854ac9f5b8f8681b5be8cf9613836f73517 Mon Sep 17 00:00:00 2001 From: TMahlatini Date: Mon, 19 Aug 2024 10:38:52 -0700 Subject: [PATCH 09/10] modified DDEINT --- DDEINT | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DDEINT b/DDEINT index 6daa5d6..9a6961b 160000 --- a/DDEINT +++ b/DDEINT @@ -1 +1 @@ -Subproject commit 6daa5d6adad4c94c685a8cf62c347b8289c54a75 +Subproject commit 9a6961bc25dc067fa60ad95bebc216e7f25e1b28 From 98d67596739ae91621c7b54a4e5eef171245c532 Mon Sep 17 00:00:00 2001 From: TMahlatini Date: Mon, 19 Aug 2024 11:06:25 -0700 Subject: [PATCH 10/10] Refactor DDEINT and implement log_step callback --- DDEINT | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DDEINT b/DDEINT index 9a6961b..b5af956 160000 --- a/DDEINT +++ b/DDEINT @@ -1 +1 @@ -Subproject commit 9a6961bc25dc067fa60ad95bebc216e7f25e1b28 +Subproject commit b5af956575ff117debdcc10606df88221ff2ca5d