diff --git a/DDEINT b/DDEINT index 58487c7..b5af956 160000 --- a/DDEINT +++ b/DDEINT @@ -1 +1 @@ -Subproject commit 58487c76ce516ef76b615e3d7ed813d623757474 +Subproject commit b5af956575ff117debdcc10606df88221ff2ca5d 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..75e5856 100644 --- a/test/2D_Heat_Equation/heat_equation.cpp +++ b/test/2D_Heat_Equation/heat_equation.cpp @@ -95,26 +95,7 @@ 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; - } - - - - file << std::endl; - - file.close(); -} double calculate_rms(const std::vector& values) { double sum_of_squares = 0.0; @@ -125,12 +106,10 @@ 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 +void dummy_callback(double time, const std::vector& state) { + std::cout << "Time: " << time << ", RMS: " << calculate_rms(state) << std::endl; +} -//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) @@ -153,59 +132,26 @@ int main() { // Initialize the state initialize_y(nx_loc, ny_loc, dx, dy, init_cond_laplacian); - std::vector output, time; - std::vector> snapshots; - snapshots.reserve(20); + std::vector> output; + 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 - - 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, 0.0005, 50000, 1e-10, 1e-5, false); - snapshots.push_back(output); - time.push_back(test_laplacian.get_t()); - } - } + 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, *dummy_callback, 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